'int', 'game_platform' => 'int', 'game_id' => 'int', 'title' => 'string', 'title_en' => 'string', 'image' => 'string', 'image_en' => 'string', 'rtp' => 'float', 'rtp_type' => 'int', 'free_game_status' => 'int', 'bet_line_count' => 'int', 'bet_max_level' => 'int', 'max_multiple_count' => 'int', 'deposit_list' => 'string', 'default_deposit' => 'float', 'default_deposit_level' => 'int', 'min_deposit' => 'float', 'terminal_spin' => 'int', 'status' => 'int', 'create_time' => 'int', '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 FREE_GAME_DISABLED = 0; // 不支持购买免费游戏 const FREE_GAME_ENABLED = 1; // 支持购买免费游戏 // 止损止赢功能 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] ?? '未知'; } /** * 获取状态文本 */ public static function getStatusText($status): string { $statusMap = [ self::STATUS_NORMAL => '正常', self::STATUS_MAINTAIN => '维护', self::STATUS_DISABLED => '停用', ]; return $statusMap[$status] ?? '未知'; } /** * 获取RTP类型文本 */ public static function getRtpTypeText($rtpType): string { $rtpTypeMap = [ self::RTP_TYPE_FIXED => '固定', self::RTP_TYPE_DYNAMIC => '动态', self::RTP_TYPE_CUSTOM => '自定义', ]; return $rtpTypeMap[$rtpType] ?? '未知'; } /** * 获取游戏列表 * * 注意:merchant_game_list表没有merchant_id字段, * 如果需要按商户过滤,需要关联其他表或调整表结构 */ public static function getGameList($page = 1, $limit = 10, $filters = []) { $query = self::where('id', '>', 0); // 基础查询 // 应用过滤条件 if (!empty($filters['title'])) { $query->where(function($q) use ($filters) { $q->where('title', 'like', '%' . $filters['title'] . '%') ->whereOr('title_en', 'like', '%' . $filters['title'] . '%'); }); } if (!empty($filters['game_id'])) { $query->where('game_id', $filters['game_id']); } if (isset($filters['game_platform']) && $filters['game_platform'] !== '') { $query->where('game_platform', $filters['game_platform']); } if (isset($filters['status']) && $filters['status'] !== '') { $query->where('status', $filters['status']); } if (isset($filters['rtp_type']) && $filters['rtp_type'] !== '') { $query->where('rtp_type', $filters['rtp_type']); } if (isset($filters['free_game_status']) && $filters['free_game_status'] !== '') { $query->where('free_game_status', $filters['free_game_status']); } if (isset($filters['terminal_spin']) && $filters['terminal_spin'] !== '') { $query->where('terminal_spin', $filters['terminal_spin']); } // RTP范围 if (!empty($filters['rtp_min'])) { $query->where('rtp', '>=', $filters['rtp_min']); } if (!empty($filters['rtp_max'])) { $query->where('rtp', '<=', $filters['rtp_max']); } // 最高倍数范围 if (!empty($filters['max_multiple_min'])) { $query->where('max_multiple_count', '>=', $filters['max_multiple_min']); } if (!empty($filters['max_multiple_max'])) { $query->where('max_multiple_count', '<=', $filters['max_multiple_max']); } // 创建时间范围 if (!empty($filters['create_time_start'])) { $query->where('create_time', '>=', strtotime($filters['create_time_start'])); } if (!empty($filters['create_time_end'])) { $query->where('create_time', '<=', strtotime($filters['create_time_end'])); } // 排序 $order = $filters['order'] ?? 'id'; $sort = $filters['sort'] ?? 'desc'; $query->order($order, $sort); // 获取总数 $total = $query->count(); // 获取列表 $list = $query->page($page, $limit)->select(); return [ 'list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit ]; } /** * 获取游戏详情 */ public static function getGameDetail($id) { return self::where('id', $id)->find(); } /** * 创建游戏 */ public static function createGame($data) { // 处理押注配置 if (isset($data['deposit_list']) && is_array($data['deposit_list'])) { $data['deposit_list'] = json_encode($data['deposit_list']); } return self::create($data); } /** * 更新游戏 */ public static function updateGame($id, $data) { // 处理押注配置 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); } /** * 更新游戏状态 */ public static function updateGameStatus($id, $status) { return self::where('id', $id)->update(['status' => $status]); } /** * 批量更新游戏状态 */ public static function batchUpdateStatus($ids, $status) { return self::whereIn('id', $ids)->update(['status' => $status]); } /** * 获取游戏统计信息 */ public static function getGameStatistics() { $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(); // 按平台统计 $platformStats = []; $platforms = [ self::PLATFORM_PG => 'PG', self::PLATFORM_PP => 'PP', self::PLATFORM_CQ9 => 'CQ9', self::PLATFORM_JDB => 'JDB', self::PLATFORM_JILI => 'JILI', ]; foreach ($platforms as $platform => $name) { $platformStats[$name] = self::where('game_platform', $platform)->count(); } return [ 'total_games' => $totalGames, 'normal_games' => $normalGames, '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(), ]; } /** * 获取所有游戏平台 */ 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'], ]; } /** * 解析押注配置 */ public function getDepositListAttr($value) { if (empty($value)) { return []; } // 如果是JSON字符串,解析它 $decoded = json_decode($value, true); if (json_last_error() === JSON_ERROR_NONE) { return $decoded; } // 如果是逗号分隔的字符串,转换为数组 if (strpos($value, ',') !== false) { return array_map('floatval', explode(',', $value)); } return []; } /** * 检查游戏ID是否已存在 */ public static function checkGameIdExists($gameId, $excludeId = null): bool { $query = self::where('game_id', $gameId); if ($excludeId) { $query->where('id', '<>', $excludeId); } return $query->count() > 0; } }