aiden 4 miesięcy temu
rodzic
commit
ed9ce3a744
3 zmienionych plików z 121 dodań i 244 usunięć
  1. 58 170
      app/controller/Game.php
  2. 61 69
      app/model/GameModel.php
  3. 2 5
      route/app.php

+ 58 - 170
app/controller/Game.php

@@ -14,6 +14,9 @@ class Game extends BaseController
      */
     public function list()
     {
+        // 获取当前用户信息
+        $userInfo = $this->getUserInfo();
+        
         // 获取查询参数
         $page = Request::get('page', 1, 'intval');
         $limit = Request::get('limit', 10, 'intval');
@@ -24,44 +27,18 @@ class Game extends BaseController
             'game_id' => Request::get('game_id', 0, 'intval'),
             'game_platform' => Request::get('game_platform', ''),
             'status' => Request::get('status', ''),
-            'rtp_type' => Request::get('rtp_type', ''),
-            'free_game_status' => Request::get('free_game_status', ''),
-            'terminal_spin' => Request::get('terminal_spin', ''),
-            'rtp_min' => Request::get('rtp_min', 0, 'floatval'),
-            'rtp_max' => Request::get('rtp_max', 0, 'floatval'),
-            'max_multiple_min' => Request::get('max_multiple_min', 0, 'intval'),
-            'max_multiple_max' => Request::get('max_multiple_max', 0, 'intval'),
-            'create_time_start' => Request::get('create_time_start', '', 'trim'),
-            'create_time_end' => Request::get('create_time_end', '', 'trim'),
             'order' => Request::get('order', 'id', 'trim'),
             'sort' => Request::get('sort', 'desc', 'trim'),
         ];
         
         try {
             // 获取游戏列表
-            $result = GameModel::getGameList($page, $limit, $filters);
+            $result = GameModel::getGameList($userInfo['merchant_id'], $page, $limit, $filters);
             
             // 处理列表数据
             foreach ($result['list'] as &$game) {
-                $game['platform_text'] = GameModel::getPlatformText($game['game_platform']);
                 $game['status_text'] = GameModel::getStatusText($game['status']);
                 $game['rtp_type_text'] = GameModel::getRtpTypeText($game['rtp_type']);
-                $game['free_game_status_text'] = $game['free_game_status'] ? '支持' : '不支持';
-                $game['terminal_spin_text'] = $game['terminal_spin'] ? '开启' : '关闭';
-                $game['create_time_text'] = date('Y-m-d H:i:s', $game['create_time']);
-                $game['update_time_text'] = date('Y-m-d H:i:s', $game['update_time']);
-                
-                // 处理押注配置显示
-                if (!empty($game['deposit_list'])) {
-                    $depositList = $game['deposit_list'];
-                    if (is_array($depositList)) {
-                        $game['deposit_list_text'] = implode(', ', $depositList);
-                    } else {
-                        $game['deposit_list_text'] = $depositList;
-                    }
-                } else {
-                    $game['deposit_list_text'] = '未设置';
-                }
             }
             
             return json_success($result, '获取成功');
@@ -75,107 +52,72 @@ class Game extends BaseController
      */
     public function detail()
     {
+        // 获取当前用户信息
+        $userInfo = $this->getUserInfo();
+        
         $id = Request::get('id', 0, 'intval');
         if (!$id) {
             return json_error([], '游戏ID不能为空');
         }
         
         try {
-            $game = GameModel::getGameDetail($id);
+            $game = GameModel::getGameDetail($id, $userInfo['merchant_id']);
             if (!$game) {
                 return json_error([], '游戏不存在');
             }
             
-            // 添加文本字段
-            $game['platform_text'] = GameModel::getPlatformText($game['game_platform']);
             $game['status_text'] = GameModel::getStatusText($game['status']);
             $game['rtp_type_text'] = GameModel::getRtpTypeText($game['rtp_type']);
-            $game['free_game_status_text'] = $game['free_game_status'] ? '支持' : '不支持';
-            $game['terminal_spin_text'] = $game['terminal_spin'] ? '开启' : '关闭';
-            $game['create_time_text'] = date('Y-m-d H:i:s', $game['create_time']);
-            $game['update_time_text'] = date('Y-m-d H:i:s', $game['update_time']);
             
             return json_success($game, '获取成功');
         } catch (\Exception $e) {
             return json_error([], '获取游戏详情失败:' . $e->getMessage());
         }
     }
-    
-    /**
-     * 创建游戏
-     */
-    public function create()
-    {
-        $data = Request::only([
-            'game_platform', 'game_id', 'title', 'title_en', 'image', 'image_en',
-            'rtp', 'rtp_type', 'free_game_status', 'bet_line_count', 'bet_max_level',
-            'max_multiple_count', 'deposit_list', 'default_deposit', 'default_deposit_level',
-            'min_deposit', 'terminal_spin', 'status'
-        ]);
-        
-        // 验证必填字段
-        if (empty($data['game_platform'])) {
-            return json_error([], '游戏平台不能为空');
-        }
-        
-        if (empty($data['game_id'])) {
-            return json_error([], '游戏ID不能为空');
-        }
-        
-        if (empty($data['title'])) {
-            return json_error([], '游戏名称不能为空');
-        }
-        
-        // 检查游戏ID是否已存在
-        if (GameModel::checkGameIdExists($data['game_id'])) {
-            return json_error([], '游戏ID已存在');
-        }
-        
-        try {
-            $game = GameModel::createGame($data);
-            return json_success(['id' => $game->id], '创建游戏成功');
-        } catch (\Exception $e) {
-            return json_error([], '创建游戏失败:' . $e->getMessage());
-        }
-    }
-    
+            
     /**
      * 更新游戏
      */
     public function update()
     {
+        // 获取当前用户信息
+        $userInfo = $this->getUserInfo();
+        
         $id = Request::post('id', 0, 'intval');
         if (!$id) {
             return json_error([], '游戏ID不能为空');
         }
         
-        $data = Request::only([
-            'game_platform', 'game_id', 'title', 'title_en', 'image', 'image_en',
-            'rtp', 'rtp_type', 'free_game_status', 'bet_line_count', 'bet_max_level',
-            'max_multiple_count', 'deposit_list', 'default_deposit', 'default_deposit_level',
-            'min_deposit', 'terminal_spin', 'status'
-        ]);
+        // 定义允许更新的字段
+        $allowedFields = [
+            'rtp', 'rtp_type', 'free_game_status', 'bet_max_level', 'terminal_spin',
+            'max_multiple_count', 'deposit_list', 'default_deposit', 'default_deposit_level', 'min_deposit',
+        ];
+        
+        // 获取请求参数
+        $params = Request::param();
+        $data = [];
         
-        // 验证必填字段
-        if (empty($data['title'])) {
-            return json_error([], '游戏名称不能为空');
+        // 只获取实际传递的字段
+        foreach ($allowedFields as $field) {
+            if (isset($params[$field])) {
+                $data[$field] = $params[$field];
+            }
         }
         
-        // 检查游戏是否存在
-        $game = GameModel::getGameDetail($id);
+        // 如果没有要更新的字段
+        if (empty($data)) {
+            return json_error([], '没有要更新的数据');
+        }
+                
+        // 检查游戏是否存在且属于当前商户
+        $game = GameModel::getGameDetail($id, $userInfo['merchant_id']);
         if (!$game) {
             return json_error([], '游戏不存在');
         }
         
-        // 如果修改了游戏ID,检查是否与其他游戏冲突
-        if (isset($data['game_id']) && $data['game_id'] != $game['game_id']) {
-            if (GameModel::checkGameIdExists($data['game_id'], $id)) {
-                return json_error([], '游戏ID已存在');
-            }
-        }
-        
         try {
-            GameModel::updateGame($id, $data);
+            GameModel::updateGame($id, $data, $userInfo['merchant_id']);
             return json_success([], '更新游戏成功');
         } catch (\Exception $e) {
             return json_error([], '更新游戏失败:' . $e->getMessage());
@@ -187,11 +129,14 @@ class Game extends BaseController
      */
     public function updateStatus()
     {
-        $id = Request::post('id', 0, 'intval');
+        // 获取当前用户信息
+        $userInfo = $this->getUserInfo();
+        
+        $ids = Request::post('ids', []);
         $status = Request::post('status', 0, 'intval');
         
-        if (!$id) {
-            return json_error([], '游戏ID不能为空');
+        if (empty($ids) || !is_array($ids)) {
+            return json_error([], '请选择要更新的游戏');
         }
         
         if (!in_array($status, [
@@ -203,7 +148,7 @@ class Game extends BaseController
         }
         
         try {
-            $result = GameModel::updateGameStatus($id, $status);
+            $result = GameModel::updateGameStatus($ids, $userInfo['merchant_id'], $status);
             if ($result) {
                 return json_success([], '状态更新成功');
             } else {
@@ -214,45 +159,17 @@ class Game extends BaseController
         }
     }
     
-    /**
-     * 批量更新游戏状态
-     */
-    public function batchUpdateStatus()
-    {
-        $ids = Request::post('ids', []);
-        $status = Request::post('status', 0, 'intval');
-        
-        if (empty($ids) || !is_array($ids)) {
-            return json_error([], '请选择要更新的游戏');
-        }
-        
-        if (!in_array($status, [
-            GameModel::STATUS_NORMAL,
-            GameModel::STATUS_MAINTAIN,
-            GameModel::STATUS_DISABLED
-        ])) {
-            return json_error([], '状态值无效');
-        }
-        
-        try {
-            $result = GameModel::batchUpdateStatus($ids, $status);
-            if ($result > 0) {
-                return json_success(['updated' => $result], '批量更新成功');
-            } else {
-                return json_error([], '批量更新失败');
-            }
-        } catch (\Exception $e) {
-            return json_error([], '批量更新游戏状态失败:' . $e->getMessage());
-        }
-    }
     
     /**
      * 获取游戏统计信息
      */
     public function statistics()
     {
+        // 获取当前用户信息
+        $userInfo = $this->getUserInfo();
+        
         try {
-            $statistics = GameModel::getGameStatistics();
+            $statistics = GameModel::getGameStatistics($userInfo['merchant_id']);
             return json_success($statistics, '获取成功');
         } catch (\Exception $e) {
             return json_error([], '获取游戏统计失败:' . $e->getMessage());
@@ -272,57 +189,28 @@ class Game extends BaseController
         }
     }
     
-    /**
-     * 删除游戏
-     */
-    public function delete()
-    {
-        $id = Request::post('id', 0, 'intval');
-        if (!$id) {
-            return json_error([], '游戏ID不能为空');
-        }
-        
-        try {
-            // 检查游戏是否存在
-            $game = GameModel::getGameDetail($id);
-            if (!$game) {
-                return json_error([], '游戏不存在');
-            }
-            
-            // 删除游戏
-            GameModel::where('id', $id)->delete();
-            
-            return json_success([], '删除成功');
-        } catch (\Exception $e) {
-            return json_error([], '删除游戏失败:' . $e->getMessage());
-        }
-    }
-    
+
     /**
      * 导出游戏列表
      */
     public function export()
     {
+        // 获取当前用户信息
+        $userInfo = $this->getUserInfo();
+        
         // 获取所有过滤条件
         $filters = [
             'title' => Request::get('title', '', 'trim'),
             'game_id' => Request::get('game_id', 0, 'intval'),
             'game_platform' => Request::get('game_platform', ''),
             'status' => Request::get('status', ''),
-            'rtp_type' => Request::get('rtp_type', ''),
-            'free_game_status' => Request::get('free_game_status', ''),
-            'terminal_spin' => Request::get('terminal_spin', ''),
-            'rtp_min' => Request::get('rtp_min', 0, 'floatval'),
-            'rtp_max' => Request::get('rtp_max', 0, 'floatval'),
-            'max_multiple_min' => Request::get('max_multiple_min', 0, 'intval'),
-            'max_multiple_max' => Request::get('max_multiple_max', 0, 'intval'),
-            'create_time_start' => Request::get('create_time_start', '', 'trim'),
-            'create_time_end' => Request::get('create_time_end', '', 'trim'),
+            'order' => Request::get('order', 'id', 'trim'),
+            'sort' => Request::get('sort', 'desc', 'trim'),
         ];
         
         try {
             // 获取所有数据
-            $result = GameModel::getGameList(1, 100000, $filters);
+            $result = GameModel::getGameList($userInfo['merchant_id'], 1, 100000, $filters);
             
             // 生成CSV数据
             $csvData = "ID,游戏ID,游戏平台,中文名称,英文名称,RTP,RTP类型,免费游戏,下注线数,最高倍数,默认押注,最低押注,止损止赢,状态,创建时间\n";
@@ -332,27 +220,27 @@ class Game extends BaseController
                     "%d,%d,%s,%s,%s,%.2f,%s,%s,%d,%d,%.2f,%.2f,%s,%s,%s\n",
                     $game['id'],
                     $game['game_id'],
-                    GameModel::getPlatformText($game['game_platform']),
+                    $game['game_platform'],
                     $game['title'],
                     $game['title_en'],
                     $game['rtp'],
                     GameModel::getRtpTypeText($game['rtp_type']),
-                    $game['free_game_status'] ? '支持' : '不支持',
+                    $game['free_game_status'] ? '开启' : '关闭',
                     $game['bet_line_count'],
                     $game['max_multiple_count'],
                     $game['default_deposit'],
                     $game['min_deposit'],
                     $game['terminal_spin'] ? '开启' : '关闭',
                     GameModel::getStatusText($game['status']),
-                    date('Y-m-d H:i:s', $game['create_time'])
+                    $game['create_time'],
                 );
             }
             
             // 返回CSV数据
             return response($csvData)
-                ->header('Content-Type', 'text/csv; charset=utf-8')
-                ->header('Content-Disposition', 'attachment; filename="games_' . date('YmdHis') . '.csv"')
-                ->header('Cache-Control', 'no-cache, must-revalidate');
+                ->header(['Content-Type' => 'text/csv; charset=utf-8'])
+                ->header(['Content-Disposition' => 'attachment; filename="games_' . date('YmdHis') . '.csv"'])
+                ->header(['Cache-Control' => 'no-cache, must-revalidate']);
                 
         } catch (\Exception $e) {
             return json_error([], '导出游戏列表失败:' . $e->getMessage());

+ 61 - 69
app/model/GameModel.php

@@ -22,7 +22,8 @@ class GameModel extends Model
     // 设置字段类型
     protected $type = [
         'id' => 'int',
-        'game_platform' => 'int',
+        'merchant_id' => 'int',
+        'game_platform' => 'string',
         'game_id' => 'int',
         'title' => 'string',
         'title_en' => 'string',
@@ -44,22 +45,14 @@ class GameModel extends Model
         'update_time' => 'int',
     ];
 
-    // 游戏平台常量
-    const PLATFORM_PG = 1;      // PG平台
-    const PLATFORM_PP = 2;      // PP平台
-    const PLATFORM_CQ9 = 3;     // CQ9平台
-    const PLATFORM_JDB = 4;     // JDB平台
-    const PLATFORM_JILI = 5;    // JILI平台
-
     // 状态常量
     const STATUS_NORMAL = 0;    // 正常
     const STATUS_MAINTAIN = 1;  // 维护
     const STATUS_DISABLED = 2;  // 停用
 
     // RTP类型常量
-    const RTP_TYPE_FIXED = 1;       // 固定RTP
-    const RTP_TYPE_DYNAMIC = 2;     // 动态RTP
-    const RTP_TYPE_CUSTOM = 3;      // 自定义RTP
+    const RTP_TYPE_AI = 1;       // AI数值
+    const RTP_TYPE_IMITATE = 2;     // 仿正版
 
     // 免费游戏状态
     const FREE_GAME_DISABLED = 0;   // 不支持购买免费游戏
@@ -69,21 +62,6 @@ class GameModel extends Model
     const TERMINAL_SPIN_DISABLED = 0;   // 关闭止损止赢
     const TERMINAL_SPIN_ENABLED = 1;    // 开启止损止赢
 
-    /**
-     * 获取游戏平台文本
-     */
-    public static function getPlatformText($platform): string
-    {
-        $platformMap = [
-            self::PLATFORM_PG => 'PG',
-            self::PLATFORM_PP => 'PP',
-            self::PLATFORM_CQ9 => 'CQ9',
-            self::PLATFORM_JDB => 'JDB',
-            self::PLATFORM_JILI => 'JILI',
-        ];
-        return $platformMap[$platform] ?? '未知';
-    }
-
     /**
      * 获取状态文本
      */
@@ -103,22 +81,18 @@ class GameModel extends Model
     public static function getRtpTypeText($rtpType): string
     {
         $rtpTypeMap = [
-            self::RTP_TYPE_FIXED => '固定',
-            self::RTP_TYPE_DYNAMIC => '动态',
-            self::RTP_TYPE_CUSTOM => '自定义',
+            self::RTP_TYPE_AI => 'AI数值',
+            self::RTP_TYPE_IMITATE => '仿正版',
         ];
         return $rtpTypeMap[$rtpType] ?? '未知';
     }
 
     /**
      * 获取游戏列表
-     * 
-     * 注意:merchant_game_list表没有merchant_id字段,
-     * 如果需要按商户过滤,需要关联其他表或调整表结构
      */
-    public static function getGameList($page = 1, $limit = 10, $filters = [])
+    public static function getGameList($merchantId, $page = 1, $limit = 10, $filters = [])
     {
-        $query = self::where('id', '>', 0); // 基础查询
+        $query = self::where('merchant_id', $merchantId); // 按商户ID过滤
 
         // 应用过滤条件
         if (!empty($filters['title'])) {
@@ -198,75 +172,84 @@ class GameModel extends Model
     /**
      * 获取游戏详情
      */
-    public static function getGameDetail($id)
+    public static function getGameDetail($id, $merchantId)
     {
-        return self::where('id', $id)->find();
+        return self::where('id', $id)
+            ->where('merchant_id', $merchantId)
+            ->find();
     }
 
     /**
      * 创建游戏
      */
-    public static function createGame($data)
+    public static function createGame($data, $merchantId)
     {
         // 处理押注配置
         if (isset($data['deposit_list']) && is_array($data['deposit_list'])) {
             $data['deposit_list'] = json_encode($data['deposit_list']);
         }
         
+        // 添加商户ID
+        $data['merchant_id'] = $merchantId;
+        
         return self::create($data);
     }
 
     /**
      * 更新游戏
      */
-    public static function updateGame($id, $data)
+    public static function updateGame($id, $data, $merchantId)
     {
         // 处理押注配置
         if (isset($data['deposit_list']) && is_array($data['deposit_list'])) {
             $data['deposit_list'] = json_encode($data['deposit_list']);
         }
         
-        return self::where('id', $id)->update($data);
+        return self::where('id', $id)
+            ->where('merchant_id', $merchantId)
+            ->update($data);
     }
 
     /**
      * 更新游戏状态
      */
-    public static function updateGameStatus($id, $status)
+    public static function updateGameStatus($ids, $merchantId, $status)
     {
-        return self::where('id', $id)->update(['status' => $status]);
+        return self::whereIn('id', $ids)
+            ->where('merchant_id', $merchantId)
+            ->update(['status' => $status]);
     }
 
     /**
      * 批量更新游戏状态
      */
-    public static function batchUpdateStatus($ids, $status)
+    public static function batchUpdateStatus($ids, $status, $merchantId)
     {
-        return self::whereIn('id', $ids)->update(['status' => $status]);
+        return self::whereIn('id', $ids)
+            ->where('merchant_id', $merchantId)
+            ->update(['status' => $status]);
     }
 
     /**
      * 获取游戏统计信息
      */
-    public static function getGameStatistics()
+    public static function getGameStatistics($merchantId)
     {
-        $totalGames = self::count();
-        $normalGames = self::where('status', self::STATUS_NORMAL)->count();
-        $maintainGames = self::where('status', self::STATUS_MAINTAIN)->count();
-        $disabledGames = self::where('status', self::STATUS_DISABLED)->count();
+        $query = self::where('merchant_id', $merchantId);
+        
+        $totalGames = (clone $query)->count();
+        $normalGames = (clone $query)->where('status', self::STATUS_NORMAL)->count();
+        $maintainGames = (clone $query)->where('status', self::STATUS_MAINTAIN)->count();
+        $disabledGames = (clone $query)->where('status', self::STATUS_DISABLED)->count();
         
         // 按平台统计
         $platformStats = [];
-        $platforms = [
-            self::PLATFORM_PG => 'PG',
-            self::PLATFORM_PP => 'PP',
-            self::PLATFORM_CQ9 => 'CQ9',
-            self::PLATFORM_JDB => 'JDB',
-            self::PLATFORM_JILI => 'JILI',
-        ];
+        $platforms = self::getAllPlatforms();
         
-        foreach ($platforms as $platform => $name) {
-            $platformStats[$name] = self::where('game_platform', $platform)->count();
+        foreach ($platforms as $platform) {
+            $platformStats[$platform['platform_name']] = self::where('game_platform', $platform['id'])
+                ->where('merchant_id', $merchantId)
+                ->count();
         }
         
         return [
@@ -275,9 +258,9 @@ class GameModel extends Model
             'maintain_games' => $maintainGames,
             'disabled_games' => $disabledGames,
             'platform_stats' => $platformStats,
-            'avg_rtp' => self::avg('rtp'),
-            'free_game_enabled' => self::where('free_game_status', self::FREE_GAME_ENABLED)->count(),
-            'terminal_spin_enabled' => self::where('terminal_spin', self::TERMINAL_SPIN_ENABLED)->count(),
+            'avg_rtp' => (clone $query)->avg('rtp'),
+            'free_game_enabled' => (clone $query)->where('free_game_status', self::FREE_GAME_ENABLED)->count(),
+            'terminal_spin_enabled' => (clone $query)->where('terminal_spin', self::TERMINAL_SPIN_ENABLED)->count(),
         ];
     }
 
@@ -286,13 +269,11 @@ class GameModel extends Model
      */
     public static function getAllPlatforms(): array
     {
-        return [
-            ['value' => self::PLATFORM_PG, 'text' => 'PG'],
-            ['value' => self::PLATFORM_PP, 'text' => 'PP'],
-            ['value' => self::PLATFORM_CQ9, 'text' => 'CQ9'],
-            ['value' => self::PLATFORM_JDB, 'text' => 'JDB'],
-            ['value' => self::PLATFORM_JILI, 'text' => 'JILI'],
-        ];
+        return self::table('merchant_game_platform')
+            ->field(['id', 'platform_name'])
+            ->order('id', 'asc')
+            ->select()
+            ->toArray();
     }
 
     /**
@@ -321,12 +302,23 @@ class GameModel extends Model
     /**
      * 检查游戏ID是否已存在
      */
-    public static function checkGameIdExists($gameId, $excludeId = null): bool
+    public static function checkGameIdExists($gameId, $merchantId, $excludeId = null): bool
     {
-        $query = self::where('game_id', $gameId);
+        $query = self::where('game_id', $gameId)
+            ->where('merchant_id', $merchantId);
         if ($excludeId) {
             $query->where('id', '<>', $excludeId);
         }
         return $query->count() > 0;
     }
+    
+    /**
+     * 删除游戏
+     */
+    public static function deleteGame($id, $merchantId): bool
+    {
+        return self::where('id', $id)
+            ->where('merchant_id', $merchantId)
+            ->delete() > 0;
+    }
 }

+ 2 - 5
route/app.php

@@ -50,12 +50,9 @@ Route::group('player', function () {
 Route::group('game', function () {
     Route::get('list', 'Game/list');
     Route::get('detail', 'Game/detail');
-    Route::post('create', 'Game/create');
     Route::post('update', 'Game/update');
-    Route::post('updateStatus', 'Game/updateStatus');
-    Route::post('batchUpdateStatus', 'Game/batchUpdateStatus');
+    Route::post('update_status', 'Game/updateStatus');
     Route::get('statistics', 'Game/statistics');
-    Route::get('getPlatforms', 'Game/getPlatforms');
-    Route::post('delete', 'Game/delete');
+    Route::get('get_platforms', 'Game/getPlatforms');
     Route::get('export', 'Game/export');
 })->middleware(\app\middleware\AuthMiddleware::class);