| | |
| | | private boolean isPrivateCarPrepayFinalStage(OrderPrivateCar orderPrivateCar) { |
| | | return orderPrivateCar != null |
| | | && Integer.valueOf(1).equals(orderPrivateCar.getPaymentMode()) |
| | | && !Integer.valueOf(5).equals(orderPrivateCar.getPrepayStage()) |
| | | && orderPrivateCar.getPayMoney() != null |
| | | && orderPrivateCar.getPayMoney() > 0; |
| | | && !Integer.valueOf(5).equals(orderPrivateCar.getPrepayStage()); |
| | | } |
| | | |
| | | private BigDecimal toMoney(Double amount) { |
| | | return new BigDecimal(String.valueOf(amount == null ? 0D : amount)).setScale(2, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | private Double getPrivateCarPrepayFinalPayAmount(OrderPrivateCar orderPrivateCar, Double finalAmount) { |
| | | private PaymentRecord getPrivateCarPrepayPaidRecord(OrderPrivateCar orderPrivateCar) throws Exception { |
| | | PaymentRecord paymentRecord = paymentRecordService.query(1, orderPrivateCar.getUserId(), 1, orderPrivateCar.getId(), 1, orderPrivateCar.getPayType(), 2); |
| | | if (paymentRecord == null) { |
| | | paymentRecord = paymentRecordService.query(1, orderPrivateCar.getUserId(), 1, orderPrivateCar.getId(), 1, null, 2); |
| | | } |
| | | if (paymentRecord != null && orderPrivateCar.getPayType() == null) { |
| | | orderPrivateCar.setPayType(paymentRecord.getPayType()); |
| | | } |
| | | return paymentRecord; |
| | | } |
| | | |
| | | private BigDecimal getPrivateCarPrepayPaidAmount(OrderPrivateCar orderPrivateCar) throws Exception { |
| | | PaymentRecord paymentRecord = getPrivateCarPrepayPaidRecord(orderPrivateCar); |
| | | if (paymentRecord != null && paymentRecord.getAmount() != null && paymentRecord.getAmount() > 0) { |
| | | return toMoney(paymentRecord.getAmount()); |
| | | } |
| | | if (orderPrivateCar.getPayMoney() != null && orderPrivateCar.getPayMoney() > 0) { |
| | | return toMoney(orderPrivateCar.getPayMoney()); |
| | | } |
| | | return BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP); |
| | | } |
| | | |
| | | private Double getPrivateCarPrepayFinalPayAmount(OrderPrivateCar orderPrivateCar, Double finalAmount) throws Exception { |
| | | if (!isPrivateCarPrepayFinalStage(orderPrivateCar)) { |
| | | return toMoney(finalAmount).doubleValue(); |
| | | } |
| | | BigDecimal spreadAmount = toMoney(finalAmount).subtract(toMoney(orderPrivateCar.getPayMoney())).setScale(2, RoundingMode.HALF_UP); |
| | | BigDecimal paidAmount = getPrivateCarPrepayPaidAmount(orderPrivateCar); |
| | | if (paidAmount.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return toMoney(finalAmount).doubleValue(); |
| | | } |
| | | BigDecimal spreadAmount = toMoney(finalAmount).subtract(paidAmount).setScale(2, RoundingMode.HALF_UP); |
| | | if (spreadAmount.compareTo(BigDecimal.ZERO) > 0) { |
| | | orderPrivateCar.setPrepayStage(3); |
| | | return spreadAmount.doubleValue(); |
| | |
| | | if (!isPrivateCarPrepayFinalStage(orderPrivateCar)) { |
| | | return null; |
| | | } |
| | | BigDecimal paidAmount = toMoney(orderPrivateCar.getPayMoney()); |
| | | BigDecimal paidAmount = getPrivateCarPrepayPaidAmount(orderPrivateCar); |
| | | if (paidAmount.compareTo(BigDecimal.ZERO) <= 0) { |
| | | return null; |
| | | } |
| | | BigDecimal settleAmount = toMoney(finalAmount); |
| | | BigDecimal refundAmount = paidAmount.subtract(settleAmount).setScale(2, RoundingMode.HALF_UP); |
| | | if (refundAmount.compareTo(BigDecimal.ZERO) < 0) { |
| | |
| | | return ResultUtil.success(); |
| | | } |
| | | |
| | | PaymentRecord paymentRecord = paymentRecordService.query(1, orderPrivateCar.getUserId(), 1, orderPrivateCar.getId(), 1, orderPrivateCar.getPayType(), 2); |
| | | PaymentRecord paymentRecord = getPrivateCarPrepayPaidRecord(orderPrivateCar); |
| | | if (paymentRecord == null) { |
| | | return ResultUtil.error("先付订单缺少已支付流水,无法退款"); |
| | | } |