bug: 无订阅情况 出现下多笔订单 支付状态乱
Build docker and publish / build (20.15.1) (push) Successful in 7m18s

This commit is contained in:
2026-03-30 00:32:41 -07:00
parent a9205cc3fc
commit df7303738a
4 changed files with 531 additions and 13 deletions
+12 -7
View File
@@ -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())
}
}
}