123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321 |
- <?php
- /**
- * PayDataController.php UTF-8
- *
- *
- * @date : 2017/12/18 11:16
- *
- * @license 这不是一个自由软件,未经授权不许任何使用和传播。
- * @author : liguanglong <lgl@huosdk.com>
- * @version : HUOSDK 8.0
- */
- namespace admin\admin\controller\data;
- use cmf\controller\AdminBaseController;
- use huo\controller\agent\AgentGame;
- use huo\logic\agent\AgentLogic;
- use huo\logic\data\GenDataLogic;
- use huo\logic\data\RemainDataLogic;
- use huolib\constant\CommonConst;
- use huolib\constant\GameConst;
- use huolib\status\CommonStatus;
- use huolib\tool\Export;
- use think\Lang;
- use think\Request;
- class RemainController extends AdminbaseController {
- protected $pub_where = [];
- protected $data_games = [];
- protected $data_agents = [];
- function _initialize() {
- parent::_initialize();
- Lang::load(APP_PATH.'admin/lang'.DS.$this->lang.DS.'remain'.EXT);
- }
- /**
- * 留存数据导出
- *
- * @param $param
- *
- * @return mixed
- */
- public function exportIndex($param) {
- $_p = 1;
- $_offset = Export::MAX_ROWS;
- Request::instance()->get(['page' => 1]);
- Request::instance()->get(['list_rows' => $_offset]);
- if (!empty($param['app_id']) && !empty($param['agent_id'])) {
- $_data = (new RemainDataLogic())->gameAgent($param)->toArray();
- } else if (empty($param['app_id']) && !empty($param['agent_id'])) {
- $_data = (new RemainDataLogic())->agent($param)->toArray();
- } else if (!empty($param['app_id']) && empty($param['agent_id'])) {
- $_data = (new RemainDataLogic())->game($param)->toArray();
- } else if (!empty($_param['cp_app_id'])) {
- $_data = (new RemainDataLogic())->cpgame($_param)->toArray();
- } else {
- $_data = (new RemainDataLogic())->main($param)->toArray();
- }
- $_total_cnt = $_data['total'];
- if ($_total_cnt <= 0) {
- $this->adminError(CommonStatus::getMsg(CommonStatus::CNT_IS_ZERO));
- }
- $_for_cnt = ceil($_total_cnt / $_offset);
- $_file_name_arr = [];
- while ($_p <= $_for_cnt) {
- $_head = ['时间'];
- if (!empty($param['app_id'])) {
- array_push($_head, '游戏');
- }
- if (!empty($param['agent_id'])) {
- array_push($_head, '渠道');
- }
- $_head2 = [
- '注册用户',
- '2日',
- '3日',
- '4日',
- '5日',
- '6日',
- '7日',
- '15日',
- '30日',
- ];
- $_head = array_merge($_head, $_head2);
- $_export_datas = [];
- foreach ($_data['data'] as $_key => $_val) {
- if (!empty($_val['reg_cnt'])) {
- $_day2 = '('.round($_val['day2'] / $_val['reg_cnt'], 4) * 100 .'%)';
- $_day3 = '('.round($_val['day3'] / $_val['reg_cnt'], 4) * 100 .'%)';
- $_day4 = '('.round($_val['day4'] / $_val['reg_cnt'], 4) * 100 .'%)';
- $_day5 = '('.round($_val['day5'] / $_val['reg_cnt'], 4) * 100 .'%)';
- $_day6 = '('.round($_val['day6'] / $_val['reg_cnt'], 4) * 100 .'%)';
- $_day7 = '('.round($_val['day7'] / $_val['reg_cnt'], 4) * 100 .'%)';
- $_day15 = '('.round($_val['day15'] / $_val['reg_cnt'], 4) * 100 .'%)';
- $_day30 = '('.round($_val['day30'] / $_val['reg_cnt'], 4) * 100 .'%)';
- } else {
- $_day2 = '(0%)';
- $_day3 = '(0%)';
- $_day4 = '(0%)';
- $_day5 = '(0%)';
- $_day6 = '(0%)';
- $_day7 = '(0%)';
- $_day15 = '(0%)';
- $_day30 = '(0%)';
- }
- $_export_data['date'] = $_val['date'];
- if (!empty($param['app_id'])) {
- $_export_data['game'] = $this->data_games[$_val['app_id']];
- }
- if (!empty($_GET['agent_id'])) {
- if (!empty($_GET['data_summary']) && 2 == $_GET['data_summary']) {
- $_export_data['agent'] = $this->data_agents[$_val['agent_id']];
- } else {
- $_export_data['agent'] = $this->data_agents[$_val['agent_id']];
- }
- }
- $_export_data['reg_cnt'] = $_val['reg_cnt'];
- $_export_data['day2'] = $_val['day2'].$_day2;
- $_export_data['day3'] = $_val['day3'].$_day3;
- $_export_data['day4'] = $_val['day4'].$_day4;
- $_export_data['day5'] = $_val['day5'].$_day5;
- $_export_data['day6'] = $_val['day6'].$_day6;
- $_export_data['day7'] = $_val['day7'].$_day7;
- $_export_data['day15'] = $_val['day15'].$_day15;
- $_export_data['day30'] = $_val['day30'].$_day30;
- $_export_datas[] = $_export_data;
- }
- if (1 == $_for_cnt) {
- Export::exportCsv($_head, $_export_datas, $path = $this->admin_id, '留存分析', '.csv', true);
- break;
- } else {
- $_file_name = '留存分析'.$_p;
- Export::exportCsv($_head, $_export_datas, $path = $this->admin_id, $_file_name);
- $_file_name_arr[] = $_file_name.'.csv';
- $_p++;
- if ($_p > 1) {
- $_data = null;
- Request::instance()->get(['page' => $_p]);
- if (!empty($param['app_id']) && !empty($param['agent_id'])) {
- $_data = (new RemainDataLogic())->gameAgent($param)->toArray();
- } else if (empty($param['app_id']) && !empty($param['agent_id'])) {
- $_data = (new RemainDataLogic())->agent($param)->toArray();
- } else if (!empty($param['app_id']) && empty($param['agent_id'])) {
- $_data = (new RemainDataLogic())->game($param)->toArray();
- } else if (!empty($_param['cp_app_id'])) {
- $_data = (new RemainDataLogic())->cpgame($_param)->toArray();
- } else {
- $_data = (new RemainDataLogic())->main($param)->toArray();
- }
- }
- }
- }
- Export::exportZip($_file_name_arr, $path = $this->admin_id, '留存分析');
- }
- /**
- * 留存数据
- * admin/data.remain/index
- */
- public function index() {
- $_param = $this->_getSearchParam();
- if ('1' == $this->request->param('export/d', 0)) {
- return $this->exportIndex($_param);
- }
- if (!empty($_param['app_id']) && !empty($_param['agent_id'])) {
- return $this->gameAgent($_param);
- } else if (empty($_param['app_id']) && !empty($_param['agent_id'])) {
- return $this->agent($_param);
- } else if (!empty($_param['app_id']) && empty($_param['agent_id'])) {
- return $this->game($_param);
- } else if (!empty($_param['cp_app_id'])) {
- return $this->cpgame($_param);
- }
- return $this->main($_param);
- }
- public function update() {
- /* 执行定时任务更新当天数据 */
- $_date = date('Y-m-d');
- (new GenDataLogic())->archiveDaily($_date);
- return $this->index();
- }
- /**
- * 总体数据
- *
- * @param $_param
- *
- * @return mixed
- */
- public function main($_param) {
- list($_data, $sum) = (new RemainDataLogic())->main($_param, '-date', true);
- $this->assign('sum', $sum);
- $this->assign('items', $_data);
- $this->assign('page', $_data->render());
- return $this->fetch('data/remain/index');
- }
- /**
- * 游戏渠道
- *
- * @param $_param
- *
- * @return mixed
- */
- public function gameAgent($_param) {
- list($_data, $sum) = (new RemainDataLogic())->gameAgent($_param, '-date', true);
- $this->assign('sum', $sum);
- $this->assign('items', $_data);
- $this->assign('page', $_data->render());
- return $this->fetch('data/remain/index');
- }
- /**
- * 游戏
- *
- * @param $_param
- *
- * @return mixed
- */
- public function game($_param) {
- list($_data, $sum) = (new RemainDataLogic())->game($_param, '-date', true);
- $this->assign('sum', $sum);
- $this->assign('items', $_data);
- $this->assign('page', $_data->render());
- return $this->fetch('data/remain/index');
- }
- /**
- * cp游戏
- *
- * @param $_param
- *
- * @return mixed
- */
- public function cpgame($_param) {
- $_data = (new RemainDataLogic())->cpgame($_param);
- $this->assign('items', $_data);
- $this->assign('page', $_data->render());
- return $this->fetch('data/remain/index');
- }
- /**
- * 渠道
- *
- * @param $_param
- *
- * @return mixed
- */
- public function agent($_param) {
- list($_data, $sum) = (new RemainDataLogic())->agent($_param, '-date', true);
- $this->assign('sum', $sum);
- $this->assign('items', $_data);
- $this->assign('page', $_data->render());
- return $this->fetch('data/remain/index');
- }
- /***
- * 获取筛选数据
- */
- public function _getSearchParam() {
- $_rq_data = $this->request->param();
- $this->assign('rq_data', $_rq_data);
- if (!input('?get.page')) {
- Request::instance()->get(['page' => 1]);
- }
- if (!input('?get.list_rows')) {
- Request::instance()->get(['list_rows' => 10]);
- }
- $_param['app_id'] = $this->request->param('app_id/d', 0);
- $_param['data_summary'] = $this->request->param('data_summary/d', 0);
- list($_param['start_time'], $_param['end_time']) = $this->_time();
- $_param['agent_id'] = $this->request->param('agent_id/d', CommonConst::CONST_ZERO);
- $this->data_agents = $this->_agents($_param['agent_id']);
- $_include_agent = $this->request->param('include_agent/d', 2);
- $this->includeAgent($_include_agent);
- /* 游戏筛选 */
- $_game_where = [];
- if (!empty($this->map['agent_id'])) {
- if (empty($_param['agent_id'])) {
- $_param['agent_id'] = $this->map['agent_id'];
- }
- /* 获取渠道游戏 */
- $_app_ids = (new AgentGame())->getGameIds($this->map);
- $_game_where['id'] = 0;
- if (!empty($_app_ids)) {
- $_game_where['id'] = ['in', $_app_ids];
- }
- }
- if (!empty($_param['agent_id']) && empty($this->map['agent_id']) && -1 != $_param['agent_id']
- && 2 == $_include_agent) {
- $_agent_ids = (new AgentLogic())->getAgentIds($_param['agent_id'], true);
- if (!empty($_agent_ids)) {
- $_param['agent_id'] = ['in', $_agent_ids];
- }
- }
- /* cp游戏 */
- if (!empty($this->cp_app_id)) {
- $_game_where['id'] = ['in', $this->cp_app_id];
- $_param['cp_app_id'] = $this->cp_app_id;
- }
- $this->data_games = $this->_games(
- $_param['app_id'], GameConst::GAME_STATUS_ON, CommonConst::CONST_NOT_DELETE,
- GameConst::GAME_IS_SDK, 0, false, true, $_game_where
- );
- $_percent = $this->request->param('percent', null);
- if (is_null($_percent)) {
- $_GET['percent'] = 1;
- }
- return $_param;
- }
- }
|