This commit is contained in:
@@ -111,7 +111,7 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
}
|
||||
}
|
||||
|
||||
// 单订阅模式下,若已有同套餐 pending 订单,直接返回,防止重复创建
|
||||
// 单订阅模式下,若已有同套餐 pending 订单,关闭旧单后继续创建新单(确保新单参数生效)
|
||||
if l.svcCtx.Config.Subscribe.SingleModel && orderType == 1 {
|
||||
var existPending order.Order
|
||||
if e := l.svcCtx.DB.WithContext(l.ctx).
|
||||
@@ -119,15 +119,20 @@ func (l *PurchaseLogic) Purchase(req *types.PurchaseOrderRequest) (resp *types.P
|
||||
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",
|
||||
l.Infow("[Purchase] single mode pending order exists, closing old order and creating new one",
|
||||
logger.Field("user_id", u.Id),
|
||||
logger.Field("order_no", existPending.OrderNo),
|
||||
logger.Field("old_order_no", existPending.OrderNo),
|
||||
logger.Field("subscribe_id", targetSubscribeID),
|
||||
)
|
||||
return &types.PurchaseOrderResponse{
|
||||
OrderNo: existPending.OrderNo,
|
||||
AppAccountToken: existPending.AppAccountToken,
|
||||
}, nil
|
||||
if closeErr := NewCloseOrderLogic(l.ctx, l.svcCtx).CloseOrder(&types.CloseOrderRequest{
|
||||
OrderNo: existPending.OrderNo,
|
||||
}); closeErr != nil {
|
||||
l.Errorw("[Purchase] close old pending order failed",
|
||||
logger.Field("error", closeErr.Error()),
|
||||
logger.Field("old_order_no", existPending.OrderNo),
|
||||
)
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DatabaseUpdateError), "close old pending order error: %v", closeErr.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user