From 46f1ac0807f7fc28a32b1c968bfffdb57c1e9591 Mon Sep 17 00:00:00 2001 From: chenxiaojun <956334972@qq.com> Date: Mon, 25 Nov 2019 19:50:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=B9=B3=E5=8F=B0->=E6=B8=B8?= =?UTF-8?q?=E6=88=8F=E7=AE=A1=E7=90=86->=E5=85=85=E5=80=BC=E7=8E=A9?= =?UTF-8?q?=E5=AE=B6--=E8=B0=83=E6=95=B4=20=E8=87=AA=E5=8A=A8=E8=84=9A?= =?UTF-8?q?=E6=9C=AC->=E7=8E=A9=E5=AE=B6=E8=A7=92=E8=89=B2=E5=85=85?= =?UTF-8?q?=E5=80=BC=E6=95=B0=E6=8D=AE=E7=BB=9F=E8=AE=A1--=E8=B0=83?= =?UTF-8?q?=E6=95=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Controller/AutoController.class.php | 6 +- .../Home/Controller/QueryController.class.php | 91 ++++++------------- Data/update.sql | 8 ++ 3 files changed, 38 insertions(+), 67 deletions(-) diff --git a/Application/Admin/Controller/AutoController.class.php b/Application/Admin/Controller/AutoController.class.php index 8bdd063ae..55602bbcb 100644 --- a/Application/Admin/Controller/AutoController.class.php +++ b/Application/Admin/Controller/AutoController.class.php @@ -923,15 +923,17 @@ public function auto_rrdae(){ $map['pay_status'] = 1; $map['pay_game_status'] = 1; $map['game_player_id'] = ['gt', 0]; - $field = 'FROM_UNIXTIME(pay_time, "%Y-%m-%d") as day,game_id,server_id,game_player_id,sum(pay_amount) as recharge_cost,count(id) as recharge_count'; + $field = 'FROM_UNIXTIME(pay_time, "%Y-%m-%d") as day,promote_id,user_id,game_id,server_id,game_player_id,sum(pay_amount) as recharge_cost,count(id) as recharge_count'; $spendData = M('spend', 'tab_')->field($field) ->where($map) - ->group('day,game_player_id,server_id,game_id') + ->group('day,game_player_id,server_id,game_id,user_id,promote_id') ->select(); if (!empty($spendData)) { $data = []; foreach ($spendData as $list) { + $save['promote_id'] = $list['promote_id']; + $save['user_id'] = $list['user_id']; $save['game_id'] = $list['game_id']; $save['server_id'] = $list['server_id']; $save['role_id'] = $list['game_player_id']; diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index 50e8def6c..a81251bfc 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -1726,6 +1726,7 @@ class QueryController extends BaseController $begTime = strtotime($initBegTime); $endTime = strtotime($initEndTime); $endTime += 3600 * 24; + $nowTime = strtotime(date('Y-m-d 00:00:00', time())); $promote = $this->getLoginPromote(); $levelPromote = $this->getLevelPromote(); @@ -1735,50 +1736,38 @@ class QueryController extends BaseController $pagination = ''; $count = 0; if (intval($endTime - $begTime) / (24 * 3600) <= 31) { - $map = [ - '_logic' => 'or', - 'id' => $queryPromote['id'], - 'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'] - ]; + $map['chain'] = ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']; $ids = M('promote', 'tab_')->where($map)->getField('id', true); + $ids[] = $queryPromote['id']; - $map = []; - if (count($ids) > 0) { - $map = ['promote_id' => ['in', $ids]]; - } else { - $map['_string'] = '1<>1'; - } + $map = ['uc.promote_id' => ['in', $ids]]; + $subMap = ['promote_id' => ['in', $ids]]; - $subMap = []; if ($relationGameId != 0) { $gameMap['relation_game_id'] = $relationGameId; if ($sdkVersion != 0) { $gameMap['sdk_version'] = $sdkVersion; } $gameId = M('game', 'tab_')->where($gameMap)->getField('id', true); - $map['game_id'] = ['in', $gameId]; + + $map['uc.game_id'] = ['in', $gameId]; $subMap['game_id'] = ['in', $gameId]; } if ($serverId != 0) { - $map['server_id'] = $serverId; + $map['uc.server_id'] = $serverId; $subMap['server_id'] = $serverId; } if ($roleName != '') { - $map['role_name'] = ['like', '%' . $roleName . '%']; + $map['ui.role_name'] = ['like', $roleName . '%']; } if ($userAccount != '') { - $map['user_account'] = ['like', '%' . $userAccount . '%']; + $map['ui.user_account'] = ['like', $userAccount . '%']; } if ($isSelf) { - $map['promote_id'] = $queryPromote['id']; + $map['uc.promote_id'] = $queryPromote['id']; } $subMap['create_time'] = ['between', [$begTime, $endTime - 1]]; - $roleIdMap = $subMap; - $roleIds = M('user_play_data_count', 'tab_')->where($roleIdMap)->group('role_id')->getField('role_id', true); - if (count($roleIds) > 0) { - $map['role_id'] = ['in', $roleIds]; - } if ($costBegin != '' || $costEnd != '') { $having = ''; if ($costBegin != '' && $costEnd != '') { @@ -1793,10 +1782,10 @@ class QueryController extends BaseController ->group('game_id,server_id,role_id') ->having($having) ->buildSql(); - $map['_string'] = 'role_id in(' . $subQuery . ')'; + $map['_string'] = 'ui.role_id in(' . $subQuery . ')'; } - $orderBy = 'play_time desc'; + $orderBy = 'ui.play_time desc'; if (!empty($sortName)) { if (in_array($sortName, $sortNameData)) { $desc = ' desc'; @@ -1819,53 +1808,25 @@ class QueryController extends BaseController } } - $spendMap['uc.create_time'] = ['between', [$begTime, $endTime - 1]]; - $spendMap['_string'] = 'uc.game_id = tab_user_play_info.game_id and uc.server_id = tab_user_play_info.server_id and uc.role_id = tab_user_play_info.role_id'; - $sqlCost = M('user_play_data_count', 'tab_')->alias('uc') - ->field('sum(uc.recharge_cost) cost') - ->where($spendMap) - ->buildSql(); - $sqlCount = M('user_play_data_count', 'tab_')->alias('uc') - ->field('sum(uc.recharge_count) count') - ->where($spendMap) - ->buildSql(); - $spendMap['uc.create_time'] = ['between', [strtotime(date('Y-m-d 00:00:00')), strtotime(date('Y-m-d 23:59:59'))]]; - $sqlTodayCost = M('user_play_data_count', 'tab_')->alias('uc') - ->field('sum(uc.recharge_count) count') - ->where($spendMap) - ->buildSql(); - $subQuery = M('user_play_info', 'tab_') - ->field("*,$sqlCost as recharge_cost,$sqlCount as recharge_count,$sqlTodayCost as recharge_cost_today") + $map['uc.create_time'] = ['between', [$begTime, $endTime - 1]]; + $fieldUC = "sum(uc.recharge_cost) recharge_cost,sum(uc.recharge_count) recharge_count,sum(if(uc.create_time = {$nowTime},uc.recharge_cost,0)) as recharge_cost_today"; + $fieldUI = "ui.user_account,ui.game_name,ui.role_name,ui.role_level,ui.server_name,ui.play_time,ui.play_ip,ui.promote_account,ui.sdk_version"; + $field = $fieldUC . ',' . $fieldUI; + $subQuery = M('user_play_data_count', 'tab_')->alias('uc') + ->field($field) + ->join('tab_user_play_info as ui on ui.promote_id = uc.promote_id and ui.game_id = uc.game_id and ui.server_id = uc.server_id and ui.role_id = uc.role_id') ->where($map) - ->having('recharge_cost > 0') - ->order('play_time desc') + ->group('uc.role_id,uc.server_id,uc.game_id') ->buildSql(); - $query = M()->field('*') + $query = M()->alias('record') ->table($subQuery) - ->alias('a') ->order($orderBy); - list($roles, $pagination, $count) = $this->paginate($query); + list($records, $pagination, $count) = $this->paginate($query); - foreach ($roles as $role) { - $records[] = [ - 'user_account' => encryption($role['user_account']), - 'game_name' => $role['game_name'], - 'role_name' => $role['role_name'], - 'role_id' => $role['role_id'], - 'role_level' => $role['role_level'], - 'server_id' => $role['server_id'], - 'server_name' => $role['server_name'], - 'recharge_cost' => empty($role['recharge_cost']) ? 0 : $role['recharge_cost'], - 'recharge_count' => empty($role['recharge_count']) ? 0 : $role['recharge_count'], - 'recharge_cost_today' => empty($role['recharge_cost_today']) ? 0 : $role['recharge_cost_today'], - 'play_time' => $role['play_time'], - 'play_ip' => $role['play_ip'], - 'promote_id' => $role['promote_id'], - 'promote_account' => $role['promote_account'], - 'sdk_version' => $role['sdk_version'], - 'unlogin_day' => intval((strtotime(date('Y-m-d 00:00:00')) - strtotime(date('Y-m-d 00:00:00', $role['play_time']))) / (24 * 3600)) - ]; + foreach ($records as &$list) { + $list['user_account'] = encryption($list['user_account']); + $list['unlogin_day'] = intval((strtotime(date('Y-m-d 00:00:00')) - strtotime(date('Y-m-d 00:00:00', $list['play_time']))) / (24 * 3600)); } } diff --git a/Data/update.sql b/Data/update.sql index c4a608160..1a0e4c31a 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -547,3 +547,11 @@ ALTER TABLE `tab_withdraw` ADD COLUMN `last_up_update_time` int(10) NOT NULL DEFAULT 0 COMMENT '最后更新时间', ADD COLUMN `spend_ids` longtext NOT NULL COMMENT '充值订单id'; +--玩家角色数据统计表--添加玩家ID和推广员ID +ALTER TABLE `tab_user_play_data_count` +ADD COLUMN `user_id` int(11) NOT NULL DEFAULT 0 COMMENT '玩家ID', +ADD COLUMN `promote_id` int(11) NOT NULL DEFAULT 0 COMMENT '推广员ID'; + +ALTER TABLE `tab_user_play_data_count` +DROP INDEX `search`, +ADD INDEX `search`(`user_id`, `promote_id`, `game_id`, `server_id`, `role_id`, `create_time`) USING BTREE; \ No newline at end of file