From 80f76c4490d0834fc278b7f365d6e06199d09a29 Mon Sep 17 00:00:00 2001 From: chenxiaojun <956334972@qq.com> Date: Fri, 22 Nov 2019 01:04:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=B9=B3=E5=8F=B0->=E6=95=B0?= =?UTF-8?q?=E6=8D=AE=E7=AE=A1=E7=90=86--=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Base/Repository/UserRepository.class.php | 44 ++++++++++++++----- .../Home/Controller/QueryController.class.php | 2 +- .../Home/View/default/Query/userRoles.html | 4 +- 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/Application/Base/Repository/UserRepository.class.php b/Application/Base/Repository/UserRepository.class.php index 3e42e4052..e3ad78ade 100644 --- a/Application/Base/Repository/UserRepository.class.php +++ b/Application/Base/Repository/UserRepository.class.php @@ -133,8 +133,13 @@ class UserRepository $dayList = $params['dayList'] ?? []; $params['time_column'] = 'create_time'; $conditions = $this->getDayGroupConditions($params); - $items = M('login_daily_record', 'tab_')->field('FROM_UNIXTIME(create_time, "%Y-%m-%d") as day, count(DISTINCT user_id, game_id) as count') + $subQuery = M('login_daily_record', 'tab_')->field('FROM_UNIXTIME(create_time, "%Y-%m-%d") as day,count(DISTINCT user_id) as count') ->where($conditions) + ->group('game_id') + ->buildSql(); + $items = M()->field('*,sum(count) as count') + ->table($subQuery) + ->alias('a') ->group('day') ->select(); @@ -294,8 +299,13 @@ class UserRepository $params['time_column'] = 'create_time'; $conditions = $this->getCreateRoleConditions($params); - $items = M('user_play_info', 'tab_')->field('count(distinct game_id,user_id) count, FROM_UNIXTIME(create_time, "%Y-%m-%d") as day') + $subQuery = M('user_play_info', 'tab_')->field('FROM_UNIXTIME(create_time, "%Y-%m-%d") as day,count(DISTINCT user_id) as count') ->where($conditions) + ->group('game_id') + ->buildSql(); + $items = M()->field('*,sum(count) as count') + ->table($subQuery) + ->alias('a') ->group('day') ->select(); return $this->assembleRecords($items, $dayList, 'count'); @@ -346,10 +356,14 @@ 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, FROM_UNIXTIME(create_time, '%Y-%m-%d') as day, - (" . $sql . ") as num") + $subQuery = $model->field('FROM_UNIXTIME(create_time, "%Y-%m-%d") as day,count(DISTINCT user_id) as count') ->where($conditions) - ->group("day") + ->group('game_id') + ->buildSql(); + $items = M()->field("*,sum(count) as count,(" . $sql . ") as num") + ->table($subQuery) + ->alias('a') + ->group('day') ->having('num = 0') ->select(); return $this->assembleRecords($items, $dayList, 'count'); @@ -411,10 +425,14 @@ 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, FROM_UNIXTIME(create_time, '%Y-%m-%d') as day, - (" . $sql . ") as num") + $subQuery = $model->field('FROM_UNIXTIME(create_time, "%Y-%m-%d") as day,count(DISTINCT create_device_number) as count') ->where($conditions) - ->group("day") + ->group('game_id') + ->buildSql(); + $items = M()->field("*,sum(count) as count,(" . $sql . ") as num") + ->table($subQuery) + ->alias('a') + ->group('day') ->having('num = 0') ->select(); return $this->assembleRecords($items, $dayList, 'count'); @@ -476,10 +494,14 @@ 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, FROM_UNIXTIME(create_time, '%Y-%m-%d') as day, - (" . $sql . ") as num") + $subQuery = $model->field('FROM_UNIXTIME(create_time, "%Y-%m-%d") as day,count(DISTINCT create_ip) as count') ->where($conditions) - ->group("day") + ->group('game_id') + ->buildSql(); + $items = M()->field("*,sum(count) as count,(" . $sql . ") as num") + ->table($subQuery) + ->alias('a') + ->group('day') ->having('num = 0') ->select(); return $this->assembleRecords($items, $dayList, 'count'); diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index 44958325c..4d0f5061b 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -1834,7 +1834,7 @@ class QueryController extends BaseController ->having('recharge_cost > 0') ->order('play_time desc') ->buildSql(); - $query = M()->field(' * ') + $query = M()->field('*') ->table($subQuery) ->alias('a') ->order($orderBy); diff --git a/Application/Home/View/default/Query/userRoles.html b/Application/Home/View/default/Query/userRoles.html index 5ceef8dfb..81e70c274 100644 --- a/Application/Home/View/default/Query/userRoles.html +++ b/Application/Home/View/default/Query/userRoles.html @@ -60,7 +60,7 @@ -