fix: 修复非单订阅模式下过期用户重复购买产生双订阅的问题
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 4m45s
All checks were successful
Build docker and publish / build (20.15.1) (push) Successful in 4m45s
1. purchaseLogic: 非单订阅模式下购买前查询已有订阅,路由为续费(type=2) 2. activateOrderLogic: 续费激活时触发节点分组重算,确保过期续费后权限生效 Co-Authored-By: claude-flow <ruv@ruv.net>
This commit is contained in:
parent
c8258dc93b
commit
9a8ae8b6fd
@ -111,6 +111,26 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
}
|
||||
}
|
||||
|
||||
// 非单订阅模式下,若用户已有同套餐订阅(含过期),提前路由为续费,防止创建重复订阅
|
||||
if !l.svcCtx.Config.Subscribe.SingleModel && orderType == 1 {
|
||||
var existSub user.Subscribe
|
||||
if e := l.svcCtx.DB.WithContext(l.ctx).
|
||||
Model(&user.Subscribe{}).
|
||||
Where("user_id = ? AND subscribe_id = ?", entitlement.EffectiveUserID, targetSubscribeID).
|
||||
Order("expire_time DESC").
|
||||
First(&existSub).Error; e == nil && existSub.Id > 0 && existSub.Token != "" {
|
||||
orderType = 2
|
||||
parentOrderID = existSub.OrderId
|
||||
subscribeToken = existSub.Token
|
||||
l.Infow("[Purchase] non-single mode purchase routed to renewal (existing subscription found)",
|
||||
logger.Field("existing_subscribe_id", existSub.Id),
|
||||
logger.Field("existing_status", existSub.Status),
|
||||
logger.Field("user_id", u.Id),
|
||||
logger.Field("subscribe_id", targetSubscribeID),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
// 单订阅模式下,若已有同套餐 pending 订单,关闭旧单后继续创建新单(确保新单参数生效)
|
||||
if l.svcCtx.Config.Subscribe.SingleModel && orderType == 1 {
|
||||
var existPending order.Order
|
||||
|
||||
@ -895,6 +895,9 @@ func (l *ActivateOrderLogic) Renewal(ctx context.Context, orderInfo *order.Order
|
||||
}
|
||||
}
|
||||
|
||||
// Trigger user group recalculation (needed when renewing an expired subscription)
|
||||
l.triggerUserGroupRecalculation(ctx, userInfo.Id)
|
||||
|
||||
// Clear user subscription cache
|
||||
err = l.svc.UserModel.ClearSubscribeCache(ctx, userSub)
|
||||
if err != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user