From b1b10645fc8a0f69ac194980e0e9fd504545edb1 Mon Sep 17 00:00:00 2001 From: chenxiaojun <956334972@qq.com> Date: Fri, 1 Nov 2019 16:33:48 +0800 Subject: [PATCH 1/3] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=90=8E=E5=8F=B0->?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=AE=A1=E7=90=86->=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=A6=82=E5=86=B5|=E6=95=B0=E6=8D=AE=E6=B1=87=E6=80=BB=20--=20?= =?UTF-8?q?=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 | 44 ++ .../Base/Repository/UserRepository.class.php | 216 +++++++-- .../Home/Controller/QueryController.class.php | 458 +++++++----------- 3 files changed, 396 insertions(+), 322 deletions(-) diff --git a/Application/Base/Repository/SpendRepository.class.php b/Application/Base/Repository/SpendRepository.class.php index 06ef2cb1d..04a53ee88 100644 --- a/Application/Base/Repository/SpendRepository.class.php +++ b/Application/Base/Repository/SpendRepository.class.php @@ -61,6 +61,28 @@ class SpendRepository { return $conditions; } + private function getDayGroupConditionsNew($params) + { + $beginTime = $params['begin_time'] ?? 0; + $endTime = $params['end_time'] ?? 0; + $gameId = $params['game_id'] ?? 0; + $serverId = $params['server_id'] ?? 0; + $ids = $params['promote_id'] ?? []; + + $conditions = []; + $conditions['pay_status'] = 1; + $conditions['promote_id'] = ['in', $ids]; + $conditions['pay_time'] = ['between', [$beginTime, $endTime]]; + $conditions['game_id'] = $gameId > 0 ? $gameId : ['gt', 0]; + if (isset($params['server_id'])) { + $conditions['server_id'] = $serverId; + } + if (isset($params['pay_way'])) { + $conditions['pay_way'] = $params['pay_way']; + } + return $conditions; + } + /** * 付费游戏数 */ @@ -84,6 +106,17 @@ class SpendRepository { return $this->assembleRecords($items, $dayList, 'amount'); } + /** + * 按天统计类型付款总额 + */ + public function getPayAmountGroupByDayAndType($params) { + $dayList = $params['dayList'] ?? []; + $conditions = $this->getDayGroupConditionsNew($params); + $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, sum(pay_amount) as amount'; + $items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select(); + return $this->assembleRecords($items, $dayList, 'amount'); + } + /** * 按游戏统计付款总额 */ @@ -106,6 +139,17 @@ class SpendRepository { return $this->assembleRecords($items, $dayList, 'count'); } + /** + * 按天统计付款次数 + */ + public function getPayCountGroupByDay($params) { + $dayList = $params['dayList'] ?? []; + $conditions = $this->getDayGroupConditions($params); + $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(*) count'; + $items = M('spend', 'tab_')->field($field)->where($conditions)->group('day')->select(); + return $this->assembleRecords($items, $dayList, 'count'); + } + /** * 游戏统计付款用户数 */ diff --git a/Application/Base/Repository/UserRepository.class.php b/Application/Base/Repository/UserRepository.class.php index 6ce7a47ff..b4731e5ef 100644 --- a/Application/Base/Repository/UserRepository.class.php +++ b/Application/Base/Repository/UserRepository.class.php @@ -1,7 +1,9 @@ $value) { + $records[$alias . '.' . $key] = $value; + } + return $records; + } + private function getDayGroupConditions($params) { $beginTime = $params['begin_time'] ?? 0; @@ -59,10 +70,32 @@ class UserRepository { return $conditions; } + private function getCreateRoleConditions($params) + { + $beginTime = $params['begin_time'] ?? 0; + $endTime = $params['end_time'] ?? 0; + $gameId = $params['game_id'] ?? 0; + $serverId = $params['server_id'] ?? 0; + $ids = $params['promote_id'] ?? []; + + $conditions = []; + $conditions['promote_id'] = ['in', $ids]; + $conditions[$params['time_column']] = ['between', [$beginTime, $endTime]]; + if ($gameId > 0) { + $conditions['game_id'] = $gameId; + } + if ($serverId > 0) { + $conditions['server_id'] = $serverId; + } + + return $conditions; + } + /** * 按照时间分组统计登录总数 */ - public function getLoginCountGroupByDay($params) { + public function getLoginCountGroupByDay($params) + { $dayList = $params['dayList'] ?? []; $params['time_column'] = 'login_time'; $conditions = $this->getDayGroupConditions($params); @@ -70,14 +103,15 @@ class UserRepository { ->where($conditions) ->group('day') ->select(); - + return $this->assembleRecords($items, $dayList, 'count'); } /** * 按照游戏分组统计登录总数 */ - public function getLoginCountGroupByGame($params) { + public function getLoginCountGroupByGame($params) + { $gameIds = $params['game_ids'] ?? []; $params['time_column'] = 'login_time'; $conditions = $this->getGameGroupConditions($params); @@ -85,18 +119,19 @@ class UserRepository { ->where($conditions) ->group('game_id') ->select(); - + return $this->assembleRecords($items, $gameIds, 'count', 'game_id'); } /** * 按照时间分组统计注册总数 */ - public function getRegisterCountGroupByDay($params) { + public function getRegisterCountGroupByDay($params) + { $dayList = $params['dayList'] ?? []; $params['time_column'] = 'register_time'; $conditions = $this->getDayGroupConditions($params); - + $items = M('user', 'tab_')->field('count(*) count, FROM_UNIXTIME(register_time, "%Y-%m-%d") as day') ->where($conditions) ->group('day') @@ -104,14 +139,15 @@ class UserRepository { return $this->assembleRecords($items, $dayList, 'count'); } - /** + /** * 按照游戏分分组统计注册总数 */ - public function getRegisterCountGroupByGame($params) { + public function getRegisterCountGroupByGame($params) + { $gameIds = $params['game_ids'] ?? []; $params['time_column'] = 'register_time'; $conditions = $this->getGameGroupConditions($params); - + $items = M('user', 'tab_')->field('count(*) count, fgame_id') ->where($conditions) ->group('fgame_id') @@ -121,49 +157,169 @@ class UserRepository { /** * 按照时间分组统计注册编号序列 - * @param string $newslist 新玩家序列 - * @param integer $end 结束时间(时间戳) - * @param integer $game_id 游戏编号 + * @param string $newslist 新玩家序列 + * @param integer $end 结束时间(时间戳) + * @param integer $game_id 游戏编号 * @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔) - * @param integer $flag 留存类型 + * @param integer $flag 留存类型 * @return array 详细数据 * @author 鹿文学 */ - public function getRatentionRate($newslist,$game_id=0,$promote_id=0,$flag=1) { + public function getRatentionRate($newslist, $game_id = 0, $promote_id = 0, $flag = 1) + { - $map['lock_status']=1; - if($game_id>0) { + $map['lock_status'] = 1; + if ($game_id > 0) { $map['up.game_id'] = $game_id; } - $map['tab_user.promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id); + $map['tab_user.promote_id'] = is_numeric($promote_id) ? $promote_id : array('in', $promote_id); $group = 'up.login_time'; - $fieldname = 'retention_rate'.$flag; + $fieldname = 'retention_rate' . $flag; foreach ($newslist as $value) { - $ct1 = strtotime("+$flag day",strtotime($value['time'])); - $ct2 = strtotime("+1 day",$ct1)-1; + $ct1 = strtotime("+$flag day", strtotime($value['time'])); + $ct2 = strtotime("+1 day", $ct1) - 1; - $map[$group] = array(array('egt',$ct1),array('elt',$ct2)); + $map[$group] = array(array('egt', $ct1), array('elt', $ct2)); + + $map['user_id'] = array('in', $value['id']); + $count = count(explode(',', $value['id'])); - $map['user_id']=array('in',$value['id']); - $count = count(explode(',',$value['id'])); - $d = $this - ->field('count(distinct up.user_id) as '.$fieldname.' ,FROM_UNIXTIME(up.login_time,"%Y-%m-%d") as play_time') - ->join('tab_user_login_record up on tab_user.id=up.user_id','right') + ->field('count(distinct up.user_id) as ' . $fieldname . ' ,FROM_UNIXTIME(up.login_time,"%Y-%m-%d") as play_time') + ->join('tab_user_login_record up on tab_user.id=up.user_id', 'right') ->where($map) ->group('play_time') ->select(); if ($d) - $data[]=array( - "play_time"=>$value['time'], - $fieldname=>($d[0][$fieldname]==0)?0:sprintf("%.2f",($d[0][$fieldname]/$count)*100) + $data[] = array( + "play_time" => $value['time'], + $fieldname => ($d[0][$fieldname] == 0) ? 0 : sprintf("%.2f", ($d[0][$fieldname] / $count) * 100) ); } return $data; } + + /** + * 按照时间统计创角数 + */ + public function getCreateRoleCountByDay($params) + { + $dayList = $params['dayList'] ?? []; + $params['time_column'] = 'create_time'; + $conditions = $this->getCreateRoleConditions($params); + + $items = M('user_play_info', 'tab_')->field('count(*) count, FROM_UNIXTIME(create_time, "%Y-%m-%d") as day') + ->where($conditions) + ->group('day') + ->select(); + return $this->assembleRecords($items, $dayList, 'count'); + } + + /** + * 按照时间统计创角用户(去重) + */ + public function getCreateRoleUserCountByDay($params) + { + $dayList = $params['dayList'] ?? []; + $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') + ->where($conditions) + ->group('day') + ->select(); + return $this->assembleRecords($items, $dayList, 'count'); + } + + /** + * 按照时间统计新创角用户(去重) + */ + public function getNewCreateRoleUserCountByDay($params) + { + $dayList = $params['dayList'] ?? []; + $params['time_column'] = 'create_time'; + $conditions = $this->getCreateRoleConditions($params); + $conditionsSql = $conditions; + unset($conditionsSql['begin_time']); + unset($conditionsSql['end_time']); + $alias = 'ti'; + $conditionsSql = $this->setKeys($conditionsSql, $alias); + $model = M('user_play_info', 'tab_'); + + $sql = $model->alias($alias) + ->where($conditionsSql) + ->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") + ->where($conditions) + ->group("day") + ->having('num = 0') + ->select(); + return $this->assembleRecords($items, $dayList, 'count'); + } + + /** + * 按照时间统计新创角设备(去重) + */ + public function getNewCreateRoleDeviceCountByDay($params) + { + $dayList = $params['dayList'] ?? []; + $params['time_column'] = 'create_time'; + $conditions = $this->getCreateRoleConditions($params); + $conditionsSql = $conditions; + unset($conditionsSql['begin_time']); + unset($conditionsSql['end_time']); + $alias = 'ti'; + $conditionsSql = $this->setKeys($conditionsSql, $alias); + $model = M('user_play_info', 'tab_'); + + $sql = $model->alias($alias) + ->where($conditionsSql) + ->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") + ->where($conditions) + ->group("day") + ->having('num = 0') + ->select(); + return $this->assembleRecords($items, $dayList, 'count'); + } + + /** + * 按照时间统计新创角IP(去重) + */ + public function getNewCreateRoleIpCountByDay($params) + { + $dayList = $params['dayList'] ?? []; + $params['time_column'] = 'create_time'; + $conditions = $this->getCreateRoleConditions($params); + $conditionsSql = $conditions; + unset($conditionsSql['begin_time']); + unset($conditionsSql['end_time']); + $alias = 'ti'; + $conditionsSql = $this->setKeys($conditionsSql, $alias); + $model = M('user_play_info', 'tab_'); + + $sql = $model->alias($alias) + ->where($conditionsSql) + ->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") + ->where($conditions) + ->group("day") + ->having('num = 0') + ->select(); + return $this->assembleRecords($items, $dayList, 'count'); + } } \ No newline at end of file diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index 006d2039b..912c4d1f1 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -46,20 +46,20 @@ class QueryController extends BaseController // $map['tab_spend.promote_id'] = ['in', $childPromoteIds]; // } - - $map1['chain'] = ['like','%'.PID.'/'.'%']; - $rs = M('promote','tab_')->where($map1)->field('id,account,nickname')->select(); + + $map1['chain'] = ['like', '%' . PID . '/' . '%']; + $rs = M('promote', 'tab_')->where($map1)->field('id,account,nickname')->select(); $childPromoteIds = ''; - if(empty($rs)) { + if (empty($rs)) { $map['tab_spend.promote_id'] = PID; - }else { - foreach ($rs as $rsKey => $rsValue) { + } else { + foreach ($rs as $rsKey => $rsValue) { $id = $rsValue['id']; - $childPromoteIds .= $id.','; + $childPromoteIds .= $id . ','; } - $childPromoteIds = rtrim($childPromoteIds, ','); - $childPromoteIds .= ',' . PID; - $map['tab_spend.promote_id'] = ['in', $childPromoteIds]; + $childPromoteIds = rtrim($childPromoteIds, ','); + $childPromoteIds .= ',' . PID; + $map['tab_spend.promote_id'] = ['in', $childPromoteIds]; } $levelPromote = $this->getLevelPromote(); @@ -70,21 +70,21 @@ class QueryController extends BaseController 'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'] ]; $ids = M('promote', 'tab_')->where($map2)->getField('id', true); - if(empty($ids)) { - $ids = array(); + if (empty($ids)) { + $ids = array(); } - if(empty($levelPromote)) { - array_push($ids,PID); - + if (empty($levelPromote)) { + array_push($ids, PID); + } - array_push($ids,$queryPromote['id']); + array_push($ids, $queryPromote['id']); if (!empty($ids)) { - $map['tab_spend.promote_id'] = ['in',$ids]; - - }else { + $map['tab_spend.promote_id'] = ['in', $ids]; + + } else { $map['_string'] = '1<>1'; } - + if (!empty(I('own_id'))) { $map['tab_spend.promote_id'] = $queryPromote['id'];//本账号 @@ -198,7 +198,7 @@ class QueryController extends BaseController } else { $row = 10; } - + //$childPromoteIds = getAllChildPromoteList(3); // if (empty($childPromoteIds)) { @@ -208,20 +208,20 @@ class QueryController extends BaseController // // $map['tab_user.promote_id'] = ['in', $childPromoteIds]; // } - // $map['tab_user.promote_id'] = ['like','%'.PID.'/'.'%']; - $map1['chain'] = ['like','%'.PID.'/'.'%']; - $rs = M('promote','tab_')->where($map1)->field('id,account,nickname')->select(); + // $map['tab_user.promote_id'] = ['like','%'.PID.'/'.'%']; + $map1['chain'] = ['like', '%' . PID . '/' . '%']; + $rs = M('promote', 'tab_')->where($map1)->field('id,account,nickname')->select(); $childPromoteIds = ''; - if(empty($rs)) { + if (empty($rs)) { $map['tab_user.promote_id'] = PID; - }else { - foreach ($rs as $rsKey => $rsValue) { + } else { + foreach ($rs as $rsKey => $rsValue) { $id = $rsValue['id']; - $childPromoteIds .= $id.','; + $childPromoteIds .= $id . ','; } - $childPromoteIds = rtrim($childPromoteIds, ','); - $childPromoteIds .= ',' . PID; - $map['tab_user.promote_id'] = ['in', $childPromoteIds]; + $childPromoteIds = rtrim($childPromoteIds, ','); + $childPromoteIds .= ',' . PID; + $map['tab_user.promote_id'] = ['in', $childPromoteIds]; } $promote = $this->getLoginPromote(); @@ -233,21 +233,21 @@ class QueryController extends BaseController 'chain' => ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%'] ]; $ids = M('promote', 'tab_')->where($map2)->getField('id', true); - if(empty($ids)) { - $ids = array(); + if (empty($ids)) { + $ids = array(); } - if(empty($levelPromote)) { - array_push($ids,PID); - + if (empty($levelPromote)) { + array_push($ids, PID); + } - array_push($ids,$queryPromote['id']); + array_push($ids, $queryPromote['id']); if (!empty($ids)) { - $map['tab_user.promote_id'] = ['in',$ids]; - - }else { + $map['tab_user.promote_id'] = ['in', $ids]; + + } else { $map['_string'] = '1<>1'; } - + if (!empty(I('own_id'))) { $map['tab_user.promote_id'] = $queryPromote['id'];//本账号 } @@ -1080,214 +1080,116 @@ class QueryController extends BaseController $loginPromote = $this->getLoginPromote(); - $map = []; $ownId = intval(I('own_id'), 0);//本账号 if ($ownId) { - $userPlayInfoWhere['tab_user_play_info.promote_id'] = $queryPromote['id']; - $userPlayInfoWhere2['ti.promote_id'] = $queryPromote['id']; - $userGameLoginWhere['tab_user_game_login_record.promote_id'] = $queryPromote['id']; - $spendWhere['tab_spend.promote_id'] = $queryPromote['id']; + $params['promote_id'] = $queryPromote['id']; } else { $map['chain'] = ['like', $queryPromote['chain'] . $queryPromote['id'] . '/%']; $ids = M('promote', 'tab_')->where($map)->getField('id', true); $ids[] = $queryPromote['id']; + $ids = implode(',', $ids); - $userPlayInfoWhere['tab_user_play_info.promote_id'] = ['in', $ids]; - $userPlayInfoWhere2['ti.promote_id'] = ['in', $ids]; - $userGameLoginWhere['tab_user_game_login_record.promote_id'] = ['in', $ids]; - $spendWhere['tab_spend.promote_id'] = ['in', $ids]; - } - $map = []; - $map['_string'] = '1 = 1'; - $join = ''; - if ($relationGameId > 0) { - $map['tab_game.relation_game_id'] = I('relation_game_id'); - $join = 'tab_game on game_id = tab_game.id'; - } - if ($sdkVersion > 0) { - $userPlayInfoWhere['tab_user_play_info.sdk_version'] = $sdkVersion; - $userPlayInfoWhere2['ti.sdk_version'] = $sdkVersion; - $userGameLoginWhere['tab_user_game_login_record.sdk_version'] = $sdkVersion; - $spendWhere['tab_spend.sdk_version'] = $sdkVersion; + $params['promote_id'] = $ids; } - $spendWhere['tab_spend.pay_status'] = 1; - if ($serverId > 0) { - $userPlayInfoWhere['tab_user_play_info.server_id'] = $serverId; - $userPlayInfoWhere2['ti.server_id'] = $serverId; - $userGameLoginWhere['tab_user_game_login_record.server_id'] = $serverId; - $spendWhere['tab_spend.server_id'] = $serverId; + if ($relationGameId > 0 || $serverId > 0) { + if ($sdkVersion > 0) { + $map['sdk_version'] = $sdkVersion; + } + if ($relationGameId > 0) { + $map = ['relation_game_id' => $relationGameId]; + } + $gameIds = M('Game', 'tab_')->where($map)->getField('id', true); + if (empty($gameIds)) { + $params['_string'] = '1=2'; + } else { + $gameIds = implode(',', $gameIds); + $params['game_id'] = ['in', $gameIds]; + } } - - $userPlayInfoModel = M('UserPlayInfo', 'tab_'); + $params['begin_time'] = $begTime; + $params['end_time'] = $endTime; $summaryData = []; - $data = []; - $dataNum = ($endTime - $begTime) / 86400 + 1; - $dateTime = $endTime; - for ($index = 0; $index < $dataNum; $index++) { - $thisDateTime = date('Ymd', $dateTime); - $summaryData['date'][] = $thisDateTime; - $data[]['day'] = $thisDateTime; - $dateTime = strtotime('-1 day', $dateTime); - } + $dayList = $this->getDayList($begTime, $endTime); + $params['dayList'] = $dayList; - $allData['role_num'] = 0; - $allData['user_num'] = 0; - $allData['new_user_num'] = 0; - $allData['new_device_num'] = 0; - $allData['new_ip_num'] = 0; - $allData['login_user_num'] = 0; - $allData['spend_user_num'] = 0; - $allData['spend_num'] = 0; - $allData['spend_all_amount'] = 0; - $allData['spend_cash'] = 0; - $allData['spend_generic'] = 0; - $allData['pay_amount'] = 0; - $allData['spend_discount'] = 0; - $allData['spend_voucher'] = 0; - foreach ($data as &$list) { - $thisDateTime = strtotime($list['day']); - $userPlayInfoWhere['tab_user_play_info.create_time'] = ['between', [$thisDateTime, $thisDateTime + 86399]]; - $userGameLoginWhere['tab_user_game_login_record.login_time'] = ['between', [$thisDateTime, $thisDateTime + 86399]]; - $spendWhere['tab_spend.pay_time'] = ['between', [$thisDateTime, $thisDateTime + 86399]]; - - $list['role_num'] = $userPlayInfoModel - ->join($join) - ->where($userPlayInfoWhere) - ->where($map) - ->order('play_time desc') - ->count();//创角数 - $list['user_num'] = count($userPlayInfoModel - ->join($join) - ->where($userPlayInfoWhere) - ->where($map) - ->group('tab_user_play_info.game_id,tab_user_play_info.user_id') - ->select());//创角用户 - - $newUserNumSql = $userPlayInfoModel - ->table('tab_user_play_info as ti') - ->where($userPlayInfoWhere2) - ->where('ti.user_id = tab_user_play_info.user_id and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $thisDateTime) - ->fetchSql(true) - ->count(); - $newUserNumData = $userPlayInfoModel - ->field('tab_user_play_info.create_time,(' . $newUserNumSql . ') as num') - ->join($join) - ->where($userPlayInfoWhere) - ->where($map) - ->group('tab_user_play_info.user_id') - ->having('num = 0') - ->order('tab_user_play_info.id') - ->select(); - $list['new_user_num'] = count($newUserNumData);//新创角用户 - - $newDeviceSql = $userPlayInfoModel - ->table('tab_user_play_info as ti') - ->where($userPlayInfoWhere2) - ->where('ti.create_device_number = tab_user_play_info.create_device_number and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $thisDateTime) - ->fetchSql(true) - ->count(); - $newDeviceData = $userPlayInfoModel - ->field('tab_user_play_info.create_time,(' . $newDeviceSql . ') as num') - ->join($join) - ->where($userPlayInfoWhere) - ->where($map) - ->group('tab_user_play_info.create_device_number') - ->having('num = 0') - ->order('tab_user_play_info.id') - ->select(); - $list['new_device_num'] = count($newDeviceData);//新创角设备 - - $newIpNumSql = $userPlayInfoModel - ->table('tab_user_play_info as ti') - ->where($userPlayInfoWhere2) - ->where('ti.create_ip = tab_user_play_info.create_ip and ti.game_id = tab_user_play_info.game_id and ti.create_time < ' . $thisDateTime) - ->fetchSql(true) - ->count(); - $newIpNumData = $userPlayInfoModel - ->field('tab_user_play_info.create_time,(' . $newIpNumSql . ') as num') - ->join($join) - ->where($userPlayInfoWhere) - ->where($map) - ->group('tab_user_play_info.create_ip') - ->having('num = 0') - ->order('tab_user_play_info.id') - ->select(); - $list['new_ip_num'] = count($newIpNumData);//新增创角IP - - $list['login_user_num'] = count(M('UserGameLoginRecord', 'tab_') - ->join($join) - ->where($userGameLoginWhere) - ->where($map) - ->group('tab_user_game_login_record.game_id,tab_user_game_login_record.user_id') - ->select());//登录用户数 - - $list['spend_user_num'] = count(M('Spend', 'tab_') - ->join($join) - ->where($spendWhere) - ->where($map) - ->group('tab_spend.game_id,tab_spend.user_id') - ->select());//充值人数 - $list['spend_num'] = M('Spend', 'tab_') - ->join($join) - ->where($spendWhere) - ->where($map) - ->count();//充值次数 - $list['spend_all_amount'] = M('Spend', 'tab_') - ->join($join) - ->where($spendWhere) - ->where($map) - ->sum('tab_spend.pay_amount');//充值总额 - $list['spend_all_amount'] = empty($list['spend_all_amount']) ? 0 : $list['spend_all_amount']; - - $list['spend_cash'] = M('Spend', 'tab_') - ->join($join) - ->where($spendWhere) - ->where($map) - ->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6'])) - ->sum('tab_spend.pay_amount');//现金充值 - $list['spend_cash'] = empty($list['spend_cash']) ? 0 : $list['spend_cash']; - - $list['spend_generic'] = M('Spend', 'tab_') - ->join($join) - ->where($spendWhere) - ->where($map) - ->where(array('tab_spend.pay_way' => 0)) - ->sum('tab_spend.pay_amount');//通用币 - $list['spend_generic'] = empty($list['spend_generic']) ? 0 : $list['spend_generic']; - - $list['spend_binding'] = M('Spend', 'tab_') - ->join($join) - ->where($spendWhere) - ->where($map) - ->where(array('tab_spend.pay_way' => -1)) - ->sum('tab_spend.pay_amount');//绑定币 - $list['spend_binding'] = empty($list['spend_binding']) ? 0 : $list['spend_binding']; - - $list['spend_discount'] = 0;//折扣币 - $list['spend_voucher'] = 0;//代金券 - - $allData['role_num'] += $list['role_num']; - $allData['user_num'] += $list['user_num']; - $allData['new_user_num'] += $list['new_user_num']; - $allData['new_device_num'] += $list['new_device_num']; - $allData['new_ip_num'] += $list['new_ip_num']; - $allData['login_user_num'] += $list['login_user_num']; - $allData['spend_user_num'] += $list['spend_user_num']; - $allData['spend_num'] += $list['spend_num']; - $allData['spend_all_amount'] = bcadd($allData['spend_all_amount'], $list['spend_all_amount'], 2); - $allData['spend_cash'] = bcadd($allData['spend_cash'], $list['spend_cash'], 2); - $allData['spend_generic'] = bcadd($allData['spend_generic'], $list['spend_generic'], 2); - $allData['spend_binding'] = bcadd($allData['spend_binding'], $list['spend_binding'], 2); - $allData['spend_discount'] = bcadd($allData['spend_discount'], $list['spend_discount'], 2); - $allData['spend_voucher'] = bcadd($allData['spend_voucher'], $list['spend_voucher'], 2); - - $summaryData['role_num'][] = $list['role_num']; - $summaryData['user_num'][] = $list['user_num']; - $summaryData['new_user_num'][] = $list['new_user_num']; - $summaryData['new_device_num'][] = $list['new_device_num']; - $summaryData['spend_user_num'][] = $list['spend_user_num']; - $summaryData['spend_all_amount'][] = $list['spend_all_amount']; + $records = []; + if (intval($endTime - $begTime) / (24 * 3600) <= 30) { + $userRepository = new UserRepository(); + $spendRepository = new SpendRepository(); + $roleNumList = $userRepository->getCreateRoleCountByDay($params);//创角数 + $userNumList = $userRepository->getCreateRoleUserCountByDay($params);//创角用户 + $newUserNumList = $userRepository->getNewCreateRoleUserCountByDay($params);//新创角用户 + $newDeviceNumList = $userRepository->getNewCreateRoleDeviceCountByDay($params);//新创角设备 + $newIpNumList = $userRepository->getNewCreateRoleIpCountByDay($params);//新创角IP + $loginUserNumList = $userRepository->getLoginCountGroupByDay($params);//登录用户数 + $spendUserNumList = $spendRepository->getPayUserCountGroupByDay($params);//充值人数 + $spendNumList = $spendRepository->getPayCountGroupByDay($params);//充值次数 + $spendAllAmountList = $spendRepository->getPayAmountGroupByDayAndType($params);//充值总额 + $params['pay_way'] = ['in', '1,2,3,4,5,6']; + $spendCashList = $spendRepository->getPayAmountGroupByDayAndType($params);//现金充值 + $params['pay_way'] = 0; + $spendGenericList = $spendRepository->getPayAmountGroupByDayAndType($params);//通用币充值 + $params['pay_way'] = -1; + $spendBindingList = $spendRepository->getPayAmountGroupByDayAndType($params);//绑定币充值 + + $allData['role_num'] = 0; + $allData['user_num'] = 0; + $allData['new_user_num'] = 0; + $allData['new_device_num'] = 0; + $allData['new_ip_num'] = 0; + $allData['login_user_num'] = 0; + $allData['spend_user_num'] = 0; + $allData['spend_num'] = 0; + $allData['spend_all_amount'] = 0; + $allData['spend_cash'] = 0; + $allData['spend_generic'] = 0; + $allData['spend_binding'] = 0; + $allData['spend_discount'] = 0; + $allData['spend_voucher'] = 0; + foreach ($dayList as $day) { + $date = date('Ymd', strtotime($day)); + $records[] = [ + 'day' => $date, + 'role_num' => $roleNumList[$day], + 'user_num' => $userNumList[$day], + 'new_user_num' => $newUserNumList[$day], + 'new_device_num' => $newDeviceNumList[$day], + 'new_ip_num' => $newIpNumList[$day], + 'login_user_num' => $loginUserNumList[$day], + 'spend_user_num' => $spendUserNumList[$day], + 'spend_num' => $spendNumList[$day], + 'spend_all_amount' => $spendAllAmountList[$day], + 'spend_cash' => $spendCashList[$day], + 'spend_generic' => $spendGenericList[$day], + 'spend_binding' => $spendBindingList[$day], + 'spend_discount' => 0, + 'spend_voucher' => 0, + ]; + + $allData['role_num'] += $roleNumList[$day]; + $allData['user_num'] += $userNumList[$day]; + $allData['new_user_num'] += $newUserNumList[$day]; + $allData['new_device_num'] += $newDeviceNumList[$day]; + $allData['new_ip_num'] += $newIpNumList[$day]; + $allData['login_user_num'] += $loginUserNumList[$day]; + $allData['spend_user_num'] += $spendUserNumList[$day]; + $allData['spend_num'] += $spendNumList[$day]; + $allData['spend_all_amount'] = bcadd($allData['spend_all_amount'], $spendAllAmountList[$day], 2); + $allData['spend_cash'] = bcadd($allData['spend_cash'], $spendCashList[$day], 2); + $allData['spend_generic'] = bcadd($allData['spend_generic'], $spendGenericList[$day], 2); + $allData['spend_binding'] = bcadd($allData['spend_binding'], $spendBindingList[$day], 2); + $allData['spend_discount'] = bcadd($allData['spend_discount'], 0, 2); + $allData['spend_voucher'] = bcadd($allData['spend_voucher'], 0, 2); + + $summaryData['date'][] = $date; + $summaryData['role_num'][] = $roleNumList[$day]; + $summaryData['user_num'][] = $userNumList[$day]; + $summaryData['new_user_num'][] = $newUserNumList[$day]; + $summaryData['new_device_num'][] = $newDeviceNumList[$day]; + $summaryData['spend_user_num'][] = $spendUserNumList[$day]; + $summaryData['spend_all_amount'][] = $spendAllAmountList[$day]; + } } $summaryData['date'] = array_reverse($summaryData['date']); @@ -1303,7 +1205,7 @@ class QueryController extends BaseController $this->assign('meta_title', '每日概况'); $this->assign('loginPromote', $loginPromote); $this->assign('ownId', $ownId); - $this->assign('listData', $data); + $this->assign('listData', $records); $this->assign('allData', $allData); $this->assign('summaryData', $summaryData); $this->assign('setdate', date("Y-m-d")); @@ -1422,72 +1324,44 @@ class QueryController extends BaseController $userGameLoginMap['tab_user_game_login_record.game_id'] = $list['game_id']; $spendMap['tab_spend.game_id'] = $list['game_id']; - $list['role_num'] = $userPlayInfoModel + $thisData = $userPlayInfoModel + ->field('count(*) as role_num,count(distinct tab_user_play_info.user_id) as user_num') ->where($userPlayInfoMap) - ->count();//创角数 - - $list['user_num'] = $userPlayInfoModel - ->where($userPlayInfoMap) - ->count('distinct tab_user_play_info.user_id');//创角用户 - - $newUserNumData = $userPlayInfoModel - ->field('tab_user_play_info.create_time') - ->where($userPlayInfoMap2) - ->group('tab_user_play_info.user_id') - ->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399)) - ->order('tab_user_play_info.id') - ->select(); - $list['new_user_num'] = count($newUserNumData);//新创角用户 - - $newDeviceData = $userPlayInfoModel - ->field('tab_user_play_info.create_time') - ->where($userPlayInfoMap2) - ->group('tab_user_play_info.create_device_number') - ->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399)) - ->order('tab_user_play_info.id') - ->select(); - $list['new_device_num'] = count($newDeviceData);//新创角设备 + ->find(); + $list['role_num'] = $thisData['role_num'];//创角数 + $list['user_num'] = $thisData['user_num'];//创角用户 - $newIpData = $userPlayInfoModel - ->field('tab_user_play_info.create_time') + $thisData = $userPlayInfoModel + ->field('tab_user_play_info.create_time,count(distinct tab_user_play_info.user_id) as new_user_num, + count(distinct tab_user_play_info.create_device_number) as new_device_num, + count(distinct tab_user_play_info.create_ip) as new_ip_num') ->where($userPlayInfoMap2) - ->group('tab_user_play_info.create_ip') ->having('tab_user_play_info.create_time between ' . $begTime . ' and ' . ($endTime + 86399)) ->order('tab_user_play_info.id') - ->select(); - $list['new_ip_num'] = count($newIpData);//新增创角IP + ->find(); + $list['new_user_num'] = empty($thisData['new_user_num']) ? 0 : $thisData['new_user_num'];//新创角用户 + $list['new_device_num'] = empty($thisData['new_device_num']) ? 0 : $thisData['new_device_num'];//新创角设备 + $list['new_ip_num'] = empty($thisData['new_ip_num']) ? 0 : $thisData['new_ip_num'];//新增创角IP $list['login_user_num'] = count($userGameLoginModel ->where($userGameLoginMap) ->group('tab_user_game_login_record.game_id,tab_user_game_login_record.user_id') ->select());//登录用户数 - $list['spend_user_num'] = $spendModel - ->where($spendMap) - ->count('distinct tab_spend.user_id');//充值人数 - - $list['spend_num'] = $spendModel + $thisData = $spendModel + ->field('count(distinct tab_spend.user_id) as spend_user_num,count(*) as spend_num, + sum(tab_spend.pay_amount) as spend_all_amount, + sum(if(tab_spend.pay_way > 0,tab_spend.pay_amount,0)) as spend_cash, + sum(if(tab_spend.pay_way = 0,tab_spend.pay_amount,0)) as spend_generic, + sum(if(tab_spend.pay_way = -1,tab_spend.pay_amount,0)) as spend_binding') ->where($spendMap) - ->count();//充值次数 - - $list['spend_all_amount'] = $spendModel - ->where($spendMap) - ->sum('tab_spend.pay_amount');//充值总额 - - $list['spend_cash'] = $spendModel - ->where($spendMap) - ->where(array('tab_spend.pay_way' => ['in', '1,2,3,4,5,6'])) - ->sum('tab_spend.pay_amount');//现金充值 - - $list['spend_generic'] = $spendModel - ->where($spendMap) - ->where(array('tab_spend.pay_way' => 0)) - ->sum('tab_spend.pay_amount');//通用币 - - $list['spend_binding'] = $spendModel - ->where($spendMap) - ->where(array('tab_spend.pay_way' => -1)) - ->sum('tab_spend.pay_amount');//绑定币 + ->find(); + $list['spend_user_num'] = $thisData['spend_user_num'];//充值人数 + $list['spend_num'] = $thisData['spend_num'];//充值次数 + $list['spend_all_amount'] = $thisData['spend_all_amount'];//充值总额 + $list['spend_cash'] = $thisData['spend_cash'];//现金充值 + $list['spend_generic'] = $thisData['spend_generic'];//通用币 + $list['spend_binding'] = $thisData['spend_binding'];//绑定币 $list['spend_discount'] = 0;//折扣币 $list['spend_voucher'] = 0;//代金券 From 42d330bbc4c8efbcef24ae47a15b5d844fd302e7 Mon Sep 17 00:00:00 2001 From: chenxiaojun <956334972@qq.com> Date: Fri, 1 Nov 2019 16:35:58 +0800 Subject: [PATCH 2/3] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=90=8E=E5=8F=B0->?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=AE=A1=E7=90=86->=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=A6=82=E5=86=B5|=E6=95=B0=E6=8D=AE=E6=B1=87=E6=80=BB=20--=20?= =?UTF-8?q?=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index 912c4d1f1..e76f40c78 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -1314,7 +1314,7 @@ class QueryController extends BaseController $allData['spend_all_amount'] = 0; $allData['spend_cash'] = 0; $allData['spend_generic'] = 0; - $allData['pay_amount'] = 0; + $allData['spend_binding'] = 0; $allData['spend_discount'] = 0; $allData['spend_voucher'] = 0; if (!empty($data)) { From 681c4016862b5b615d95003643e0d9972bfd7ece Mon Sep 17 00:00:00 2001 From: chenxiaojun <956334972@qq.com> Date: Fri, 1 Nov 2019 16:44:32 +0800 Subject: [PATCH 3/3] =?UTF-8?q?=E6=8E=A8=E5=B9=BF=E5=90=8E=E5=8F=B0->?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E7=AE=A1=E7=90=86->=E6=AF=8F=E6=97=A5?= =?UTF-8?q?=E6=A6=82=E5=86=B5|=E6=95=B0=E6=8D=AE=E6=B1=87=E6=80=BB=20--=20?= =?UTF-8?q?=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 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index e76f40c78..623f8d767 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -1110,7 +1110,7 @@ class QueryController extends BaseController $params['end_time'] = $endTime; $summaryData = []; - $dayList = $this->getDayList($begTime, $endTime); + $dayList = $this->getDayList($begTime, $endTime + 3600 * 24); $params['dayList'] = $dayList; $records = [];