fix
This commit is contained in:
@@ -45,6 +45,9 @@ func (l *AlipayCallbackLogic) AlipayCallback(w http.ResponseWriter, r *http.Requ
|
||||
} else if strings.HasPrefix(orderNo, "U_") {
|
||||
// 代理升级订单处理
|
||||
return l.handleAgentUpgradeOrderPayment(w, notification)
|
||||
} else if strings.HasPrefix(orderNo, "W_") {
|
||||
// 白名单下架订单处理
|
||||
return l.handleWhitelistOrderPayment(w, notification)
|
||||
} else if strings.HasPrefix(orderNo, "A_") {
|
||||
// 旧系统会员充值订单(已废弃,新系统使用升级功能)
|
||||
// return l.handleAgentVipOrderPayment(w, notification)
|
||||
@@ -110,6 +113,96 @@ func (l *AlipayCallbackLogic) handleQueryOrderPayment(w http.ResponseWriter, not
|
||||
return nil
|
||||
}
|
||||
|
||||
// 处理白名单下架订单支付
|
||||
func (l *AlipayCallbackLogic) handleWhitelistOrderPayment(w http.ResponseWriter, notification *alipay.Notification) error {
|
||||
orderNo := notification.OutTradeNo
|
||||
|
||||
// 1. 查找订单
|
||||
order, findOrderErr := l.svcCtx.OrderModel.FindOneByOrderNo(l.ctx, orderNo)
|
||||
if findOrderErr != nil {
|
||||
logx.Errorf("支付宝白名单支付回调,查找订单失败: %+v", findOrderErr)
|
||||
alipay.ACKNotification(w)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 2. 验证金额
|
||||
amount := lzUtils.ToAlipayAmount(order.Amount)
|
||||
user, err := l.svcCtx.UserModel.FindOne(l.ctx, order.UserId)
|
||||
if err == nil && user.Inside != 1 {
|
||||
if amount != notification.TotalAmount {
|
||||
logx.Errorf("支付宝白名单支付回调,金额不一致,订单号: %s", orderNo)
|
||||
alipay.ACKNotification(w)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// 3. 检查订单状态
|
||||
if order.Status != "pending" {
|
||||
alipay.ACKNotification(w)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 4. 查找白名单订单
|
||||
whitelistOrder, findWhitelistErr := l.svcCtx.WhitelistOrderModel.FindOneByOrderNo(l.ctx, orderNo)
|
||||
if findWhitelistErr != nil {
|
||||
logx.Errorf("支付宝白名单支付回调,查找白名单订单失败,订单号: %s, 错误: %+v", orderNo, findWhitelistErr)
|
||||
alipay.ACKNotification(w)
|
||||
return nil
|
||||
}
|
||||
if whitelistOrder.Status != 1 {
|
||||
// 白名单订单状态不是待支付,直接返回成功
|
||||
alipay.ACKNotification(w)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 5. 处理支付状态
|
||||
switch notification.TradeStatus {
|
||||
case alipay.TradeStatusSuccess:
|
||||
order.Status = "paid"
|
||||
order.PayTime = lzUtils.TimeToNullTime(time.Now())
|
||||
order.PlatformOrderId = lzUtils.StringToNullString(notification.TradeNo)
|
||||
whitelistOrder.Status = 2 // 已支付
|
||||
whitelistOrder.PayTime = lzUtils.TimeToNullTime(time.Now())
|
||||
case alipay.TradeStatusClosed:
|
||||
order.Status = "closed"
|
||||
order.CloseTime = lzUtils.TimeToNullTime(time.Now())
|
||||
whitelistOrder.Status = 3 // 已取消
|
||||
default:
|
||||
alipay.ACKNotification(w)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 6. 更新订单和白名单订单 + 创建白名单记录并删除报告数据
|
||||
err = l.svcCtx.WhitelistOrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
|
||||
// 6.1 更新订单状态
|
||||
if updateErr := l.svcCtx.OrderModel.UpdateWithVersion(ctx, session, order); updateErr != nil {
|
||||
return errors.Wrapf(updateErr, "支付宝白名单支付回调,更新订单状态失败")
|
||||
}
|
||||
|
||||
// 6.2 更新白名单订单状态
|
||||
if updateErr := l.svcCtx.WhitelistOrderModel.UpdateWithVersion(ctx, session, whitelistOrder); updateErr != nil {
|
||||
return errors.Wrapf(updateErr, "支付宝白名单支付回调,更新白名单订单状态失败")
|
||||
}
|
||||
|
||||
// 6.3 如果支付成功,调用 WhitelistService 处理白名单和报告数据
|
||||
if whitelistOrder.Status == 2 {
|
||||
if processErr := l.svcCtx.WhitelistService.ProcessPaidWhitelistOrder(ctx, session, order, whitelistOrder); processErr != nil {
|
||||
return errors.Wrapf(processErr, "支付宝白名单支付回调,处理白名单订单失败")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
})
|
||||
if err != nil {
|
||||
logx.Errorf("支付宝白名单支付回调,事务处理失败: %+v", err)
|
||||
alipay.ACKNotification(w)
|
||||
return nil
|
||||
}
|
||||
|
||||
alipay.ACKNotification(w)
|
||||
return nil
|
||||
}
|
||||
|
||||
// 处理代理升级订单支付
|
||||
func (l *AlipayCallbackLogic) handleAgentUpgradeOrderPayment(w http.ResponseWriter, notification *alipay.Notification) error {
|
||||
orderNo := notification.OutTradeNo
|
||||
|
||||
Reference in New Issue
Block a user