|
@@ -629,65 +629,85 @@ class GameDataController extends Controller
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 游戏参与情况统计
|
|
* 游戏参与情况统计
|
|
|
- * 按照注册时间统计不同GameID尾号对应的游戏参与情况
|
|
|
|
|
|
|
+ * 按照注册时间统计不同UserMedal(推荐游戏ID)对应的游戏参与情况
|
|
|
*/
|
|
*/
|
|
|
public function gameParticipationStatistics(Request $request)
|
|
public function gameParticipationStatistics(Request $request)
|
|
|
{
|
|
{
|
|
|
- // 获取注册时间范围
|
|
|
|
|
- $startDate = $request->input('start_date', date('Y-m-d', strtotime('-30 days')));
|
|
|
|
|
|
|
+ // 获取注册时间范围,默认近3天
|
|
|
|
|
+ $startDate = $request->input('start_date', date('Y-m-d', strtotime('-3 days')));
|
|
|
$endDate = $request->input('end_date', date('Y-m-d'));
|
|
$endDate = $request->input('end_date', date('Y-m-d'));
|
|
|
|
|
|
|
|
// 转换为日期时间格式(包含时间)
|
|
// 转换为日期时间格式(包含时间)
|
|
|
$startDateTime = $startDate . ' 00:00:00';
|
|
$startDateTime = $startDate . ' 00:00:00';
|
|
|
$endDateTime = $endDate . ' 23:59:59';
|
|
$endDateTime = $endDate . ' 23:59:59';
|
|
|
|
|
|
|
|
- // 1. 统计注册人数(按GameID尾号分组)
|
|
|
|
|
- // 使用 SUBSTRING 和 LEN 函数获取最后一位数字(SQL Server 兼容)
|
|
|
|
|
|
|
+ // 1. 统计注册人数(按UserMedal分组)
|
|
|
$registerStats = DB::connection('read')
|
|
$registerStats = DB::connection('read')
|
|
|
->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
|
|
->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
|
|
|
->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
|
|
->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
|
|
|
- ->whereNotNull('ai.GameID')
|
|
|
|
|
- ->where('ai.GameID', '!=', '')
|
|
|
|
|
|
|
+ ->whereNotNull('ai.UserMedal')
|
|
|
|
|
+ ->where('ai.UserMedal', '!=', '')
|
|
|
|
|
+ ->where('ai.UserMedal', '!=', 0)
|
|
|
|
|
+ ->where('ai.Channel', '!=', 100)
|
|
|
->selectRaw('
|
|
->selectRaw('
|
|
|
- CAST(SUBSTRING(CAST(ai.GameID AS VARCHAR), LEN(CAST(ai.GameID AS VARCHAR)), 1) AS INT) as last_digit,
|
|
|
|
|
|
|
+ ai.UserMedal as game_id,
|
|
|
COUNT(DISTINCT ai.UserID) as register_count
|
|
COUNT(DISTINCT ai.UserID) as register_count
|
|
|
')
|
|
')
|
|
|
- ->groupBy(DB::raw('CAST(SUBSTRING(CAST(ai.GameID AS VARCHAR), LEN(CAST(ai.GameID AS VARCHAR)), 1) AS INT)'))
|
|
|
|
|
|
|
+ ->groupBy('ai.UserMedal')
|
|
|
->get()
|
|
->get()
|
|
|
- ->keyBy('last_digit');
|
|
|
|
|
|
|
+ ->keyBy('game_id');
|
|
|
|
|
|
|
|
- // 2. 获取所有参与游戏的用户(WinInning + LostInning > 0)
|
|
|
|
|
- $playedUsers = DB::connection('read')
|
|
|
|
|
|
|
+ // 2. 统计参与游戏的用户数(WinInning + LostInning > 0,按UserMedal分组)
|
|
|
|
|
+ $playedStats = DB::connection('read')
|
|
|
->table('QPRecordDB.dbo.RecordUserTotalStatistics as ut')
|
|
->table('QPRecordDB.dbo.RecordUserTotalStatistics as ut')
|
|
|
->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ut.UserID', '=', 'ai.UserID')
|
|
->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ut.UserID', '=', 'ai.UserID')
|
|
|
->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
|
|
->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
|
|
|
- ->whereNotNull('ai.GameID')
|
|
|
|
|
- ->where('ai.GameID', '!=', '')
|
|
|
|
|
|
|
+ ->whereNotNull('ai.UserMedal')
|
|
|
|
|
+ ->where('ai.UserMedal', '!=', '')
|
|
|
|
|
+ ->where('ai.UserMedal', '!=', 0)
|
|
|
|
|
+ ->where('ai.Channel', '!=', 100)
|
|
|
->whereRaw('(ISNULL(ut.WinInning, 0) + ISNULL(ut.LostInning, 0)) > 0')
|
|
->whereRaw('(ISNULL(ut.WinInning, 0) + ISNULL(ut.LostInning, 0)) > 0')
|
|
|
->selectRaw('
|
|
->selectRaw('
|
|
|
- ai.UserID,
|
|
|
|
|
- CAST(SUBSTRING(CAST(ai.GameID AS VARCHAR), LEN(CAST(ai.GameID AS VARCHAR)), 1) AS INT) as last_digit
|
|
|
|
|
|
|
+ ai.UserMedal as game_id,
|
|
|
|
|
+ COUNT(DISTINCT ai.UserID) as played_count
|
|
|
')
|
|
')
|
|
|
|
|
+ ->groupBy('ai.UserMedal')
|
|
|
->get()
|
|
->get()
|
|
|
- ->groupBy('last_digit')
|
|
|
|
|
- ->map(function ($users) {
|
|
|
|
|
- return $users->pluck('UserID')->unique()->count();
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- // 3. 获取游戏映射关系
|
|
|
|
|
- $gameMappings = DB::connection('write')
|
|
|
|
|
- ->table('agent.dbo.game_number_mapping')
|
|
|
|
|
- ->select('number', 'game_id')
|
|
|
|
|
|
|
+ ->keyBy('game_id');
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 统计付费用户数(Recharge > 0,按UserMedal分组)
|
|
|
|
|
+ $paidStats = DB::connection('read')
|
|
|
|
|
+ ->table('QPRecordDB.dbo.RecordUserTotalStatistics as ut')
|
|
|
|
|
+ ->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ut.UserID', '=', 'ai.UserID')
|
|
|
|
|
+ ->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
|
|
|
|
|
+ ->whereNotNull('ai.UserMedal')
|
|
|
|
|
+ ->where('ai.UserMedal', '!=', '')
|
|
|
|
|
+ ->where('ai.UserMedal', '!=', 0)
|
|
|
|
|
+ ->where('ai.Channel', '!=', 100)
|
|
|
|
|
+ ->where('ut.Recharge', '>', 0)
|
|
|
|
|
+ ->selectRaw('
|
|
|
|
|
+ ai.UserMedal as game_id,
|
|
|
|
|
+ COUNT(DISTINCT ai.UserID) as paid_count
|
|
|
|
|
+ ')
|
|
|
|
|
+ ->groupBy('ai.UserMedal')
|
|
|
->get()
|
|
->get()
|
|
|
- ->keyBy('number');
|
|
|
|
|
|
|
+ ->keyBy('game_id');
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 获取所有涉及的游戏ID
|
|
|
|
|
+ $allGameIds = collect([$registerStats, $playedStats, $paidStats])
|
|
|
|
|
+ ->flatMap(function ($stats) {
|
|
|
|
|
+ return $stats->pluck('game_id');
|
|
|
|
|
+ })
|
|
|
|
|
+ ->unique()
|
|
|
|
|
+ ->filter()
|
|
|
|
|
+ ->toArray();
|
|
|
|
|
|
|
|
- // 4. 获取游戏信息(从MySQL)
|
|
|
|
|
- $gameIds = $gameMappings->pluck('game_id')->unique()->toArray();
|
|
|
|
|
|
|
+ // 5. 获取游戏信息(从MySQL)
|
|
|
$games = [];
|
|
$games = [];
|
|
|
- if (!empty($gameIds)) {
|
|
|
|
|
|
|
+ if (!empty($allGameIds)) {
|
|
|
$gamesData = DB::connection('mysql')
|
|
$gamesData = DB::connection('mysql')
|
|
|
->table('webgame.games')
|
|
->table('webgame.games')
|
|
|
- ->whereIn('id', $gameIds)
|
|
|
|
|
|
|
+ ->whereIn('id', $allGameIds)
|
|
|
->select('id', 'brand', 'title')
|
|
->select('id', 'brand', 'title')
|
|
|
->get();
|
|
->get();
|
|
|
|
|
|
|
@@ -696,27 +716,39 @@ class GameDataController extends Controller
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 5. 组装统计数据
|
|
|
|
|
|
|
+ // 6. 组装统计数据
|
|
|
$statistics = [];
|
|
$statistics = [];
|
|
|
- for ($i = 0; $i <= 9; $i++) {
|
|
|
|
|
- $registerStat = $registerStats->get($i);
|
|
|
|
|
- $registerCount = $registerStat ? $registerStat->register_count : 0;
|
|
|
|
|
- $playedCount = $playedUsers->get($i) ?? 0;
|
|
|
|
|
|
|
+ foreach ($allGameIds as $gameId) {
|
|
|
|
|
+ $registerStat = $registerStats->get($gameId);
|
|
|
|
|
+ $registerCount = $registerStat ? (int)$registerStat->register_count : 0;
|
|
|
|
|
+
|
|
|
|
|
+ $playedStat = $playedStats->get($gameId);
|
|
|
|
|
+ $playedCount = $playedStat ? (int)$playedStat->played_count : 0;
|
|
|
|
|
+
|
|
|
|
|
+ $paidStat = $paidStats->get($gameId);
|
|
|
|
|
+ $paidCount = $paidStat ? (int)$paidStat->paid_count : 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 参游率 = 参与游戏人数 / 注册人数
|
|
|
$participationRate = $registerCount > 0 ? round(($playedCount / $registerCount) * 100, 2) : 0;
|
|
$participationRate = $registerCount > 0 ? round(($playedCount / $registerCount) * 100, 2) : 0;
|
|
|
-
|
|
|
|
|
- $mapping = $gameMappings->get($i);
|
|
|
|
|
- $gameName = '未配置';
|
|
|
|
|
- if ($mapping && isset($games[$mapping->game_id])) {
|
|
|
|
|
- $game = $games[$mapping->game_id];
|
|
|
|
|
|
|
+
|
|
|
|
|
+ // 付费率 = 付费人数 / 注册人数
|
|
|
|
|
+ $paidRate = $registerCount > 0 ? round(($paidCount / $registerCount) * 100, 2) : 0;
|
|
|
|
|
+
|
|
|
|
|
+ // 获取游戏名称
|
|
|
|
|
+ $gameName = '未知游戏';
|
|
|
|
|
+ if (isset($games[$gameId])) {
|
|
|
|
|
+ $game = $games[$gameId];
|
|
|
$gameName = $game->brand . ' - ' . $game->title;
|
|
$gameName = $game->brand . ' - ' . $game->title;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$statistics[] = [
|
|
$statistics[] = [
|
|
|
- 'last_digit' => $i,
|
|
|
|
|
|
|
+ 'game_id' => $gameId,
|
|
|
'game_name' => $gameName,
|
|
'game_name' => $gameName,
|
|
|
'register_count' => $registerCount,
|
|
'register_count' => $registerCount,
|
|
|
'played_count' => $playedCount,
|
|
'played_count' => $playedCount,
|
|
|
'participation_rate' => $participationRate,
|
|
'participation_rate' => $participationRate,
|
|
|
|
|
+ 'paid_count' => $paidCount,
|
|
|
|
|
+ 'paid_rate' => $paidRate,
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|