Files
bl/modules/config/model/shop.go
昔念 a62b94446a ```
feat(pet): 添加精灵进化功能并优化融合系统

- 新增PetELV方法实现精灵进化功能,支持分支进化选择
- 添加进化相关的数据结构定义
- 实现进化材料检查和扣除逻辑
- 优化宠物融合失败处理机制

fix(fight): 修复战斗系统和效果计算问题

- 修复NewSeIdx_11和effect_60中的伤害计算逻辑
- 修复战斗状态判断条件,避免非PVP模式下的错误处理
- 优化战斗回合处理流程,修复效果缓存清空时机
- 修复effect_69
2026-01-03 01:35:32 +08:00

140 lines
4.7 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/cool"
"errors"
"time"
)
// 表名常量定义:商店配置表
const (
TableNameShopConfig = "shop_config" // 商店配置表(记录商品信息、价格、库存、分类等)
)
// ShopConfig 商店商品核心配置模型
type ShopConfig struct {
*cool.Model `json:"-" gorm:"embedded"` // 嵌入通用ModelID/创建时间/更新时间不参与json序列化
// 核心字段
ProductName string `gorm:"not null;size:128;comment:'商品名称'" json:"product_name" description:"商品名称"`
Description string `gorm:"not null;size:512;comment:'商品描述'" json:"description" description:"商品描述"`
// 价格信息
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"`
// 状态信息
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:"限购周期(小时)"`
// 备注信息
Remark string `gorm:"size:512;default:'';comment:'商品备注'" json:"remark" description:"备注信息"`
}
// -------------------------- 核心配套方法(遵循项目规范)--------------------------
func (*ShopConfig) TableName() string {
return TableNameShopConfig
}
func (*ShopConfig) GroupName() string {
return "default"
}
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: "",
}
}
// 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{})
}