```
feat(config): 添加炫彩皮肤配置服务和数据库查询功能 - 新增ShinyService服务,提供Args方法用于根据ID查询炫彩皮肤配置 - 修改ColorfulSkin模型,将BindElfIds字段的gorm类型从json改为jsonb以支持数组查询 - 移除ColorfulSkin模型中嵌入的cool.Model的json标签,优化序列化 - 实现基于JSONB数组查询的精灵绑定功能,支持概率随机和刷新计数统计 debug(common): 添加数据库缓存清除调试信息 - 在ModifyAfter方法中添加er1变量接收ClearCache返回值 - 使用println输出缓存清除结果,便于调试缓存机制 refactor(player): 重构玩家宠物异色信息生成逻辑 - 引入config服务包,通过配置动态生成宠物炫彩效果 - 注释掉原有的固定炫彩效果生成代码 - 添加条件判断,仅当配置存在时才
This commit is contained in:
@@ -11,7 +11,7 @@ const (
|
||||
|
||||
// ColorfulSkin 炫彩皮肤核心配置模型(完整保留原有字段,仅更名适配)
|
||||
type ColorfulSkin struct {
|
||||
*cool.Model `json:"-" gorm:"embedded"` // 嵌入通用Model(ID/创建时间/更新时间,不参与json序列化)
|
||||
*cool.Model
|
||||
|
||||
// 核心必填字段
|
||||
Color string `gorm:"not null;default:'';comment:'炫彩皮肤颜色(唯一标识每条配置)'" json:"color" description:"炫彩皮肤颜色"`
|
||||
@@ -20,7 +20,7 @@ type ColorfulSkin struct {
|
||||
Author string `gorm:"not null;size:64;default:'';comment:'炫彩皮肤配置作者(创建人/配置者名称)'" json:"author" description:"作者"`
|
||||
RefreshCount uint32 `gorm:"not null;default:0;comment:'累计刷新次数(炫彩皮肤外观刷新次数统计)'" json:"refresh_count" description:"刷新次数"`
|
||||
UsageCount uint32 `gorm:"not null;default:0;comment:'累计使用次数(炫彩皮肤使用次数统计)'" json:"usage_count" description:"使用次数"`
|
||||
BindElfIds []uint32 `gorm:"not null;type:json;default:'[]';comment:'绑定精灵ID数组,关联config_pet_boss表主键,空数组表示未绑定具体精灵'" json:"bind_elf_ids" description:"绑定精灵数组"`
|
||||
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:"野生精灵概率"`
|
||||
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"blazing/common/data"
|
||||
"blazing/cool"
|
||||
"blazing/modules/config/model"
|
||||
"context"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/gogf/gf/v2/database/gdb"
|
||||
"github.com/gogf/gf/v2/frame/g"
|
||||
"github.com/gogf/gf/v2/util/grand"
|
||||
)
|
||||
|
||||
type ShinyService struct {
|
||||
@@ -26,3 +30,34 @@ func NewShinyService() *ShinyService {
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
func (s *ShinyService) Args(id uint32) *data.GlowFilter {
|
||||
var ret []model.ColorfulSkin
|
||||
|
||||
// 执行 Raw SQL 并扫描返回值
|
||||
cool.DBM(s.Model).Wheref(`bind_elf_ids @> ?::jsonb`, id).Wheref(`jsonb_typeof(bind_elf_ids) = ?`, "array").Cache(gdb.CacheOption{
|
||||
// Duration: time.Hour,
|
||||
|
||||
Force: false,
|
||||
}).Scan(&ret)
|
||||
|
||||
for _, v := range ret {
|
||||
//print(v.ID)
|
||||
|
||||
id := v.ID
|
||||
|
||||
if grand.Meet(int(v.ElfProbability), 1000) {
|
||||
var t data.GlowFilter
|
||||
|
||||
r := json.Unmarshal([]byte(v.Color), &t)
|
||||
if r == nil {
|
||||
m := cool.DBM(s.Model).Where("id", id)
|
||||
m.Increment("refresh_count", 1)
|
||||
return &t
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user