From 144e4e4ea7133f66163a9823b3ade7017cf6677d Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Thu, 16 Apr 2020 21:55:27 +0800 Subject: [PATCH] =?UTF-8?q?=E8=AE=A1=E7=AE=97ARPU?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ConsoleController.class.php | 107 ++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php index b6bdf7ee3..7fd9fc095 100644 --- a/Application/Admin/Controller/ConsoleController.class.php +++ b/Application/Admin/Controller/ConsoleController.class.php @@ -428,4 +428,111 @@ class ConsoleController extends Think { } } + + public function arpu() + { + $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); + + // 新增用户 + + /* 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([ + 'game_id' => ['in', $gameIdRows], + '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([ + 'game_id' => ['in', $gameIdRows], + 'create_time' => ['between', [$startTime, $endTime]] + ]) + ->group('date') + ->select(); + $loginUsers = index_by_column('date', $loginUsers); + + // 付费玩家,付费金额 + $payLogs = M('spend', 'tab_') + ->field('count(DISTINCT user_id) count, sum(pay_amount) amount, FROM_UNIXTIME(pay_time, "%Y-%m-%d") date') + ->where([ + 'game_id' => ['in', $gameIdRows], + 'pay_time' => ['between', [$startTime, $endTime]], + 'pay_status' => 1, + ]) + ->group('date') + ->select(); + $payLogs = index_by_column('date', $payLogs); + + // 起始时间前的总充值金额 + /* $beforePayAmount =M('spend', 'tab_') + ->where([ + 'game_id' => ['in', $gameIdRows], + 'pay_time' => ['lt', $startTime], + 'pay_status' => 1, + ]) + ->sum('pay_amount'); */ + + $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) . '%') : '--', + 'arpu' => $loginUser > 0 ? (round($payAmount / $loginUser, 2)) : '0.00', + 'arppu' => $payUser > 0 ? (round($payAmount / $payUser, 2)) : '0.00', + ]; + } + + $thml = ''; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + foreach ($rows as $row) { + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + $html .= '' . PHP_EOL; + } + $html .= '
日期新增用户活跃玩家充值金额付费玩家付费率ARPUARPPU
' . $row['date'] . '' . $row['new_user'] . '' . $row['login_user'] . '' . $row['pay_amount'] . '' . $row['pay_user'] . '' . $row['pay_rate'] . '' . $row['arpu'] . '' . $row['arppu'] . '
' . PHP_EOL; + echo $html; + + // 付费率 (当日充值用户数/当日活跃用户数) + // ARPU (当日充值金额/当日活跃用户数) + // ARRPU (当日充值金额/当日充值用户数) + } }