'int', 'merchant_id' => 'int', 'game_platform' => 'string', '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 STATUS_NORMAL = 0; // 正常 const STATUS_MAINTAIN = 1; // 维护 const STATUS_DISABLED = 2; // 停用 // RTP类型常量 const RTP_TYPE_AI = 1; // AI数值 const RTP_TYPE_IMITATE = 2; // 仿正版 // 免费游戏状态 const FREE_GAME_DISABLED = 0; // 不支持购买免费游戏 const FREE_GAME_ENABLED = 1; // 支持购买免费游戏 // 止损止赢功能 const TERMINAL_SPIN_DISABLED = 0; // 关闭止损止赢 const TERMINAL_SPIN_ENABLED = 1; // 开启止损止赢 /** * 获取状态文本 */ 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_AI => 'AI数值', self::RTP_TYPE_IMITATE => '仿正版', ]; return $rtpTypeMap[$rtpType] ?? '未知'; } /** * 获取游戏列表 */ public static function getGameList($merchantId, $page = 1, $limit = 10, $filters = []) { $query = self::where('merchant_id', $merchantId); // 按商户ID过滤 // 应用过滤条件 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, $merchantId) { return self::where('id', $id) ->where('merchant_id', $merchantId) ->find(); } /** * 创建游戏 */ 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, $merchantId) { // 处理押注配置 if (isset($data['deposit_list']) && is_array($data['deposit_list'])) { $data['deposit_list'] = json_encode($data['deposit_list']); } return self::where('id', $id) ->where('merchant_id', $merchantId) ->update($data); } /** * 更新游戏状态 */ public static function updateGameStatus($ids, $merchantId, $status) { return self::whereIn('id', $ids) ->where('merchant_id', $merchantId) ->update(['status' => $status]); } /** * 批量更新游戏状态 */ public static function batchUpdateStatus($ids, $status, $merchantId) { 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(); } /** * 解析押注配置 */ 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, $merchantId, $excludeId = null): bool { $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; } }