Files
bl/modules/config/model/shiny.go

121 lines
4.5 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package model
import (
"blazing/common/data"
"blazing/cool"
"errors"
"fmt"
)
// 表名常量定义:炫彩皮肤表
const (
TableNameColorfulSkin = "colorful_skin" // 炫彩皮肤表(记录炫彩皮肤颜色、光环、绑定精灵等核心配置)
)
// ColorfulSkin 炫彩皮肤核心配置模型(完整保留原有字段,仅更名适配)
type ColorfulSkin struct {
*cool.Model `json:"-" gorm:"embedded"` // 嵌入通用ModelID/创建时间/更新时间不参与json序列化
// 核心必填字段
Color string `gorm:"not null;default:'';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:"作者"`
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:"绑定精灵数组"`
//野生精灵概率
ElfProbability uint32 `gorm:"not null;default:0;comment:'野生精灵概率0-10000'" json:"elf_probability" description:"野生精灵概率"`
// 辅助备注字段
Remark string `gorm:"size:512;default:'';comment:'炫彩皮肤备注'" json:"remark" description:"备注信息"`
}
// ColorfulSkinEX 炫彩皮肤扩展模型(用于前端/业务层展示,非数据库存储字段)
type ColorfulSkinEX struct {
ColorfulSkin // 嵌入核心炫彩皮肤模型
ColorS data.GlowFilter `json:"color" description:"光环名称(前端展示用,关联光环配置表查询)"`
BindElfNames []string `json:"bind_elf_names" description:"绑定精灵名称列表"`
IsEnabledDesc string `json:"is_enabled_desc" description:"启用状态描述"`
IsUniversalDesc string `json:"is_universal_desc" description:"通用状态描述"`
}
// -------------------------- 核心配套方法(仅更名适配,逻辑不变)--------------------------
func (*ColorfulSkin) TableName() string {
return TableNameColorfulSkin
}
func (*ColorfulSkin) GroupName() string {
return "default"
}
func NewColorfulSkin() *ColorfulSkin {
return &ColorfulSkin{
Model: cool.NewModel(),
Color: "",
IsEnabled: 1,
Author: "",
RefreshCount: 0,
UsageCount: 0,
BindElfIds: []uint32{},
Remark: "",
}
}
// -------------------------- 业务操作方法(逻辑不变,仅调整提示信息标识)--------------------------
// AddBindElfId 为炫彩皮肤添加单个绑定精灵ID避免重复添加
func (c *ColorfulSkin) AddBindElfId(elfId uint32) error {
if elfId == 0 {
return errors.New("绑定精灵ID不能为空不能为0")
}
// 检查是否已绑定,避免重复
for _, id := range c.BindElfIds {
if id == elfId {
return fmt.Errorf("精灵ID%d已绑定当前炫彩皮肤配置无需重复添加", elfId)
}
}
c.BindElfIds = append(c.BindElfIds, elfId)
return nil
}
// RemoveBindElfId 从炫彩皮肤移除单个绑定精灵ID
func (c *ColorfulSkin) RemoveBindElfId(elfId uint32) error {
if elfId == 0 {
return errors.New("绑定精灵ID不能为空不能为0")
}
for i, id := range c.BindElfIds {
if id == elfId {
c.BindElfIds = append(c.BindElfIds[:i], c.BindElfIds[i+1:]...)
return nil
}
}
return fmt.Errorf("当前炫彩皮肤配置未绑定精灵ID%d无法移除", elfId)
}
// AddRefreshCount 增加刷新次数支持批量累加默认累加1
func (c *ColorfulSkin) AddRefreshCount(addNum uint32) error {
if addNum <= 0 {
return errors.New("增加的刷新次数必须大于0")
}
c.RefreshCount += addNum
return nil
}
// AddUsageCount 增加使用次数支持批量累加默认累加1
func (c *ColorfulSkin) AddUsageCount(addNum uint32) error {
if addNum <= 0 {
return errors.New("增加的使用次数必须大于0")
}
c.UsageCount += addNum
return nil
}
// -------------------------- 表结构自动同步 --------------------------
func init() {
cool.CreateTable(&ColorfulSkin{})
}