From 43bec155e140c15674696e97af6d960ce803995a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=98=94=E5=BF=B5?= <1@72wo.cn> Date: Mon, 5 Jan 2026 01:04:52 +0800 Subject: [PATCH] =?UTF-8?q?```=20feat(config):=20=E6=B7=BB=E5=8A=A0?= =?UTF-8?q?=E6=9C=8D=E5=8A=A1=E5=99=A8=E7=99=BB=E5=BD=95=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E5=AD=97=E6=AE=B5=E5=92=8C=E5=95=86=E5=BA=97=E5=95=86=E5=93=81?= =?UTF-8?q?ID=E5=AD=97=E6=AE=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在ServerList模型中新增LoginAddr、Account、Password字段用于服务器登录配置 - 在Shiny模型中新增VoteCount字段用于记录投票次数 - 在ShopConfig模型中新增ProductID字段作为商品唯一标识 - 移除ShopConfig中不必要的CategoryID、IconURL、时间验证相关字段 - 删除ShopConfig的Validate和时间验证相关方法,简化模型 --- logic/controller/fight_tawor.go | 10 +-- login/go.mod | 1 - modules/blazing/model/title.go | 47 ++++++++++++++ modules/config/model/server_list.go | 14 +++-- modules/config/model/shiny.go | 2 + modules/config/model/shop.go | 96 +++-------------------------- 6 files changed, 72 insertions(+), 98 deletions(-) create mode 100644 modules/blazing/model/title.go diff --git a/logic/controller/fight_tawor.go b/logic/controller/fight_tawor.go index 7ec11bcfc..ddfad15d6 100644 --- a/logic/controller/fight_tawor.go +++ b/logic/controller/fight_tawor.go @@ -10,7 +10,7 @@ import ( "blazing/modules/blazing/model" configmodel "blazing/modules/config/model" "blazing/modules/config/service" - configservice "blazing/modules/config/service" + "sync/atomic" "github.com/gogf/gf/v2/util/gconv" @@ -25,7 +25,7 @@ func (h Controller) FreshOPEN(data *fight.C2S_OPEN_DARKPORTAL, c *player.Player) boss := service.NewTower110Service().Boss(uint32(data.Level)) result = &fight.S2C_OPEN_DARKPORTAL{} for _, v := range boss.BossIds { - r := configservice.NewBossService().Get(v) + r := service.NewBossService().Get(v) result.CurBossID = uint32(r.MonID) } @@ -81,7 +81,7 @@ func (h Controller) FreshChoiceFightLevel(data *fight.C2S_FRESH_CHOICE_FIGHT_LEV if boss != nil { for _, v := range boss.BossIds { - r := configservice.NewBossService().Get(v) + r := service.NewBossService().Get(v) result.BossId = append(result.BossId, uint32(r.MonID)) } @@ -130,13 +130,13 @@ func (h Controller) PetTawor(data *fight.StartTwarInboundInfo, c *player.Player) } if next != nil { for _, v := range next.BossIds { - r := configservice.NewBossService().Get(v) + r := service.NewBossService().Get(v) result.BossID = append(result.BossID, uint32(r.MonID)) } } for i, v := range boss.BossIds { - r := configservice.NewBossService().Get(v) + r := service.NewBossService().Get(v) if r != nil { monster := model.GenPetInfo(int(r.MonID), 24, int(r.Nature), 0, int(r.Lv), nil) diff --git a/login/go.mod b/login/go.mod index 417ba12c4..653f53e69 100644 --- a/login/go.mod +++ b/login/go.mod @@ -47,6 +47,5 @@ require ( golang.org/x/sys v0.30.0 // indirect golang.org/x/text v0.22.0 // indirect golang.org/x/time v0.8.0 // indirect - gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) diff --git a/modules/blazing/model/title.go b/modules/blazing/model/title.go new file mode 100644 index 000000000..7af494c32 --- /dev/null +++ b/modules/blazing/model/title.go @@ -0,0 +1,47 @@ +package model + +import ( + "blazing/cool" +) + +// 表名常量 +const TableNamePlayerTitle = "player_title" + +// PlayerTitle 对应数据库表 +type Title struct { + *cool.Model + PlayerID uint64 `gorm:"not null;index:idx_player_title_by_player_id;comment:'所属玩家ID'" json:"player_id"` + TitleID uint32 `gorm:"not null;comment:'称号ID'" json:"title_id"` + //可用称号 + AvailableTitle []uint32 `json:"available_title"` +} + +// TitleInfo 用于前端返回的称号信息 +type TitleInfo struct { + TitleId uint32 `json:"titleId"` // 称号ID + LeftTime uint32 `json:"leftTime"` // 剩余时间(秒),永久称号可设为 0 + ItemLevel uint32 `json:"itemLevel"` // 称号等级,可固定为 0 + IsActive bool `json:"isActive"` // 是否当前使用 +} + +// TableName 返回表名 +func (*Title) TableName() string { + return TableNamePlayerTitle +} + +// GroupName 返回表组名 +func (*Title) GroupName() string { + return "default" +} + +// NewPlayerTitle 创建一个新的称号记录 +func NewPlayerTitle() *Title { + return &Title{ + Model: cool.NewModel(), + } +} + +// init 程序启动时自动创建表 +func init() { + cool.CreateTable(&Title{}) +} diff --git a/modules/config/model/server_list.go b/modules/config/model/server_list.go index 075120172..9b0b67a41 100644 --- a/modules/config/model/server_list.go +++ b/modules/config/model/server_list.go @@ -10,10 +10,16 @@ const TableNameServerList = "server_list" // ServerList mapped from table type ServerList struct { *cool.Model - OnlineID uint16 `gorm:"column:online_id;comment:'在线ID';uniqueIndex" json:"online_id"` - IP string `gorm:"type:string;comment:'服务器IP'" json:"ip"` - Port uint16 `gorm:"comment:'端口号,通常是小整数'" json:"port"` - IsOpen bool `gorm:"default:true;not null;comment:'服务器是否开启,默认为开启状态'" json:"is_open"` + OnlineID uint16 `gorm:"column:online_id;comment:'在线ID';uniqueIndex" json:"online_id"` + IP string `gorm:"type:string;comment:'服务器IP'" json:"ip"` + Port uint16 `gorm:"comment:'端口号,通常是小整数'" json:"port"` + IsOpen bool `gorm:"default:true;not null;comment:'服务器是否开启,默认为开启状态'" json:"is_open"` + //登录地址 + LoginAddr string `gorm:"type:string;comment:'登录地址'" json:"login_addr"` + //账号 + Account string `gorm:"type:string;comment:'账号'" json:"account"` + //密码 + Password string `gorm:"type:string;comment:'密码'" json:"password"` CanPort []uint32 `gorm:"type:jsonb;comment:'可连接端口'" json:"can_port"` IsVip uint32 `gorm:"default:0;not null;comment:'是否为VIP服务器'" json:"is_vip"` //服务器异色概率设定ServerList diff --git a/modules/config/model/shiny.go b/modules/config/model/shiny.go index e895e89e3..83caf78f1 100644 --- a/modules/config/model/shiny.go +++ b/modules/config/model/shiny.go @@ -23,6 +23,8 @@ type ColorfulSkin struct { BindElfIds []uint32 `gorm:"not null;type:jsonb;default:'[]';comment:'绑定精灵ID数组,关联config_pet_boss表主键,空数组表示未绑定具体精灵'" json:"bind_elf_ids" description:"绑定精灵数组"` //野生精灵概率 ElfProbability uint32 `gorm:"not null;default:0;comment:'野生精灵概率(0-10000)'" json:"elf_probability" description:"野生精灵概率"` + //投票 + VoteCount uint32 `gorm:"not null;default:0;comment:'投票次数'" json:"vote_count" description:"投票次数"` // 辅助备注字段 Remark string `gorm:"size:512;default:'';comment:'炫彩皮肤备注'" json:"remark" description:"备注信息"` diff --git a/modules/config/model/shop.go b/modules/config/model/shop.go index cf640b25e..c0a729c2f 100644 --- a/modules/config/model/shop.go +++ b/modules/config/model/shop.go @@ -2,8 +2,6 @@ package model import ( "blazing/cool" - "errors" - "time" ) // 表名常量定义:商店配置表 @@ -17,32 +15,25 @@ type ShopConfig struct { // 核心字段 ProductName string `gorm:"not null;size:128;comment:'商品名称'" json:"product_name" description:"商品名称"` + //商品ID + ProductID uint32 `gorm:"not null;uniqueIndex;comment:'商品ID'" json:"product_id" description:"商品ID"` Description string `gorm:"not null;size:512;comment:'商品描述'" json:"description" description:"商品描述"` - // 价格信息 + // 价格信息 -1代表不允许购买,0免费赠送 SeerdouPrice uint32 `gorm:"not null;default:0;comment:'骄阳豆价格'" json:"seerdou_price" description:"骄阳豆价格"` JindouPrice uint32 `gorm:"not null;default:0;comment:'价格'" json:"jindou_price" description:"金豆价格"` // 库存信息 Stock uint32 `gorm:"not null;default:0;comment:'商品库存数量(0表示无限库存)'" json:"stock" description:"库存数量"` - // 分类信息 - CategoryID uint32 `gorm:"not null;default:0;comment:'商品分类ID'" json:"category_id" description:"分类ID"` - Category string `gorm:"not null;size:64;comment:'商品分类名称'" json:"category" description:"分类名称"` - - // 图片信息 - IconURL string `gorm:"not null;size:255;comment:'商品图标URL'" json:"icon_url" description:"图标URL"` + Category uint32 `gorm:"not null;size:64;comment:'商品分类名称'" json:"category" description:"分类名称"` // 状态信息 IsOnSale uint32 `gorm:"not null;default:1;comment:'是否上架(0-下架 1-上架)'" json:"is_on_sale" description:"是否上架"` - // 时间信息 - ValidStartTime time.Time `gorm:"not null;comment:'商品有效开始时间'" json:"valid_start_time" description:"有效开始时间"` - ValidEndTime time.Time `gorm:"not null;comment:'商品有效结束时间'" json:"valid_end_time" description:"有效结束时间"` - // 限购信息 - QuotaLimit uint32 `gorm:"not null;default:0;comment:'单位时间内的限购数量(0表示不限购)'" json:"quota_limit" description:"限购数量"` - QuotaCycle uint32 `gorm:"not null;default:0;comment:'限购周期(单位:小时,0表示不限购)'" json:"quota_cycle" description:"限购周期(小时)"` + QuotaLimit uint32 `gorm:"not null;default:0;comment:'单位时间内的限购数量(0表示不限购)'" json:"quota_limit" description:"限购数量"` + QuotaCycle uint32 `gorm:"not null;default:0;comment:'限购周期(单位:小时,0表示不限购)'" json:"quota_cycle" description:"限购周期(小时)"` // 备注信息 Remark string `gorm:"size:512;default:'';comment:'商品备注'" json:"remark" description:"备注信息"` @@ -59,82 +50,11 @@ func (*ShopConfig) GroupName() string { func NewShopConfig() *ShopConfig { return &ShopConfig{ - Model: cool.NewModel(), - ProductName: "", - Description: "", - SeerdouPrice: 0, - JindouPrice: 0, - Stock: 0, - CategoryID: 0, - Category: "", - IconURL: "", - IsOnSale: 1, // 默认上架 - ValidStartTime: time.Now(), - ValidEndTime: time.Now().AddDate(1, 0, 0), // 默认有效期1年 - QuotaLimit: 0, // 默认不限购 - QuotaCycle: 0, // 默认不限时 - Remark: "", + Model: cool.NewModel(), } } -// Validate 验证ShopConfig字段的有效性 -func (s *ShopConfig) Validate() error { - if s.ProductName == "" { - return errors.New("商品名称不能为空") - } - - if len(s.ProductName) > 128 { - return errors.New("商品名称长度不能超过128个字符") - } - - if len(s.Description) > 512 { - return errors.New("商品描述长度不能超过512个字符") - } - - if len(s.Category) > 64 { - return errors.New("商品分类名称长度不能超过64个字符") - } - - if len(s.IconURL) > 255 { - return errors.New("商品图标URL长度不能超过255个字符") - } - - if len(s.Remark) > 512 { - return errors.New("备注信息长度不能超过512个字符") - } - - if s.ValidStartTime.After(s.ValidEndTime) { - return errors.New("有效开始时间不能晚于结束时间") - } - - if s.IsOnSale != 0 && s.IsOnSale != 1 { - return errors.New("上架状态值不正确,应为0或1") - } - - if s.QuotaCycle > 0 && s.QuotaLimit == 0 { - return errors.New("设置了限购周期但未设置限购数量") - } - - return nil -} - -// IsInValidPeriod 检查当前时间是否在商品有效期内 -func (s *ShopConfig) IsInValidPeriod() bool { - now := time.Now() - return now.After(s.ValidStartTime) && now.Before(s.ValidEndTime) -} - -// IsAvailable 检查商品是否可用(上架状态且在有效期内) -func (s *ShopConfig) IsAvailable() bool { - return s.IsOnSale == 1 && s.IsInValidPeriod() -} - -// HasQuotaRestriction 检查商品是否有时间周期限购 -func (s *ShopConfig) HasQuotaRestriction() bool { - return s.QuotaLimit > 0 && s.QuotaCycle > 0 -} - // -------------------------- 表结构自动同步 -------------------------- func init() { cool.CreateTable(&ShopConfig{}) -} \ No newline at end of file +}