input('start_date', $today); $endDate = $request->input('end_date', $today); $rows = DB::connection('read')->table(GameEnterDailyStat::TABLE) ->whereBetween('log_date', [$startDate, $endDate]) ->select('log_date', 'game_id', 'enter_count', 'total_duration_ms') ->orderByDesc('log_date') ->orderByDesc('enter_count') ->get(); $gameIds = $rows->pluck('game_id')->filter()->unique()->values()->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; } } $statistics = []; foreach ($rows as $row) { $gameId = (int) $row->game_id; $enterCount = (int) $row->enter_count; $totalMs = (int) $row->total_duration_ms; $avgMs = $enterCount > 0 ? $totalMs / $enterCount : 0; $gameName = __('auto.δ֪ÓÎÏ·'); if (isset($games[$gameId])) { $game = $games[$gameId]; $gameName = $game->brand . ' - ' . $game->title; } $statistics[] = [ 'log_date' => $row->log_date, 'game_id' => $gameId, 'game_name' => $gameName, 'enter_count' => $enterCount, 'avg_duration_ms' => round($avgMs, 2), 'avg_duration_sec' => round($avgMs / 1000, 3), ]; } return view('admin.game_enter_log.statistics', [ 'statistics' => $statistics, 'start_date' => $startDate, 'end_date' => $endDate, ]); } }