diff --git a/Application/Base/Service/PromoteGradeService.class.php b/Application/Base/Service/PromoteGradeService.class.php index 4f303e06b..f15d088d6 100644 --- a/Application/Base/Service/PromoteGradeService.class.php +++ b/Application/Base/Service/PromoteGradeService.class.php @@ -6,6 +6,8 @@ use Base\Tool\GameCatClient; class PromoteGradeService { + const FOREVER_TIME = 300001; + public static $symbols = [ 1 => '>=', 2 => '>', @@ -22,6 +24,14 @@ class PromoteGradeService { $id = $params['id'] ?? 0; + if (empty($params['base_game_id'])) { + throw new \Exception('请选择游戏'); + } + $monthBegin = isset($params['month_begin']) && $params['month_begin'] ? + date('Ym', strtotime($params['month_begin'])) : 0; + $monthEnd = isset($params['month_end']) && $params['month_end'] ? + date('Ym', strtotime($params['month_end'])) : self::FOREVER_TIME; + $setting = null; if ($id > 0) { $setting = M('promote_grade_setting', 'tab_')->where(['id' => $id])->find(); @@ -32,12 +42,16 @@ class PromoteGradeService throw new \Exception('不允许修改其他公司的配置'); } } else { - $setting = M('promote_grade_setting', 'tab_')->where(['company_id' => $promote['company_id']])->find(); - if ($setting) { - throw new \Exception('您已经设置过了'); + $count = $this->getRepeatRuleCount($promote['company_id'], $params['base_game_id'], $monthBegin, $monthEnd); + if ($count > 0) { + throw new \Exception('该游戏在相同时间段内已经设置规则'); } } + if ($monthBegin > 0 && $monthEnd > 0 && $monthBegin > $monthEnd) { + throw new \Exception('规则截止时间不能大于规则开始时间'); + } + $config = []; $config['reach_level'] = $params['level']; $config['grades'] = $this->sortGrades($params['grades']); @@ -45,6 +59,9 @@ class PromoteGradeService $data = []; $data['status'] = 1; + $data['base_game_id'] = $params['base_game_id']; + $data['month_begin'] = $monthBegin; + $data['month_end'] = $monthEnd; $data['name'] = $params['name']; $data['config'] = json_encode($config); @@ -75,9 +92,35 @@ class PromoteGradeService return $grades; } - public function getCurrentSetting($promote) + public function getTimeRepeatCondition($monthBegin, $monthEnd) + { + return ' ((month_begin >= ' . $monthBegin . ' AND month_begin <= ' . $monthEnd . ') OR (month_begin <= ' . $monthBegin . ' AND month_end >= ' . $monthEnd + . ') OR (month_end >= ' . $monthBegin . ' AND month_end <= ' . $monthEnd . '))'; + } + + public function getRepeatRuleCount($companyId, $baseGameId, $monthBegin, $monthEnd) + { + $conditions = [ + 'compnay_id' => $companyId, + 'base_game_id' => $baseGameId, + ]; + $conditions['_string'] = $this->getTimeRepeatCondition($monthBegin, $monthEnd); + $count = M('promote_grade_setting', 'tab_')->where($conditions)->count(); + return intval($count); + } + + public function getCurrentSetting($promote, $baseGameId, $month) { - return M('promote_grade_setting', 'tab_')->where(['status' => 1, 'company_id' => $promote['company_id']])->find(); + $timeCondition = 'month_end >= ' . $month . ' and month_begin <= ' . $month; + + return M('promote_grade_setting', 'tab_') + ->where([ + 'status' => 1, + 'company_id' => $promote['company_id'], + 'base_game_id' => $baseGameId, + '_string' => $timeCondition + ]) + ->find(); } public function searchGradeByPromotes($promotes, $params, $setting) @@ -85,6 +128,7 @@ class PromoteGradeService $config = json_decode($setting['config'], true); $settingLevel = $config['reach_level']; $month = $params['month'] ?? date('Y-m'); + $baseGameId = $params['base_game_id'] ?? 0; $promoteIds = array_column($promotes, 'id'); $beginTime = strtotime($month . '-01 00:00:00'); $endDate = date('Y-m-01 00:00:00', strtotime($month . '-01' . ' +1 month')); @@ -97,26 +141,44 @@ class PromoteGradeService ->where(['register_time' => ['between', $betweenTime], 'promote_id' => ['in', $promoteIds]]) ->group('promote_id') ->select(false); + + $baseGame = null; + if ($baseGameId > 0) { + $baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find(); + } + $roleMap = [ + 'role_level' => ['egt', $settingLevel], + 'create_time' => ['between', $betweenTime], + 'promote_id' => ['in', $promoteIds], + '_string' => 'user_id in (' . $userSubSql . ')' + ]; + + $spendMap = [ + 'pay_time' => ['between', $betweenTime], + 'pay_status' => 1, + 'promote_id' => ['in', $promoteIds], + '_string' => 'user_id in (' . $userSubSql . ')' + ]; + + if ($baseGame) { + $roleMap['game_id'] = ['in', [$baseGame['android_game_id'], $baseGame['ios_game_id']]]; + $spendMap['game_id'] = ['in', [$baseGame['android_game_id'], $baseGame['ios_game_id']]]; + } else { + $roleMap['_string'] .= ' and 1=0'; + $spendMap['_string'] .= ' and 1=0'; + } + $accountItems = M('user_play_info', 'tab_') ->field(['promote_id', 'count(DISTINCT user_id) num']) - ->where([ - 'role_level' => ['egt', $settingLevel], - 'create_time' => ['between', $betweenTime], - 'promote_id' => ['in', $promoteIds], - '_string' => 'user_id in (' . $userSubSql . ')' - ]) + ->where($roleMap) ->group('promote_id') ->select(); $accountItems = index_by_column('promote_id', $accountItems); - + $amountItems = M('spend', 'tab_') ->field(['promote_id', 'sum(pay_amount) amount']) - ->where([ - 'pay_time' => ['between', $betweenTime], - 'pay_status' => 1, 'promote_id' => ['in', $promoteIds], - '_string' => 'user_id in (' . $userSubSql . ')' - ]) + ->where($spendMap) ->group('promote_id') ->select(); $amountItems = index_by_column('promote_id', $amountItems); diff --git a/Application/Base/Service/PromoteService.class.php b/Application/Base/Service/PromoteService.class.php index e40bf47e9..0d2cbb3a2 100644 --- a/Application/Base/Service/PromoteService.class.php +++ b/Application/Base/Service/PromoteService.class.php @@ -1194,6 +1194,19 @@ class PromoteService { return $groupName; } + public function getVisibleBaseGames($promote) + { + $gameIds = $this->getVisibleGameIds($promote); + if (count($gameIds) == 0) { + return []; + } + return M('base_game', 'tab_')->where([ + '_logic' => 'or', + 'android_game_id' => ['in', $gameIds], + 'ios_game_id' => ['in', $gameIds], + ])->select(); + } + public function getVisibleGameIds($promote) { /* $gameIds = M('game', 'tab_')->getField('id', true); diff --git a/Application/Home/Controller/DownloadController.class.php b/Application/Home/Controller/DownloadController.class.php index 2f260fbc7..8500853e4 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> @@ -1893,12 +1894,18 @@ class DownloadController extends BaseController { public function promote_grade_export() { $month = I('month', date('Y-m')); + $month = $month ? $month : date('Y-m'); + $baseGameId = I('base_game_id', 0); $loginPromote = $this->getLoginPromote(); + if ($baseGameId == 0) { + return $this->error('未选择游戏'); + } $promoteGradeService = new PromoteGradeService(); - $setting = $promoteGradeService->getCurrentSetting($loginPromote); + $monthNumber = date('Ym', strtotime($month . '-01')); + $setting = $promoteGradeService->getCurrentSetting($loginPromote, $baseGameId, $monthNumber); if (is_null($setting)) { - return $this->error('未设置评级规则'); + return $this->error('该游戏在此月份未设置评级规则'); } $parentId = I('parent_id', 0); @@ -1930,7 +1937,7 @@ class DownloadController extends BaseController { $promotes = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map)->select(); array_unshift($promotes, $parent); - $conditions = json_encode(['promotes' => $promotes, 'setting' => $setting, 'month' => $month], true); + $conditions = json_encode(['promotes' => $promotes, 'setting' => $setting, 'month' => $month, 'base_game_id' => $baseGameId], true); $addtime = time(); $data1 = [ 'logid' => 'pg_'.time(), @@ -1950,8 +1957,9 @@ class DownloadController extends BaseController { $this->success('添加下载成功', U('listsIndex')); } //玩家角色 - public function userRoles_data_export() { - $gameId = I('relation_game_id', 0); + public function userRoles_data_export() + { + $relationGameId = I('relation_game_id', 0); $serverId = I('server_id', 0); $isSelf = I('is_self', 0); $roleName = I('role_name', ''); @@ -1961,65 +1969,30 @@ class DownloadController extends BaseController { $roleLevelBegin = intval(I('role_level_begin', 0)); $roleLevelEnd = intval(I('role_level_end', 0)); $headmanPromoteId = I('headman_promote_id', 0); - $playTime = I('create_time', ''); - $promote = $this->getLoginPromote(); - if (empty($playTime)) { + $createTime = I('create_time', date('Y-m-d') . ' 至 ' . date('Y-m-d', time()-7*24*3600)); + $lastSortName = trim(I('last_sort_name', '')); + $sortName = trim(I('sort_name', '')); + $sort = intval(I('sort', 1)); + if (empty($createTime)) { $this->error('请选择创建时间'); } - $map1['chain'] = ['like','%'.'/'.PID.'/'.'%']; - $rs = M('promote','tab_')->where($map1)->field('id,account,nickname')->select(); - $childPromoteIds = ''; - if(empty($rs)) { - $map['tab_user.promote_id'] = PID; - }else { - foreach ($rs as $rsKey => $rsValue) { - $id = $rsValue['id']; - $childPromoteIds .= $id.','; - } - $childPromoteIds = rtrim($childPromoteIds, ','); - $childPromoteIds .= ',' . PID; - $map['promote_id'] = ['in', $childPromoteIds]; - } - + $promote = $this->getLoginPromote(); $levelPromote = $this->getLevelPromote(); $queryPromote = $this->getQueryPromote($levelPromote); - - $map2[] = [ - '_logic' => 'or', - 'id' => $queryPromote['id'], - 'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'] - ]; - $ids = M('promote', 'tab_')->where($map2)->getField('id', true); - if(empty($ids)) { - $ids = array(); - } - if(empty($levelPromote)) { - array_push($ids,PID); - - } - //array_push($ids,$queryPromote['id']); - if (!empty($ids)) { - $map['promote_id'] = ['in',$ids]; - - }else { - $map['_string'] = '1<>1'; - } - - if ($gameId != 0 || $sdkVersion != 0) { - if ($gameId != 0) { - $gameMap['relation_game_id'] = $gameId; - } - if ($sdkVersion != 0) { - $gameMap['sdk_version'] = $sdkVersion; - } - $gameId1 = M('game', 'tab_')->where($gameMap)->getField('id', true); - if(empty($gameId1)) { - $gameId1 = [-100]; - } - $map['game_id'] = ['in', $gameId1]; + + $promoteService = new PromoteService(); + $subInSql = $promoteService->subInSql($queryPromote); + + $map = []; + $map['_string'] = '1=1'; + $map['_string'] .= ' and role.promote_id in (' . $subInSql . ')'; + + if ($relationGameId != 0 || $sdkVersion != 0) { + $gameIds = gameSearch($relationGameId, $sdkVersion); + $map['game_id'] = ['in', $gameIds]; } if ($serverId != 0) { - $map['serverId'] = $serverId; + $map['server_id'] = $serverId; } if ($roleName != '') { $map['role_name'] = ['like', '%' . $roleName . '%']; @@ -2027,9 +2000,6 @@ class DownloadController extends BaseController { if ($userAccount != '') { $map['user_account'] = ['like', '%' . $userAccount . '%']; } - if ($sdkVersion != 0) { - $map['sdk_version'] = $sdkVersion; - } if ($roleLevelBegin != 0 && $roleLevelEnd == 0) { $map['role_level'] = ['egt', $roleLevelBegin]; } elseif ($roleLevelEnd != 0 && $roleLevelBegin == 0) { @@ -2037,37 +2007,46 @@ class DownloadController extends BaseController { } elseif ($roleLevelEnd != 0 && $roleLevelBegin != 0) { $map['role_level'] = ['between', [$roleLevelBegin, $roleLevelEnd]]; } - if ($playTime != '') { - $playTimeRow = explode(' 至 ', $playTime); - $playTimeBegin = 0; - $playTimeEnd = 0; - if (count($playTimeRow) == 2) { - $playTimeBegin = strtotime($playTimeRow[0] . ' 00:00:00'); - $playTimeEnd = strtotime($playTimeRow[1] . ' 23:59:59'); + if ($createTime != '') { + $createTimeRow = explode(' 至 ', $createTime); + $createTimeBegin = 0; + $createTimeEnd = 0; + if (count($createTimeRow) == 2) { + $createTimeBegin = strtotime($createTimeRow[0] . ' 00:00:00'); + $createTimeEnd = strtotime($createTimeRow[1] . ' 23:59:59'); } else { - $playTimeBegin = strtotime($playTimeRow[0] . ' 00:00:00'); - $playTimeEnd = strtotime($playTimeRow[0] . ' 23:59:59'); + $createTimeBegin = strtotime($createTimeRow[0] . ' 00:00:00'); + $createTimeEnd = strtotime($createTimeRow[0] . ' 23:59:59'); } - if (($playTimeEnd - $playTimeBegin) > 31 * 24 * 3600) { - $this->error('时间范围不能超过31天'); + if (($createTimeEnd - $createTimeBegin) > 7*24*3600) { + $this->error('时间范围不能超过7天'); } - $map['create_time'] = ['between', [$playTimeBegin, $playTimeEnd]]; + $map['create_time'] = ['between', [$createTimeBegin, $createTimeEnd]]; } if ($isSelf) { $map['promote_id'] = $queryPromote['id']; - } else { - if ($headmanPromoteId != 0) { - $map['promote_id'] = $headmanPromoteId; - } - if ($promoteId != 0) { - $map['promote_id'] = $promoteId; + } + + $orderBy = 'create_time desc'; + $sortNameData = ['login_time', 'create_time', 'role_level', 'register_time', 'role.promote_account']; + 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; } } - $conditions = json_encode($map,TRUE); - $addtime = time(); - $data = [ + $conditions = json_encode(['map' => $map, 'order' => $orderBy], true); + $addtime = time(); + $data = [ 'logid' => 'js_'.time(), 'promote_id' => PID, 'type' => '/Home/Query/userRoles', @@ -2076,17 +2055,191 @@ class DownloadController extends BaseController { 'addtime' => $addtime, 'begintime' => 0, 'content' => '', - 'conditions' =>$conditions - ]; - $res = M('downloadlog','tab_')->add($data); - if (!$res) { - // $this->ajaxReturn(array("status" => -1, "msg" => "添加导出日志失败", 'ret' => $res)); - $this->error('添加下载失败'); - } - $this->success('添加下载成功',U('listsIndex')); + 'conditions' => $conditions + ]; + $res = M('downloadlog','tab_')->add($data); + if (!$res) { + $this->error('添加下载失败'); + } + $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 @@ -2195,7 +2348,7 @@ class DownloadController extends BaseController { $dataname = $downloadStatus[0]['dataname']; $conditions = $downloadStatus[0]['conditions']; $map = array(); - foreach (json_decode($conditions,FALSE) as $key => $value) { + foreach (json_decode($conditions, FALSE) as $key => $value) { if($value !== 0 && $value !== "" ) { $map[$key] = $value; } @@ -2291,6 +2444,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; } @@ -2938,7 +3097,7 @@ public function iosDetailExcelInfo($id,$map) { } //玩家角色excel信息 - public function userRolesExcelInfo($id,$map) { + public function userRolesExcelInfo($id, $map) { $xlsName = "角色查询"; $xlsCell = array( array('user_account','玩家账号'), @@ -2957,16 +3116,35 @@ public function iosDetailExcelInfo($id,$map) { array('create_time','创建时间'), ); $records = recordPromoteLogs('数据管理','角色查询导出'); - $model = M('user_play_info','tab_'); - $data = $model->field('user_id,user_account,promote_account,game_name,server_name,role_name,role_level,create_time,play_time')->where($map)->order('create_time desc')->select(); - $users = []; - if (count($data) > 0) { - $userIds = array_column($data, 'user_id'); - $users = M('user', 'tab_')->field(['id', 'register_time', 'login_time', 'register_ip', 'login_ip', 'device_number'])->where(['id' => ['in', $userIds]])->select(); - $users = index_by_column('id', $users); - } + $map = json_decode(json_encode($map), true); + $columns = [ + 'user_account', + 'role.promote_account', + 'role.game_name', + 'user.device_number', + 'user.register_time', + 'user.register_ip', + 'user.login_time', + 'user.login_ip', + 'role.server_name', + 'role.sdk_version', + 'role.role_name', + 'role.role_level', + 'role.create_time', + 'role.play_time', + 'role.play_ip' + ]; + + $data = M('user_play_info', 'tab_') + ->field($columns) + ->alias('role') + ->join('tab_user user on role.user_id = user.id') + ->where($map['map']) + ->order($map['order']) + ->select(); + $xlsData = []; foreach ($data as $key1 => $value1) { $value1['user_account'] = $this->encryption($value1['user_account']); @@ -2975,20 +3153,8 @@ public function iosDetailExcelInfo($id,$map) { } else { $value1['create_time'] = date('Y-m-d H:i:s', $value1['create_time']); } - if (isset($users[$value1['user_id']])) { - $user = $users[$value1['user_id']]; - $value1['register_time'] = date('Y-m-d H:i:s', $user['register_time']); - $value1['login_time'] = date('Y-m-d H:i:s', $user['login_time']); - $value1['register_ip'] = $user['register_ip']; - $value1['login_ip'] = $user['login_ip']; - $value1['device_number'] = $user['device_number']; - } else { - $value1['register_time'] = '--'; - $value1['login_time'] = '--'; - $value1['register_ip'] = '--'; - $value1['login_ip'] = '--'; - $value1['device_number'] = '--'; - } + $value1['register_time'] = date('Y-m-d H:i:s', $value1['register_time']); + $value1['login_time'] = date('Y-m-d H:i:s', $value1['login_time']); $xlsData[] = $value1; } $this->exportExcel($xlsName, $xlsCell, $xlsData,$id); @@ -4057,6 +4223,7 @@ public function iosDetailExcelInfo($id,$map) { $promoteGradeService = new PromoteGradeService(); $records = $promoteGradeService->searchGradeByPromotes($map['promotes'], [ 'month' => $map['month'], + 'base_game_id' => $map['base_game_id'] ], $map['setting']); $xlsData = []; @@ -5060,5 +5227,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/PromoteGradeController.class.php b/Application/Home/Controller/PromoteGradeController.class.php index 7a58b03bc..dc3e43cc1 100644 --- a/Application/Home/Controller/PromoteGradeController.class.php +++ b/Application/Home/Controller/PromoteGradeController.class.php @@ -24,14 +24,9 @@ class PromoteGradeController extends BaseController public function index($p = 1) { $month = I('month', date('Y-m')); + $month = $month ? $month : date('Y-m'); + $baseGameId = I('base_game_id', 0); $loginPromote = $this->getLoginPromote(); - - $promoteGradeService = new PromoteGradeService(); - $setting = $promoteGradeService->getCurrentSetting($loginPromote); - if (is_null($setting)) { - return $this->error('未设置评级规则'); - } - $parentId = I('parent_id', 0); $promoteId = I('promote_id', 0); $searchLevel = 0; @@ -51,6 +46,9 @@ class PromoteGradeController extends BaseController $currentDisplay = '自己'; } + $searchLevel = $parent['level'] + 1; + $searchLevelName = $promoteService->getLevelName($searchLevel); + $subPromotes = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'group_remark'])->where(['parent_id' => $parent['id']])->select(); $map = ['parent_id' => $parent['id']]; @@ -58,34 +56,72 @@ class PromoteGradeController extends BaseController $map['id'] = $promoteId; } - $query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map); - list($promotes, $pagination, $count) = $this->paginate($query); + $promoteGradeService = new PromoteGradeService(); - if (I('p', 1) == 1) { - array_unshift($promotes, $parent); + $error = ''; + $status = true; + $setting = null; + $pagination = null; + if ($baseGameId == 0) { + $status = false; + $error = '请选择游戏'; + } else { + $monthNumber = date('Ym', strtotime($month . '-01')); + $setting = $promoteGradeService->getCurrentSetting($loginPromote, $baseGameId, $monthNumber); + if (is_null($setting)) { + $status = false; + $error = '该游戏在此月份未设置评级规则'; + } } - $records = $promoteGradeService->searchGradeByPromotes($promotes, [ - 'month' => $month, - ], $setting); + $records = []; + if ($status) { + $query = M('promote', 'tab_')->field(['id', 'account', 'real_name', 'level', 'chain'])->where($map); + list($promotes, $pagination, $count) = $this->paginate($query); + + if (I('p', 1) == 1) { + array_unshift($promotes, $parent); + } + + $records = $promoteGradeService->searchGradeByPromotes($promotes, [ + 'month' => $month, + 'base_game_id' => $baseGameId + ], $setting); - if (I('p', 1) == 1) { - $records[0]['current_display'] = $currentDisplay; + if (I('p', 1) == 1) { + $records[0]['current_display'] = $currentDisplay; + } } $this->meta_title = '团队评级'; - $this->assign('month', $month); + $baseGames = $promoteService->getVisibleBaseGames($loginPromote); + $this->assign('baseGames', $baseGames); + $this->assign('error', $error); $this->assign('prevParentId', $prevParentId); $this->assign('searchLevelName', $searchLevelName); $this->assign('subPromotes', $subPromotes); $this->assign('parentId', $parentId); $this->assign('records', $records); + $this->assign('month', $month); $this->assign('pagination', $pagination); $this->display(); } + private function getMonthRangeDisplay($monthBegin, $monthEnd) + { + if ($monthBegin == 0 && $monthEnd == 0) { + return '永久'; + } elseif ($monthBegin == 0 && $monthEnd > 0) { + return '从前 至 ' . date('Y-m', strtotime($monthEnd . '01')); + } elseif ($monthBegin > 0 && $monthEnd == 0) { + return date('Y-m', strtotime($monthBegin . '01')) . ' 至 永久'; + } else { + return date('Y-m', strtotime($monthBegin . '01')) . ' 至 ' . date('Y-m', strtotime($monthEnd . '01')); + } + } + public function settings() { $this->checkSettingPermission(); @@ -93,6 +129,13 @@ class PromoteGradeController extends BaseController $loginPromote = $this->getLoginPromote(); $items = M('promote_grade_setting', 'tab_')->where(['company_id' => $loginPromote['company_id']])->select(); + $baseGameIds = array_column($items, 'base_game_id'); + $itemBaseGames = []; + if (count($baseGameIds) > 0) { + $itemBaseGames = M('base_game', 'tab_')->where(['id' => ['in', $baseGameIds]])->select(); + $itemBaseGames = index_by_column('id', $itemBaseGames); + } + $symbols = PromoteGradeService::$symbols; $records = []; @@ -100,11 +143,16 @@ class PromoteGradeController extends BaseController $i = 0; $config = json_decode($item['config'], true); $gradeCount = count($config['grades']) + 1; + $baseGame = $itemBaseGames[$item['base_game_id']] ?? null; + $baseGameName = $baseGame ? $baseGame['name'] : '--'; + $monthRangeDisplay = $this->getMonthRangeDisplay($item['month_begin'], $item['month_end']); if ($gradeCount == 1) { $records[] = [ 'id' => $item['id'], 'name' => $item['name'], + 'game_name' => $baseGameName, 'grade_count' => $gradeCount, + 'month_range' => $monthRangeDisplay, 'reach_level' => $config['reach_level'], 'grade_name' => $config['default_grade_name'], 'grade_value' => '全部' @@ -114,7 +162,9 @@ class PromoteGradeController extends BaseController $records[] = [ 'id' => $item['id'], 'name' => $item['name'], + 'game_name' => $baseGameName, 'grade_count' => $gradeCount, + 'month_range' => $monthRangeDisplay, 'reach_level' => $config['reach_level'], 'grade_name' => $config['default_grade_name'], 'grade_value' => ($firstGrade['symbol'] == 1 ? '<' : '<=') . $firstGrade['value'] @@ -123,7 +173,9 @@ class PromoteGradeController extends BaseController $records[] = [ 'id' => $item['id'], 'name' => $item['name'], + 'game_name' => $baseGameName, 'grade_count' => 0, + 'month_range' => $monthRangeDisplay, 'reach_level' => $config['reach_level'], 'grade_name' => $grade['name'], 'grade_value' => $symbols[$grade['symbol']] . $grade['value'] @@ -131,6 +183,10 @@ class PromoteGradeController extends BaseController } } } + + $promoteService = new PromoteService(); + $baseGames = $promoteService->getVisibleBaseGames($loginPromote); + $this->assign('baseGames', $baseGames); $this->assign('records', $records); $this->display(); } @@ -138,6 +194,8 @@ class PromoteGradeController extends BaseController public function setting() { $this->checkSettingPermission(); + $loginPromote = $this->getLoginPromote(); + $id = I('id', 0); $setting = null; if ($id > 0) { @@ -148,6 +206,10 @@ class PromoteGradeController extends BaseController $setting['config'] = json_decode($setting['config'], true); } } + + $promoteService = new PromoteService(); + $baseGames = $promoteService->getVisibleBaseGames($loginPromote); + $this->assign('baseGames', $baseGames); $this->assign('setting', $setting); $this->display(); } diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index 0c3222223..7ed07e925 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -8,6 +8,8 @@ use Base\Repository\PromoteRepository; use Base\Repository\SpendRepository; use Base\Repository\UserRepository; use Base\Service\PromoteService; +use GuzzleHttp\Client; +use Base\Repository\GameRepository; /** * 前台首页控制器 @@ -1681,7 +1683,10 @@ class QueryController extends BaseController $roleLevelBegin = intval(I('role_level_begin', 0)); $roleLevelEnd = intval(I('role_level_end', 0)); $headmanPromoteId = I('headman_promote_id', 0); - $createTime = I('create_time', ''); + $createTime = I('create_time', date('Y-m-d') . ' 至 ' . date('Y-m-d', time()-7*24*3600)); + $lastSortName = trim(I('last_sort_name', '')); + $sortName = trim(I('sort_name', '')); + $sort = intval(I('sort', 1)); $promote = $this->getLoginPromote(); $levelPromote = $this->getLevelPromote(); @@ -1692,20 +1697,7 @@ class QueryController extends BaseController $map = []; $map['_string'] = '1=1'; - $map['_string'] .= ' and promote_id in (' . $subInSql . ')'; - /* $map[] = [ - '_logic' => 'or', - 'id' => $queryPromote['id'], - 'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'] - ]; - $ids = M('promote', 'tab_')->where($map)->getField('id', true); - - $map = []; - if (count($ids) > 0) { - $map = ['promote_id' => ['in', $ids]]; - } else { - $map['_string'] = '1<>1'; - } */ + $map['_string'] .= ' and role.promote_id in (' . $subInSql . ')'; if ($relationGameId != 0 || $sdkVersion != 0) { $gameIds = gameSearch($relationGameId, $sdkVersion); @@ -1743,26 +1735,69 @@ class QueryController extends BaseController if ($isSelf) { $map['promote_id'] = $queryPromote['id']; } - $query = M('user_play_info', 'tab_')->where($map)->order('create_time desc'); - list($records, $pagination, $count) = $this->paginate($query); - $countRow = M('user_play_info', 'tab_')->field(['count(distinct user_id) user_count'])->where($map)->find(); + $orderBy = 'create_time desc'; + $sortNameData = ['login_time', 'create_time', 'role_level', 'register_time', 'role.promote_account']; + 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; + } + } + + $columns = [ + 'user_account', + 'role.promote_account', + 'role.game_name', + 'user.device_number', + 'user.register_time', + 'user.register_ip', + 'user.login_time', + 'user.login_ip', + 'role.server_name', + 'role.sdk_version', + 'role.role_name', + 'role.role_level', + 'role.create_time', + 'role.play_time', + 'role.play_ip' + ]; + + $query = M('user_play_info', 'tab_') + ->field($columns) + ->alias('role') + ->join('tab_user user on role.user_id = user.id') + ->where($map) + ->order($orderBy); + $countQuery = clone $query; + + list($records, $pagination, $count) = $this->paginate($query->order($orderBy)); + + $countRow = $countQuery->field(['count(distinct user_id) user_count'])->find(); - $countMap = $map; $subSql = M('user', 'tab_')->field('id')->where(['is_repeat' => 0])->select(false); - $countMap['_string'] .= ' and user_id in (' . $subSql . ')'; - $uniqueCountRow = M('user_play_info', 'tab_')->field(['count(distinct user_id) user_count, count(*) count'])->where($countMap)->find(); + $map['_string'] = str_replace('role.promote_id', 'promote_id', $map['_string']) . ' and user_id in (' . $subSql . ')'; + $uniqueCountRow = M('user_play_info', 'tab_')->field(['count(distinct user_id) user_count, count(*) count'])->where($map)->find(); - $users = []; + /* $users = []; if (count($records) > 0) { $userIds = array_column($records, 'user_id'); $users = M('user', 'tab_')->field(['id', 'register_time', 'login_time', 'register_ip', 'login_ip', 'device_number'])->where(['id' => ['in', $userIds]])->select(); $users = index_by_column('id', $users); - } + } */ + + // var_dump($records);die(); foreach ($records as $key => $value) { - //订单隐藏算法 + //隐藏算法 $orderLen = strlen($value['user_account']); $strLen = 3; $hideChar = ''; @@ -1780,7 +1815,10 @@ class QueryController extends BaseController } $records[$key]['user_account'] = substr($value['user_account'], 0, $strLen) . $hideChar . substr($value['user_account'], $orderLen - $strLen); - if (isset($users[$value['user_id']])) { + $records[$key]['register_time'] = date('Y-m-d', $value['register_time']) . '
' . date('H:i:s', $value['register_time']); + $records[$key]['login_time'] = date('Y-m-d', $value['login_time']) . '
' . date('H:i:s', $value['login_time']); + + /* if (isset($users[$value['user_id']])) { $user = $users[$value['user_id']]; $records[$key]['register_time'] = date('Y-m-d', $user['register_time']) . '
' . date('H:i:s', $user['register_time']); $records[$key]['login_time'] = date('Y-m-d', $user['login_time']) . '
' . date('H:i:s', $user['login_time']); @@ -1793,7 +1831,7 @@ class QueryController extends BaseController $records[$key]['register_ip'] = '--'; $records[$key]['login_ip'] = '--'; $records[$key]['device_number'] = '--'; - } + } */ } $games = get_promote_serach_game(); @@ -1801,11 +1839,13 @@ class QueryController extends BaseController $this->assign('user_count', $countRow['user_count']); $this->assign('unique_user_count', $uniqueCountRow['user_count']); $this->assign('unique_count', $uniqueCountRow['count']); - + $this->assign('sort', $sort); + $this->assign('setdate', date('Y-m-d', $nowTime)); $this->assign('games', $games); $this->assign('records', $records); $this->assign('pagination', $pagination); $this->assign('count', $count); + $this->assign('createTime', $createTime); $this->display('userRoles'); } @@ -2772,4 +2812,241 @@ class QueryController extends BaseController $this->assign('initEndTime', $initEndTime); $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() + { + $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) { + + $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' => $queryPromote['id'], + '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); + } + } else { + $this->assign('error', $error); + } + + $baseGames = M('base_game', 'tab_')->select(); + + $this->assign('baseGames', $baseGames); + $this->assign('sortName', $sortName); + $this->assign('sort', $sort); + $this->assign('data', $data); + $this->assign('start', $start); + $this->assign('end', $end); + $this->display(); + } + + public function gameData() + { + $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; + } + + $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']; + 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; + } + } + + $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); + } + list($records, $pagination, $count) = $this->paginate($query); + + $gameRepository = new GameRepository(); + + $this->assign('games', $gameRepository->getChoiceGames()); + $this->assign('servers', $gameRepository->getServersByGameId($gameId)); + $this->assign('sort', $sort); + $this->assign('sortName', $sortName); + $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/PromoteGrade/index.html b/Application/Home/View/default/PromoteGrade/index.html index 7d619ae9c..889c8cb7e 100644 --- a/Application/Home/View/default/PromoteGrade/index.html +++ b/Application/Home/View/default/PromoteGrade/index.html @@ -39,6 +39,16 @@ +
+ +
@@ -63,7 +73,9 @@ 操作 -

暂无数据

+ + ' . $error . '': '

暂无数据

' ?> + @@ -82,7 +94,7 @@ {$record.amount} - 查看下级 + 查看下级 @@ -93,7 +105,7 @@
- 导出 + 导出 {$pagination}
diff --git a/Application/Home/View/default/PromoteGrade/setting.html b/Application/Home/View/default/PromoteGrade/setting.html index 635f0203b..c95df102a 100644 --- a/Application/Home/View/default/PromoteGrade/setting.html +++ b/Application/Home/View/default/PromoteGrade/setting.html @@ -61,6 +61,33 @@ + + * 对应游戏: + + + + + + 规则开始月份: + + + 仅可选月份 + + + + 规则截止月份: + + + 仅可选月份,不选则表示截止时间为永久 + + * 玩家角色达标等级: @@ -109,10 +136,18 @@ + + + + + + + + \ No newline at end of file diff --git a/Application/Home/View/default/Query/userRoles.html b/Application/Home/View/default/Query/userRoles.html index 6fd9e83ee..ecb8c5b46 100644 --- a/Application/Home/View/default/Query/userRoles.html +++ b/Application/Home/View/default/Query/userRoles.html @@ -1,6 +1,7 @@ + @@ -52,7 +66,7 @@
- +
@@ -61,6 +75,9 @@
+ + +
@@ -72,20 +89,70 @@ - + - + - + - - + + @@ -189,21 +256,32 @@ $(function() { var promoteUrl = "{:U('Query/getSubPromotes')}" initPromoteSelect(promoteUrl) - $('#submit').click(function () { - var url = $(this).attr('url'); - console.log(url); - var query = $('.jssearch').find('input').serialize(); - query += "&" + $('.jssearch').find('select').serialize(); - query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, ''); - query = query.replace(/^&/g, ''); - if (url.indexOf('?') > 0) { - url += '&' + query; - } else { - url += '?' + query; - } - window.location.href = url; + $('.sort').click(function () { + var element = $(this); + var sortName = element.attr('sort-name'); + var sort = parseInt($('#sort').val()); - }); + sort = (sort === 1) ? 2 : 1; + $('#sort').val(sort); + $('#sort_name').val(sortName); + $('#submit').trigger('click'); + }); + + $('#submit').click(function () { + var url = $(this).attr('url'); + console.log(url); + var query = $('.jssearch').find('input').serialize(); + query += "&" + $('.jssearch').find('select').serialize(); + query = query.replace(/(&|^)(\w*?\d*?\-*?_*?)*?=?((?=&)|(?=$))/g, ''); + query = query.replace(/^&/g, ''); + if (url.indexOf('?') > 0) { + url += '&' + query; + } else { + url += '?' + query; + } + window.location.href = url; + + }); }) \ No newline at end of file diff --git a/Application/Home/View/default/Query/userretention.html b/Application/Home/View/default/Query/userretention.html new file mode 100644 index 000000000..c5acc3c42 --- /dev/null +++ b/Application/Home/View/default/Query/userretention.html @@ -0,0 +1,295 @@ + + + + + + + +
+
+
+
当前位置:数据管理>用户留存率
+
+ + 用户留存率 +
+
+ +
+
玩家帐号推广账号推广账号 + + + + + + + + + + 游戏名称 设备码注册时间注册时间 + + + + + + + + + + 注册IP最近登录时间最近登录时间 + + + + + + + + + + 最近登录IP 平台 游戏区服 角色名等级创建时间等级 + + + + + + + + + + 创建时间 + + + + + + + + + +

暂无数据

+ + + + + + + + + + + + + + + + + + + + + + + + + + 0):?> + + + + + + + + + + + + + + + + + + + + + + + +
日期 + + + + + + + + + + 游戏名称渠道名称新增玩家 + + + + + + + + + + 1日留存 + + + + + + + + + + 2日留存 + + + + + + + + + + 3日留存 + + + + + + + + + + 4日留存 + + + + + + + + + + 5日留存 + + + + + + + + + + 6日留存 + + + + + + + + + + 7日留存 + + + + + + + + + + 15日留存 + + + + + + + + + + 30日留存 + + + + + + + + + +
+ ' . $error . '': '

暂无数据

' ?>
{$vo.date}{$vo.game_name}{$vo.promote_name}{$vo.register_count}{$vo['retention_day1']}%{$vo['retention_day2']}%{$vo['retention_day3']}%{$vo['retention_day4']}%{$vo['retention_day5']}%{$vo['retention_day6']}%{$vo['retention_day7']}%{$vo['retention_day15']}%{$vo['retention_day30']}%------------------
+ + +
+ + 导出 + +
+ +
+
+
+
+ +
+ + + + + + + + \ No newline at end of file diff --git a/Data/update.sql b/Data/update.sql index c1812dbf1..9949d5214 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -2674,4 +2674,10 @@ CREATE TABLE `tab_testing_game_setting` ( `create_time` int(11) NOT NULL DEFAULT '0', `update_time` int(11) NOT NULL DEFAULT '0', PRIMARY KEY (`id`) -) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='测试资源游戏设置'; \ No newline at end of file +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='测试资源游戏设置'; + + +ALTER TABLE `tab_promote_grade_setting` +ADD COLUMN `base_game_id` int(11) not NULL DEFAULT 0 COMMENT '游戏ID' AFTER `name`, +ADD COLUMN `month_begin` int(11) not NULL DEFAULT 0 COMMENT '规则截止月份' AFTER `base_game_id`, +ADD COLUMN `month_end` int(11) not NULL DEFAULT 0 COMMENT '规则开始月份' AFTER `month_begin`; \ No newline at end of file