This commit is contained in:
22
modules/config/controller/admin/egg.go
Normal file
22
modules/config/controller/admin/egg.go
Normal file
@@ -0,0 +1,22 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/service"
|
||||
)
|
||||
|
||||
type EggController struct {
|
||||
*cool.Controller
|
||||
}
|
||||
|
||||
func init() {
|
||||
var task_info_controller = &EggController{
|
||||
&cool.Controller{
|
||||
Prefix: "/admin/config/egg",
|
||||
Api: []string{"Add", "Delete", "Update", "Info", "List", "Page"},
|
||||
Service: service.NewEggService(),
|
||||
},
|
||||
}
|
||||
// 注册路由
|
||||
cool.RegisterController(task_info_controller)
|
||||
}
|
||||
@@ -4,49 +4,43 @@ import (
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
// 表名常量定义:egg配置表
|
||||
const (
|
||||
TableNameeggConfig = "config_pet_egg" // egg配置表(记录egg编号、可兑换次数、奖励配置等核心信息)
|
||||
TableNameEgg = "config_egg" // 性别配置表(替换原宠物融合表名)
|
||||
)
|
||||
|
||||
// EggConfig egg核心配置模型(含可兑换次数,满足查询`where 可兑换次数 != 0`需求)
|
||||
type EggConfig struct {
|
||||
*cool.Model
|
||||
|
||||
// Egg 性别配置模型(替换原宠物融合配方模型)
|
||||
type Egg struct {
|
||||
*cool.Model // 保留通用Model(ID/创建时间/更新时间等)
|
||||
//雄性
|
||||
|
||||
MalePet int32 `gorm:"not null;comment:'雄性宠物ID'" json:"male_pet"`
|
||||
MalePetIDs []int32 `gorm:"type:int[];comment:'雄性宠物ID列表(如:[1001,1002])'" json:"male_pet_ids"`
|
||||
//雌性
|
||||
FemalePet int32 `gorm:"not null;comment:'雌性宠物ID'" json:"female_pet"`
|
||||
FemalePetIDs []int32 `gorm:"type:int[];comment:'雌性宠物ID列表(如:[1001,1002])'" json:"female_pet_ids"`
|
||||
//子代指定性别配置表名
|
||||
OutputMons []int32 `gorm:"type:int[];not null;comment:'宠物类型ID'" json:"pet_type_id"`
|
||||
Probs []int32 `gorm:"type:int[];not null;comment:'对应子代宠物类型的概率(如:[50,50]表示均等概率)'" json:"probs"`
|
||||
|
||||
// 生成的精灵ID及对应概率
|
||||
GeneratedPetIDs []GeneratedPetID `gorm:"type:jsonb;comment:'生成的精灵ID及概率配置'" json:"generated_pet_ids"`
|
||||
|
||||
Remark string `gorm:"size:512;default:'';comment:'egg备注'" json:"remark" description:"备注信息"`
|
||||
//ItemGift []*ItemGift `gorm:"-" orm:"with:item_id=id"`
|
||||
}
|
||||
type GeneratedPetID struct {
|
||||
PetID int32 `json:"pet_id" comment:"生成的精灵ID"`
|
||||
Prob float64 `json:"prob" comment:"该精灵生成概率"`
|
||||
IsEnable int32 `gorm:"not null;default:1;comment:'是否启用(1:启用,0:禁用)'" json:"is_enable"` // 保留原有逻辑
|
||||
Remark string `gorm:"type:varchar(255);default:'';comment:'性别配置备注(如:默认性别规则)'" json:"remark"` // 调整注释
|
||||
}
|
||||
|
||||
// -------------------------- 核心配套方法(遵循项目规范)--------------------------
|
||||
func (*EggConfig) TableName() string {
|
||||
return TableNameeggConfig
|
||||
// TableName 指定性别配置表名(替换原宠物融合表名)
|
||||
func (*Egg) TableName() string {
|
||||
return TableNameEgg
|
||||
}
|
||||
|
||||
func (*EggConfig) GroupName() string {
|
||||
// GroupName 表分组(保持原逻辑的default分组)
|
||||
func (*Egg) GroupName() string {
|
||||
return "default"
|
||||
}
|
||||
|
||||
func NeweggConfig() *EggConfig {
|
||||
return &EggConfig{
|
||||
// NewEgg 创建性别配置实例(替换原NewPetFusion)
|
||||
func NewEgg() *Egg {
|
||||
return &Egg{
|
||||
Model: cool.NewModel(),
|
||||
}
|
||||
}
|
||||
|
||||
// -------------------------- 表结构自动同步 --------------------------
|
||||
// init 初始化性别配置表结构(替换原宠物融合表初始化)
|
||||
func init() {
|
||||
|
||||
cool.CreateTable(&EggConfig{})
|
||||
cool.CreateTable(&Egg{})
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"blazing/common/data"
|
||||
"blazing/cool"
|
||||
)
|
||||
|
||||
@@ -14,7 +15,7 @@ type ColorfulSkin struct {
|
||||
*cool.Model
|
||||
|
||||
// 核心必填字段
|
||||
Color string `gorm:"not null;default:'';comment:'炫彩皮肤颜色(唯一标识每条配置)'" json:"color" description:"炫彩皮肤颜色"`
|
||||
Color data.GlowFilter `gorm:"type:jsonb;not null;;comment:'炫彩皮肤颜色(唯一标识每条配置)'" json:"color" description:"炫彩皮肤颜色"`
|
||||
|
||||
IsEnabled uint32 `gorm:"not null;default:1;comment:'是否启用(0-禁用 1-启用)'" json:"is_enabled" description:"是否启用"`
|
||||
Author string `gorm:"not null;size:64;default:'';comment:'炫彩皮肤配置作者(创建人/配置者名称)'" json:"author" description:"作者"`
|
||||
@@ -42,15 +43,6 @@ func (*ColorfulSkin) GroupName() string {
|
||||
func NewColorfulSkin() *ColorfulSkin {
|
||||
return &ColorfulSkin{
|
||||
Model: cool.NewModel(),
|
||||
Color: "",
|
||||
|
||||
IsEnabled: 1,
|
||||
Author: "",
|
||||
RefreshCount: 0,
|
||||
UsageCount: 0,
|
||||
BindElfIds: []uint32{},
|
||||
|
||||
Remark: "",
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
32
modules/config/service/egg.go
Normal file
32
modules/config/service/egg.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
)
|
||||
|
||||
type EggService struct {
|
||||
*cool.Service
|
||||
}
|
||||
|
||||
func NewEggService() *EggService {
|
||||
return &EggService{
|
||||
&cool.Service{
|
||||
Model: model.NewEgg(),
|
||||
PageQueryOp: &cool.QueryOp{
|
||||
KeyWordField: []string{"desc"},
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *EggService) Get(id uint32) *model.Egg {
|
||||
if id == 0 {
|
||||
return nil
|
||||
}
|
||||
var item *model.Egg
|
||||
dbm(s.Model).Where("id", id).Scan(&item)
|
||||
|
||||
return item
|
||||
|
||||
}
|
||||
@@ -42,7 +42,7 @@ func (s *ShinyService) ModifyBefore(ctx context.Context, method string, param g.
|
||||
}
|
||||
return nil
|
||||
}
|
||||
func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
|
||||
func (s *ShinyService) RandShiny(id uint32) *model.ColorfulSkin {
|
||||
var ret []model.ColorfulSkin
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
@@ -57,24 +57,20 @@ func (s *ShinyService) RandShiny(id uint32) *data.GlowFilter {
|
||||
id := v.ID
|
||||
|
||||
if grand.Meet(int(v.ElfProbability), 1000) {
|
||||
var t data.GlowFilter
|
||||
|
||||
r := json.Unmarshal([]byte(v.Color), &t)
|
||||
if r == nil {
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", id)
|
||||
m.Increment("refresh_count", 1)
|
||||
}
|
||||
|
||||
return &t
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", id)
|
||||
m.Increment("refresh_count", 1)
|
||||
}
|
||||
|
||||
return &v
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
func (s *ShinyService) FixShiny(id uint32) *data.GlowFilter {
|
||||
func (s *ShinyService) FixShiny(id uint32) *model.ColorfulSkin {
|
||||
var ret []model.ColorfulSkin
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
@@ -87,17 +83,26 @@ func (s *ShinyService) FixShiny(id uint32) *data.GlowFilter {
|
||||
}
|
||||
v := ret[grand.Intn(len(ret))]
|
||||
|
||||
var t data.GlowFilter
|
||||
|
||||
r := json.Unmarshal([]byte(v.Color), &t)
|
||||
if r == nil {
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", v.ID)
|
||||
m.Increment("usage_count", 1)
|
||||
}
|
||||
|
||||
return &t
|
||||
if cool.Config.ServerInfo.IsVip == 0 {
|
||||
m := cool.DBM(s.Model).Where("id", v.ID)
|
||||
m.Increment("usage_count", 1)
|
||||
}
|
||||
|
||||
return &v
|
||||
|
||||
}
|
||||
func (s *ShinyService) GetShiny(id int) *data.GlowFilter {
|
||||
var ret []model.ColorfulSkin
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
dbm(s.Model).
|
||||
Where("id", id).Scan(&ret)
|
||||
if len(ret) == 0 {
|
||||
return nil
|
||||
}
|
||||
v := ret[grand.Intn(len(ret))]
|
||||
|
||||
return &v.Color
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user