feat(model): 新增金豆消费、CDK配置、炫彩皮肤及双塔模型,优化物品奖励和BOSS配置
This commit is contained in:
68
modules/blazing/model/GoldBeanConsume.go
Normal file
68
modules/blazing/model/GoldBeanConsume.go
Normal file
@@ -0,0 +1,68 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"errors"
|
||||
)
|
||||
|
||||
// 表名常量定义:金豆消费记录表
|
||||
const (
|
||||
TableNameGoldBeanConsume = "gold_bean_consume_record" // 金豆消费记录表(记录用户金豆消耗的明细、类型、关联业务等信息)
|
||||
)
|
||||
|
||||
// 通过金豆消费时间来确认金豆物品的购买重置周期
|
||||
// GoldBeanConsume 金豆消费核心模型(与数据库表字段一一对应,存储消费明细)
|
||||
type GoldBeanConsume struct {
|
||||
*cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化)
|
||||
|
||||
UID uint32 `gorm:"not null;default:0;index;comment:'玩家唯一ID,关联玩家表主键'" json:"uid" description:"玩家ID"`
|
||||
ConsumeNum uint32 `gorm:"not null;default:0;comment:'金豆消费数量(非负数)'" json:"consume_num" description:"消费金豆数量"`
|
||||
BizID uint32 `gorm:"not null;default:0;comment:'关联业务ID(如道具ID/扭蛋池ID,无则填0)'" json:"biz_id" description:"关联业务ID"`
|
||||
BeforeBalance uint32 `gorm:"not null;default:0;comment:'消费前金豆余额'" json:"before_balance" description:"消费前余额"`
|
||||
}
|
||||
|
||||
// GoldBeanConsumeEX 金豆消费扩展模型(用于前端/业务层展示,补充非存储字段)
|
||||
type GoldBeanConsumeEX struct {
|
||||
GoldBeanConsume // 嵌入核心消费模型
|
||||
UserName string `json:"user_name" description:"玩家昵称"` // 关联玩家表查询,前端展示用
|
||||
ConsumeTypeDesc string `json:"consume_type_desc" description:"消费类型描述"` // 如"购买道具"/"扭蛋抽奖"
|
||||
}
|
||||
|
||||
// -------------------------- 核心配套方法 --------------------------
|
||||
|
||||
// TableName 指定GoldBeanConsume对应的数据库表名(遵循项目规范)
|
||||
func (*GoldBeanConsume) TableName() string {
|
||||
return TableNameGoldBeanConsume
|
||||
}
|
||||
|
||||
// GroupName 指定表所属分组(与其他精灵/玩家相关表保持一致)
|
||||
func (*GoldBeanConsume) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
// NewGoldBeanConsume 创建金豆消费记录实例(初始化通用Model及默认值)
|
||||
func NewGoldBeanConsume() *GoldBeanConsume {
|
||||
return &GoldBeanConsume{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// ValidateConsume 校验消费记录的合法性(避免无效/非法数据)
|
||||
func (g *GoldBeanConsume) ValidateConsume() error {
|
||||
// 校验玩家ID
|
||||
if g.UID == 0 {
|
||||
return errors.New("玩家ID不能为空")
|
||||
}
|
||||
// 校验消费数量
|
||||
if g.ConsumeNum <= 0 {
|
||||
return errors.New("金豆消费数量必须大于0")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// -------------------------- 表结构自动同步 --------------------------
|
||||
func init() {
|
||||
// 程序启动时自动创建/同步金豆消费记录表
|
||||
cool.CreateTable(&GoldBeanConsume{})
|
||||
}
|
||||
Reference in New Issue
Block a user