This commit is contained in:
@@ -111,6 +111,26 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
}
|
||||
}
|
||||
|
||||
// 单订阅模式下,若已有同套餐 pending 订单,直接返回,防止重复创建
|
||||
if l.svcCtx.Config.Subscribe.SingleModel && orderType == 1 {
|
||||
var existPending order.Order
|
||||
if e := l.svcCtx.DB.WithContext(l.ctx).
|
||||
Model(&order.Order{}).
|
||||
Where("user_id = ? AND subscribe_id = ? AND status = 1", u.Id, targetSubscribeID).
|
||||
Order("id DESC").
|
||||
First(&existPending).Error; e == nil && existPending.Id > 0 {
|
||||
l.Infow("[Purchase] single mode pending order exists, returning existing",
|
||||
logger.Field("user_id", u.Id),
|
||||
logger.Field("order_no", existPending.OrderNo),
|
||||
logger.Field("subscribe_id", targetSubscribeID),
|
||||
)
|
||||
return &types.PurchaseOrderResponse{
|
||||
OrderNo: existPending.OrderNo,
|
||||
AppAccountToken: existPending.AppAccountToken,
|
||||
}, nil
|
||||
}
|
||||
}
|
||||
|
||||
// find subscribe plan
|
||||
sub, err := l.svcCtx.SubscribeModel.FindOne(l.ctx, targetSubscribeID)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user