| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332 |
- <?php
- declare (strict_types = 1);
- namespace app\model;
- use think\Model;
- /**
- * 商户游戏模型
- */
- class GameModel extends Model
- {
- // 设置表名
- protected $name = 'game_list';
- // 设置主键
- protected $pk = 'id';
- // 设置自动时间戳
- protected $autoWriteTimestamp = 'int';
- // 设置字段类型
- protected $type = [
- 'id' => '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;
- }
- }
|