| | |
| | | import com.ruoyi.other.api.vo.ExchangeCodeConsumeResultVO; |
| | | import com.ruoyi.payment.api.feignClient.AliPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.H5AliPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.IcbcPaymentClient; |
| | | import com.ruoyi.payment.api.feignClient.WxPaymentClient; |
| | | import com.ruoyi.payment.api.model.RefundReq; |
| | | import com.ruoyi.payment.api.model.RefundResp; |
| | | import com.ruoyi.payment.api.model.WxPaymentRefundModel; |
| | | import com.ruoyi.payment.api.vo.IcbcRefundReq; |
| | | import com.ruoyi.payment.api.vo.IcbcRefundResp; |
| | | import lombok.extern.slf4j.Slf4j; |
| | | import org.redisson.api.RLock; |
| | | import org.redisson.api.RedissonClient; |
| | |
| | | private WxPaymentClient wxPaymentClient; |
| | | |
| | | @Resource |
| | | private IcbcPaymentClient icbcPaymentClient; |
| | | |
| | | @Resource |
| | | private AliPaymentClient aliPaymentClient; |
| | | @Resource |
| | | private H5AliPaymentClient h5AliPaymentClient; |
| | |
| | | BigDecimal thirdPayAmount = money(order.getThirdPayAmount()); |
| | | if (thirdPayAmount.compareTo(BigDecimal.ZERO) > 0) { |
| | | return thirdPayAmount; |
| | | } |
| | | if ("ICBC".equalsIgnoreCase(order.getSourceName())) { |
| | | return money(order.getRechargeAmount()) |
| | | .subtract(money(order.getBalancePayAmount())) |
| | | .max(BigDecimal.ZERO) |
| | | .setScale(2, RoundingMode.HALF_UP); |
| | | } |
| | | if (Integer.valueOf(3).equals(order.getPayMethod())) { |
| | | return money(order.getRechargeAmount()); |
| | |
| | | //开始构建退款费用 |
| | | refundAmount = refundAmount.setScale(2, RoundingMode.HALF_EVEN); |
| | | BigDecimal refundableThirdPayAmount = getRefundableThirdPayAmount(order); |
| | | BigDecimal refundableAmount = refundableThirdPayAmount.add(money(order.getBalancePayAmount())).setScale(2, RoundingMode.HALF_UP); |
| | | BigDecimal remainingThirdAmount = refundableThirdPayAmount |
| | | .subtract(money(order.getThirdRefundAmount())).max(BigDecimal.ZERO); |
| | | BigDecimal remainingBalanceAmount = money(order.getBalancePayAmount()) |
| | | .subtract(money(order.getBalanceRefundAmount())).max(BigDecimal.ZERO); |
| | | BigDecimal refundableAmount = remainingThirdAmount.add(remainingBalanceAmount).setScale(2, RoundingMode.HALF_UP); |
| | | // 白名单全部免费只记录预估预充金额,实际渠道退款金额保持0,防止补偿任务重复发起退款。 |
| | | BigDecimal recordedRefundAmount = isWhitelistAllFreeOrder(order) ? money(order.getRechargeAmount()) : refundAmount; |
| | | BigDecimal channelRefundAmount = isWhitelistAllFreeOrder(order) |
| | | ? BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP) |
| | | : refundAmount.min(refundableAmount).setScale(2, RoundingMode.HALF_UP); |
| | | Integer rechargePaymentType = order.getRechargePaymentType(); |
| | | Integer payMethod = order.getPayMethod(); |
| | | BigDecimal thirdRefundAmount = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); |
| | | BigDecimal balanceRefundAmount = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); |
| | | if (Integer.valueOf(1).equals(payMethod)) { |
| | | balanceRefundAmount = channelRefundAmount.min(money(order.getBalancePayAmount())).setScale(2, RoundingMode.HALF_UP); |
| | | } else if (Integer.valueOf(2).equals(payMethod)) { |
| | | thirdRefundAmount = channelRefundAmount.min(refundableThirdPayAmount).setScale(2, RoundingMode.HALF_UP); |
| | | balanceRefundAmount = channelRefundAmount.subtract(thirdRefundAmount).min(money(order.getBalancePayAmount())).setScale(2, RoundingMode.HALF_UP); |
| | | } else { |
| | | thirdRefundAmount = channelRefundAmount.min(refundableThirdPayAmount).setScale(2, RoundingMode.HALF_UP); |
| | | } |
| | | BigDecimal thirdRefundAmount = channelRefundAmount.min(remainingThirdAmount).setScale(2, RoundingMode.HALF_UP); |
| | | BigDecimal balanceRefundAmount = channelRefundAmount.subtract(thirdRefundAmount) |
| | | .min(remainingBalanceAmount).setScale(2, RoundingMode.HALF_UP); |
| | | if (channelRefundAmount.compareTo(BigDecimal.ZERO) > 0) { |
| | | refundAmount = thirdRefundAmount.add(balanceRefundAmount).setScale(2, RoundingMode.HALF_UP); |
| | | order.setThirdRefundAmount(thirdRefundAmount); |
| | | order.setBalanceRefundAmount(balanceRefundAmount); |
| | | order.setThirdRefundAmount(money(order.getThirdRefundAmount()).add(thirdRefundAmount)); |
| | | order.setBalanceRefundAmount(money(order.getBalanceRefundAmount()).add(balanceRefundAmount)); |
| | | order.setRefundAmount(recordedRefundAmount); |
| | | order.setRefundStatus(refundAmount.compareTo(BigDecimal.ZERO) > 0 ? 1 : 2); |
| | | chargingOrderService.updateById(order); |
| | |
| | | order.setRefundStatus(2); |
| | | order.setRefundTime(LocalDateTime.now()); |
| | | chargingOrderService.updateById(order); |
| | | } else if ("ICBC".equalsIgnoreCase(order.getSourceName())) { |
| | | IcbcRefundReq req = new IcbcRefundReq(); |
| | | req.setOutTradeNo(order.getCode()); |
| | | req.setOrderId(order.getRechargeSerialNumber()); |
| | | req.setOutRefundNo(chargingOrderRefund.getRefundCode()); |
| | | req.setRefundAmount(thirdRefundAmount); |
| | | req.setTotalAmount(getRefundableThirdPayAmount(order)); |
| | | req.setReason("充电完成退款"); |
| | | R<IcbcRefundResp> result = icbcPaymentClient.refund(req); |
| | | IcbcRefundResp resp = result == null ? null : result.getData(); |
| | | if (result != null && result.getCode() == 200 && resp != null && "SUCCESS".equals(resp.getStatus())) { |
| | | chargingOrderRefundService.save(chargingOrderRefund); |
| | | String refundId = StringUtils.isNotEmpty(resp.getRefundId()) ? resp.getRefundId() : resp.getOutRefundNo(); |
| | | chargingOrderService.chargingOrderStartupFailureWxRefund( |
| | | chargingOrderRefund.getRefundCode(), refundId, "SUCCESS", resp.getRefundTime()); |
| | | } else { |
| | | log.error("工行充电完成退款失败,订单号:{},退款单号:{},返回:{}", |
| | | order.getCode(), chargingOrderRefund.getRefundCode(), result == null ? null : result.getMsg()); |
| | | } |
| | | } else if (1 == rechargePaymentType) { |
| | | WxPaymentRefundModel model = new WxPaymentRefundModel(); |
| | | model.setOut_trade_no(order.getCode()); |