package model import "gorm.io/plugin/soft_delete" // 游戏引擎类型常量 const ( EngineCanvas = "canvas" // 2D 画布游戏 EngineThree = "three" // Three.js 三维游戏 EngineOnline = "online" // WebSocket 联机游戏 ) // Game 游戏表:平台全部游戏(37 款) type Game struct { ID int `gorm:"primaryKey" json:"id"` // 游戏ID Code string `gorm:"size:32;uniqueIndex" json:"code"` // 游戏编码(前端据此加载组件) Name string `gorm:"size:32" json:"name"` // 游戏名称 Category string `gorm:"size:16" json:"category"` // 分类:益智/街机/动作/射击/棋牌/休闲/3D/联机 Icon string `gorm:"size:16" json:"icon"` // emoji 图标 Description string `gorm:"size:255" json:"description"` // 玩法简介 Price int `gorm:"default:0" json:"price"` // 售价(积分,0=免费) Engine string `gorm:"size:16" json:"engine"` // 实现引擎:canvas/three/online ScorePerPoint int `gorm:"default:10" json:"score_per_point"` // 多少游戏得分兑1积分(0=不兑换) MaxPointsPerPlay int `gorm:"default:50" json:"max_points_per_play"` // 单局积分上限(防刷) PlayCount int `gorm:"default:0" json:"play_count"` // 累计游玩次数 Sort int `gorm:"default:0" json:"sort"` // 排序权重 Carousel int `gorm:"default:0" json:"carousel"` // 大厅轮播:0=不参与,>0=参与且按值升序排列 Status int `gorm:"default:1" json:"status"` // 状态:1上架 2下架 CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 创建时间(int 时间戳) UpdatedAt int64 `gorm:"autoUpdateTime" json:"updated_at"` // 更新时间(int 时间戳) DeletedAt soft_delete.DeletedAt `gorm:"default:0" json:"-"` // 软删除时间(0=未删除) } // TableName 指定表名 func (Game) TableName() string { return "games" } // GameRecord 游玩记录表:单机游戏每局结算写一条 type GameRecord struct { ID int `gorm:"primaryKey" json:"id"` // 记录ID UserID int `gorm:"index" json:"user_id"` // 玩家用户ID GameID int `gorm:"index" json:"game_id"` // 游戏ID Score int `gorm:"default:0" json:"score"` // 本局得分 PointsGained int `gorm:"default:0" json:"points_gained"` // 本局获得的平台积分 Duration int `gorm:"default:0" json:"duration"` // 游玩时长(秒) CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 结算时间(int 时间戳) } // TableName 指定表名 func (GameRecord) TableName() string { return "game_records" } // 对战模式常量 const ( BattleModePVP = 1 // 好友联机 BattleModeAI = 2 // 人机对战 ) // 对战结果常量 const ( BattleResultWin = 1 // 胜利 BattleResultLose = 2 // 失败 BattleResultDraw = 3 // 平局 ) // BattleRecord 对战记录表:斗地主/象棋每局结束后,每个真人玩家写一条 type BattleRecord struct { ID int `gorm:"primaryKey" json:"id"` // 记录ID UserID int `gorm:"index" json:"user_id"` // 玩家用户ID GameID int `json:"game_id"` // 游戏ID(斗地主或象棋) RoomCode string `gorm:"size:16" json:"room_code"` // 房间邀请码 Mode int `gorm:"default:1" json:"mode"` // 模式:1好友联机 2人机 // 注意:AI 不在 GORM 常见缩写词表内,默认会被映射成 a_iprovider,必须显式指定列名 AIProvider string `gorm:"size:16;column:ai_provider" json:"ai_provider"` // AI 提供方:spark/deepseek/rule AIDifficulty string `gorm:"size:16;column:ai_difficulty" json:"ai_difficulty"` // AI 难度:easy/medium/hard Result int `gorm:"default:1" json:"result"` // 结果:1胜 2负 3平 PointsChange int `gorm:"default:0" json:"points_change"` // 积分变动(胜利奖励) Duration int `gorm:"default:0" json:"duration"` // 对局时长(秒) Detail string `gorm:"size:255" json:"detail"` // 对局详情摘要 CreatedAt int64 `gorm:"autoCreateTime" json:"created_at"` // 结算时间(int 时间戳) } // TableName 指定表名 func (BattleRecord) TableName() string { return "battle_records" }