This commit is contained in:
2026-03-02 14:32:18 +08:00
parent 764ad2f684
commit 2c99e6b6a4
40 changed files with 3895 additions and 60 deletions

View File

@@ -5,13 +5,13 @@ import (
"net/http"
"strings"
"time"
"qnc-server/app/main/api/internal/svc"
"qnc-server/app/main/model"
"qnc-server/pkg/lzkit/lzUtils"
"github.com/pkg/errors"
"github.com/smartwalle/alipay/v3"
"qnc-server/app/main/api/internal/svc"
"github.com/zeromicro/go-zero/core/logx"
"github.com/zeromicro/go-zero/core/stores/sqlx"
)
@@ -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)
@@ -226,6 +229,51 @@ func (l *AlipayCallbackLogic) handleAgentUpgradeOrderPayment(w http.ResponseWrit
return nil
}
// handleWhitelistOrderPayment 处理白名单下架订单支付
func (l *AlipayCallbackLogic) handleWhitelistOrderPayment(w http.ResponseWriter, notification *alipay.Notification) error {
wo, err := l.svcCtx.WhitelistOrderModel.FindOneByOrderNo(l.ctx, notification.OutTradeNo)
if err != nil {
if errors.Is(err, model.ErrNotFound) {
logx.Errorf("支付宝支付回调,白名单订单不存在: %s", notification.OutTradeNo)
} else {
logx.Errorf("支付宝支付回调,查找白名单订单失败: %+v", err)
}
alipay.ACKNotification(w)
return nil
}
if wo.Status != 1 {
alipay.ACKNotification(w)
return nil
}
amount := lzUtils.ToAlipayAmount(wo.TotalAmount)
if amount != notification.TotalAmount {
logx.Errorf("支付宝支付回调,白名单订单金额不一致")
alipay.ACKNotification(w)
return nil
}
if notification.TradeStatus != alipay.TradeStatusSuccess {
alipay.ACKNotification(w)
return nil
}
wo.Status = 2
wo.PaymentMethod = lzUtils.StringToNullString("alipay")
wo.PayTime = lzUtils.TimeToNullTime(time.Now())
wo.PlatformOrderId = lzUtils.StringToNullString(notification.TradeNo)
if updateErr := l.svcCtx.WhitelistOrderModel.UpdateWithVersion(l.ctx, nil, wo); updateErr != nil {
logx.Errorf("支付宝支付回调,更新白名单订单失败: %+v", updateErr)
alipay.ACKNotification(w)
return nil
}
err = l.svcCtx.WhitelistOrderModel.Trans(l.ctx, func(ctx context.Context, session sqlx.Session) error {
return l.svcCtx.WhitelistService.ProcessPaidWhitelistOrder(ctx, session, nil, wo)
})
if err != nil {
logx.Errorf("支付宝支付回调,处理白名单订单失败: %+v", err)
}
alipay.ACKNotification(w)
return nil
}
// 处理代理会员订单支付(已废弃,新系统使用升级功能)
/*
func (l *AlipayCallbackLogic) handleAgentVipOrderPayment(w http.ResponseWriter, notification *alipay.Notification) error {