From e2fa14c1c879e17f5a1a4b42da9d40c180cbd9d1 Mon Sep 17 00:00:00 2001 From: chenxiaojun <956334972@qq.com> Date: Mon, 11 Nov 2019 17:35:58 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=B9=B3=E5=8F=B0->?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=AE=A1=E7=90=86->=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B1=87=E6=80=BB->=E5=90=88=E8=AE=A1--=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Base/Repository/SpendRepository.class.php | 32 +++++ .../Base/Repository/UserRepository.class.php | 122 ++++++++++++------ .../Home/Controller/QueryController.class.php | 40 +++--- 3 files changed, 143 insertions(+), 51 deletions(-) diff --git a/Application/Base/Repository/SpendRepository.class.php b/Application/Base/Repository/SpendRepository.class.php index 9f7e41df2..fa0260cd5 100644 --- a/Application/Base/Repository/SpendRepository.class.php +++ b/Application/Base/Repository/SpendRepository.class.php @@ -171,6 +171,15 @@ class SpendRepository return $this->assembleRecords($items, $gameIds, 'amount', 'game_id'); } + /** + * 按游戏统计付款总额--cxj + */ + public function getPayAmountByGameAndType($params) + { + $conditions = $this->getGameGroupConditionsNew($params); + return M('spend', 'tab_')->where($conditions)->sum('pay_amount'); + } + /** * 按天统计付款用户数 */ @@ -219,6 +228,15 @@ class SpendRepository return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); } + /** + * 按游戏统计付款次数--cxj + */ + public function getPayCountByGame($params) + { + $conditions = $this->getGameGroupConditions($params); + return M('spend', 'tab_')->where($conditions)->count(); + } + /** * 游戏统计付款用户数 */ @@ -231,6 +249,20 @@ class SpendRepository return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); } + /** + * 游戏统计付款用户数--cxj + */ + public function getPayUserCountByGame($params) + { + $conditions = $this->getGameGroupConditions($params); + $sql = M('spend', 'tab_')->field('distinct game_id, user_id') + ->where($conditions) + ->fetchSql(true) + ->select(); + $model = new \Think\Model(); + return $model->query("select count(*) as num from ($sql) as t")[0]['num']; + } + /** * 按照时间分组统计新增付费用户数 */ diff --git a/Application/Base/Repository/UserRepository.class.php b/Application/Base/Repository/UserRepository.class.php index f2dc740cd..bb2628551 100644 --- a/Application/Base/Repository/UserRepository.class.php +++ b/Application/Base/Repository/UserRepository.class.php @@ -66,9 +66,11 @@ class UserRepository $conditions = []; $conditions['promote_id'] = ['in', $ids]; $conditions[$params['time_column']] = ['between', [$beginTime, $endTime]]; - $conditions['game_id'] = ['in', $gameIds]; - if (!empty($params['server_id'])) { - $conditions['server_id'] = $params['server_id']; + if (!empty($gameIds)) { + $conditions['game_id'] = ['in', $gameIds]; + if (!empty($params['server_id'])) { + $conditions['server_id'] = $params['server_id']; + } } return $conditions; @@ -154,12 +156,21 @@ class UserRepository $gameIds = $params['game_ids'] ?? []; $params['time_column'] = 'login_time'; $conditions = $this->getGameGroupConditions($params); - $items = M('user_login_record', 'tab_')->field('game_id, count(DISTINCT user_id) as count') - ->where($conditions) - ->group('game_id') - ->select(); + if (isset($params['all_data'])) { + $sql = M('user_login_record', 'tab_')->field('distinct game_id, user_id') + ->where($conditions) + ->fetchSql(true) + ->select(); + $model = new \Think\Model(); + return $model->query("select count(*) as num from ($sql) as t")[0]['num']; + } else { + $items = M('user_login_record', 'tab_')->field('game_id, count(DISTINCT user_id) as count') + ->where($conditions) + ->group('game_id') + ->select(); - return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + } } /** @@ -268,11 +279,17 @@ class UserRepository $params['time_column'] = 'create_time'; $conditions = $this->getCreateRoleByGameConditions($params); - $items = M('user_play_info', 'tab_')->field('count(*) count, game_id') - ->where($conditions) - ->group('game_id') - ->select(); - return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + if (isset($params['all_data'])) { + return M('user_play_info', 'tab_') + ->where($conditions) + ->count(); + } else { + $items = M('user_play_info', 'tab_')->field('count(*) count, game_id') + ->where($conditions) + ->group('game_id') + ->select(); + return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + } } /** @@ -300,11 +317,20 @@ class UserRepository $params['time_column'] = 'create_time'; $conditions = $this->getCreateRoleByGameConditions($params); - $items = M('user_play_info', 'tab_')->field('count(distinct game_id,user_id) count, game_id') - ->where($conditions) - ->group('game_id') - ->select(); - return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + if (isset($params['all_data'])) { + $sql = M('user_play_info', 'tab_')->field('distinct game_id, user_id') + ->where($conditions) + ->fetchSql(true) + ->select(); + $model = new \Think\Model(); + return $model->query("select count(*) as num from ($sql) as t")[0]['num']; + } else { + $items = M('user_play_info', 'tab_')->field('count(distinct user_id) count, game_id') + ->where($conditions) + ->group('game_id') + ->select(); + return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + } } /** @@ -356,12 +382,20 @@ class UserRepository ->where("ti.user_id = user_id and ti.game_id = game_id and ti.create_time < " . $params['begin_time']) ->fetchSql(true) ->count(); - $items = $model->field("count(distinct game_id,user_id) count, game_id, (" . $sql . ") as num") - ->where($conditions) - ->group("game_id") - ->having('num = 0') - ->select(); - return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + if (isset($params['all_data'])) { + return count($model->field("game_id, (" . $sql . ") as num") + ->where($conditions) + ->group('game_id, user_id') + ->having('num = 0') + ->select()); + } else { + $items = $model->field("count(distinct user_id) count, game_id, (" . $sql . ") as num") + ->where($conditions) + ->group("game_id") + ->having('num = 0') + ->select(); + return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + } } /** @@ -413,12 +447,20 @@ class UserRepository ->where("ti.create_device_number = create_device_number and ti.game_id = game_id and ti.create_time < " . $params['begin_time']) ->fetchSql(true) ->count(); - $items = $model->field("count(distinct game_id,create_device_number) count, game_id, (" . $sql . ") as num") - ->where($conditions) - ->group("game_id") - ->having('num = 0') - ->select(); - return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + if (isset($params['all_data'])) { + return count($model->field("game_id, (" . $sql . ") as num") + ->where($conditions) + ->group('game_id, create_device_number') + ->having('num = 0') + ->select()); + } else { + $items = $model->field("count(distinct game_id,create_device_number) count, game_id, (" . $sql . ") as num") + ->where($conditions) + ->group("game_id") + ->having('num = 0') + ->select(); + return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + } } /** @@ -470,11 +512,19 @@ class UserRepository ->where("ti.create_ip = create_ip and ti.game_id = game_id and ti.create_time < " . $params['begin_time']) ->fetchSql(true) ->count(); - $items = $model->field("count(distinct game_id,create_ip) count, game_id, (" . $sql . ") as num") - ->where($conditions) - ->group("game_id") - ->having('num = 0') - ->select(); - return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + if (isset($params['all_data'])) { + return count($model->field("game_id, (" . $sql . ") as num") + ->where($conditions) + ->group('game_id, create_ip') + ->having('num = 0') + ->select()); + } else { + $items = $model->field("count(distinct game_id,create_ip) count, game_id, (" . $sql . ") as num") + ->where($conditions) + ->group("game_id") + ->having('num = 0') + ->select(); + return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); + } } } \ No newline at end of file diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index c73166fe7..ed08fdd47 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -1265,6 +1265,13 @@ class QueryController extends BaseController ->join($serverJoin) ->where($map) ->count('distinct a.game_id'); + $allGameIs = M('Apply', 'tab_')->alias('a') + ->field('distinct a.game_id') + ->join('tab_game as g on g.id = a.game_id') + ->join($serverJoin) + ->where($map) + ->select(); + $allGameIs = array_column($allGameIs, 'game_id'); $records = []; $allData['role_num'] = 0; @@ -1327,22 +1334,25 @@ class QueryController extends BaseController 'spend_discount' => 0, 'spend_voucher' => 0, ]; - - $allData['role_num'] += $roleNumList[$gameId]; - $allData['user_num'] += $userNumList[$gameId]; - $allData['new_user_num'] += $newUserNumList[$gameId]; - $allData['new_device_num'] += $newDeviceNumList[$gameId]; - $allData['new_ip_num'] += $newIpNumList[$gameId]; - $allData['login_user_num'] += $loginUserNumList[$gameId]; - $allData['spend_user_num'] += $spendUserNumList[$gameId]; - $allData['spend_num'] += $spendNumList[$gameId]; - $allData['spend_all_amount'] = bcadd($allData['spend_all_amount'], $spendAllAmountList[$gameId], 2); - $allData['spend_cash'] = bcadd($allData['spend_cash'], $spendCashList[$gameId], 2); - $allData['spend_generic'] = bcadd($allData['spend_generic'], $spendGenericList[$gameId], 2); - $allData['spend_binding'] = bcadd($allData['spend_binding'], $spendBindingList[$gameId], 2); - $allData['spend_discount'] = bcadd($allData['spend_discount'], 0, 2); - $allData['spend_voucher'] = bcadd($allData['spend_voucher'], 0, 2); } + $params['all_data'] = 1; + $params['game_ids'] = $allGameIs; + $allData['role_num'] = $userRepository->getCreateRoleCountByGame($params);//创角数 + $allData['user_num'] = $userRepository->getCreateRoleUserCountByGame($params);//创角用户 + $allData['new_user_num'] = $userRepository->getNewCreateRoleUserCountByGame($params);//新创角用户 + $allData['new_device_num'] = $userRepository->getNewCreateRoleDeviceCountByGame($params);//新创角设备 + $allData['new_ip_num'] = $userRepository->getNewCreateRoleIpCountByGame($params);//新创角IP + $allData['login_user_num'] = $userRepository->getLoginCountGroupByGame($params);//登录用户数 + $allData['spend_user_num'] = $spendRepository->getPayUserCountByGame($params);//充值人数 + $allData['spend_num'] = $spendRepository->getPayCountByGame($params);//充值次数 + unset($params['pay_way']); + $allData['spend_all_amount'] = $spendRepository->getPayAmountByGameAndType($params);//充值总额 + $params['pay_way'] = ['in', '1,2,3,4,5,6']; + $allData['spend_cash'] = $spendRepository->getPayAmountByGameAndType($params);//现金充值 + $params['pay_way'] = 0; + $allData['spend_generic'] = $spendRepository->getPayAmountByGameAndType($params);//通用币充值 + $params['pay_way'] = -1; + $allData['spend_binding'] = $spendRepository->getPayAmountByGameAndType($params);//绑定币充值 } } From ee97f422611bfd8113a394d52b821fe4d869bce8 Mon Sep 17 00:00:00 2001 From: chenxiaojun <956334972@qq.com> Date: Mon, 11 Nov 2019 17:40:31 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=B9=B3=E5=8F=B0->?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=AE=A1=E7=90=86->=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=E6=B1=87=E6=80=BB--=E6=A3=80=E7=B4=A2=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Application/Home/Controller/QueryController.class.php | 3 ++- Application/Home/View/default/Query/summary.html | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index ed08fdd47..bd72999e8 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -1194,6 +1194,7 @@ class QueryController extends BaseController $page = intval(I('get.p', 1)); $page = $page ? $page : 1; //默认显示第一页数据arraypage $row = intval(I('get.row', 10)); + $ownId = intval(I('own_id'), 0);//本账号 $relationGameId = intval(I('relation_game_id', 0)); $sdkVersion = intval(I('sdk_version', 0)); $serverId = intval(I('server_id'), 0); @@ -1216,13 +1217,13 @@ class QueryController extends BaseController $parameter['level_promote_4'] = $levelPromote[2]; $parameter['begtime'] = $initBegTime; $parameter['endtime'] = $initEndTime; + $parameter['own_id'] = $ownId; $parameter['p'] = $page; $parameter['row'] = $row; $loginPromote = $this->getLoginPromote(); $map = []; - $ownId = intval(I('own_id'), 0);//本账号 if ($ownId) { $map['a.promote_id'] = $queryPromote['id']; $params['promote_ids'] = $queryPromote['id']; diff --git a/Application/Home/View/default/Query/summary.html b/Application/Home/View/default/Query/summary.html index 68ee66fae..45dd0de9a 100644 --- a/Application/Home/View/default/Query/summary.html +++ b/Application/Home/View/default/Query/summary.html @@ -81,7 +81,7 @@