Преглед изворни кода

fix: 退款回调交易后余额计算错误导致显示负数

applyWxRefund 已将 balance 清零,wxRefundNotify 中 account.getBalance() 返回 0,
0 - 退款金额 产生负数。修复为:beforeBalance = 退款金额,afterBalance = 0

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
skyline пре 2 дана
родитељ
комит
c47febff9a

+ 6 - 3
car-wash-service/src/main/java/com/kym/service/wechat/impl/WxPayServiceImpl.java

@@ -720,14 +720,17 @@ public class WxPayServiceImpl implements WxPayService {
                         .eq(Account::getUserId, refundLog.getUserId()).update();
 
                 // 更新资金流水
+                // 注意:此时 balance 已在 applyWxRefund 阶段清零,
+                // beforeBalance 应反映退款前余额(即退款金额),afterBalance 为 0
                 var walletDetail = walletDetailService.getWalletDetailByOrderNo(refundNotification.getOutRefundNo(), WalletDetail.TYPE_退款);
+                var refundAmount = refundNotification.getAmount().getRefund().intValue();
                 walletDetailService.lambdaUpdate()
                         .set(WalletDetail::getStatus, WalletDetail.STATUS_已确认)
                         .set(WalletDetail::getTransactionId, refundNotification.getTransactionId())
                         .set(WalletDetail::getTransactionTime, successTime)
-                        .set(WalletDetail::getAmount, refundNotification.getAmount().getRefund().intValue())
-                        .set(WalletDetail::getBeforeBalance, account.getBalance())
-                        .set(WalletDetail::getAfterBalance, account.getBalance() - refundNotification.getAmount().getRefund().intValue())
+                        .set(WalletDetail::getAmount, refundAmount)
+                        .set(WalletDetail::getBeforeBalance, account.getBalance() + refundAmount)
+                        .set(WalletDetail::getAfterBalance, account.getBalance())
                         .set(WalletDetail::getTransactionTime, successTime)
                         .eq(WalletDetail::getId, walletDetail.getId()).update();
                 LOGGER.info("微信退款回调{}:业务处理结束", notifyRes[2]);