* @version : HUOSDK 8.0 */ namespace huo\logic\data; use huo\model\common\CommonModel; use huo\model\data\DayAgentGameCountryModel; use huo\model\data\DayAgentGameCountryVipModel; use huo\model\game\GameModel; use huo\logic\user\UserLogic; class CpDataLogic extends CommonModel { protected $_id; protected $_agent_id; protected $_app_id; protected $_cp_id; public function __construct($data = []) { parent::__construct($data); List($this->_id, $this->_cp_id, $this->_agent_id, $this->_app_id) = (new UserLogic())->getRoleLevelID(session('ADMIN_ID')); } /** * cp对账单 * @param null $date * @param null $cp_id * * @return array * @throws \think\exception\DbException */ public function getBalanceIndex($yearMonth = null, $cp_id = null){ $_model = new DayAgentGameCountryVipModel(); $_fields = <<field($_fields); if($yearMonth){ $_model = $_model->where('left(date, 7) = "'.$yearMonth.'"' ); } if($cp_id){ $_game_model = new GameModel(); $_app_id = $_game_model->where('cp_id', $cp_id)->column('id'); $_model = $_model->whereIn('app_id', $_app_id); } $_model = $_model->whereIn('app_id', $this->_app_id) ->whereIn('agent_id', $this->_agent_id) ->with('game') ->group('app_id') ->paginate(10); $_page = $_model->render(); $_data = $_model->toArray()['data']; $this->getBalanceScope($_data); $this->handleBalanceData($_data); return [$_data, $_page]; } /** * 封装 * @param $data */ private function handleBalanceData(&$data){ if(count($data)){ foreach ($data as &$val){ /*游戏名*/ $val['game_name'] = null; /*下载占比*/ $val['vip_down_cnt_percent'] = number_format($val['vip_down_cnt'] / $val['vip_day_cnt'], 2) * 100 .'%'; /*vip订阅数*/ $val['vip_sub_cnt'] = $val['vip_user_cnt'] + $val['vip_free_cnt']; if(!empty($val['game'])){ $val['game_name'] = $val['game']['name']; unset($val['game']); } } } } /** * cp附加数据 * @param $data * * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\ModelNotFoundException * @throws \think\exception\DbException */ private function getBalanceScope(&$data){ if(!empty($data)){ $_model = new DayAgentGameCountryModel(); $_fields = <<field($_fields); $_model = $_model->where('left(date, 7) = "'.substr($data[0]['date'], 0, 7).'"') ->whereIn('app_id', array_column($data, 'app_id')) ->group('app_id') ->select() ->toArray(); foreach ($data as &$val){ /*活跃玩家数*/ $val['scope_user_cnt'] = 0; if(count($_model)){ foreach ($_model as $vale){ if($vale['date'] == $val['date'] && $vale['app_id'] == $val['app_id']){ $val['scope_user_cnt'] = $vale['user_cnt']; break; } } } } } } }