|
|
@@ -320,7 +320,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
// 异步处理充值服务费打折权益活动相关逻辑
|
|
|
activityService.handleRechargeActivity(walletDetail.getUserId(), transaction.getAmount().getTotal());
|
|
|
-
|
|
|
+
|
|
|
// 支付记录
|
|
|
var payLog = new PayLog();
|
|
|
payLog.setUserId(walletDetail.getUserId());
|
|
|
@@ -391,6 +391,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
|
|
|
// 余减去优惠金额作为退款金额
|
|
|
AtomicInteger refundAmount = new AtomicInteger(account.getBalance() - account.getDiscountAmount());
|
|
|
+ var originalRefundAmount = refundAmount.get();
|
|
|
// 充值记录
|
|
|
var payLogs = payLogService.lambdaQuery().eq(PayLog::getUserId, userId).eq(PayLog::getTradeState, RefundLog.STATUS_退款成功).orderByDesc(PayLog::getSuccessTime).list();
|
|
|
// 充值金额综合不足以支付余额退款
|
|
|
@@ -423,6 +424,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
var size = refundPayLogs.size();
|
|
|
|
|
|
var refundLogList = new ArrayList<RefundLog>(size);
|
|
|
+ var newRefundLogList = new ArrayList<RefundLog>(size);
|
|
|
|
|
|
refundPayLogs.forEach(LambadaTools.forEachWithIndex((item, index) -> {
|
|
|
// 如果不是最后一笔,金额全退,最后一笔退剩余的金额
|
|
|
@@ -438,23 +440,25 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
}));
|
|
|
|
|
|
// 不可退金额按退款金额比例放入每笔退款中
|
|
|
+
|
|
|
refundLogList.forEach(LambadaTools.forEachWithIndex((refundLog, index) -> {
|
|
|
- refundLogList.remove(index.intValue());
|
|
|
+// refundLogList.remove(index.intValue());
|
|
|
int discountAmount;
|
|
|
if (index < size) {
|
|
|
- discountAmount = account.getDiscountAmount() * (refundLog.getRefund() / refundAmount.get());
|
|
|
+ discountAmount = account.getDiscountAmount() * (refundLog.getRefund() / originalRefundAmount);
|
|
|
} else {
|
|
|
- // 前面存在精度误差,最后一个元素用总数详见最精确
|
|
|
+ // 前面存在精度误差,最后一个元素用总数相减最精确
|
|
|
discountAmount = account.getDiscountAmount() - refundLogList.stream().mapToInt(RefundLog::getDiscountAmount).sum();
|
|
|
}
|
|
|
refundLog.setDiscountAmount(discountAmount);
|
|
|
- refundLogList.add(index, refundLog);
|
|
|
+// refundLogList.add(index, refundLog);
|
|
|
+ newRefundLogList.add(index, refundLog);
|
|
|
}));
|
|
|
|
|
|
- refundLogService.saveBatch(refundLogList);
|
|
|
+ refundLogService.saveBatch(newRefundLogList);
|
|
|
} else {
|
|
|
// 退款异常
|
|
|
- LOGGER.error("退款异常:userId:{},余额:{},payLogs:{}", userId, refundAmount.get(), payLogs);
|
|
|
+ LOGGER.error("退款异常:userId:{},退款金额:{},payLogs:{}", userId, originalRefundAmount, payLogs);
|
|
|
throw new BusinessException("退款异常");
|
|
|
}
|
|
|
}
|
|
|
@@ -554,7 +558,6 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
.set(RefundLog::getStatus, refundNotification.getRefundStatus().name())
|
|
|
.set(RefundLog::getTotal, refundNotification.getAmount().getTotal().intValue())
|
|
|
.set(RefundLog::getRefund, refundNotification.getAmount().getRefund().intValue())
|
|
|
- .set(RefundLog::getCreateTime, LocalDateTimeUtil.of(DateUtil.parse(refundNotification.getCreateTime())))
|
|
|
.eq(RefundLog::getId, refundLog.getId()).update();
|
|
|
|
|
|
if (RefundLog.STATUS_退款成功.equals(refundNotification.getRefundStatus().name())) {
|