IndexDataLogic.php 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. <?php
  2. /**
  3. * DayPayLogic.php UTF-8
  4. *
  5. *
  6. * @date : 2017/12/18 11:42
  7. *
  8. * @license 这不是一个自由软件,未经授权不许任何使用和传播。
  9. * @author : liguanglong <lgl@huosdk.com>
  10. * @version : HUOSDK 8.0
  11. */
  12. namespace huo\logic\data;
  13. use huo\logic\user\UserLogic;
  14. use huo\model\common\CommonModel;
  15. use huo\model\data\DayAgentModel;
  16. use huo\model\data\DayGameModel;
  17. use huo\model\game\GameAgentModel;
  18. use huo\model\game\GameModel;
  19. use huo\model\member\MemberModel;
  20. use huo\model\user\UserModel;
  21. class IndexDataLogic extends CommonModel {
  22. public function getRechargeData($agentIDs = array(), $gameIDs = array()){
  23. $_collect = $this->scopesRecharge($agentIDs, $gameIDs);
  24. $_previous = $this->scopesRecharge($agentIDs, $gameIDs,'date = "'. date('Y-m-d', strtotime('-1 day')).'"');
  25. $_now = $this->scopesRecharge($agentIDs, $gameIDs,'date = "'. date('Y-m-d').'"');
  26. $this->handle($_collect, $_previous, $_now);
  27. return [$_collect, $_previous, $_now];
  28. }
  29. public function getPlatformData($agentIDs = array(), $gameIDs = array()){
  30. $_collect = $this->scopesPlatform($agentIDs);
  31. $_time = $this->getLastDate();
  32. $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1];
  33. $_previous = $this->scopesPlatform($agentIDs, $gameIDs, $_where);
  34. $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1];
  35. $_now = $this->scopesPlatform($agentIDs, $gameIDs, $_where);
  36. $this->handle($_collect, $_previous, $_now);
  37. return [$_collect, $_previous, $_now];
  38. }
  39. public function getExpenseUserData($agentIDs = array(), $gameIDs = array()){
  40. $_collect = $this->scopesExpense($agentIDs);
  41. $_previous = $this->scopesExpense($agentIDs, $gameIDs, 'date = "'. date('Y-m-d', strtotime('-1 day')).'"');
  42. $_now = $this->scopesExpense($agentIDs, $gameIDs, 'date = "'. date('Y-m-d').'"');
  43. $this->handle($_collect, $_previous, $_now);
  44. return [$_collect, $_previous, $_now];
  45. }
  46. public function getGameAgentData($agentIDs = array()){
  47. $_collect = $_previous = $_now = null;
  48. $_model = new GameAgentModel();
  49. $_app_ids = $_model->whereIn('agent_id', $agentIDs)->column('app_id');
  50. if(!empty($_app_ids)){
  51. $_time = $this->getLastDate();
  52. $_collect = $this->scopesGameAgentData($_app_ids);
  53. $_where = 'run_time >= '.$_time[1][0].' and run_time <= '.$_time[1][1];
  54. $_previous = $this->scopesGameAgentData($_app_ids, $_where);
  55. $_where = 'run_time >= '.$_time[0][0].' and run_time <= '.$_time[0][1];
  56. $_now = $this->scopesGameAgentData($_app_ids, $_where);
  57. $this->handle($_collect, $_previous, $_now);
  58. }
  59. $this->handle($_collect, $_previous, $_now);
  60. return [$_collect, $_previous, $_now];
  61. }
  62. public function getGameCpData($adminID = array()){
  63. $_collect = $_previous = $_now = null;
  64. $_model = new UserModel();
  65. $_model = $_model->whereIn('id', $adminID)->find();
  66. if(!empty($_model)){
  67. $_time = $this->getLastDate();
  68. $_collect = $this->scopesGameCp($_model['cp_id']);
  69. $_where = 'run_time >= '.$_time[1][0].' and run_time <= '.$_time[1][1];
  70. $_previous = $this->scopesGameCp($_model['cp_id'], $_where);
  71. $_where = 'run_time >= '.$_time[0][0].' and run_time <= '.$_time[0][1];
  72. $_now = $this->scopesGameCp($_model['cp_id'], $_where);
  73. }
  74. $this->handle($_collect, $_previous, $_now);
  75. return [$_collect, $_previous, $_now];
  76. }
  77. public function getChannelAgentData($agentIDs = array()){
  78. $_time = $this->getLastDate();
  79. $_collect = $this->scopesChannelAgent($agentIDs);
  80. $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1];
  81. $_previous = $this->scopesChannelAgent($agentIDs, $_where);
  82. $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1];
  83. $_now = $this->scopesChannelAgent($agentIDs, $_where);
  84. $this->handle($_collect, $_previous, $_now);
  85. return [$_collect, $_previous, $_now];
  86. }
  87. public function getChannelGameData($adminID = 0){
  88. $_collect = $_previous = $_now = null;
  89. $_model = new UserModel();
  90. $_model = $_model->where('id', $adminID)->find();
  91. if(!empty($_model)){
  92. $_time = $this->getLastDate();
  93. $_collect = $this->scopesChannelGame($_model['cp_id']);
  94. $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1];
  95. $_previous = $this->scopesChannelGame($_model['cp_id'], $_where);
  96. $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1];
  97. $_now = $this->scopesChannelGame($_model['cp_id'], $_where);
  98. }
  99. $this->handle($_collect, $_previous, $_now);
  100. return [$_collect, $_previous, $_now];
  101. }
  102. private function scopesChannelGame($cpID = 0, $where = null){
  103. $_model = new GameModel();
  104. $_app_ids = $_model->where('cp_id', $cpID)->column('id');
  105. if(!empty($_app_ids)){
  106. $_model = new MemberModel();
  107. $_model = $_model->field('count(distinct(app_id)) count')->whereIn('app_id', $_app_ids);
  108. if(!empty($where)){
  109. $_model = $_model->where($where);
  110. }
  111. return $_model->find();
  112. }
  113. return null;
  114. }
  115. private function scopesChannelAgent($agentIDs = array(), $where = null){
  116. $_model = new GameAgentModel();
  117. $_model = $_model->field('count(distinct(agent_id)) count')
  118. ->whereIn('agent_id', $agentIDs);
  119. if(!empty($where)){
  120. $_model = $_model->where($where);
  121. }
  122. $_model = $_model->find();
  123. return $_model;
  124. }
  125. private function scopesGameAgentData($appIDs = array(), $where = null){
  126. $_model = new GameModel();
  127. $_model = $_model->field('count(distinct(id)) count')
  128. ->where('run_time', '>', 0)
  129. ->whereIn('id', $appIDs);
  130. if(!empty($where)){
  131. $_model = $_model->where($where);
  132. }
  133. return $_model->find();
  134. }
  135. private function scopesGameCp($cpID = 0, $where = null){
  136. $_model = new GameModel();
  137. $_model = $_model->field('count(distinct(id)) count')
  138. ->where('run_time', '>', 0)
  139. ->where('cp_id', $cpID);
  140. if(!empty($where)){
  141. $_model = $_model->where($where);
  142. }
  143. return $_model->find();
  144. }
  145. private function scopesExpense($agentIDs = array(), $gameIDs = array(), $where = null){
  146. if(empty($agentIDs) && empty($agentIDs)){
  147. return [];
  148. }
  149. if(!empty($agentIDs)){
  150. $_model = new DayAgentModel();
  151. $_model = $_model->field('id, sum(pay_user_cnt) pay_user_cnt')->whereIn('agent_id', $agentIDs);
  152. }
  153. if(!empty($gameIDs)){
  154. $_model = new DayGameModel();
  155. $_model = $_model->field('id, date, sum(pay_user_cnt) pay_user_cnt')->whereIn('app_id', $gameIDs);
  156. }
  157. if(!empty($where)){
  158. $_model = $_model->where($where);
  159. }
  160. return $_model->find();
  161. }
  162. private function scopesPlatform($agentIDs = array(), $gameIDs = array(), $where = null){
  163. $_model = new MemberModel();
  164. $_model = $_model->field('sum(id) count');
  165. if(!empty($agentIDs)){
  166. $_model = $_model->whereIn('agent_id', $agentIDs);
  167. }
  168. if(!empty($gameIDs)){
  169. $_model = $_model->whereIn('app_id', $gameIDs);
  170. }
  171. if(!empty($where)){
  172. $_model = $_model->where($where);
  173. }
  174. $_model = $_model->find();
  175. return $_model;
  176. }
  177. private function scopesRecharge($agentIDs = array(), $gameIDs = array(), $where = null){
  178. if(empty($agentIDs) && empty($gameIDs)) return [];
  179. if(!empty($agentIDs)) $_model = new DayAgentModel();
  180. if(!empty($gameIDs)) $_model = new DayGameModel();
  181. $_model = $_model->field("id, date, sum(sum_money) sum_money");
  182. if(!empty($agentIDs)){
  183. $_model = $_model->whereIn('agent_id', $agentIDs);
  184. }
  185. if(!empty($gameIDs)){
  186. $_model = $_model->whereIn('app_id', $gameIDs);
  187. }
  188. if(!empty($where)){
  189. $_model = $_model->where($where);
  190. }
  191. $_model = $_model->find();
  192. return $_model;
  193. }
  194. private function getLastDate(){
  195. return [
  196. [
  197. strtotime(date('Y-m-d').' 00:00:00'),
  198. strtotime(date('Y-m-d').' 23:59:59')
  199. ],
  200. [
  201. strtotime(date('Y-m-d', strtotime('-1 day')).' 00:00:00'),
  202. strtotime(date('Y-m-d', strtotime('-1 day')).' 23:59:59')
  203. ]
  204. ];
  205. }
  206. private function handle(&$collect, &$previous, &$now){
  207. if(empty($collect['sum_money'])){
  208. $collect['sum_money'] = 0;
  209. }
  210. if(empty($collect['count'])){
  211. $collect['count'] = 0;
  212. }
  213. if(empty($collect['pay_user_cnt'])){
  214. $collect['pay_user_cnt'] = 0;
  215. }
  216. if(empty($previous['count'])){
  217. $previous['count'] = 0;
  218. }
  219. if(empty($previous['pay_user_cnt'])){
  220. $previous['pay_user_cnt'] = 0;
  221. }
  222. if(empty($previous['sum_money'])){
  223. $previous['sum_money'] = 0;
  224. }
  225. if(empty($now['sum_money'])){
  226. $now['sum_money'] = 0;
  227. }
  228. if(empty($now['pay_user_cnt'])){
  229. $now['pay_user_cnt'] = 0;
  230. }
  231. if(empty($now['count'])){
  232. $now['count'] = 0;
  233. }
  234. }
  235. // TODO: liguanglong 2017/12/28
  236. public function getSwiftList(){
  237. $_list = [
  238. [
  239. 'title' => lang('player list'),
  240. 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc2f59d134.png',
  241. 'uri' => url('admin/member.member/index')],
  242. [
  243. 'title' => lang('order list'),
  244. 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc3c0bdf3c.png',
  245. 'uri' => ''
  246. ],
  247. [
  248. 'title' => lang('platform currency'),
  249. 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc315a481d.png',
  250. 'uri' => ''
  251. ],
  252. [
  253. 'title' => lang('game currency'),
  254. 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc30952f4e.png',
  255. 'uri' => ''
  256. ],
  257. [
  258. 'title' => lang('game list'),
  259. 'img' => 'http://demo.vlcms.com/Public/Admin/images/icon146.png',
  260. 'uri' => url('admin/game.game/index')
  261. ],
  262. [
  263. 'title' => lang('channel list'),
  264. 'img' => 'http://demo.vlcms.com/Public/Admin/images/icon185.png',
  265. 'uri' => ''
  266. ],
  267. [
  268. 'title' => lang('open service management'),
  269. 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc44c40905.png',
  270. 'uri' => ''
  271. ],
  272. [
  273. 'title' => lang('news list'),
  274. 'img' => 'http://demo.vlcms.com/Public/Admin/images/icon2.png',
  275. 'uri' => url('admin/news.news/index')
  276. ],
  277. [
  278. 'title' => lang('advertising effect'),
  279. 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc30177ed3.png',
  280. 'uri' => ''
  281. ],
  282. ];
  283. return $_list;
  284. }
  285. // TODO: liguanglong 2017/12/28
  286. public function getWaitingList(){
  287. $_list = [
  288. [
  289. 'title' => lang('subcontracting audit'),
  290. 'content' => '...',
  291. 'uri' => ''
  292. ],
  293. [
  294. 'title' => lang('channel management'),
  295. 'content' => '...',
  296. 'uri' => ''
  297. ],
  298. [
  299. 'title' => lang('finance review'),
  300. 'content' => '...',
  301. 'uri' => ''
  302. ],
  303. [
  304. 'title' => lang('game recharge'),
  305. 'content' => '...',
  306. 'uri' => ''
  307. ],
  308. ];
  309. return $_list;
  310. }
  311. // TODO: liguanglong 2017/12/28
  312. public function getTipList(){
  313. $_list = [
  314. [
  315. 'title' => lang('promotion games'),
  316. 'content' => '...',
  317. 'uri' => ''
  318. ],
  319. [
  320. 'title' => lang('rebate setting'),
  321. 'content' => '...',
  322. 'uri' => ''
  323. ],
  324. [
  325. 'title' => lang('gift list'),
  326. 'content' => '...',
  327. 'uri' => 'http://www.huos.com/admin/gift.gift/index.html'
  328. ],
  329. [
  330. 'title' => lang('channel list'),
  331. 'content' => '...',
  332. 'uri' => ''
  333. ],
  334. ];
  335. return $_list;
  336. }
  337. }