Ver código fonte

update:优化代码

aiden 3 meses atrás
pai
commit
8f15c25316
2 arquivos alterados com 33 adições e 98 exclusões
  1. 5 25
      app/controller/Game.php
  2. 28 73
      app/model/GameModel.php

+ 5 - 25
app/controller/Game.php

@@ -41,12 +41,12 @@ class Game extends BaseController
             foreach ($result['list'] as &$game) {
                 $game['status_text'] = GameModel::getStatusText($game['status']);
                 $game['rtp_type_text'] = GameModel::getRtpTypeText($game['rtp_type']);
+                $game['game_type_text'] = GameModel::getPlatFormText($game['game_platform']);                
 
                 $gameImages = CommonUtils::getGameDefaultImage($game);
                 $game['game_image_url'] = $gameImages['image_url'] ?? '';
                 $game['image_en_url'] = $gameImages['image_en_url'] ?? '';
                 $game['game_title'] = $game['title'] ?? '';
-                $game['game_type_text'] = $game['game_platform'];                
             }
             
             return json_success($result, '获取成功');
@@ -76,7 +76,8 @@ class Game extends BaseController
             
             $game['status_text'] = GameModel::getStatusText($game['status']);
             $game['rtp_type_text'] = GameModel::getRtpTypeText($game['rtp_type']);
-            
+            $game['game_type_text'] = GameModel::getPlatFormText($game['game_platform']);                
+
             return json_success($game, '获取成功');
         } catch (\Exception $e) {
             return json_error([], '获取游戏详情失败:' . $e->getMessage());
@@ -159,11 +160,7 @@ class Game extends BaseController
             return json_error([], '请选择要更新的游戏');
         }
         
-        if (!in_array($status, [
-            GameModel::STATUS_NORMAL,
-            GameModel::STATUS_MAINTAIN,
-            GameModel::STATUS_DISABLED
-        ])) {
+        if (!in_array($status, array_keys(GameModel::STATUS))) {
             return json_error([], '状态值无效');
         }
         
@@ -179,23 +176,6 @@ class Game extends BaseController
         }
     }
     
-    
-    /**
-     * 获取游戏统计信息
-     */
-    public function statistics()
-    {
-        // 获取当前用户信息
-        $userInfo = $this->getUserInfo();
-        
-        try {
-            $statistics = GameModel::getGameStatistics($userInfo['merchant_id']);
-            return json_success($statistics, '获取成功');
-        } catch (\Exception $e) {
-            return json_error([], '获取游戏统计失败:' . $e->getMessage());
-        }
-    }
-    
     /**
      * 获取游戏平台列表
      */
@@ -255,7 +235,7 @@ 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'],
-                    $game['game_platform'],
+                    GameModel::getPlatFormText($game['game_platform']),
                     $game['title'],
                     $game['title_en'],
                     $game['rtp'],

+ 28 - 73
app/model/GameModel.php

@@ -46,33 +46,30 @@ class GameModel extends Model
     ];
 
     // 状态常量
-    const STATUS_NORMAL = 0;    // 正常
-    const STATUS_MAINTAIN = 1;  // 维护
-    const STATUS_DISABLED = 2;  // 停用
-
-    // RTP类型常量
-    const RTP_TYPE_AI = 1;       // AI数值
-    const RTP_TYPE_IMITATE = 2;     // 仿正版
+    const STATUS = [
+        0 => "初始",
+        1 => "正常",
+        2 => "维护",
+    ];
 
-    // 免费游戏状态
-    const FREE_GAME_DISABLED = 0;   // 不支持购买免费游戏
-    const FREE_GAME_ENABLED = 1;    // 支持购买免费游戏
+    // 止损止赢功能开关状态
+    const FREE_STATUS = [
+        0 => '关闭',
+        1 => '开启',
+    ];
 
-    // 止损止赢功能
-    const TERMINAL_SPIN_DISABLED = 0;   // 关闭止损止赢
-    const TERMINAL_SPIN_ENABLED = 1;    // 开启止损止赢
+    // 购买免费游戏功能开关状态
+    const TERMINAL_SPIN_STATUS = [
+        0 => '关闭',
+        1 => '开启',
+    ];
 
     /**
      * 获取状态文本
      */
     public static function getStatusText($status): string
     {
-        $statusMap = [
-            self::STATUS_NORMAL => '正常',
-            self::STATUS_MAINTAIN => '维护',
-            self::STATUS_DISABLED => '停用',
-        ];
-        return $statusMap[$status] ?? '未知';
+        return self::STATUS[$status] ?? '未知';
     }
 
     /**
@@ -80,11 +77,17 @@ class GameModel extends Model
      */
     public static function getRtpTypeText($rtpType): string
     {
-        $rtpTypeMap = [
-            self::RTP_TYPE_AI => 'AI数值',
-            self::RTP_TYPE_IMITATE => '仿正版',
-        ];
-        return $rtpTypeMap[$rtpType] ?? '未知';
+        $rtpTypeMap = $GLOBALS['gamePgGameConfig']['rtp_type_config'];
+        return $rtpTypeMap[$rtpType]['name'] ?? '未知';
+    }
+
+    /**
+     * 获取游戏平台文本
+     */
+    public static function getPlatFormText($platform): string
+    {
+        $platforms = self::getAllPlatforms();
+        return $platforms[$platform] ?? '未知';
     }
 
     /**
@@ -228,60 +231,12 @@ class GameModel extends Model
             ->update($data);
     }
 
-    /**
-     * 更新游戏状态
-     */
-    public static function updateGameStatus($merchantId, $ids, $status)
-    {
-        return self::whereIn('id', $ids)
-            ->where('merchant_id', $merchantId)
-            ->update(['status' => $status]);
-    }
-
-    /**
-     * 获取游戏统计信息
-     */
-    public static function getGameStatistics($merchantId)
-    {
-        $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::getAllPlatforms();
-        
-        foreach ($platforms as $platform) {
-            $platformStats[$platform['platform_name']] = self::where('game_platform', $platform['id'])
-                ->where('merchant_id', $merchantId)
-                ->count();
-        }
-        
-        return [
-            'total_games' => $totalGames,
-            'normal_games' => $normalGames,
-            'maintain_games' => $maintainGames,
-            'disabled_games' => $disabledGames,
-            'platform_stats' => $platformStats,
-            '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(),
-        ];
-    }
-
     /**
      * 获取所有游戏平台
      */
     public static function getAllPlatforms(): array
     {
-        return self::table('merchant_game_platform')
-            ->field(['id', 'platform_name'])
-            ->order('id', 'asc')
-            ->select()
-            ->toArray();
+        return $GLOBALS['gameGameTypeConfig'];
     }
 
     /**