From 3c11826a1c29585f723315d3042e325e3fa3613c Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Mon, 26 Oct 2020 11:16:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/DownloadController.class.php | 335 +++++++++++++++++- .../Home/Controller/QueryController.class.php | 76 +++- .../View/default/Public/promote_base.html | 2 + .../Home/View/default/Query/gameData.html | 59 ++- .../View/default/Query/userretention.html | 40 +-- 5 files changed, 420 insertions(+), 92 deletions(-) diff --git a/Application/Home/Controller/DownloadController.class.php b/Application/Home/Controller/DownloadController.class.php index e69f443ec..4d72a450c 100644 --- a/Application/Home/Controller/DownloadController.class.php +++ b/Application/Home/Controller/DownloadController.class.php @@ -13,6 +13,7 @@ use Base\Facade\Request; use Base\Service\ApplyService; use Base\Service\PromoteCoinRecordService; use Base\Service\PromoteCoinTransferLogService; +use GuzzleHttp\Client; /** * @author elf<360197197@qq.com> @@ -2054,10 +2055,185 @@ class DownloadController extends BaseController { if (!$res) { $this->error('添加下载失败'); } - $this->success('添加下载成功',U('listsIndex')); + $this->success('添加下载成功',U('listsIndex')); + } + + + public function userretention_data_export() + { + $baseGameId = I('game_id', 0); + $deviceType = I('device_type', ''); + $timeRange = I('time_range', date('Y-m-d',strtotime('-7 day')) . ' 至 ' . date('Y-m-d')); + $lastSortName = trim(I('last_sort_name', '')); + $sortName = trim(I('sort_name', '')); + $sort = intval(I('sort', 1)); + + $start = ''; + $end = ''; + $timeRangeRow = explode(' 至 ', $timeRange); + if (count($timeRangeRow) == 2) { + $start = $timeRangeRow[0]; + $end = $timeRangeRow[1]; + } else { + $start = $timeRangeRow[0]; + $end = $timeRangeRow[0]; + } + + $promote = $this->getLoginPromote(); + $levelPromote = $this->getLevelPromote(); + $queryPromote = $this->getQueryPromote($levelPromote); + + $orderColumn = $sortName; + $orderType = ($sort == 1) ? 'desc' : 'asc'; + if (!empty($sortName)) { + $orderColumn = $sortName; + $orderType = ($sort == 1) ? 'desc' : 'asc'; + } + + $status = true; + $data = false; + $error = ''; + if ($baseGameId == 0) { + $error = '请选择游戏!'; + $status = false; + } + $startTime = strtotime($start . ' 00:00:00'); + $endTime = strtotime($end . ' 23:59:59') + 1; + if ((($endTime - $startTime)/(24*3600)) > 31) { + $error = '时间间隔不能超过31天'; + $status = false; + } + $searchGameId = 0; + if (!$status) { + $this->error($error); + } - } + $conditions = json_encode([ + 'base_game_id' => $baseGameId, + 'start' => $start, + 'end' => $end, + 'promote_id' => $queryPromote['id'], + 'device_type' => $deviceType, + 'orderColumn' => $orderColumn, + 'orderType' => $orderType, + ], true); + + $addtime = time(); + $data = [ + 'logid' => 'ur_'.time(), + 'promote_id' => PID, + 'type' => '/Home/Query/userretention', + 'dataname' => '用户留存率', + 'status' => 0, + 'addtime' => $addtime, + 'begintime' => 0, + 'content' => '', + 'conditions' => $conditions + ]; + $res = M('downloadlog','tab_')->add($data); + if (!$res) { + $this->error('添加下载失败'); + } + $this->success('添加下载成功',U('listsIndex')); + } + + public function gameData_data_export() + { + $gameId = I('game_id', 0); + $serverId = I('server_id', ''); + $timeRange = I('time_range', date('Y-m-d',strtotime('-7 day')) . ' 至 ' . date('Y-m-d')); + $lastSortName = trim(I('last_sort_name', '')); + $sortName = trim(I('sort_name', '')); + $sort = intval(I('sort', 1)); + + $promote = $this->getLoginPromote(); + $levelPromote = $this->getLevelPromote(); + $queryPromote = $this->getQueryPromote($levelPromote); + + $start = ''; + $end = ''; + $timeRangeRow = explode(' 至 ', $timeRange); + if (count($timeRangeRow) == 2) { + $start = $timeRangeRow[0]; + $end = $timeRangeRow[1]; + } else { + $start = $timeRangeRow[0]; + $end = $timeRangeRow[0]; + } + + $spendMap = ['pay_status' => 1, '_string' => '1=1']; + $roleMap = ['_string' => '1=1']; + $map = []; + + $betweenTime = [strtotime($start . ' 00:00:00'), strtotime($start . ' 23:59:59')]; + $spendMap['pay_time'] = ['between', $betweenTime]; + $roleMap['create_time'] = ['between', $betweenTime]; + + $promoteService = new PromoteService(); + $subInSql = $promoteService->subInSql($queryPromote); + + $spendMap['_string'] .= ' and promote_id in (' . $subInSql . ')'; + $roleMap['_string'] .= ' and promote_id in (' . $subInSql . ')'; + + + if ($gameId > 0) { + $spendMap['game_id'] = $gameId; + $roleMap['game_id'] = $gameId; + $map['a.game_id'] = $gameId; + } + + if ($serverId != '') { + $spendMap['server_id'] = $serverId; + $roleMap['server_id'] = $serverId; + $map['a.server_id'] = $serverId; + } + + $orderBy = ''; + $sortNameData = ['amount', 'count']; + if (!empty($sortName)) { + if (in_array($sortName, $sortNameData)) { + $desc = ' desc'; + $asc = ' asc'; + if ($lastSortName != $sortName) { + $sortString = $desc; + $sort = 1; + } else { + $sortString = ($sort == 1) ? $desc : $asc; + } + $orderBy = $sortName . $sortString; + } + } + + $spendSubSql = M('spend', 'tab_')->field(['game_id', 'server_id', 'sum(pay_amount) amount'])->where($spendMap)->group('game_id, server_id')->select(false); + $roleSubSql = M('user_play_info', 'tab_')->field(['game_id', 'server_id', 'count(*) count'])->where($roleMap)->group('game_id, server_id')->select(false); + + $conditions = json_encode([ + 'spendSubSql' => $spendSubSql, + 'roleSubSql' => $roleSubSql, + 'map' => $map, + 'orderBy' => $orderBy, + ], true); + + $addtime = time(); + $data = [ + 'logid' => 'gd_'.time(), + 'promote_id' => PID, + 'type' => '/Home/Query/gameData', + 'dataname' => '游戏分区数据汇总', + 'status' => 0, + 'addtime' => $addtime, + 'begintime' => 0, + 'content' => '', + 'conditions' => $conditions + ]; + $res = M('downloadlog','tab_')->add($data); + if (!$res) { + $this->error('添加下载失败'); + } + $this->success('添加下载成功',U('listsIndex')); + } + /** * 数据汇总添加下载 * @author sunke @@ -2262,6 +2438,12 @@ class DownloadController extends BaseController { case "结算单明细": $this->WithdrawOrderExcelInfo($id,$map); break; + case "用户留存率": + $this->userretentionExcelInfo($id,$map); + break; + case "游戏分区数据汇总": + $this->gameDataExcelInfo($id,$map); + break; default: break; } @@ -5038,5 +5220,154 @@ public function iosDetailExcelInfo($id,$map) { $this->backSuccessExport($id); } + public function multisort($records, $column, $type = 'asc') + { + $length = count($records); + for ($i = 0; $i < $length; $i ++) { + for ($j = $i + 1; $j < $length; $j ++) { + if ($type == 'asc') { + if ($records[$i][$column] > $records[$j][$column]) { + $temp = $records[$i]; + $records[$i] = $records[$j]; + $records[$j] = $temp; + } + } else if ($type == 'desc') { + if ($records[$i][$column] < $records[$j][$column]) { + $temp = $records[$i]; + $records[$i] = $records[$j]; + $records[$j] = $temp; + } + } + } + } + return $records; + } + + public function userretentionExcelInfo($id,$map) + { + $xlsName = "用户留存率"; + $xlsCell = array( + array('date','日期'), + array('game_name','游戏名称'), + array('promote_name','渠道名称'), + array('register_count','新增玩家'), + array('retention_day1', '1日留存'), + array('retention_day2', '2日留存'), + array('retention_day3', '3日留存'), + array('retention_day4', '4日留存'), + array('retention_day5', '5日留存'), + array('retention_day6', '6日留存'), + array('retention_day7', '7日留存'), + array('retention_day15', '15日留存'), + array('retention_day30', '30日留存'), + ); + $records = recordPromoteLogs('数据管理', '用户留存率导出'); + + $map = json_decode(json_encode($map), true); + $baseGameId = $map['base_game_id']; + $start = $map['start']; + $end = $map['end']; + $queryPromoteId = $map['promote_id']; + $deviceType = $map['device_type']; + $orderColumn = $map['orderColumn']; + $orderType = $map['orderType']; + + $baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find(); + $gameIds = []; + if ($deviceType) { + $searchGameId = $deviceType == 'android' ? $baseGame['android_game_id'] : $baseGame['ios_game_id']; + $gameIds[] = $searchGameId; + } else { + $gameIds = [$baseGame['android_game_id'], $baseGame['ios_game_id']]; + } + + $client = new Client([ + 'base_uri' => C('TASK_URL'), + 'timeout' => 10.0, + ]); + $response = $client->post('/statistics/player-retention', [ + 'verify' => false, + 'form_params' => [ + 'start_time' => $start, + 'end_time' => $end, + 'promote_id' => $queryPromoteId, + 'game_ids' => $gameIds, + ] + ]); + + $result = (string)$response->getBody(); + $result = json_decode($result, true); + if (!$result) { + $this->assign('error', '数据请求异常!'); + } + $data = $result['data']['records']; + $dayList = [1, 2, 3, 4, 5, 6, 7, 15, 30]; + $gameName = $deviceType ? get_game_name($searchGameId) : $baseGame['name']; + $promoteName = '全部'; + if ($promoteId) { + $promoteName = get_promote_account($promoteId); + } + foreach ($data as $key => $item) { + $item['promote_name'] = $promoteName; + $item['game_name'] = $gameName; + foreach ($dayList as $day) { + if ($item['register_count'] > 0) { + $item['retention_day'. $day] = round($item['retention_day'. $day]/$item['register_count'], 4)*100; + } else { + $item['retention_day'. $day] = '--'; + } + } + $data[$key] = $item; + } + if ($orderColumn) { + $data = $this->multisort($data, $orderColumn, $orderType); + } + foreach ($data as $key => $item) { + foreach ($dayList as $day) { + if ($item['retention_day' . $day] === '--') { + + } else { + $item['retention_day' . $day] .= '%'; + } + } + $data[$key] = $item; + } + $this->exportExcel($xlsName, $xlsCell, $data, $id); + } + + public function gameDataExcelInfo($id,$map) + { + $xlsName = "游戏分区数据汇总"; + $xlsCell = array( + array('game_name','游戏名称'), + array('server_name','区服名称'), + array('count','创角数'), + array('amount', '消费金额'), + ); + $records = recordPromoteLogs('数据管理', '游戏分区数据汇总'); + + $map = json_decode(json_encode($map), true); + $spendSubSql = $map['spendSubSql']; + $roleSubSql = $map['roleSubSql']; + $queryMap = $map['map']; + $orderBy = $map['orderBy']; + + $query = M('server', 'tab_')->alias('a') + ->field(['a.game_id', 'a.game_name', 'a.server_id', 'a.server_name', 'b.amount', 'c.count']) + ->join('left join (' . $spendSubSql . ') b on a.game_id = b.game_id and a.server_id = b.server_id') + ->join('left join (' . $roleSubSql . ') c on a.game_id = c.game_id and a.server_id = c.server_id') + ->where($queryMap); + + if ($orderBy) { + $query->order($orderBy); + } + $data = $query->select(); + foreach ($data as $key => $item) { + $item['amount'] = floatval($item['amount']); + $item['count'] = intval($item['count']); + $data[$key] = $item; + } + $this->exportExcel($xlsName, $xlsCell, $data, $id); + } } diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index 6d8dabc7e..7ed07e925 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -2813,9 +2813,31 @@ class QueryController extends BaseController $this->display(); } + public function multisort($records, $column, $type = 'asc') + { + $length = count($records); + for ($i = 0; $i < $length; $i ++) { + for ($j = $i + 1; $j < $length; $j ++) { + if ($type == 'asc') { + if ($records[$i][$column] > $records[$j][$column]) { + $temp = $records[$i]; + $records[$i] = $records[$j]; + $records[$j] = $temp; + } + } else if ($type == 'desc') { + if ($records[$i][$column] < $records[$j][$column]) { + $temp = $records[$i]; + $records[$i] = $records[$j]; + $records[$j] = $temp; + } + } + } + } + return $records; + } + public function userretention() { - $dataOrder = I('data_order', ''); $baseGameId = I('game_id', 0); $deviceType = I('device_type', ''); $timeRange = I('time_range', date('Y-m-d',strtotime('-7 day')) . ' 至 ' . date('Y-m-d')); @@ -2908,7 +2930,7 @@ class QueryController extends BaseController } $data[$key] = $item; } - if ($dataOrder) { + if ($orderColumn) { $data = $this->multisort($data, $orderColumn, $orderType); } } else { @@ -2918,8 +2940,6 @@ class QueryController extends BaseController $baseGames = M('base_game', 'tab_')->select(); $this->assign('baseGames', $baseGames); - // $this->checkListOrCountAuthRestMap($map,[]); - $this->assign('sortName', $sortName); $this->assign('sort', $sort); $this->assign('data', $data); @@ -2937,6 +2957,10 @@ class QueryController extends BaseController $sortName = trim(I('sort_name', '')); $sort = intval(I('sort', 1)); + $promote = $this->getLoginPromote(); + $levelPromote = $this->getLevelPromote(); + $queryPromote = $this->getQueryPromote($levelPromote); + $start = ''; $end = ''; $timeRangeRow = explode(' 至 ', $timeRange); @@ -2948,34 +2972,35 @@ class QueryController extends BaseController $end = $timeRangeRow[0]; } - $spendMap = ['pay_status' => 1]; - $roleMap = []; + $spendMap = ['pay_status' => 1, '_string' => '1=1']; + $roleMap = ['_string' => '1=1']; $map = []; $betweenTime = [strtotime($start . ' 00:00:00'), strtotime($start . ' 23:59:59')]; $spendMap['pay_time'] = ['between', $betweenTime]; - $spendMap['create_time'] = ['between', $betweenTime]; + $roleMap['create_time'] = ['between', $betweenTime]; + + $promoteService = new PromoteService(); + $subInSql = $promoteService->subInSql($queryPromote); + + $spendMap['_string'] .= ' and promote_id in (' . $subInSql . ')'; + $roleMap['_string'] .= ' and promote_id in (' . $subInSql . ')'; + if ($gameId > 0) { $spendMap['game_id'] = $gameId; $roleMap['game_id'] = $gameId; - $map['game_id'] = $gameId; + $map['a.game_id'] = $gameId; } - if ($serverId == '') { + if ($serverId != '') { $spendMap['server_id'] = $serverId; $roleMap['server_id'] = $serverId; - $map['server_id'] = $serverId; + $map['a.server_id'] = $serverId; } - $spendSubSql = M('spend', 'tab_')->field(['game_id', 'server_id', 'sum(pay_amount) amount'])->where($spendMap)->groupBy('game_id, server_id')->select(false); - $roleSubSql = M('user_play_info', 'tab_')->field(['game_id', 'server_id', 'count(*) count'])->where($roleMap)->groupBy('game_id, server_id')->select(false); - - $query = M('server', 'tab_')->alias('a') - ->field(['a.game_id', 'a.game_name', 'a.server_id', 'a.server_name', 'b.amount', 'c.count']) - ->join('left join (' . $spendSubSql . ') b on a.game_id = b.game_id and a.server_id = b.server_id') - ->join('left join (' . $roleSubSql . ') c on a.game_id = c.game_id and a.server_id = c.server_id') - ->where($map); + $spendSubSql = M('spend', 'tab_')->field(['game_id', 'server_id', 'sum(pay_amount) amount'])->where($spendMap)->group('game_id, server_id')->select(false); + $roleSubSql = M('user_play_info', 'tab_')->field(['game_id', 'server_id', 'count(*) count'])->where($roleMap)->group('game_id, server_id')->select(false); $orderBy = ''; $sortNameData = ['amount', 'count']; @@ -2993,6 +3018,12 @@ class QueryController extends BaseController } } + $query = M('server', 'tab_')->alias('a') + ->field(['a.game_id', 'a.game_name', 'a.server_id', 'a.server_name', 'b.amount', 'c.count']) + ->join('left join (' . $spendSubSql . ') b on a.game_id = b.game_id and a.server_id = b.server_id') + ->join('left join (' . $roleSubSql . ') c on a.game_id = c.game_id and a.server_id = c.server_id') + ->where($map); + if ($orderBy) { $query->order($orderBy); } @@ -3007,6 +3038,15 @@ class QueryController extends BaseController $this->assign('records', $records); $this->assign('start', $start); $this->assign('end', $end); + $this->assign('pagination', $pagination); $this->display(); } + + public function getServers() + { + $gameId = I('game_id', 0); + $gameRepository = new GameRepository(); + $servers = $gameRepository->getServersByGameId($gameId); + return $this->ajaxReturn(['status' => 1, 'message' => '获取成功', 'data' => ['servers' => $servers]]); + } } diff --git a/Application/Home/View/default/Public/promote_base.html b/Application/Home/View/default/Public/promote_base.html index b29b7a23e..f1fcf3710 100644 --- a/Application/Home/View/default/Public/promote_base.html +++ b/Application/Home/View/default/Public/promote_base.html @@ -75,6 +75,8 @@ 团队/推广员业绩 IOS下载数统计 + 用户留存率 + 游戏分区数据汇总 diff --git a/Application/Home/View/default/Query/gameData.html b/Application/Home/View/default/Query/gameData.html index 396260f03..850c3a972 100644 --- a/Application/Home/View/default/Query/gameData.html +++ b/Application/Home/View/default/Query/gameData.html @@ -30,26 +30,14 @@