feat(game): 宠物融合系统添加物品消耗异常处理 - 在宠物融合过程中添加物品扣除失败的错误检查 - 当物品不足时返回ErrInsufficientItems错误码 fix(pet): 宠物仓库管理功能增加数据库操作错误处理 - 在宠物释放到仓库和从仓库取出时验证数据库更新结果 - 添加宠物背包切换功能的错误检查机制 feat(fight):
This commit is contained in:
@@ -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()
|
||||
|
||||
// 阶段1:0-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
|
||||
}
|
||||
}
|
||||
|
||||
// 阶段2:24-30小时(禁止下架)
|
||||
if hours >= 24 && hours < 30 {
|
||||
return false, 0.0, errors.New("24-30小时交易期,禁止下架")
|
||||
}
|
||||
|
||||
// 阶段3:30小时后(自由下架,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 {
|
||||
|
||||
Reference in New Issue
Block a user