|
|
@@ -626,4 +626,143 @@ class GameDataController extends Controller
|
|
|
]);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 游戏参与情况统计
|
|
|
+ * 按照注册时间统计不同UserMedal(推荐游戏ID)对应的游戏参与情况
|
|
|
+ */
|
|
|
+ public function gameParticipationStatistics(Request $request)
|
|
|
+ {
|
|
|
+ // 获取注册时间范围,默认近3天
|
|
|
+ $startDate = $request->input('start_date', date('Y-m-d', strtotime('-3 days')));
|
|
|
+ $endDate = $request->input('end_date', date('Y-m-d'));
|
|
|
+
|
|
|
+ // 转换为日期时间格式(包含时间)
|
|
|
+ $startDateTime = $startDate . ' 00:00:00';
|
|
|
+ $endDateTime = $endDate . ' 23:59:59';
|
|
|
+
|
|
|
+ // 1. 统计注册人数(按UserMedal分组)
|
|
|
+ $registerStats = DB::connection('read')
|
|
|
+ ->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
|
|
|
+ ->whereBetween('ai.RegisterDate', [$startDateTime, $endDateTime])
|
|
|
+ ->whereNotNull('ai.UserMedal')
|
|
|
+ ->where('ai.UserMedal', '!=', '')
|
|
|
+ ->where('ai.UserMedal', '!=', 0)
|
|
|
+ ->where('ai.Channel', '!=', 100)
|
|
|
+ ->selectRaw('
|
|
|
+ ai.UserMedal as game_id,
|
|
|
+ COUNT(DISTINCT ai.UserID) as register_count
|
|
|
+ ')
|
|
|
+ ->groupBy('ai.UserMedal')
|
|
|
+ ->get()
|
|
|
+ ->keyBy('game_id');
|
|
|
+
|
|
|
+ // 2. 统计参与游戏的用户数(WinInning + LostInning > 0,按UserMedal分组)
|
|
|
+ $playedStats = 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)
|
|
|
+ ->whereRaw('(ISNULL(ut.WinInning, 0) + ISNULL(ut.LostInning, 0)) > 0')
|
|
|
+ ->selectRaw('
|
|
|
+ ai.UserMedal as game_id,
|
|
|
+ COUNT(DISTINCT ai.UserID) as played_count
|
|
|
+ ')
|
|
|
+ ->groupBy('ai.UserMedal')
|
|
|
+ ->get()
|
|
|
+ ->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()
|
|
|
+ ->keyBy('game_id');
|
|
|
+
|
|
|
+ // 4. 获取所有涉及的游戏ID
|
|
|
+ $allGameIds = collect([$registerStats, $playedStats, $paidStats])
|
|
|
+ ->flatMap(function ($stats) {
|
|
|
+ return $stats->pluck('game_id');
|
|
|
+ })
|
|
|
+ ->unique()
|
|
|
+ ->filter()
|
|
|
+ ->toArray();
|
|
|
+
|
|
|
+ // 5. 获取游戏信息(从MySQL)
|
|
|
+ $games = [];
|
|
|
+ if (!empty($allGameIds)) {
|
|
|
+ $gamesData = DB::connection('mysql')
|
|
|
+ ->table('webgame.games')
|
|
|
+ ->whereIn('id', $allGameIds)
|
|
|
+ ->select('id', 'brand', 'title')
|
|
|
+ ->get();
|
|
|
+
|
|
|
+ foreach ($gamesData as $game) {
|
|
|
+ $games[$game->id] = $game;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 组装统计数据
|
|
|
+ $statistics = [];
|
|
|
+ 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;
|
|
|
+
|
|
|
+ // 付费率 = 付费人数 / 注册人数
|
|
|
+ $paidRate = $registerCount > 0 ? round(($paidCount / $registerCount) * 100, 2) : 0;
|
|
|
+
|
|
|
+ // 获取游戏名称
|
|
|
+ $gameName = '未知游戏';
|
|
|
+ if (isset($games[$gameId])) {
|
|
|
+ $game = $games[$gameId];
|
|
|
+ $gameName = $game->brand . ' - ' . $game->title;
|
|
|
+ }
|
|
|
+
|
|
|
+ $statistics[] = [
|
|
|
+ 'game_id' => $gameId,
|
|
|
+ 'game_name' => $gameName,
|
|
|
+ 'register_count' => $registerCount,
|
|
|
+ 'played_count' => $playedCount,
|
|
|
+ 'participation_rate' => $participationRate,
|
|
|
+ 'paid_count' => $paidCount,
|
|
|
+ 'paid_rate' => $paidRate,
|
|
|
+ ];
|
|
|
+ }
|
|
|
+
|
|
|
+ // 按注册人数排序(降序)
|
|
|
+ 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,
|
|
|
+ ]);
|
|
|
+ }
|
|
|
+
|
|
|
}
|