Просмотр исходного кода

推荐游戏配置 数据统计

Tree 3 недель назад
Родитель
Сommit
0079c60506

+ 139 - 0
app/Http/Controllers/Admin/GameDataController.php

@@ -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,
+        ]);
+    }
+
 }

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

@@ -32,7 +32,7 @@ class GameNumberMappingController
                 ->whereIn('id', $gameIds)
                 ->select('id', 'brand', 'title')
                 ->get();
-            
+
             // 转换为以 game_id 为键的数组
             foreach ($gamesData as $game) {
                 $games[$game->id] = $game;
@@ -64,21 +64,21 @@ class GameNumberMappingController
                 ->table('agent.dbo.game_number_mapping')
                 ->where('number', $request->number)
                 ->exists();
-            
+
             if ($exists) {
                 return apiReturnFail('该数字已被使用');
             }
-            
+
             // 从 MySQL 检查游戏是否存在
             $gameExists = DB::connection('mysql')
                 ->table('webgame.games')
                 ->where('id', $request->game_id)
                 ->exists();
-            
+
             if (!$gameExists) {
                 return apiReturnFail('选择的游戏不存在');
             }
-            
+
             $validator = Validator::make($request->all(), [
                 'number' => 'required|integer|min:0|max:9',
                 'game_id' => 'required|integer',
@@ -153,21 +153,21 @@ class GameNumberMappingController
                 ->where('number', $request->number)
                 ->where('id', '!=', $id)
                 ->exists();
-            
+
             if ($exists) {
                 return apiReturnFail('该数字已被使用');
             }
-            
+
             // 从 MySQL 检查游戏是否存在
             $gameExists = DB::connection('mysql')
                 ->table('webgame.games')
                 ->where('id', $request->game_id)
                 ->exists();
-            
+
             if (!$gameExists) {
                 return apiReturnFail('选择的游戏不存在');
             }
-            
+
             $validator = Validator::make($request->all(), [
                 'number' => 'required|integer|min:0|max:9',
                 'game_id' => 'required|integer',
@@ -186,7 +186,7 @@ class GameNumberMappingController
             try {
                 // 获取旧的 number,用于清除旧缓存
                 $oldNumber = $mapping->number;
-                
+
                 DB::connection('write')
                     ->table('agent.dbo.game_number_mapping')
                     ->where('id', $id)

+ 55 - 0
app/Http/Controllers/Game/LoginController.php

@@ -1092,6 +1092,61 @@ class LoginController extends Controller
 //        }
         $guser['reg'] = 1;
 
+
+        $defaultGameId = 931;
+        $recommendGame = '/game/' . $defaultGameId;
+        $guser['recommendGame'] = $recommendGame;
+        // 如果用户信息存在,根据GameID的最后一位数字查询映射关系
+        if ($guser && isset($guser['GameID'])) {
+            $gameId = (string)$guser['GameID'];
+            $lastDigit = (int)substr($gameId, -1); // 获取最后一位数字
+
+            // 查询映射关系(带缓存)
+            $cacheKey = 'game_number_mapping:' . $lastDigit;
+            $mapping = null;
+            $cacheHit = false;
+
+            // 尝试从缓存获取
+            $cached = Redis::get($cacheKey);
+            if ($cached !== null) {
+                $decoded = json_decode($cached, true);
+                // 如果解码成功且不是空数组,说明有数据
+                if (is_array($decoded) && !empty($decoded)) {
+                    $mapping = (object)$decoded; // 转换为对象以保持兼容性
+                    $cacheHit = true;
+                } elseif ($decoded === []) {
+                    // 空数组表示数据库中没有记录,已缓存,直接跳过查询
+                    $cacheHit = true;
+                    $mapping = null;
+                }
+            }
+
+            // 缓存未命中,查询数据库
+            if (!$cacheHit) {
+                $mapping = DB::connection('write')
+                    ->table('agent.dbo.game_number_mapping')
+                    ->where('number', $lastDigit)
+                    ->first();
+
+                // 存入缓存,24小时过期
+                if ($mapping) {
+                    Redis::setex($cacheKey, 86400, json_encode($mapping));
+                } else {
+                    // 即使不存在也缓存,避免频繁查询,缓存5分钟
+                    Redis::setex($cacheKey, 300, json_encode([]));
+                }
+            }
+
+            if ($mapping && !empty($mapping) && isset($mapping->game_id) && $mapping->game_id) {
+                $defaultGameId = $mapping->game_id;
+                $recommendGame = '/game/' . $mapping->game_id;
+            }
+            $guser['recommendGame'] = $recommendGame;
+        }
+
+        AccountsInfo::where('UserID', $UserID)->update(['UserMedal' => $defaultGameId ]);
+
+
         if($type=='guest'){
             $guser['account'] = $account;
             $guser['password'] = $password;

+ 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>

+ 7 - 4
routes/web.php

@@ -720,28 +720,31 @@ Route::group([
         // 游戏输赢排行榜
         $route->get('/game_data/winlose_rank', 'Admin\GameWinLoseRankController@index')->defaults('name', '游戏输赢排行榜');
 
+        $route->any('/game_data/participation_statistics', 'Admin\GameDataController@gameParticipationStatistics')->defaults('name', '游戏参与情况统计');
+
+
         // PG游戏参数配置
         $route->any('/pg-game-config', 'Admin\PGGameConfigController@index')->name('admin.pg-game-config');
         $route->any('/common-config', 'Admin\CommonConfigController@index')->name('admin.common-config');
         $route->any('/common-config/update', 'Admin\CommonConfigController@update')->name('admin.common-config.update');
         $route->any('/pg-game-config/update', 'Admin\PGGameConfigController@update')->name('admin.pg-game-config.update');
         $route->post('/pg-game-config/copy_all', 'Admin\PGGameConfigController@copyAll')->name('admin.pg-game-config.copy_all');
-        
+
         // 个控回报配置
         $route->any('/game-some-config', 'Admin\GameSomeConfigController@index')->name('admin.game-some-config');
         $route->post('/game-some-config/update', 'Admin\GameSomeConfigController@update')->name('admin.game-some-config.update');
-        
+
         // 数字游戏映射管理
         $route->get('/game-number-mapping', 'Admin\GameNumberMappingController@index')->name('admin.game-number-mapping');
         $route->any('/game-number-mapping/add', 'Admin\GameNumberMappingController@add')->name('admin.game-number-mapping.add');
         $route->any('/game-number-mapping/update/{id}', 'Admin\GameNumberMappingController@update')->name('admin.game-number-mapping.update');
         $route->post('/game-number-mapping/delete/{id}', 'Admin\GameNumberMappingController@delete')->name('admin.game-number-mapping.delete');
-        
+
         // 节假日大转盘配置
         $route->any('/holiday-wheel', 'Admin\HolidayWheelController@index')->name('admin.holiday-wheel');
         $route->post('/holiday-wheel/update', 'Admin\HolidayWheelController@update')->name('admin.holiday-wheel.update');
         $route->get('/holiday-wheel/history', 'Admin\HolidayWheelController@history')->name('admin.holiday-wheel.history');
-        
+
         // Bonus购买回报配置
         $route->any('/game-buy-bonus-config', 'Admin\GameBuyBonusConfigController@index')->name('admin.game-buy-bonus-config');
         $route->post('/game-buy-bonus-config/update', 'Admin\GameBuyBonusConfigController@update')->name('admin.game-buy-bonus-config.update');