|
@@ -315,12 +315,12 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// 将余额转移至冻结余额
|
|
// 将余额转移至冻结余额
|
|
|
- accountService.lambdaUpdate().setSql(" frozen_amount = balance ,balance = 0").eq(Account::getUserId, userId).update();
|
|
|
|
|
|
|
+ accountService.lambdaUpdate().setSql(" frozen_amount = (frozen_amount + balance) ,balance = 0").eq(Account::getUserId, userId).update();
|
|
|
|
|
|
|
|
// 余额作为退款金额
|
|
// 余额作为退款金额
|
|
|
AtomicInteger refundAmount = new AtomicInteger(account.getBalance());
|
|
AtomicInteger refundAmount = new AtomicInteger(account.getBalance());
|
|
|
// 充值记录
|
|
// 充值记录
|
|
|
- var payLogs = payLogService.lambdaQuery().eq(PayLog::getUserId, userId).eq(PayLog::getTradeState, PayLog.STATUS_退款成功).orderByDesc(PayLog::getSuccessTime).list();
|
|
|
|
|
|
|
+ var payLogs = payLogService.lambdaQuery().eq(PayLog::getUserId, userId).eq(PayLog::getTradeState, RefundLog.STATUS_退款成功).orderByDesc(PayLog::getSuccessTime).list();
|
|
|
// 充值金额综合不足以支付余额退款
|
|
// 充值金额综合不足以支付余额退款
|
|
|
if (!CommUtil.isEmptyOrNull(payLogs)) {
|
|
if (!CommUtil.isEmptyOrNull(payLogs)) {
|
|
|
var total = payLogs.stream().mapToInt(PayLog::getTotal).sum();
|
|
var total = payLogs.stream().mapToInt(PayLog::getTotal).sum();
|
|
@@ -445,19 +445,25 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
*
|
|
*
|
|
|
* @param request
|
|
* @param request
|
|
|
*/
|
|
*/
|
|
|
- @SneakyThrows
|
|
|
|
|
@Override
|
|
@Override
|
|
|
|
|
+ @Transactional(rollbackFor = Exception.class)
|
|
|
public void wxRefundNotify(HttpServletRequest request) {
|
|
public void wxRefundNotify(HttpServletRequest request) {
|
|
|
var notifyRes = handleWxNotify(request);
|
|
var notifyRes = handleWxNotify(request);
|
|
|
|
|
+
|
|
|
try {
|
|
try {
|
|
|
// 以支付通知回调为例,验签、解密并转换成 RefundNotification
|
|
// 以支付通知回调为例,验签、解密并转换成 RefundNotification
|
|
|
RefundNotification refundNotification = ((NotificationParser) notifyRes[1]).parse((RequestParam) notifyRes[0], RefundNotification.class);
|
|
RefundNotification refundNotification = ((NotificationParser) notifyRes[1]).parse((RequestParam) notifyRes[0], RefundNotification.class);
|
|
|
LOGGER.info("微信退款回调{}:验签解密完毕,数据:\n{}", notifyRes[2], refundNotification);
|
|
LOGGER.info("微信退款回调{}:验签解密完毕,数据:\n{}", notifyRes[2], refundNotification);
|
|
|
- DateTime dt = DateUtil.parse(refundNotification.getSuccessTime());
|
|
|
|
|
- LocalDateTime successTime = LocalDateTimeUtil.of(dt);
|
|
|
|
|
|
|
|
|
|
//退款日志在申请时插入,接收通知时更新
|
|
//退款日志在申请时插入,接收通知时更新
|
|
|
var refundLog = refundLogService.lambdaQuery().eq(RefundLog::getOutRefundNo, refundNotification.getOutRefundNo()).one();
|
|
var refundLog = refundLogService.lambdaQuery().eq(RefundLog::getOutRefundNo, refundNotification.getOutRefundNo()).one();
|
|
|
|
|
+ if (RefundLog.STATUS_退款成功.equals(refundLog.getStatus())) {
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ DateTime dt = DateUtil.parse(refundNotification.getSuccessTime());
|
|
|
|
|
+ LocalDateTime successTime = LocalDateTimeUtil.of(dt);
|
|
|
|
|
+
|
|
|
refundLog
|
|
refundLog
|
|
|
.setRefundId(refundNotification.getRefundId())
|
|
.setRefundId(refundNotification.getRefundId())
|
|
|
.setTransactionId(refundNotification.getTransactionId())
|
|
.setTransactionId(refundNotification.getTransactionId())
|
|
@@ -469,7 +475,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
refundLog.setCreateTime(LocalDateTimeUtil.of(DateUtil.parse(refundNotification.getCreateTime())));
|
|
refundLog.setCreateTime(LocalDateTimeUtil.of(DateUtil.parse(refundNotification.getCreateTime())));
|
|
|
refundLogService.updateById(refundLog);
|
|
refundLogService.updateById(refundLog);
|
|
|
|
|
|
|
|
- if (PayLog.STATUS_退款成功.equals(refundNotification.getRefundStatus().name())) {
|
|
|
|
|
|
|
+ if (RefundLog.STATUS_退款成功.equals(refundNotification.getRefundStatus().name())) {
|
|
|
// 冻结金额扣减此次退款金额
|
|
// 冻结金额扣减此次退款金额
|
|
|
accountService.lambdaUpdate().setSql(" frozen_amount = (frozen_amount - %d)".formatted(refundNotification.getAmount().getRefund().intValue())).eq(Account::getUserId, refundLog.getUserId()).update();
|
|
accountService.lambdaUpdate().setSql(" frozen_amount = (frozen_amount - %d)".formatted(refundNotification.getAmount().getRefund().intValue())).eq(Account::getUserId, refundLog.getUserId()).update();
|
|
|
// 更新资金流水
|
|
// 更新资金流水
|