Merge branch 'hotfix/user_retention_6090' of wmtx/platform into master

新增60/90日留存率统计
master
廖金灵 4 years ago committed by Gogs
commit c3a97d1766

@ -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 .= '<tr>' . PHP_EOL;
$trs .= '<td>' . $dateStr . '</td>' . PHP_EOL;
$trs .= '<td>' . $userRegisterCount . '</td>' . PHP_EOL;
$trs .= '<td>' . $userRetentionCount60 . '</td>' . PHP_EOL;
$trs .= '<td>' . $userRetentionCount90 . '</td>' . PHP_EOL;
$trs .= '<td>' . round($userRetentionCount60 / $userRegisterCount * 100, 2) . '%' . '</td>' . PHP_EOL;
$trs .= '<td>' . round($userRetentionCount90 / $userRegisterCount * 100, 2) . '%' . '</td>' . PHP_EOL;
$trs .= '</tr>'. PHP_EOL;
}
echo '<table>' . PHP_EOL . $trs . '</table>';
}
}

@ -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();
}
}
Loading…
Cancel
Save