|
|
@@ -410,13 +410,13 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
if (account.getBalance() <= 0) {
|
|
|
throw new BusinessException("账户余额不足,无需退款");
|
|
|
}
|
|
|
- // 校验余额大于优惠金额
|
|
|
- if (account.getBalance() <= account.getDiscountAmount()) {
|
|
|
- throw new BusinessException("不可退金额高于钱包余额,不支持退款");
|
|
|
- }
|
|
|
+ // // 校验余额大于优惠金额
|
|
|
+ // if (account.getBalance() <= account.getDiscountAmount()) {
|
|
|
+ // throw new BusinessException("不可退金额高于钱包余额,不支持退款");
|
|
|
+ // }
|
|
|
|
|
|
- // 将余额转移至冻结余额,同时清零充值余额和赠款余额
|
|
|
- accountService.lambdaUpdate().setSql(" frozen_amount = (frozen_amount + balance), balance = 0, recharge_balance = 0, grants_balance = 0").eq(Account::getUserId, userId).update();
|
|
|
+ // 将充值余额转移至冻结余额,同时清零充值余额和赠款余额
|
|
|
+ accountService.lambdaUpdate().setSql(" frozen_amount = (frozen_amount + recharge_balance), balance = 0, recharge_balance = 0, grants_balance = 0").eq(Account::getUserId, userId).update();
|
|
|
|
|
|
// 退款时,充值权益失效(权益余额转入冻结余额,权益状态设置为失效)
|
|
|
userRechargeRightsService.lambdaUpdate()
|
|
|
@@ -426,8 +426,8 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
.eq(UserRechargeRights::getStatus, UserRechargeRights.STATUS_有效)
|
|
|
.update();
|
|
|
|
|
|
- // 余减去优惠金额作为退款金额
|
|
|
- AtomicInteger refundAmount = new AtomicInteger(account.getBalance() - account.getDiscountAmount());
|
|
|
+ // 退款金额=充值余额(由于现在的资金消耗逻辑是先消耗充值余额再消耗赠款,所以不考虑优惠金额的影响)
|
|
|
+ AtomicInteger refundAmount = new AtomicInteger(account.getRechargeBalance());
|
|
|
var originalRefundAmount = BigDecimal.valueOf(refundAmount.get());
|
|
|
// 充值记录
|
|
|
var payLogs = payLogService.lambdaQuery().eq(PayLog::getUserId, userId).eq(PayLog::getTradeState, PayLog.STATUS_充值成功).orderByDesc(PayLog::getSuccessTime).list();
|
|
|
@@ -436,7 +436,7 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
// 充值金额-历史退款金额不足以支付余额退款
|
|
|
if (!CommUtil.isEmptyOrNull(payLogs)) {
|
|
|
var total = payLogs.stream().mapToInt(PayLog::getTotal).sum();
|
|
|
- if ((total - refundsAmount) < account.getBalance()) {
|
|
|
+ if ((total - refundsAmount) < refundAmount.get()) {
|
|
|
LOGGER.error("用户:{},历史充值金额:{},不足以支付余额退款金额:{}", userId, total - refundsAmount, account.getBalance());
|
|
|
throw new BusinessException("充值金额不足以支付余额退款");
|
|
|
}
|
|
|
@@ -491,10 +491,11 @@ public class WxPayServiceImpl implements WxPayService {
|
|
|
discountAmount = account.getDiscountAmount() - newRefundLogList.stream().mapToInt(RefundLog::getDiscountAmount).sum();
|
|
|
}
|
|
|
refundLog.setDiscountAmount(discountAmount);
|
|
|
- refundLog.setReason(CommUtil.isEmptyOrNull(reason) ? reason : JSONObject.parseObject(reason).getString("reason"));
|
|
|
newRefundLogList.add(index, refundLog);
|
|
|
}));
|
|
|
|
|
|
+ newRefundLogList.forEach(item -> item.setReason(reason));
|
|
|
+
|
|
|
refundLogService.saveBatch(newRefundLogList);
|
|
|
} else {
|
|
|
// 退款异常
|