From ceadb8562f69adadebfebcd88c66e69f03ac7757 Mon Sep 17 00:00:00 2001 From: ELF <360197197@qq.com> Date: Thu, 12 Nov 2020 15:34:17 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E60/90=E6=97=A5=E7=95=99?= =?UTF-8?q?=E5=AD=98=E7=8E=87=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controller/ConsoleController.class.php | 32 +++++++++++ .../Base/Repository/GameRepository.class.php | 53 +++++++++++++++++++ 2 files changed, 85 insertions(+) diff --git a/Application/Admin/Controller/ConsoleController.class.php b/Application/Admin/Controller/ConsoleController.class.php index c720d5d4b..85cf9a5a9 100644 --- a/Application/Admin/Controller/ConsoleController.class.php +++ b/Application/Admin/Controller/ConsoleController.class.php @@ -13,6 +13,7 @@ use think\Db; use Base\Task\Task; use Base\Service\MarketService; use Base\Tool\AggregateClient; +use Base\Repository\GameRepository; class ConsoleController extends Think { @@ -615,4 +616,35 @@ class ConsoleController extends Think { // ARPU (当日充值金额/当日活跃用户数) // ARRPU (当日充值金额/当日充值用户数) } + + public function statUserRetention() + { + $begin = I('begin', date('Y-m-d')); + $end = I('end', date('Y-m-d')); + $baseGameId = I('base_game_id', 0); + + $repository = new GameRepository(); + $baseGame = M('base_game', 'tab_')->where(['id' => $baseGameId])->find(); + + $beginDate = strtotime($begin); + $endDate = strtotime($end); + $dayTime = 24 * 3600; + + $trs = ''; + for ($date = $beginDate; $date <= $endDate; $date = $date + $dayTime) { + $dateStr = date('Y-m-d', $date); + $userRegisterCount = $repository->getUserRegisterCount($baseGame, $dateStr); + $userRetentionCount60 = $repository->getUserRetentionCount($baseGame, $dateStr, 60); + $userRetentionCount90 = $repository->getUserRetentionCount($baseGame, $dateStr, 90); + $trs .= '' . PHP_EOL; + $trs .= '' . $dateStr . '' . PHP_EOL; + $trs .= '' . $userRegisterCount . '' . PHP_EOL; + $trs .= '' . $userRetentionCount60 . '' . PHP_EOL; + $trs .= '' . $userRetentionCount90 . '' . PHP_EOL; + $trs .= '' . round($userRetentionCount60 / $userRegisterCount * 100, 2) . '%' . '' . PHP_EOL; + $trs .= '' . round($userRetentionCount90 / $userRegisterCount * 100, 2) . '%' . '' . PHP_EOL; + $trs .= ''. PHP_EOL; + } + echo '' . PHP_EOL . $trs . '
'; + } } diff --git a/Application/Base/Repository/GameRepository.class.php b/Application/Base/Repository/GameRepository.class.php index 25e3d44e0..3e358037e 100644 --- a/Application/Base/Repository/GameRepository.class.php +++ b/Application/Base/Repository/GameRepository.class.php @@ -53,4 +53,57 @@ class GameRepository ->order('server_id asc') ->select(); } + + public function getGameIdsByBaseGame($baseGame, $deviceType = 0) + { + $gameIds = []; + if ($deviceType == 1) { + $gameIds[] = $baseGame['android_game_id']; + } elseif ($deviceType == 2) { + $gameIds[] = $baseGame['ios_game_id']; + } else { + $gameIds[] = $baseGame['android_game_id']; + $gameIds[] = $baseGame['ios_game_id']; + } + return $gameIds; + } + + public function getUserRegisterCount($baseGame, $date, $deviceType = 0) + { + $gameIds = $this->getGameIdsByBaseGame($baseGame, $deviceType); + $timeBegin = strtotime($date . ' 00:00:00'); + $timeEnd = strtotime($date . ' 23:59:59'); + + $subCondition = [ + 'game_id' => ['in', $gameIds], + '_string' => 'tab_user.id=tab_user_play_info.user_id' + ]; + + $subSql = M('user_play_info', 'tab_')->field('1')->where($subCondition)->select(false); + return M('user', 'tab_')->where([ + 'register_time' => ['between', [$timeBegin, $timeEnd]], + '_string' => 'exists (' . $subSql . ')' + ])->count(); + } + + public function getUserRetentionCount($baseGame, $date, $day, $deviceType = 0) + { + $gameIds = $this->getGameIdsByBaseGame($baseGame, $deviceType); + + $timeBegin = strtotime($date . ' 00:00:00'); + $timeEnd = strtotime($date . ' 23:59:59'); + $retentionTime = $timeBegin + ($day * 24 * 3600); + + $subCondition = [ + 'game_id' => ['in', $gameIds], + '_string' => 'tab_user.id=tab_user_play_info.user_id', + 'play_time' => ['egt', $retentionTime], + ]; + + $subSql = M('user_play_info', 'tab_')->field('1')->where($subCondition)->select(false); + return M('user', 'tab_')->where([ + 'register_time' => ['between', [$timeBegin, $timeEnd]], + '_string' => 'exists (' . $subSql . ')' + ])->count(); + } } \ No newline at end of file