| | |
| | | dto.setThirdPayAmount(order.getThirdPayAmount()); |
| | | dto.setBalanceRefundAmount(order.getBalanceRefundAmount()); |
| | | dto.setThirdRefundAmount(order.getThirdRefundAmount()); |
| | | dto.setRefundableAmount(getManualRefundableAmount(order)); |
| | | return R.ok(dto); |
| | | } |
| | | |
| | | @Override |
| | | public BigDecimal getManualRefundableAmount(Long chargingOrderId) { |
| | | if (chargingOrderId == null) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | return getManualRefundableAmount(this.getById(chargingOrderId)); |
| | | } |
| | | |
| | | private BigDecimal getManualRefundableAmount(TChargingOrder order) { |
| | | if (order == null || order.getId() == null) { |
| | | return BigDecimal.ZERO; |
| | | } |
| | | List<TChargingOrderRefund> successfulRefunds = chargingOrderRefundService.list( |
| | | new LambdaQueryWrapper<TChargingOrderRefund>() |
| | | .eq(TChargingOrderRefund::getChargingOrderId, order.getId()) |
| | | .eq(TChargingOrderRefund::getRefundStatus, 2)); |
| | | return calculateManualRefundableAmount(order.getPaymentAmount(), successfulRefunds); |
| | | } |
| | | |
| | | static BigDecimal calculateManualRefundableAmount(BigDecimal paymentAmount, List<TChargingOrderRefund> successfulRefunds) { |
| | | BigDecimal successfulManualRefundAmount = Optional.ofNullable(successfulRefunds) |
| | | .orElse(Collections.emptyList()) |
| | | .stream() |
| | | .filter(refund -> "后台退款".equals(refund.getRefundTitle()) |
| | | || SPECIAL_REFUND_TITLE.equals(refund.getRefundTitle())) |
| | | .map(TChargingOrderRefund::getRefundAmount) |
| | | .map(amount -> amount == null ? BigDecimal.ZERO : amount) |
| | | .reduce(BigDecimal.ZERO, BigDecimal::add); |
| | | return (paymentAmount == null ? BigDecimal.ZERO : paymentAmount) |
| | | .subtract(successfulManualRefundAmount) |
| | | .max(BigDecimal.ZERO) |
| | | .setScale(2, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | @Override |
| | |
| | | } |
| | | mergeSuccessfulRefundAmounts(order); |
| | | BigDecimal refundAmount = money(payOrderQueryDto.getRefundAmount()); |
| | | BigDecimal refundableAmount = money(order.getPaymentAmount()).subtract(money(order.getRefundAmount())).setScale(2, RoundingMode.HALF_UP); |
| | | BigDecimal refundableAmount = getManualRefundableAmount(order); |
| | | if (refundAmount.compareTo(refundableAmount) > 0) { |
| | | return R.fail("退款金额不能超过剩余可退金额"); |
| | | } |
| | |
| | | return R.fail("充电订单不存在"); |
| | | } |
| | | BigDecimal manualRefundAmount = money(payOrderQueryDto.getRefundAmount()); |
| | | BigDecimal remainingRefundAmount = money(tChargingOrder.getPaymentAmount()) |
| | | .subtract(money(tChargingOrder.getRefundAmount())).max(BigDecimal.ZERO); |
| | | BigDecimal remainingRefundAmount = getManualRefundableAmount(tChargingOrder); |
| | | if (manualRefundAmount.compareTo(remainingRefundAmount) > 0) { |
| | | return R.fail("退款金额不能超过剩余可退金额" + remainingRefundAmount.toPlainString() + "元"); |
| | | } |