diff --git a/Application/Base/Repository/PromoteRepository.class.php b/Application/Base/Repository/PromoteRepository.class.php index f899e325e..b02423985 100644 --- a/Application/Base/Repository/PromoteRepository.class.php +++ b/Application/Base/Repository/PromoteRepository.class.php @@ -19,13 +19,10 @@ class PromoteRepository { } /** - * 获取指定推广员底下的角色创建数 + * 获取业绩公共map */ - public function getCreateRoleCountByIds(array $ids, array $params = []) + private function getPublicAchievementMap($ids, $params) { - if (count($ids) == 0) { - return []; - } $isContainSubs = false; if (isset($params['isContainSubs']) && $params['isContainSubs']) { $isContainSubs = true; @@ -36,9 +33,6 @@ class PromoteRepository { if ($isContainSubs) { $map['promote_id'] = ['in', array_merge($ids, array_keys($params['basicPromotes']))]; } - if (isset($params['begin_time']) && isset($params['begin_time'])) { - $map['create_time'] = ['between', [$params['begin_time'], $params['end_time']]]; - } if (isset($params['game_id'])) { $map['game_id'] = $params['game_id']; } @@ -48,6 +42,21 @@ class PromoteRepository { if (isset($params['sdk_version'])) { $map['sdk_version'] = $params['sdk_version']; } + if (isset($params['begin_time']) && isset($params['begin_time'])) { + $map['create_time'] = ['between', [$params['begin_time'], $params['end_time']]]; + } + return $map; + } + + /** + * 获取指定推广员底下的角色创建数 + */ + public function getCreateRoleCountByIds(array $ids, array $params = []) + { + if (count($ids) == 0) { + return []; + } + $map = $this->getPublicAchievementMap($ids, $params); $items = M('user_play_info', 'tab_')->field(['count(*) count', 'promote_id'])->where($map)->group('promote_id')->select(); $records = []; foreach ($items as $item) { @@ -75,27 +84,7 @@ class PromoteRepository { if (count($ids) == 0) { return []; } - $isContainSubs = false; - if (isset($params['isContainSubs']) && $params['isContainSubs']) { - $isContainSubs = true; - } - $map = []; - $map['promote_id'] = ['in', $ids]; - if ($isContainSubs) { - $map['promote_id'] = ['in', array_merge($ids, array_keys($params['basicPromotes']))]; - } - if (isset($params['begin_time']) && isset($params['begin_time'])) { - $map['create_time'] = ['between', [$params['begin_time'], $params['end_time']]]; - } - if (isset($params['game_id'])) { - $map['game_id'] = $params['game_id']; - } - if (isset($params['server_id'])) { - $map['server_id'] = $params['server_id']; - } - if (isset($params['sdk_version'])) { - $map['sdk_version'] = $params['sdk_version']; - } + $map = $this->getPublicAchievementMap($ids, $params); $items = M('user_play_info', 'tab_')->field(['count(distinct user_id) count', 'promote_id'])->where($map)->group('promote_id')->select(); $records = []; @@ -121,6 +110,36 @@ class PromoteRepository { */ public function getNewCreateRoleDeviceCountByIds(array $ids, array $params = []) { + if (count($ids) == 0) { + return []; + } + $map = $this->getPublicAchievementMap($ids, $params); + + $subMap = $map; + if (isset($params['begin_time']) && isset($params['begin_time'])) { + $subMap['create_time'] = ['lt', $params['begin_time']]; + } + + $subQuery = M('user_play_info', 'tab_')->field('create_device_number')->group('create_device_number')->where($subMap)->buildSql(); + $map['create_device_number'] = ['exp', ' not in (' . $subQuery . ')']; + $inQuery = M('user_play_info', 'tab_')->field('create_device_number')->group('create_device_number')->where($map)->buildSql(); + + $resultMap = ['create_device_number' => ['exp', ' in (' . $inQuery . ')']]; + $items = M('user_play_info', 'tab_')->field(['count(*) count', 'promote_id'])->where($resultMap)->group('promote_id')->select(); + + $records = []; + foreach ($items as $item) { + $promoteId = $item['promote_id']; + if (isset($params['basicPromotes'][$item['promote_id']])) { + $promoteId = $params['basicPromotes'][$item['promote_id']]; + } + if (isset($records[$promoteId])) { + $records[$promoteId] += $item['count']; + } else { + $records[$promoteId] = $item['count']; + } + } + $records = $this->assembleZero($ids, [], 0); return $records; } @@ -130,6 +149,36 @@ class PromoteRepository { */ public function getNewCreateRoleIpCountByIds(array $ids, array $params = []) { + if (count($ids) == 0) { + return []; + } + $map = $this->getPublicAchievementMap($ids, $params); + + $subMap = $map; + if (isset($params['begin_time']) && isset($params['begin_time'])) { + $subMap['create_time'] = ['lt', $params['begin_time']]; + } + + $subQuery = M('user_play_info', 'tab_')->field('create_ip')->group('create_ip')->where($subMap)->buildSql(); + $map['create_ip'] = ['exp', ' not in (' . $subQuery . ')']; + $inQuery = M('user_play_info', 'tab_')->field('create_ip')->group('create_ip')->where($map)->buildSql(); + + $resultMap = ['create_ip' => ['exp', ' in (' . $inQuery . ')']]; + $items = M('user_play_info', 'tab_')->field(['count(*) count', 'promote_id'])->where($resultMap)->group('promote_id')->select(); + + $records = []; + foreach ($items as $item) { + $promoteId = $item['promote_id']; + if (isset($params['basicPromotes'][$item['promote_id']])) { + $promoteId = $params['basicPromotes'][$item['promote_id']]; + } + if (isset($records[$promoteId])) { + $records[$promoteId] += $item['count']; + } else { + $records[$promoteId] = $item['count']; + } + } + $records = $this->assembleZero($ids, [], 0); return $records; } @@ -139,6 +188,36 @@ class PromoteRepository { */ public function getNewCreateRoleUserCountByIds(array $ids, array $params = []) { + if (count($ids) == 0) { + return []; + } + $map = $this->getPublicAchievementMap($ids, $params); + + $subMap = $map; + if (isset($params['begin_time']) && isset($params['begin_time'])) { + $subMap['create_time'] = ['lt', $params['begin_time']]; + } + + $subQuery = M('user_play_info', 'tab_')->field('user_id')->group('user_id')->where($subMap)->buildSql(); + $map['user_id'] = ['exp', ' not in (' . $subQuery . ')']; + $inQuery = M('user_play_info', 'tab_')->field('user_id')->group('user_id')->where($map)->buildSql(); + + $resultMap = ['user_id' => ['exp', ' in (' . $inQuery . ')']]; + $items = M('user_play_info', 'tab_')->field(['count(*) count', 'promote_id'])->where($resultMap)->group('promote_id')->select(); + + $records = []; + foreach ($items as $item) { + $promoteId = $item['promote_id']; + if (isset($params['basicPromotes'][$item['promote_id']])) { + $promoteId = $params['basicPromotes'][$item['promote_id']]; + } + if (isset($records[$promoteId])) { + $records[$promoteId] += $item['count']; + } else { + $records[$promoteId] = $item['count']; + } + } + $records = $this->assembleZero($ids, [], 0); return $records; } @@ -151,27 +230,7 @@ class PromoteRepository { if (count($ids) == 0) { return []; } - $isContainSubs = false; - if (isset($params['isContainSubs']) && $params['isContainSubs']) { - $isContainSubs = true; - } - $map = []; - $map['promote_id'] = ['in', $ids]; - if ($isContainSubs) { - $map['promote_id'] = ['in', array_merge($ids, array_keys($params['basicPromotes']))]; - } - if (isset($params['begin_time']) && isset($params['begin_time'])) { - $map['login_time'] = ['between', [$params['begin_time'], $params['end_time']]]; - } - if (isset($params['game_id'])) { - $map['game_id'] = $params['game_id']; - } - if (isset($params['server_id'])) { - $map['server_id'] = $params['server_id']; - } - if (isset($params['sdk_version'])) { - $map['sdk_version'] = $params['sdk_version']; - } + $map = $this->getPublicAchievementMap($ids, $params); $items = M('user', 'tab_')->field(['count(*) count', 'promote_id'])->where($map)->group('promote_id')->select(); $records = []; @@ -200,26 +259,7 @@ class PromoteRepository { if (count($ids) == 0) { return []; } - $isContainSubs = false; - if (isset($params['isContainSubs']) && $params['isContainSubs']) { - $isContainSubs = true; - } - $map = ['pay_status' => 1, 'promote_id' => ['in', $ids]]; - if ($isContainSubs) { - $map['promote_id'] = ['in', array_merge($ids, array_keys($params['basicPromotes']))]; - } - if (isset($params['begin_time']) && isset($params['begin_time'])) { - $map['pay_time'] = ['between', [$params['begin_time'], $params['end_time']]]; - } - if (isset($params['game_id'])) { - $map['game_id'] = $params['game_id']; - } - if (isset($params['server_id'])) { - $map['server_id'] = $params['server_id']; - } - if (isset($params['sdk_version'])) { - $map['sdk_version'] = $params['sdk_version']; - } + $map = $this->getPublicAchievementMap($ids, $params); $items = M('spend', 'tab_')->field(['count(*) count', 'promote_id'])->where($map)->group('promote_id')->select(); @@ -249,26 +289,7 @@ class PromoteRepository { if (count($ids) == 0) { return []; } - $isContainSubs = false; - if (isset($params['isContainSubs']) && $params['isContainSubs']) { - $isContainSubs = true; - } - $map = ['pay_status' => 1, 'promote_id' => ['in', $ids]]; - if ($isContainSubs) { - $map['promote_id'] = ['in', array_merge($ids, array_keys($params['basicPromotes']))]; - } - if (isset($params['begin_time']) && isset($params['begin_time'])) { - $map['pay_time'] = ['between', [$params['begin_time'], $params['end_time']]]; - } - if (isset($params['game_id'])) { - $map['game_id'] = $params['game_id']; - } - if (isset($params['server_id'])) { - $map['server_id'] = $params['server_id']; - } - if (isset($params['sdk_version'])) { - $map['sdk_version'] = $params['sdk_version']; - } + $map = $this->getPublicAchievementMap($ids, $params); $items = M('spend', 'tab_')->field(['count(distinct user_id) count', 'promote_id'])->where($map)->group('promote_id')->select(); $records = []; @@ -297,26 +318,7 @@ class PromoteRepository { if (count($ids) == 0) { return []; } - $isContainSubs = false; - if (isset($params['isContainSubs']) && $params['isContainSubs']) { - $isContainSubs = true; - } - $map = ['pay_status' => 1, 'promote_id' => ['in', $ids]]; - if ($isContainSubs) { - $map['promote_id'] = ['in', array_merge($ids, array_keys($params['basicPromotes']))]; - } - if (isset($params['begin_time']) && isset($params['begin_time'])) { - $map['pay_time'] = ['between', [$params['begin_time'], $params['end_time']]]; - } - if (isset($params['game_id'])) { - $map['game_id'] = $params['game_id']; - } - if (isset($params['server_id'])) { - $map['server_id'] = $params['server_id']; - } - if (isset($params['sdk_version'])) { - $map['sdk_version'] = $params['sdk_version']; - } + $map = $this->getPublicAchievementMap($ids, $params); $items = M('spend', 'tab_')->field(['sum(pay_amount) amount', 'promote_id', 'pay_way'])->where($map)->group('promote_id, pay_way')->select(); $records = []; foreach ($items as $item) { diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index bd49d7530..b9b8751ea 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -1884,9 +1884,27 @@ class QueryController extends BaseController $this->display('view_spend_detailed'); } + private function getBetweenTime($time, $defaultBegin = 0, $defaultEnd = 0) + { + $delimiter = ' 至 '; + $begin = $defaultBegin; + $end = $defaultEnd; + if ($time != '') { + if (strpos($time, $delimiter) == -1) { + $begin = strtotime($time . ' 00:00:00'); + $end = strtotime($time . ' 23:59:59'); + } else { + $timeRow = explode($delimiter, $time); + $begin = strtotime($timeRow[0] . ' 00:00:00'); + $end = strtotime($timeRow[1] . ' 23:59:59'); + } + } + return [$begin, $end]; + } + public function achievement() { - $time = I('time', ''); + $time = I('time', date('Y-m-d')); $sdkVersion = I('sdk_version', 0); $gameId = I('game_id', 0); $serverId = I('server_id', 0); @@ -1931,6 +1949,10 @@ class QueryController extends BaseController if ($sdkVersion > 0) { $params['sdk_version'] = $sdkVersion; } + list($beginTime, $endTime) = $this->getBetweenTime($time); + $params['begin_time'] = $beginTime; + $params['end_time'] = $endTime; + $promoteRepository = new PromoteRepository(); $createRoleCountList = $promoteRepository->getCreateRoleCountByIds($ids, $params); diff --git a/Application/Home/View/default/Query/achievement.html b/Application/Home/View/default/Query/achievement.html index 82c62f7cc..8b485437b 100644 --- a/Application/Home/View/default/Query/achievement.html +++ b/Application/Home/View/default/Query/achievement.html @@ -104,7 +104,7 @@ -

暂无数据

+

暂无数据

diff --git a/Data/update.sql b/Data/update.sql index a8d21b29f..a129b964a 100644 --- a/Data/update.sql +++ b/Data/update.sql @@ -64,4 +64,6 @@ alter table tab_game_source add column `original_url` varchar(255) NOT NULL defa alter table tab_game_source add column `org_plist_url` varchar(255) NOT NULL default '' COMMENT '原包Plist路径'; -- 2019-10-09 by elf -alter table tab_user_play_info add column `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '角色创建时间'; \ No newline at end of file +alter table tab_user_play_info add column `create_time` int(11) NOT NULL DEFAULT '0' COMMENT '角色创建时间'; +alter table tab_user_play_info add column `create_ip` varchar(16) NOT NULL DEFAULT '' COMMENT '角色创建IP'; +alter table tab_user_play_info add column `create_device_number` varchar(50) NOT NULL DEFAULT '' COMMENT '角色创建设备号'; \ No newline at end of file