소스 검색

玩家推荐游戏统计

Tree 3 주 전
부모
커밋
d229f9d599

+ 2 - 0
app/Http/Controllers/Admin/ExchangeController.php

@@ -623,6 +623,8 @@ class ExchangeController extends Controller
 //        $data = array_merge($prize,$prop);
         //$data = $prize;
         $data = [['PropID'=>30000,'PropName'=>'金币']];
+
+        $data = [['PropID'=>31000,'PropName'=>'免费币']];
         return response()->json($data);
     }
 

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

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

+ 3 - 0
app/Models/Order.php

@@ -266,6 +266,9 @@ class Order extends Model
             case 302:
                 $GiftsName = '破产礼包';
                 break;
+            case 401:
+                $GiftsName = '大转盘';
+                break;
 
             default:
                 $GiftsName = '商城(充值)';

+ 75 - 0
resources/views/admin/game_data/participation_statistics.blade.php

@@ -0,0 +1,75 @@
+@extends('base.base')
+@section('base')
+    <!-- 内容区域 -->
+    <div class="main-panel">
+        <div class="content-wrapper">
+            <div class="page-header">
+                <h3 class="page-title">
+                     <span class="page-title-icon bg-gradient-primary text-white mr-2">
+                        <i class="mdi mdi-chart-line"></i>
+                    </span>
+                    {{ __('auto.游戏参与情况统计') }}
+                </h3>
+                <nav aria-label="breadcrumb">
+                    <ol class="breadcrumb">
+                        <li class="breadcrumb-item"><a href="#">{{ __('auto.游戏数据') }}</a></li>
+                        <li class="breadcrumb-item active" aria-current="page">{{ __('auto.游戏参与情况统计') }}</li>
+                    </ol>
+                </nav>
+            </div>
+            <div class="row">
+                <div class="col-lg-12 grid-margin stretch-card">
+                    <div class="card">
+                        <div class="card-body">
+                            <h4 class="card-title">{{ __('auto.游戏参与情况统计') }}</h4>
+                            <form class="well form-inline margin-top-20" method="get" action="">
+                                <span style="padding-left: 10px">{{ __('auto.注册时间:') }}</span>
+                                <input type="date" name="start_date" class="form-control" value="{{ $start_date }}" />
+                                <span style="padding-left: 10px">{{ __('auto.至') }}</span>
+                                <input type="date" name="end_date" class="form-control" value="{{ $end_date }}" />
+                                <input type="submit" class="btn btn-sm btn-gradient-dark btn-icon-text" value="{{ __('auto.搜索') }}"/>&nbsp;&nbsp;
+                                <a href="/admin/game_data/participation_statistics" class="btn btn-sm btn-gradient-warning btn-icon-text">{{ __('auto.清空') }}</a>
+                            </form>
+                            <br>
+                            <table class="table table-bordered">
+                                <thead>
+                                <tr>
+                                    <th width="10%">{{ __('auto.GameID尾号') }}</th>
+                                    <th width="30%">{{ __('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['register_count'] }}</td>
+                                        <td>{{ $stat['played_count'] }}</td>
+                                        <td>
+                                            @if($stat['register_count'] > 0)
+                                                <span class="badge badge-{{ $stat['participation_rate'] >= 50 ? 'success' : ($stat['participation_rate'] >= 30 ? 'warning' : 'danger') }}">
+                                                    {{ $stat['participation_rate'] }}%
+                                                </span>
+                                            @else
+                                                <span class="badge badge-secondary">-</span>
+                                            @endif
+                                        </td>
+                                    </tr>
+                                @endforeach
+                                </tbody>
+                            </table>
+                            @if(count($statistics) == 0)
+                                <div class="alert alert-info">
+                                    <p>{{ __('auto.暂无统计数据,请选择其他时间范围。') }}</p>
+                                </div>
+                            @endif
+                        </div>
+                    </div>
+                </div>
+            </div>
+        </div>
+    </div>
+@endsection

+ 3 - 0
routes/web.php

@@ -720,6 +720,9 @@ 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');