* @version : HUOSDK 8.0 */ namespace huo\logic\data; use huo\logic\user\UserLogic; use huo\model\common\CommonModel; use huo\model\data\DayAgentModel; use huo\model\data\DayGameModel; use huo\model\game\GameAgentModel; use huo\model\game\GameModel; use huo\model\member\MemberModel; use huo\model\user\UserModel; class IndexDataLogic extends CommonModel { public function getRechargeData($agentIDs = array(), $gameIDs = array()){ $_collect = $this->scopesRecharge($agentIDs, $gameIDs); $_previous = $this->scopesRecharge($agentIDs, $gameIDs,'date = "'. date('Y-m-d', strtotime('-1 day')).'"'); $_now = $this->scopesRecharge($agentIDs, $gameIDs,'date = "'. date('Y-m-d').'"'); $this->handle($_collect, $_previous, $_now); return [$_collect, $_previous, $_now]; } public function getPlatformData($agentIDs = array(), $gameIDs = array()){ $_collect = $this->scopesPlatform($agentIDs); $_time = $this->getLastDate(); $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1]; $_previous = $this->scopesPlatform($agentIDs, $gameIDs, $_where); $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1]; $_now = $this->scopesPlatform($agentIDs, $gameIDs, $_where); $this->handle($_collect, $_previous, $_now); return [$_collect, $_previous, $_now]; } public function getExpenseUserData($agentIDs = array(), $gameIDs = array()){ $_collect = $this->scopesExpense($agentIDs); $_previous = $this->scopesExpense($agentIDs, $gameIDs, 'date = "'. date('Y-m-d', strtotime('-1 day')).'"'); $_now = $this->scopesExpense($agentIDs, $gameIDs, 'date = "'. date('Y-m-d').'"'); $this->handle($_collect, $_previous, $_now); return [$_collect, $_previous, $_now]; } public function getGameAgentData($agentIDs = array()){ $_collect = $_previous = $_now = null; $_model = new GameAgentModel(); $_app_ids = $_model->whereIn('agent_id', $agentIDs)->column('app_id'); if(!empty($_app_ids)){ $_time = $this->getLastDate(); $_collect = $this->scopesGameAgentData($_app_ids); $_where = 'run_time >= '.$_time[1][0].' and run_time <= '.$_time[1][1]; $_previous = $this->scopesGameAgentData($_app_ids, $_where); $_where = 'run_time >= '.$_time[0][0].' and run_time <= '.$_time[0][1]; $_now = $this->scopesGameAgentData($_app_ids, $_where); $this->handle($_collect, $_previous, $_now); } $this->handle($_collect, $_previous, $_now); return [$_collect, $_previous, $_now]; } public function getGameCpData($adminID = array()){ $_collect = $_previous = $_now = null; $_model = new UserModel(); $_model = $_model->whereIn('id', $adminID)->find(); if(!empty($_model)){ $_time = $this->getLastDate(); $_collect = $this->scopesGameCp($_model['cp_id']); $_where = 'run_time >= '.$_time[1][0].' and run_time <= '.$_time[1][1]; $_previous = $this->scopesGameCp($_model['cp_id'], $_where); $_where = 'run_time >= '.$_time[0][0].' and run_time <= '.$_time[0][1]; $_now = $this->scopesGameCp($_model['cp_id'], $_where); } $this->handle($_collect, $_previous, $_now); return [$_collect, $_previous, $_now]; } public function getChannelAgentData($agentIDs = array()){ $_time = $this->getLastDate(); $_collect = $this->scopesChannelAgent($agentIDs); $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1]; $_previous = $this->scopesChannelAgent($agentIDs, $_where); $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1]; $_now = $this->scopesChannelAgent($agentIDs, $_where); $this->handle($_collect, $_previous, $_now); return [$_collect, $_previous, $_now]; } public function getChannelGameData($adminID = 0){ $_collect = $_previous = $_now = null; $_model = new UserModel(); $_model = $_model->where('id', $adminID)->find(); if(!empty($_model)){ $_time = $this->getLastDate(); $_collect = $this->scopesChannelGame($_model['cp_id']); $_where = 'create_time >= '.$_time[1][0].' and create_time <= '.$_time[1][1]; $_previous = $this->scopesChannelGame($_model['cp_id'], $_where); $_where = 'create_time >= '.$_time[0][0].' and create_time <= '.$_time[0][1]; $_now = $this->scopesChannelGame($_model['cp_id'], $_where); } $this->handle($_collect, $_previous, $_now); return [$_collect, $_previous, $_now]; } private function scopesChannelGame($cpID = 0, $where = null){ $_model = new GameModel(); $_app_ids = $_model->where('cp_id', $cpID)->column('id'); if(!empty($_app_ids)){ $_model = new MemberModel(); $_model = $_model->field('count(distinct(app_id)) count')->whereIn('app_id', $_app_ids); if(!empty($where)){ $_model = $_model->where($where); } return $_model->find(); } return null; } private function scopesChannelAgent($agentIDs = array(), $where = null){ $_model = new GameAgentModel(); $_model = $_model->field('count(distinct(agent_id)) count') ->whereIn('agent_id', $agentIDs); if(!empty($where)){ $_model = $_model->where($where); } $_model = $_model->find(); return $_model; } private function scopesGameAgentData($appIDs = array(), $where = null){ $_model = new GameModel(); $_model = $_model->field('count(distinct(id)) count') ->where('run_time', '>', 0) ->whereIn('id', $appIDs); if(!empty($where)){ $_model = $_model->where($where); } return $_model->find(); } private function scopesGameCp($cpID = 0, $where = null){ $_model = new GameModel(); $_model = $_model->field('count(distinct(id)) count') ->where('run_time', '>', 0) ->where('cp_id', $cpID); if(!empty($where)){ $_model = $_model->where($where); } return $_model->find(); } private function scopesExpense($agentIDs = array(), $gameIDs = array(), $where = null){ if(empty($agentIDs) && empty($agentIDs)){ return []; } if(!empty($agentIDs)){ $_model = new DayAgentModel(); $_model = $_model->field('id, sum(pay_user_cnt) pay_user_cnt')->whereIn('agent_id', $agentIDs); } if(!empty($gameIDs)){ $_model = new DayGameModel(); $_model = $_model->field('id, date, sum(pay_user_cnt) pay_user_cnt')->whereIn('app_id', $gameIDs); } if(!empty($where)){ $_model = $_model->where($where); } return $_model->find(); } private function scopesPlatform($agentIDs = array(), $gameIDs = array(), $where = null){ $_model = new MemberModel(); $_model = $_model->field('sum(id) count'); if(!empty($agentIDs)){ $_model = $_model->whereIn('agent_id', $agentIDs); } if(!empty($gameIDs)){ $_model = $_model->whereIn('app_id', $gameIDs); } if(!empty($where)){ $_model = $_model->where($where); } $_model = $_model->find(); return $_model; } private function scopesRecharge($agentIDs = array(), $gameIDs = array(), $where = null){ if(empty($agentIDs) && empty($gameIDs)) return []; if(!empty($agentIDs)) $_model = new DayAgentModel(); if(!empty($gameIDs)) $_model = new DayGameModel(); $_model = $_model->field("id, date, sum(sum_money) sum_money"); if(!empty($agentIDs)){ $_model = $_model->whereIn('agent_id', $agentIDs); } if(!empty($gameIDs)){ $_model = $_model->whereIn('app_id', $gameIDs); } if(!empty($where)){ $_model = $_model->where($where); } $_model = $_model->find(); return $_model; } private function getLastDate(){ return [ [ strtotime(date('Y-m-d').' 00:00:00'), strtotime(date('Y-m-d').' 23:59:59') ], [ strtotime(date('Y-m-d', strtotime('-1 day')).' 00:00:00'), strtotime(date('Y-m-d', strtotime('-1 day')).' 23:59:59') ] ]; } private function handle(&$collect, &$previous, &$now){ if(empty($collect['sum_money'])){ $collect['sum_money'] = 0; } if(empty($collect['count'])){ $collect['count'] = 0; } if(empty($collect['pay_user_cnt'])){ $collect['pay_user_cnt'] = 0; } if(empty($previous['count'])){ $previous['count'] = 0; } if(empty($previous['pay_user_cnt'])){ $previous['pay_user_cnt'] = 0; } if(empty($previous['sum_money'])){ $previous['sum_money'] = 0; } if(empty($now['sum_money'])){ $now['sum_money'] = 0; } if(empty($now['pay_user_cnt'])){ $now['pay_user_cnt'] = 0; } if(empty($now['count'])){ $now['count'] = 0; } } // TODO: liguanglong 2017/12/28 public function getSwiftList(){ $_list = [ [ 'title' => lang('player list'), 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc2f59d134.png', 'uri' => url('admin/member.member/index')], [ 'title' => lang('order list'), 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc3c0bdf3c.png', 'uri' => '' ], [ 'title' => lang('platform currency'), 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc315a481d.png', 'uri' => '' ], [ 'title' => lang('game currency'), 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc30952f4e.png', 'uri' => '' ], [ 'title' => lang('game list'), 'img' => 'http://demo.vlcms.com/Public/Admin/images/icon146.png', 'uri' => url('admin/game.game/index') ], [ 'title' => lang('channel list'), 'img' => 'http://demo.vlcms.com/Public/Admin/images/icon185.png', 'uri' => '' ], [ 'title' => lang('open service management'), 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc44c40905.png', 'uri' => '' ], [ 'title' => lang('news list'), 'img' => 'http://demo.vlcms.com/Public/Admin/images/icon2.png', 'uri' => url('admin/news.news/index') ], [ 'title' => lang('advertising effect'), 'img' => 'https://demo.vlcms.com/Uploads/Picture/2017-01-17/587dc30177ed3.png', 'uri' => '' ], ]; return $_list; } // TODO: liguanglong 2017/12/28 public function getWaitingList(){ $_list = [ [ 'title' => lang('subcontracting audit'), 'content' => '...', 'uri' => '' ], [ 'title' => lang('channel management'), 'content' => '...', 'uri' => '' ], [ 'title' => lang('finance review'), 'content' => '...', 'uri' => '' ], [ 'title' => lang('game recharge'), 'content' => '...', 'uri' => '' ], ]; return $_list; } // TODO: liguanglong 2017/12/28 public function getTipList(){ $_list = [ [ 'title' => lang('promotion games'), 'content' => '...', 'uri' => '' ], [ 'title' => lang('rebate setting'), 'content' => '...', 'uri' => '' ], [ 'title' => lang('gift list'), 'content' => '...', 'uri' => 'http://www.huos.com/admin/gift.gift/index.html' ], [ 'title' => lang('channel list'), 'content' => '...', 'uri' => '' ], ]; return $_list; } }