重构支付接口,以动态支持多种产品类型,整合长短效套餐的购买支付逻辑;引入 decimal 类型的金额计算;
This commit is contained in:
@@ -305,28 +305,33 @@ func findResource(q *q.Query, resourceId int32, userId int32, count int, now tim
|
||||
return nil, ErrResourceInvalid
|
||||
}
|
||||
|
||||
// 检查每日限额
|
||||
used := 0
|
||||
if now.Format("2006-01-02") == info.DailyLast.Format("2006-01-02") {
|
||||
used = int(info.DailyUsed)
|
||||
}
|
||||
excess := used+count > int(info.DailyLimit)
|
||||
if excess {
|
||||
return nil, ErrResourceDailyLimit
|
||||
}
|
||||
|
||||
// 检查时间或配额
|
||||
// 检查套餐使用情况
|
||||
switch info.Mode {
|
||||
default:
|
||||
return nil, ChannelServiceErr("不支持的套餐模式")
|
||||
|
||||
// 包时
|
||||
case resource2.ModeTime:
|
||||
// 检查过期时间
|
||||
if info.Expire.Before(now) {
|
||||
return nil, ErrResourceExpired
|
||||
}
|
||||
// 检查每日限额
|
||||
used := 0
|
||||
if now.Format("2006-01-02") == info.DailyLast.Format("2006-01-02") {
|
||||
used = int(info.DailyUsed)
|
||||
}
|
||||
excess := used+count > int(info.DailyLimit)
|
||||
if excess {
|
||||
return nil, ErrResourceDailyLimit
|
||||
}
|
||||
|
||||
// 包量
|
||||
case resource2.ModeCount:
|
||||
// 检查可用配额
|
||||
if int(info.Quota)-int(info.Used) < count {
|
||||
return nil, ErrResourceExhausted
|
||||
}
|
||||
default:
|
||||
return nil, ChannelServiceErr("不支持的套餐模式")
|
||||
}
|
||||
|
||||
return info, nil
|
||||
|
||||
Reference in New Issue
Block a user