feat: 单订阅模式下赠送订阅自动合并,保持token不变
Build docker and publish / build (20.15.1) (push) Failing after 7m38s
Build docker and publish / build (20.15.1) (push) Failing after 7m38s
- purchaseLogic: 允许只有赠送订阅(order_id=0)的用户在SingleModel下新购 - activateOrderLogic: NewPurchase激活时检测赠送订阅,在原有订阅上延长到期时间而非创建新记录
This commit is contained in:
@@ -66,7 +66,15 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseQueryError), "find user subscription error: %v", err.Error())
|
||||
}
|
||||
if l.svcCtx.Config.Subscribe.SingleModel {
|
||||
if len(userSub) > 0 {
|
||||
// 检查是否有非赠送的活跃订阅(order_id > 0 表示付费订阅)
|
||||
hasPaidSubscription := false
|
||||
for _, s := range userSub {
|
||||
if s.OrderId > 0 {
|
||||
hasPaidSubscription = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if hasPaidSubscription {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.UserSubscribeExist), "user has subscription")
|
||||
}
|
||||
}
|
||||
@@ -103,7 +111,7 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
}
|
||||
price := sub.UnitPrice * req.Quantity
|
||||
// discount amount
|
||||
amount := int64(math.Round(float64(price) * discount))
|
||||
amount := int64(math.Round(float64(price) * discount))
|
||||
discountAmount := price - amount
|
||||
var coupon int64 = 0
|
||||
// Calculate the coupon deduction
|
||||
|
||||
Reference in New Issue
Block a user