Tree 3 هفته پیش
والد
کامیت
cc9899806b

+ 73 - 41
app/Http/Controllers/Admin/GameDataController.php

@@ -629,65 +629,85 @@ class GameDataController extends Controller
 
     /**
      * 游戏参与情况统计
-     * 按照注册时间统计不同GameID尾号对应的游戏参与情况
+     * 按照注册时间统计不同UserMedal(推荐游戏ID)对应的游戏参与情况
      */
     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'));
 
         // 转换为日期时间格式(包含时间)
         $startDateTime = $startDate . ' 00:00:00';
         $endDateTime = $endDate . ' 23:59:59';
 
-        // 1. 统计注册人数(按GameID尾号分组)
-        // 使用 SUBSTRING 和 LEN 函数获取最后一位数字(SQL Server 兼容)
+        // 1. 统计注册人数(按UserMedal分组)
         $registerStats = DB::connection('read')
             ->table(TableName::QPAccountsDB() . 'AccountsInfo as ai')
             ->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('
-                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
             ')
-            ->groupBy(DB::raw('CAST(SUBSTRING(CAST(ai.GameID AS VARCHAR), LEN(CAST(ai.GameID AS VARCHAR)), 1) AS INT)'))
+            ->groupBy('ai.UserMedal')
             ->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')
             ->join(TableName::QPAccountsDB() . 'AccountsInfo as ai', 'ut.UserID', '=', 'ai.UserID')
             ->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')
             ->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()
-            ->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()
-            ->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 = [];
-        if (!empty($gameIds)) {
+        if (!empty($allGameIds)) {
             $gamesData = DB::connection('mysql')
                 ->table('webgame.games')
-                ->whereIn('id', $gameIds)
+                ->whereIn('id', $allGameIds)
                 ->select('id', 'brand', 'title')
                 ->get();
 
@@ -696,27 +716,39 @@ class GameDataController extends Controller
             }
         }
 
-        // 5. 组装统计数据
+        // 6. 组装统计数据
         $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;
-
-            $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;
             }
 
             $statistics[] = [
-                'last_digit' => $i,
+                'game_id' => $gameId,
                 'game_name' => $gameName,
                 'register_count' => $registerCount,
                 'played_count' => $playedCount,
                 'participation_rate' => $participationRate,
+                'paid_count' => $paidCount,
+                'paid_rate' => $paidRate,
             ];
         }
 

+ 10 - 10
app/Http/Controllers/Admin/LiveDataController.php

@@ -70,11 +70,11 @@ class LiveDataController extends Controller
 
         $ccsall=array_merge($ccs1,$ccs2);
 
-        $dataGropSums=[991=>$ccsall,992=>$ccs1,993=>$ccs2];
+        $dataGropSums=[991=>$ccsall];
 
-        $Channels[991]="24680总计";
-        $Channels[992]="自营";
-        $Channels[993]="24680ARIES";
+        $Channels[991]="总计";
+//        $Channels[992]="自营";
+//        $Channels[993]="24680ARIES";
 
 
 
@@ -131,14 +131,14 @@ class LiveDataController extends Controller
         }
 
 //        $chanel_orders = [  121,101,110,125,105, 100,122,126,130,146,124,156,158,129,133,146,152,    106,123, 103,  104, 113,127, 131,141,144,148,149,150,151       ,128,132];
-        $chanel_orders=array_merge($dataGropSums[992],$dataGropSums[993]);
+//        $chanel_orders=array_merge($dataGropSums[992],$dataGropSums[993]);
 
         $nadmins = [];
-        foreach ($chanel_orders as $channel) {
-            if (in_array($channel, $adminChannels)) {
-                array_push($nadmins, $channel);
-            }
-        }
+//        foreach ($chanel_orders as $channel) {
+//            if (in_array($channel, $adminChannels)) {
+//                array_push($nadmins, $channel);
+//            }
+//        }
 
         foreach ($adminChannels as $channel) {
             if (!in_array($channel, $nadmins)) {

+ 14 - 4
resources/views/admin/game_data/participation_statistics.blade.php

@@ -34,18 +34,18 @@
                             <table class="table table-bordered">
                                 <thead>
                                 <tr>
-                                    <th width="10%">{{ __('auto.GameID尾号') }}</th>
-                                    <th width="30%">{{ __('auto.尾号对应的游戏') }}</th>
+                                    <th width="25%">{{ __('auto.推荐进入的游戏') }}</th>
                                     <th width="15%">{{ __('auto.注册人数') }}</th>
                                     <th width="15%">{{ __('auto.参与游戏人数') }}</th>
                                     <th width="15%">{{ __('auto.参游率') }}</th>
+                                    <th width="15%">{{ __('auto.付费人数') }}</th>
+                                    <th width="15%">{{ __('auto.付费率') }}</th>
                                 </tr>
                                 </thead>
                                 <tbody>
                                 @foreach($statistics as $stat)
                                     <tr>
-                                        <td>{{ $stat['last_digit'] }}</td>
-                                        <td>{{ $stat['game_name'] }}</td>
+                                        <td>{{ $stat['game_name'] }} <small class="text-muted">(ID: {{ $stat['game_id'] }})</small></td>
                                         <td>{{ $stat['register_count'] }}</td>
                                         <td>{{ $stat['played_count'] }}</td>
                                         <td>
@@ -57,6 +57,16 @@
                                                 <span class="badge badge-secondary">-</span>
                                             @endif
                                         </td>
+                                        <td>{{ $stat['paid_count'] }}</td>
+                                        <td>
+                                            @if($stat['register_count'] > 0)
+                                                <span class="badge badge-{{ $stat['paid_rate'] >= 20 ? 'success' : ($stat['paid_rate'] >= 10 ? 'warning' : 'danger') }}">
+                                                    {{ $stat['paid_rate'] }}%
+                                                </span>
+                                            @else
+                                                <span class="badge badge-secondary">-</span>
+                                            @endif
+                                        </td>
                                     </tr>
                                 @endforeach
                                 </tbody>