```
All checks were successful
ci/woodpecker/push/my-first-workflow Pipeline was successful

feat(game): 宠物融合系统添加物品消耗异常处理

- 在宠物融合过程中添加物品扣除失败的错误检查
- 当物品不足时返回ErrInsufficientItems错误码

fix(pet): 宠物仓库管理功能增加数据库操作错误处理

- 在宠物释放到仓库和从仓库取出时验证数据库更新结果
- 添加宠物背包切换功能的错误检查机制

feat(fight):
This commit is contained in:
昔念
2026-03-19 14:50:11 +08:00
parent e2ac5a6325
commit b558f46d7a
10 changed files with 142 additions and 63 deletions

View File

@@ -38,6 +38,52 @@ type Pet struct {
Data PetInfo `gorm:"type:jsonb;not null;comment:'精灵全部数据'" json:"data"`
}
// GetOffShelfFee 计算商品下架扣费规则
// 返回值allowOffShelf(是否允许下架), feeRate(扣费比例), err(错误信息)
func (tt *Pet) GetOffShelfFee() (bool, float64, error) {
// 获取当前时间
now := time.Now()
// 计算上架到现在的时长(小时)
duration := now.Sub(tt.UpdateTime.Time)
hours := duration.Hours()
// 阶段10-24小时展示期可下架但阶梯扣费
if hours >= 0 && hours < 24 {
switch {
case hours < 6:
// 0-6小时0扣费允许下架
return true, 0.0, nil
case hours < 12:
// 6-12小时扣30%,允许下架
return true, 0.3, nil
case hours < 18:
// 12-18小时扣60%,允许下架
return true, 0.6, nil
case hours < 24:
// 18-24小时扣90%,允许下架
return true, 0.9, nil
}
}
// 阶段224-30小时禁止下架
if hours >= 24 && hours < 30 {
return false, 0.0, errors.New("24-30小时交易期禁止下架")
}
// 阶段330小时后自由下架0扣费
if hours >= 30 {
return true, 0.0, nil
}
// 异常情况(上架时间在未来)
return false, 0.0, errors.New("商品未到上架时间,无法操作下架")
}
// CalculateOffShelfAmount 根据扣费比例计算实际扣费金额
func (tt *Pet) CalculateOffShelfAmount(feeRate float64) float64 {
return float64(tt.SalePrice) * feeRate
}
type Attr uint32
func (r Attr) sub() uint32 {