From cda67249ac5b2c8d90258922e6075b77e67d2b02 Mon Sep 17 00:00:00 2001 From: "elf@home" <360197197@qq.com> Date: Mon, 14 Oct 2019 07:58:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Base/Repository/SpendRepository.class.php | 130 +++-- .../Base/Repository/UserRepository.class.php | 34 +- .../Home/Controller/QueryController.class.php | 62 ++- .../Home/View/default/Query/achievement.html | 45 +- Application/Home/View/default/Query/arpu.html | 447 ++++++++++++++++++ .../View/default/Query/arpu_analysis.html | 3 - .../View/default/Query/userRecharges.html | 97 ++-- .../Home/View/default/Query/userRoles.html | 97 ++-- 8 files changed, 724 insertions(+), 191 deletions(-) create mode 100644 Application/Home/View/default/Query/arpu.html diff --git a/Application/Base/Repository/SpendRepository.class.php b/Application/Base/Repository/SpendRepository.class.php index 0233657ed..f29d14dd2 100644 --- a/Application/Base/Repository/SpendRepository.class.php +++ b/Application/Base/Repository/SpendRepository.class.php @@ -8,6 +8,21 @@ class SpendRepository { } + private function assembleDayRecords($items, $dayList, $valueColumn, $dayColumn = 'day') + { + $records = []; + foreach ($dayList as $day) { + $dayValue = 0; + foreach ($items as $item) { + if ($item[$dayColumn] == $day) { + $dayValue = $item[$valueColumn]; + } + } + $records[$day] = $dayValue; + } + return $records; + } + /** * 付费游戏数 */ @@ -18,6 +33,7 @@ class SpendRepository { $serverId = $params['server_id'] ?? 0; $ids = $params['promote_id'] ?? []; $isBan = $params['is_ban'] ?? false; + $dayList = $params['dayList'] ?? []; $map = []; $map['pay_status'] = 1; @@ -26,12 +42,14 @@ class SpendRepository { $map['game_id'] = $gameId > 0 ? $gameId : ['gt', 0]; $map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1']; - $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time, game_id'; - $subTable = M('spend', 'tab_')->field($field)->where($map)->group('pay_time')->select(false); - $data = M()->field('a.pay_time, count(DISTINCT a.game_id) as pay_num')->table('(' . $subTable . ') as a')->group('a.pay_time')->select(); - return $data; + $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(DISTINCT game_id) count'; + $items = M('spend', 'tab_')->field($field)->where($map)->group('day')->select(); + return $this->assembleDayRecords($items, $dayList, 'count'); } + /** + * 按天统计付款总额 + */ public function getPayAmountByDay($params) { $beginTime = $params['begin_time'] ?? 0; $endTime = $params['end_time'] ?? 0; @@ -39,6 +57,7 @@ class SpendRepository { $serverId = $params['server_id'] ?? 0; $ids = $params['promote_id'] ?? []; $isBan = $params['is_ban'] ?? false; + $dayList = $params['dayList'] ?? []; $map['pay_status'] = 1; $map['pay_time'] = ['between', [$beginTime, $endTime]]; @@ -46,12 +65,14 @@ class SpendRepository { $map['promote_id'] = ['in', $ids]; $map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1']; - $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,sum(pay_amount) as money_amount'; - $data = M('spend', 'tab_')->field($field)->where($map)->group('FROM_UNIXTIME(pay_time,"%Y-%m-%d")')->select(); - - return $data; + $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day,sum(pay_amount) as amount'; + $items = M('spend', 'tab_')->field($field)->where($map)->group('FROM_UNIXTIME(day, "%Y-%m-%d")')->select(); + return $this->assembleDayRecords($items, $dayList, 'amount'); } + /** + * 按天统计付款用户数 + */ public function getPayUserCountByDay($params) { $beginTime = $params['begin_time'] ?? 0; $endTime = $params['end_time'] ?? 0; @@ -59,6 +80,7 @@ class SpendRepository { $serverId = $params['server_id'] ?? 0; $ids = $params['promote_id'] ?? []; $isBan = $params['is_ban'] ?? false; + $dayList = $params['dayList'] ?? []; $map['pay_status'] = 1; $map['pay_time'] = ['between', [$beginTime, $endTime]]; @@ -66,12 +88,10 @@ class SpendRepository { $map['promote_id'] = ['in', $ids]; $map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1']; - $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time,user_id as pay_num'; - - $subTable = M('spend', 'tab_')->field($field)->where($map)->group('pay_time')->buildSql(); - - return M('spend', 'tab_')->field('a.pay_time,count(distinct a.pay_num) as pay_num')->table('(' . $subTable . ') as a')->group('a.pay_time')->select(); + $field = 'FROM_UNIXTIME(pay_time,"%Y-%m-%d") as day, count(distinct user_id) count'; + $items = M('spend', 'tab_')->field($field)->where($map)->group('day')->select(); + return $this->assembleDayRecords($items, $dayList, 'count'); } /** @@ -100,7 +120,7 @@ class SpendRepository { foreach ($dayList as $day) { $time = strtotime($day); $oldMap['pay_time'] = ['lt', $time]; - $map['pay_time'] = ['between', $time, ($time + 24 * 3600 -1)]; + $map['pay_time'] = ['between', [$time, ($time + 24 * 3600 -1)]]; $oldQuery = M('spend', 'tab_')->field('user_id')->where($oldMap)->group('user_id')->buildSql(); $map['user_id'] = ['exp', ' not in (' . $oldQuery . ')']; $result = M('spend', 'tab_')->field('count(distinct user_id) count')->where($map)->find(); @@ -110,7 +130,7 @@ class SpendRepository { } /** - * 按照时间分组统计新增付费用户数 + * 按照时间分组统计新增付费用户付费金额 */ public function getNewPayAmountByDay($params) { $dayList = $params['dayList'] ?? []; @@ -135,74 +155,44 @@ class SpendRepository { foreach ($dayList as $day) { $time = strtotime($day); $oldMap['pay_time'] = ['lt', $time]; - $map['pay_time'] = ['between', $time, ($time + 24 * 3600 -1)]; + $map['pay_time'] = ['between', [$time, ($time + 24 * 3600 -1)]]; $oldQuery = M('spend', 'tab_')->field('user_id')->where($oldMap)->group('user_id')->buildSql(); $map['user_id'] = ['exp', ' not in (' . $oldQuery . ')']; $result = M('spend', 'tab_')->field('sum(pay_amount) amount')->where($map)->find(); - $records[$day] = $result['amount']; + $records[$day] = floatval($result['amount']); } return $records; } - /** - * 按照时间分组统计付费玩家付费数(新付费用户指用户第一次付费) - * @param array $daylist 时间序列 - * @param integer $game_id 游戏编号 - * @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔) - * @param integer $flag 类别(1:新玩家,2:老玩家) - * @return array 详细数据 - * @author 鹿文学 - */ - public function pay_sum_by_time_class_game($daylist,$game_id=0,$promote_id=0,$flag=1,$bangbi=true) { - $map['pay_status']=1; - $oldmap['game_id'] = $map['game_id'] = $game_id>0?$game_id:array('gt',0); - $map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id); - $map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1); - if ($flag == 1) {$str='user_id not in ';$map['_string']='(small_id=0 or small_id=user_id)';} else {$str = 'user_id in';} - foreach ($daylist as $value) { - $time = strtotime($value); - $oldmap['pay_time'] = array('lt',$time); - $old_sdk_id=$this->field('user_id') - ->where($oldmap)->group('user_id') - ->buildSql(); - $map['pay_time'] = array(array('egt',$time),array('elt',strtotime("+1 day",$time)-1)); - $map['_string'] = $map['_string']?($map['_string'].' and '.$str.$old_sdk_id):($str.$old_sdk_id); - $sql=$this - ->field('user_id,pay_amount,FROM_UNIXTIME(pay_time,"%Y-%m-%d") as pay_time') - - ->where($map) - ->buildSql(); - $d = $this->query('select sum(a.pay_amount) as pay_sum, a.pay_time as pay_time from '.$sql.' as a group by pay_time'); - - if ($d) - $data[]=$d[0]; - } - return $data; - } - /** * 统计给定时间前的付费玩家总数 - * @param integer $start 开始时间(时间戳) - * @param integer $game_id 游戏编号 - * @param integer/string $promote_id 渠道编号或渠道编号列表字符串(字符串逗号分隔) - * @return integer 结果 - * @author 鹿文学 */ - public function payUsersStatisticsAgo($start,$game_id,$promote_id,$bangbi=true) { + public function getHistoryPayCountByDay($params) { + $dayList = $params['dayList'] ?? []; + $gameId = $params['game_id'] ?? 0; + $serverId = $params['server_id'] ?? 0; + $ids = $params['promote_id'] ?? []; + $isBan = $params['is_ban'] ?? false; + $map = []; $map['pay_status']=1; + if ($gameId > 0) { + $map['game_id'] = $gameId; + } + if ($serverId > 0) { + $map['server_id'] = $serverId; + } + $map['promote_id'] = ['in', $ids]; + $map['pay_way'] = $isBan ? ['neq', '-10'] : ['neq', '-1']; - $map['pay_time'] = array('lt',$start); - - $map['game_id'] = $game_id>0?$game_id:array('gt',0); - - $map['promote_id'] = is_numeric($promote_id)?$promote_id:array('in',$promote_id); - - $map['pay_way'] = $bangbi ? array('neq','-10') : array('neq',-1); - - $data = $this->field('count(DISTINCT user_id) as user_id')->where($map)->select(); - - return $data[0]['user_id']?$data[0]['user_id']:0; + $records = []; + foreach ($dayList as $day) { + $time = strtotime($day); + $map['pay_time'] = ['elt', $time]; + $result = M('spend', 'tab_')->field('count(DISTINCT user_id) as count')->where($map)->find(); + $records[$day] = $result['count']; + } + return $records; } } \ No newline at end of file diff --git a/Application/Base/Repository/UserRepository.class.php b/Application/Base/Repository/UserRepository.class.php index 92e8bff81..af2b7adbf 100644 --- a/Application/Base/Repository/UserRepository.class.php +++ b/Application/Base/Repository/UserRepository.class.php @@ -8,6 +8,21 @@ class UserRepository { } + private function assembleDayRecords($items, $dayList, $valueColumn, $dayColumn = 'day') + { + $records = []; + foreach ($dayList as $day) { + $dayValue = 0; + foreach ($items as $item) { + if ($item[$dayColumn] == $day) { + $dayValue = $item[$valueColumn]; + } + } + $records[$day] = $dayValue; + } + return $records; + } + /** * 按照时间分组统计登录总数 */ @@ -17,6 +32,7 @@ class UserRepository { $gameId = $params['game_id'] ?? 0; $serverId = $params['server_id'] ?? 0; $ids = $params['promote_id'] ?? []; + $dayList = $params['dayList'] ?? []; $map = []; $map['login_time'] = ['between', [$beginTime, $endTime]]; @@ -29,20 +45,24 @@ class UserRepository { } $map['promote_id'] = ['in', $ids]; - $records = M('user_login_record', 'tab_')->field('FROM_UNIXTIME(login_time, "%Y-%m-%d") as time, count(DISTINCT user_id) as count') + $items = M('user_login_record', 'tab_')->field('FROM_UNIXTIME(login_time, "%Y-%m-%d") as day, count(DISTINCT user_id) as count') ->where($map) - ->group('time') + ->group('day') ->select(); - return $records; + return $this->assembleDayRecords($items, $dayList, 'count'); } + /** + * 按照时间分组统计注册总数 + */ public function getRegisterCountByDay($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'] ?? []; + $dayList = $params['dayList'] ?? []; $dateform = '%Y-%m-%d'; @@ -56,13 +76,11 @@ class UserRepository { $map['promote_id'] = ['in', $ids]; $map['puid'] = 0; - - $records = M('user', 'tab_')->field('group_concat(id) as id,FROM_UNIXTIME(register_time,"'.$dateform.'") as time') + $items = M('user', 'tab_')->field('count(*) count, FROM_UNIXTIME(register_time,"'.$dateform.'") as day') ->where($map) - ->group('time') + ->group('day') ->select(); - return $records; - + return $this->assembleDayRecords($items, $dayList, 'count'); } /** diff --git a/Application/Home/Controller/QueryController.class.php b/Application/Home/Controller/QueryController.class.php index a254b466c..bb0143123 100644 --- a/Application/Home/Controller/QueryController.class.php +++ b/Application/Home/Controller/QueryController.class.php @@ -629,10 +629,26 @@ class QueryController extends BaseController } } + private function getDayList($beginTime, $endTime) + { + $dayList = []; + do { + $dayList[] = date('Y-m-d', $beginTime); + $beginTime += 24*60*60; + } while($beginTime < $endTime); + return $dayList; + } - public function arpu_analysis() + public function arpu() { - $this->meta_title = "ARPU统计"; + $this->meta_title = 'ARPU统计'; + + $defaultTime = date('Y-m-d', time() - 7*24*3600) . ' 至 ' . date('Y-m-d'); + + $time = I('time', $defaultTime); + $sdkVersion = I('sdk_version', 0); + $gameId = I('game_id', 0); + $serverId = I('server_id', 0); $promote = $this->getLoginPromote(); $map = [ @@ -643,11 +659,6 @@ class QueryController extends BaseController ]; $ids = M('promote', 'tab_')->where($map)->getField('id', true); - $time = I('time', date('Y-m-d')); - $sdkVersion = I('sdk_version', 0); - $gameId = I('game_id', 0); - $serverId = I('server_id', 0); - $params = []; if ($gameId > 0) { $params['game_id'] = $gameId; @@ -663,12 +674,45 @@ class QueryController extends BaseController $params['begin_time'] = $beginTime; $params['end_time'] = $endTime; + $dayList = $this->getDayList($beginTime, $endTime); + $params['dayList'] = $dayList; + $userRepository = new UserRepository(); $spendRepository = new SpendRepository(); $payGameCountList = $spendRepository->getPayGameCountByDay($params); + $payUserCountList = $spendRepository->getPayUserCountByDay($params); + $newPayUserCountList = $spendRepository->getNewPayUserCountByDay($params); + $payAmountList = $spendRepository->getPayAmountByDay($params); + $newPayAmountList = $spendRepository->getNewPayAmountByDay($params); + $historyPayCountList = $spendRepository->getHistoryPayCountByDay($params); $loginCountList = $userRepository->getLoginCountByDay($params); - var_dump($loginCountList); + $registerCountList = $userRepository->getRegisterCountByDay($params); + $records = []; + foreach ($dayList as $day) { + $records[] = [ + 'day' => $day, + 'payGameCount' => $payGameCountList[$day], + 'payUserCount' => $payUserCountList[$day], + 'newPayUserCount' => $newPayUserCountList[$day], + 'payAmount' => number_format($payAmountList[$day], 2), + 'newPayAmount' => number_format($newPayAmountList[$day], 2), + 'historyPayCount' => $historyPayCountList[$day], + 'loginCount' => $loginCountList[$day], + 'registerCount' => $registerCountList[$day], + 'payRate' => $loginCountList[$day] == 0 ? '--' : round($payUserCountList[$day]/$loginCountList[$day]*100, 2) . '%', + 'ratentionOneDay' => '--', + 'arpu' => $loginCountList[$day] == 0 ? '0.00' : number_format(round($payAmount[$day]/$loginCountList[$day], 2), 2), + 'arppu' => $payUserCount[$day] == 0 ? '0.00' : number_format(round($payAmount[$day]/$payUserCount[$day], 2), 2), + ]; + } + $this->assign('records', $records); + $this->display(); + } + + public function arpu_analysis() + { + $this->meta_title = "ARPU统计"; A('User', 'Event')->arpu_analysis(); } @@ -738,7 +782,7 @@ class QueryController extends BaseController } $spend2 = D('Spend'); - $data = M('Apply', 'tab_')->field('game_id, game_name')->order('game_id desc')->select(); + $data = M('Apply', 'tab_')->field('game_id, game_name')->where(['promote_id' => $promote_id])->order('game_id desc')->select(); foreach ($data as $key => $value) { $game_id = $value['game_id']; $map_list['game_id'] = $game_id; diff --git a/Application/Home/View/default/Query/achievement.html b/Application/Home/View/default/Query/achievement.html index 8b485437b..d0cc15b94 100644 --- a/Application/Home/View/default/Query/achievement.html +++ b/Application/Home/View/default/Query/achievement.html @@ -33,11 +33,8 @@