|
@@ -626,4 +626,112 @@ class GameDataController extends Controller
|
|
|
]);
|
|
]);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 游戏参与情况统计
|
|
|
|
|
+ * 按照注册时间统计不同GameID尾号对应的游戏参与情况
|
|
|
|
|
+ */
|
|
|
|
|
+ public function gameParticipationStatistics(Request $request)
|
|
|
|
|
+ {
|
|
|
|
|
+ // 获取注册时间范围
|
|
|
|
|
+ $startDate = $request->input('start_date', date('Y-m-d', strtotime('-30 days')));
|
|
|
|
|
+ $endDate = $request->input('end_date', date('Y-m-d'));
|
|
|
|
|
+
|
|
|
|
|
+ // 转换为日期时间格式(包含时间)
|
|
|
|
|
+ $startDateTime = $startDate . ' 00:00:00';
|
|
|
|
|
+ $endDateTime = $endDate . ' 23:59:59';
|
|
|
|
|
+
|
|
|
|
|
+ // 1. 统计注册人数(按GameID尾号分组)
|
|
|
|
|
+ // 使用 SUBSTRING 和 LEN 函数获取最后一位数字(SQL Server 兼容)
|
|
|
|
|
+ $registerStats = DB::connection('read')
|
|
|
|
|
+ ->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
|
|
|
|
|
+ ->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
|
|
|
|
|
+ ->whereNotNull('ai.GameID')
|
|
|
|
|
+ ->where('ai.GameID', '!=', '')
|
|
|
|
|
+ ->selectRaw('
|
|
|
|
|
+ CAST(SUBSTRING(CAST(ai.GameID AS VARCHAR), LEN(CAST(ai.GameID AS VARCHAR)), 1) AS INT) as last_digit,
|
|
|
|
|
+ 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)'))
|
|
|
|
|
+ ->get()
|
|
|
|
|
+ ->keyBy('last_digit');
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 获取所有参与游戏的用户(WinInning + LostInning > 0)
|
|
|
|
|
+ $playedUsers = 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.GameID')
|
|
|
|
|
+ ->where('ai.GameID', '!=', '')
|
|
|
|
|
+ ->whereRaw('(ISNULL(ut.WinInning, 0) + ISNULL(ut.LostInning, 0)) > 0')
|
|
|
|
|
+ ->selectRaw('
|
|
|
|
|
+ ai.UserID,
|
|
|
|
|
+ CAST(SUBSTRING(CAST(ai.GameID AS VARCHAR), LEN(CAST(ai.GameID AS VARCHAR)), 1) AS INT) as last_digit
|
|
|
|
|
+ ')
|
|
|
|
|
+ ->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')
|
|
|
|
|
+ ->get()
|
|
|
|
|
+ ->keyBy('number');
|
|
|
|
|
+
|
|
|
|
|
+ // 4. 获取游戏信息(从MySQL)
|
|
|
|
|
+ $gameIds = $gameMappings->pluck('game_id')->unique()->toArray();
|
|
|
|
|
+ $games = [];
|
|
|
|
|
+ if (!empty($gameIds)) {
|
|
|
|
|
+ $gamesData = DB::connection('mysql')
|
|
|
|
|
+ ->table('webgame.games')
|
|
|
|
|
+ ->whereIn('id', $gameIds)
|
|
|
|
|
+ ->select('id', 'brand', 'title')
|
|
|
|
|
+ ->get();
|
|
|
|
|
+
|
|
|
|
|
+ foreach ($gamesData as $game) {
|
|
|
|
|
+ $games[$game->id] = $game;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 5. 组装统计数据
|
|
|
|
|
+ $statistics = [];
|
|
|
|
|
+ for ($i = 0; $i <= 9; $i++) {
|
|
|
|
|
+ $registerStat = $registerStats->get($i);
|
|
|
|
|
+ $registerCount = $registerStat ? $registerStat->register_count : 0;
|
|
|
|
|
+ $playedCount = $playedUsers->get($i) ?? 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];
|
|
|
|
|
+ $gameName = $game->brand . ' - ' . $game->title;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $statistics[] = [
|
|
|
|
|
+ 'last_digit' => $i,
|
|
|
|
|
+ 'game_name' => $gameName,
|
|
|
|
|
+ 'register_count' => $registerCount,
|
|
|
|
|
+ 'played_count' => $playedCount,
|
|
|
|
|
+ 'participation_rate' => $participationRate,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 按注册人数排序(降序)
|
|
|
|
|
+ usort($statistics, function ($a, $b) {
|
|
|
|
|
+ return $b['register_count'] <=> $a['register_count'];
|
|
|
|
|
+ });
|
|
|
|
|
+
|
|
|
|
|
+ return view('admin.game_data.participation_statistics', [
|
|
|
|
|
+ 'statistics' => $statistics,
|
|
|
|
|
+ 'start_date' => $startDate,
|
|
|
|
|
+ 'end_date' => $endDate,
|
|
|
|
|
+ ]);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
}
|
|
}
|