f
This commit is contained in:
@@ -67,7 +67,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
}
|
||||
|
||||
case "query":
|
||||
paymentTypeResp, err = l.QueryOrderPayment(req, session)
|
||||
paymentTypeResp, err = l.QueryOrderPayment(req, session, useXpay)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -225,7 +225,7 @@ func (l *PaymentLogic) Payment(req *types.PaymentReq) (resp *types.PaymentResp,
|
||||
}
|
||||
}
|
||||
|
||||
func (l *PaymentLogic) QueryOrderPayment(req *types.PaymentReq, session sqlx.Session) (resp *PaymentTypeResp, err error) {
|
||||
func (l *PaymentLogic) QueryOrderPayment(req *types.PaymentReq, session sqlx.Session, useXpay bool) (resp *PaymentTypeResp, err error) {
|
||||
userID, getUidErr := ctxdata.GetUidFromCtx(l.ctx)
|
||||
if getUidErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.SERVER_COMMON_ERROR), "生成订单, 获取用户信息失败, %+v", getUidErr)
|
||||
@@ -271,12 +271,43 @@ func (l *PaymentLogic) QueryOrderPayment(req *types.PaymentReq, session sqlx.Ses
|
||||
if user.Inside == 1 {
|
||||
amount = 0.01
|
||||
}
|
||||
|
||||
// 同一 queryId 重复发起支付:复用已有订单,避免 order_no 唯一键冲突导致二次支付失败
|
||||
if existingOrder, findOrderErr := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, outTradeNo); findOrderErr == nil {
|
||||
switch existingOrder.Status {
|
||||
case model.OrderStatusPaid:
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单已支付,请前往报告查看"), "订单号: %s", outTradeNo)
|
||||
case model.OrderStatusPending:
|
||||
if existingOrder.Status != model.OrderStatusPending {
|
||||
existingOrder.Status = model.OrderStatusPending
|
||||
if updateErr := l.svcCtx.OrderModel.UpdateWithVersion(l.ctx, session, existingOrder); updateErr != nil {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "重置订单状态失败: %+v", updateErr)
|
||||
}
|
||||
}
|
||||
return &PaymentTypeResp{
|
||||
amount: existingOrder.Amount,
|
||||
outTradeNo: outTradeNo,
|
||||
description: product.ProductName,
|
||||
orderID: existingOrder.Id,
|
||||
productEn: product.ProductEn,
|
||||
}, nil
|
||||
default:
|
||||
return nil, errors.Wrapf(xerr.NewErrMsg("订单状态异常,请重新发起查询"), "status=%s", existingOrder.Status)
|
||||
}
|
||||
} else if !errors.Is(findOrderErr, model.ErrNotFound) {
|
||||
return nil, errors.Wrapf(xerr.NewErrCode(xerr.DB_ERROR), "查询订单失败: %+v", findOrderErr)
|
||||
}
|
||||
|
||||
paymentPlatform := req.PayMethod
|
||||
if useXpay {
|
||||
paymentPlatform = model.PaymentPlatformWechatXpay
|
||||
}
|
||||
order := model.Order{
|
||||
Id: uuid.NewString(),
|
||||
OrderNo: outTradeNo,
|
||||
UserId: userID,
|
||||
ProductId: product.Id,
|
||||
PaymentPlatform: req.PayMethod,
|
||||
PaymentPlatform: paymentPlatform,
|
||||
PaymentScene: resolvePaymentScene(l.ctx),
|
||||
Amount: amount,
|
||||
Status: "pending",
|
||||
@@ -376,18 +407,9 @@ func (l *PaymentLogic) shouldUseXpay(req *types.PaymentReq) bool {
|
||||
func resolvePaymentScene(ctx context.Context) string {
|
||||
platform, err := ctxdata.GetPlatformFromCtx(ctx)
|
||||
if err != nil {
|
||||
return "app"
|
||||
}
|
||||
switch platform {
|
||||
case model.PlatformWxMini:
|
||||
return "wxmini"
|
||||
case model.PlatformWxH5:
|
||||
return "wxh5"
|
||||
case model.PlatformH5:
|
||||
return "h5"
|
||||
default:
|
||||
return "app"
|
||||
return model.PaymentSceneApp
|
||||
}
|
||||
return model.PaymentSceneFromPlatform(platform)
|
||||
}
|
||||
|
||||
// AgentVipOrderPayment 代理会员充值订单(已废弃,新系统使用升级功能替代)
|
||||
|
||||
Reference in New Issue
Block a user