From e981a1e069cb73240a4c472bec6112aa0efa9f9a Mon Sep 17 00:00:00 2001 From: liangzai <2440983361@qq.com> Date: Thu, 19 Jun 2025 02:58:09 +0800 Subject: [PATCH] fix refurn --- .../logic/pay/wechatpayrefundcallbacklogic.go | 34 +++++++++++++++---- 1 file changed, 27 insertions(+), 7 deletions(-) diff --git a/app/main/api/internal/logic/pay/wechatpayrefundcallbacklogic.go b/app/main/api/internal/logic/pay/wechatpayrefundcallbacklogic.go index c80c228..d00af8e 100644 --- a/app/main/api/internal/logic/pay/wechatpayrefundcallbacklogic.go +++ b/app/main/api/internal/logic/pay/wechatpayrefundcallbacklogic.go @@ -189,19 +189,39 @@ func (l *WechatPayRefundCallbackLogic) WechatPayRefundCallback(w http.ResponseWr l.sendSuccessResponse(w) return nil } - if notification.Status == nil { - logx.Errorf("【退款回调】Status字段为空") + + orderNo := *notification.OutTradeNo + logx.Infof("【退款回调】提取到订单号: %s", orderNo) + + // 3. 判断退款状态,优先使用Status,如果Status为nil则使用SuccessTime判断 + var status refunddomestic.Status + var statusDetermined bool = false + + if notification.Status != nil { + status = *notification.Status + statusDetermined = true + logx.Infof("【退款回调】从Status字段获取状态: %v", status) + } else if notification.SuccessTime != nil && !notification.SuccessTime.IsZero() { + // 如果Status为空但SuccessTime有值,说明退款成功 + status = refunddomestic.STATUS_SUCCESS + statusDetermined = true + logx.Infof("【退款回调】Status为空,但SuccessTime有值(%v),判断为退款成功", notification.SuccessTime) + } else { + logx.Errorf("【退款回调】Status和SuccessTime都为空,无法确定退款状态") l.sendSuccessResponse(w) return nil } - orderNo := *notification.OutTradeNo - status := *notification.Status - logx.Infof("【退款回调】提取到订单号: %s, 状态: %v", orderNo, status) + if !statusDetermined { + logx.Errorf("【退款回调】无法确定退款状态") + l.sendSuccessResponse(w) + return nil + } + logx.Infof("【退款回调】最终确定状态: %v", status) var processErr error - // 3. 根据订单号前缀处理不同类型的订单 + // 4. 根据订单号前缀处理不同类型的订单 logx.Infof("【退款回调】开始根据订单号前缀分发处理") switch { case strings.HasPrefix(orderNo, "Q_"): @@ -216,7 +236,7 @@ func (l *WechatPayRefundCallbackLogic) WechatPayRefundCallback(w http.ResponseWr processErr = l.handleQueryOrderRefund(orderNo, status) } - // 4. 处理错误并响应 + // 5. 处理错误并响应 if processErr != nil { logx.Errorf("【退款回调】处理退款订单失败: orderNo=%s, err=%v", orderNo, processErr) } else {