From 0af6a53ba7edb6ea5e8d835f4ffff7b9543906d4 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Tue, 21 Apr 2020 15:53:45 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E5=90=8E=E5=8F=B0arpu=E5=8A=9F=E8=83=BD?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ConsoleController.class.php | 1 - .../Admin/Controller/StatController.class.php | 130 ++++++ Application/Admin/View/Stat/userarpu.html | 108 ++--- Application/Admin/View/Stat/userarpu_old.html | 407 ++++++++++++++++++ 4 files changed, 577 insertions(+), 69 deletions(-) create mode 100644 Application/Admin/View/Stat/userarpu_old.html diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php index 7fd9fc095..fc7bef092 100644 --- a/Application/Admin/Controller/ConsoleController.class.php +++ b/Application/Admin/Controller/ConsoleController.class.php @@ -434,7 +434,6 @@ class ConsoleController extends Think { $start = I('start', date('Y-m-d')); $end = I('end', date('Y-m-d')); $gameIds = I('game_ids', ''); - $startTime = strtotime($start . ' 00:00:00'); $endTime = strtotime($end . ' 23:59:59'); $gameIdRows = explode(',', $gameIds); diff --git a/Application/Admin/Controller/StatController.class.php b/Application/Admin/Controller/StatController.class.php index 12b37a10a..3543c2d9b 100644 --- a/Application/Admin/Controller/StatController.class.php +++ b/Application/Admin/Controller/StatController.class.php @@ -672,6 +672,136 @@ AND UNIX_TIMESTAMP( } public function userarpu($p=0) + { + $start = I('start', date('Y-m-d')); + $end = I('end', date('Y-m-d')); + $gameIds = I('game_ids', ''); + $promoteId = I('promote_id', 0); + $dataOrder = I('data_order', ''); + $containBindCoins = I('contain_bind_coins', 0); + + $orderType = ''; + $order = 0; + if ($dataOrder != '') { + $dataOrderRow = explode(',', $dataOrder); + $order = $dataOrderRow[0]; + $orderType = $dataOrderRow[1]; + } + + $promoteIds = []; + if ($promoteId > 0) { + $promote = M('promote', 'tab_')->field(['id', 'chain'])->where(['id' => $promoteId])->find(); + $promoteIds = M('promote', 'tab_')->where(['chain' => ['like', $promote['chain'] . $promote['id'] . '/%']])->getField('id', true); + $promoteIds[] = $promote['id']; + } + + $startTime = strtotime($start . ' 00:00:00'); + $endTime = strtotime($end . ' 23:59:59'); + $gameIdRows = $gameIds ? explode(',', $gameIds) : []; + + $conditions = []; + if (count($gameIdRows)) { + $conditions['game_id'] = ['in', $gameIdRows]; + } + if (count($promoteIds)) { + $conditions['promote_id'] = ['in', $promoteIds]; + } + // 新增用户 + + /* M('user', 'tab_') + ->field('count(*) count, FROM_UNIXTIME(register_time, "%Y-%m-%d") date') + ->where([ + 'game_id' => ['in', $gameIdRows], + 'register_time' => ['between', [$startTime, $endTime]] + ]) + ->group('date') + ->select(); */ + + $newUsers = M('user_play', 'tab_') + ->field('count(DISTINCT user_id) count, FROM_UNIXTIME(create_time, "%Y-%m-%d") date') + ->where(array_merge($conditions, ['create_time' => ['between', [$startTime, $endTime]]])) + ->group('date') + ->select(); + $newUsers = index_by_column('date', $newUsers); + + // 活跃用户 + $loginUsers = M('login_daily_record', 'tab_') + ->field('count(DISTINCT user_id) count, FROM_UNIXTIME(create_time, "%Y-%m-%d") date') + ->where(array_merge($conditions, ['create_time' => ['between', [$startTime, $endTime]]])) + ->group('date') + ->select(); + $loginUsers = index_by_column('date', $loginUsers); + + $spendConditions = array_merge($conditions, [ + 'pay_time' => ['between', [$startTime, $endTime]], + 'pay_status' => 1, + ]); + if ($containBindCoins == 0) { + $spendConditions['pay_way'] = ['gt', -1]; + } + + // 付费玩家,付费金额 + $payLogs = M('spend', 'tab_') + ->field('count(DISTINCT user_id) count, sum(pay_amount) amount, FROM_UNIXTIME(pay_time, "%Y-%m-%d") date') + ->where($spendConditions) + ->group('date') + ->select(); + $payLogs = index_by_column('date', $payLogs); + + $rows = []; + for ($time = $startTime; $time < $endTime; $time = $time + 24*3600) { + $date = date('Y-m-d', $time); + $newUser = isset($newUsers[$date]) ? $newUsers[$date]['count'] : 0; + $loginUser = isset($loginUsers[$date]) ? $loginUsers[$date]['count'] : 0; + $payAmount = isset($payLogs[$date]) ? $payLogs[$date]['amount'] : 0; + $payUser = isset($payLogs[$date]) ? $payLogs[$date]['count'] : 0; + $rows[] = [ + 'date' => $date, + 'new_user' => $newUser, + 'login_user' => $loginUser, + 'pay_amount' => $payAmount, + 'pay_user' => $payUser, + 'pay_rate' => $loginUser > 0 ? (round($payUser / $loginUser * 100, 2)) : '0', + 'arpu' => $loginUser > 0 ? (round($payAmount / $loginUser, 2)) : '0.00', + 'arppu' => $payUser > 0 ? (round($payAmount / $payUser, 2)) : '0.00', + ]; + } + + if (I('export', 0) == 1) { + $fields = [ + 'date' => '日期', + 'new_user' => '新增玩家', + 'login_user' => '活跃玩家', + 'pay_account' => '充值金额', + 'pay_user' => '付费玩家', + 'pay_rate' => '付费率', + 'arpu' => 'ARPU', + 'arppu' => 'ARPPU', + ]; + foreach ($rows as &$item) { + $item['pay_rate'] = $item['pay_rate'] . '%'; + } + + addOperationLog(['op_type'=>3,'key'=>getNowDate(),'op_name'=>'ARPU分析','url'=>U('Stat/userarpu'),'menu'=>'统计-数据分析-ARPU分析']); + + data2csv($rows, '数据分析_ARPU分析', $fields); + exit; + } + + if ($dataOrder) { + $sort = $order == 3 ? SORT_DESC : SORT_ASC; + $orderColumn = array_column($rows, $orderType); + array_multisort($orderColumn, $sort, SORT_REGULAR, $rows); + } + + $this->meta_title = 'ARPU统计'; + $this->assign('records', $rows); + $this->assign('order', $order); + $this->assign('orderType', $orderType); + $this->display(); + } + + public function userarpu_old($p=0) { $request=$_REQUEST; $page = intval($p); diff --git a/Application/Admin/View/Stat/userarpu.html b/Application/Admin/View/Stat/userarpu.html index de5c56d00..45e9da560 100644 --- a/Application/Admin/View/Stat/userarpu.html +++ b/Application/Admin/View/Stat/userarpu.html @@ -48,18 +48,18 @@ 活跃玩家 当天登录的玩家总数 -
  • +
  • 付费玩家 当天付费的玩家数量
  • -
  • +
  • 付费率 付费玩家/活跃玩家 @@ -83,12 +83,12 @@
    参与统计设置: - +
    @@ -103,7 +103,7 @@
    - @@ -132,63 +132,35 @@ - 日期▲日期▼日期 - - 游戏名称 - - - 渠道名称 - + 日期▲日期▼日期 - 新增玩家▲新增玩家▼新增玩家 - - 活跃玩家▲活跃玩家▼活跃玩家 + 新增玩家▲新增玩家▼新增玩家 - 1日留存▲1日留存▼1日留存 + 活跃玩家▲活跃玩家▼活跃玩家 - 充值▲充值▼充值 + 充值金额▲充值金额▼充值金额 - 付费玩家▲付费玩家▼付费玩家 + 付费玩家▲付费玩家▼付费玩家 - 新付费玩家▲新付费玩家▼新付费玩家 + 付费率▲付费率▼付费率 - 付费率▲付费率▼付费率 - - ARPU▲ARPU▼ARPU + ARPU▲ARPU▼ARPU - ARPPU▲ARPPU▼ARPPU - - 累计付费玩家▲累计付费玩家▼累计付费玩家 - - - 详情 - + ARPPU▲ARPPU▼ARPPU - + - {$vo.time} - - {$game_name} - - - {$promote_name} - - {$vo.register_num} - {$vo.act_user} - {$vo.keep_num}% - {$vo.spend} - {$vo.spend_people} - {$vo.new_pop} - {$vo.spend_rate}% - {$vo.ARPU} - {$vo.ARPPU} - {$vo.pop_num} - - 查看 - + {$vo.date} + {$vo.new_user} + {$vo.login_user} + {$vo.pay_amount} + {$vo.pay_user} + {$vo.pay_rate}% + {$vo.arpu} + {$vo.arppu} @@ -196,13 +168,13 @@
    - 导出 + 导出 {$_page|default=''}
    @@ -210,11 +182,11 @@ @@ -249,8 +221,8 @@ $(function(){ if(interval < 0 || start == ''){ layer.msg('请选择搜索时间'); return false; - }else if(interval>90){ - layer.msg('请选择90日内的时间段'); + }else if(interval>31){ + layer.msg('请选择31日内的时间段'); return false; } @@ -283,8 +255,8 @@ $(function(){ $(".paixu").click(function(){ var that=$(this); $data_order=that.attr('data-order'); - $order_type='{$userarpu_order}'; - if($order_type==''||$order_type=='4'){ + $order_type='{$order}'; + if($order_type==0||$order_type=='4'){ $(".sortBy").attr('name','data_order'); val='3,'+$data_order; $(".sortBy").attr('value',val); diff --git a/Application/Admin/View/Stat/userarpu_old.html b/Application/Admin/View/Stat/userarpu_old.html new file mode 100644 index 000000000..de5c56d00 --- /dev/null +++ b/Application/Admin/View/Stat/userarpu_old.html @@ -0,0 +1,407 @@ + + + + + + + + + + + + + +
    +
    +
    + 参与统计设置: + + +
    +
    + +
    +
    + +
    +
    + +  -  + +
    +
    + +
    +
    + +
    + +
    + 搜索 +
    +
    +
    + + +
    +
    + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
    日期▲日期▼日期游戏名称渠道名称新增玩家▲新增玩家▼新增玩家活跃玩家▲活跃玩家▼活跃玩家1日留存▲1日留存▼1日留存充值▲充值▼充值付费玩家▲付费玩家▼付费玩家新付费玩家▲新付费玩家▼新付费玩家付费率▲付费率▼付费率ARPU▲ARPU▼ARPUARPPU▲ARPPU▼ARPPU累计付费玩家▲累计付费玩家▼累计付费玩家详情
    {$vo.time}{$game_name}{$promote_name}{$vo.register_num}{$vo.act_user}{$vo.keep_num}%{$vo.spend}{$vo.spend_people}{$vo.new_pop}{$vo.spend_rate}%{$vo.ARPU}{$vo.ARPPU}{$vo.pop_num}查看
    +
    +
    +
    + 导出 + {$_page|default=''} +
    +
    + + + + +if(C('COLOR_STYLE')=='blue_color') echo ''; + + + + + + From 486b5e1f833ff8608c234c2992fefcf8f2c8b4d9 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Mon, 15 Jun 2020 12:59:24 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BC=98=E5=8C=96curl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Admin/Controller/StatController.class.php | 56 ++++++++++++++++--- Application/Admin/View/Stat/userarpu.html | 15 ++++- .../Admin/View/Stat/userretention.html | 15 +++-- 3 files changed, 71 insertions(+), 15 deletions(-) diff --git a/Application/Admin/Controller/StatController.class.php b/Application/Admin/Controller/StatController.class.php index 3543c2d9b..fe17da456 100644 --- a/Application/Admin/Controller/StatController.class.php +++ b/Application/Admin/Controller/StatController.class.php @@ -145,7 +145,8 @@ class StatController extends ThinkController $start = I('start', date('Y-m-d',strtotime('-7 day'))); $end = empty(I('end')) ? time_format(time(),'Y-m-d') : I('end'); $dataOrder = I('data_order', ''); - $gameId = I('game_id', 0); + $baseGameId = I('game_id', 0); + $deviceType = I('device_type', ''); $promoteId = I('promote_id', 0); $orderType = 'asc'; @@ -160,10 +161,14 @@ class StatController extends ThinkController $status = true; $data = false; $error = ''; - if ($gameId == 0) { + if ($baseGameId == 0) { $error = '请选择游戏!'; $status = false; } + if ($deviceType == '') { + $error = '请选择设备类型!'; + $status = false; + } $startTime = strtotime($start . ' 00:00:00'); $endTime = strtotime($end . ' 23:59:59') + 1; if ((($endTime - $startTime)/(24*3600)) > 31) { @@ -171,6 +176,10 @@ class StatController extends ThinkController $status = false; } if ($status) { + + $baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find(); + $gameId = $deviceType == 'android' ? $baseGame['android_game_id'] : $baseGame['ios_game_id']; + $client = new Client([ 'base_uri' => C('TASK_URL'), 'timeout' => 10.0, @@ -216,7 +225,9 @@ class StatController extends ThinkController $this->assign('error', $error); } - $this->assign('data', $data); + $baseGames = M('base_game', 'tab_')->select(); + + $this->assign('baseGames', $baseGames); $this->assign('order_type', $orderType); $this->assign('order_column', $orderColumn); $this->assign('data', $data); @@ -675,9 +686,10 @@ AND UNIX_TIMESTAMP( { $start = I('start', date('Y-m-d')); $end = I('end', date('Y-m-d')); - $gameIds = I('game_ids', ''); + $baseGameIds = I('game_ids', ''); $promoteId = I('promote_id', 0); $dataOrder = I('data_order', ''); + $deviceType = I('device_type', ''); $containBindCoins = I('contain_bind_coins', 0); $orderType = ''; @@ -697,15 +709,42 @@ AND UNIX_TIMESTAMP( $startTime = strtotime($start . ' 00:00:00'); $endTime = strtotime($end . ' 23:59:59'); - $gameIdRows = $gameIds ? explode(',', $gameIds) : []; - + $baseGameIdRows = $baseGameIds ? explode(',', $baseGameIds) : []; + $baseGames = M('base_game', 'tab_')->select(); + + $gameIds = null; $conditions = []; - if (count($gameIdRows)) { - $conditions['game_id'] = ['in', $gameIdRows]; + if (count($baseGameIdRows)) { + $tmpBaseGames = M('base_game', 'tab_')->where(['id' => ['in', $baseGameIdRows]])->select(); + $gameIds = array_merge(array_column($tmpBaseGames, 'android_game_id'), array_column($tmpBaseGames, 'ios_game_id')); } if (count($promoteIds)) { $conditions['promote_id'] = ['in', $promoteIds]; } + if ($deviceType != '') { + if ($gameIds) { + $gameIds = ( + $deviceType == 'android' ? + array_intersect($gameIds, array_column($baseGames, 'android_game_id')) : + array_intersect($gameIds, array_column($baseGames, 'ios_game_id')) + ); + } else { + $gameIds = ( + $deviceType == 'android' ? + array_column($baseGames, 'android_game_id') : + array_column($baseGames, 'ios_game_id') + ); + } + } + + if ($gameIds && count($gameIds)) { + if (count($gameIds)) { + $conditions['game_id'] = ['in', $gameIds]; + } else { + $conditions['game_id'] = ['in', 0]; + } + } + // 新增用户 /* M('user', 'tab_') @@ -795,6 +834,7 @@ AND UNIX_TIMESTAMP( } $this->meta_title = 'ARPU统计'; + $this->assign('baseGames', $baseGames); $this->assign('records', $rows); $this->assign('order', $order); $this->assign('orderType', $orderType); diff --git a/Application/Admin/View/Stat/userarpu.html b/Application/Admin/View/Stat/userarpu.html index 45e9da560..82a9db2f0 100644 --- a/Application/Admin/View/Stat/userarpu.html +++ b/Application/Admin/View/Stat/userarpu.html @@ -105,9 +105,16 @@
    +
    +
    +
    @@ -173,6 +180,7 @@ 'end'=>$_GET['end'], 'game_ids'=>$_GET['game_ids'], 'promote_id'=>$_GET['promote_id'], + 'device_type'=>$_GET['device_type'], 'export'=>1, ),false)}">导出 {$_page|default=''} @@ -187,6 +195,7 @@ Think.setValue('start',"{$Think.get.start|default=''}"); Think.setValue('end',"{$Think.get.end|default=''}"); Think.setValue('promote_id',{$Think.get.promote_id|default='""'}); Think.setValue('game_ids',{$Think.get.game_ids|default='""'}); +Think.setValue('device_type',{$Think.get.device_type|default='""'}); Think.setValue('row',{$Think.get.row|default=10}); $(".select_gallery").select2(); diff --git a/Application/Admin/View/Stat/userretention.html b/Application/Admin/View/Stat/userretention.html index 1c3cf81e0..eae3a6368 100644 --- a/Application/Admin/View/Stat/userretention.html +++ b/Application/Admin/View/Stat/userretention.html @@ -47,10 +47,17 @@
    + + + + +
    +
    +