| | |
| | | BigDecimal currentReversal = proratedEarning(order.getGuideEarningAmount(), current, paidAmount); |
| | | BigDecimal reversal = currentReversal.subtract(previousReversal).setScale(2, RoundingMode.HALF_UP); |
| | | if (reversal.signum() <= 0) return; |
| | | boolean debited; |
| | | if (order.getCommissionTeamId() != null) { |
| | | balanceService.debitTeamForRefund(order.getCommissionTeamId(), reversal); |
| | | debited = balanceService.debitTeamForRefund(order.getCommissionTeamId(), reversal); |
| | | } else if (order.getGuideId() != null) { |
| | | balanceService.debitForRefund(order.getGuideId(), reversal); |
| | | debited = balanceService.debitForRefund(order.getGuideId(), reversal); |
| | | } else { |
| | | return; |
| | | } |
| | | if (!debited) { |
| | | throw new BusinessException(500, "退款后导游收益冲正失败"); |
| | | } |
| | | } |
| | | |
| | |
| | | && order.getGuideId() != null |
| | | && order.getGuideEarningAmount() != null |
| | | && order.getGuideEarningAmount().signum() >= 0 |
| | | && !RefundStatus.REFUNDED.matches(order.getRefundStatus()); |
| | | && canSettleRefund(order.getRefundStatus()); |
| | | } |
| | | |
| | | private BigDecimal effectiveEarning(TourOrder order) { |
| | |
| | | private BigDecimal nonNegative(BigDecimal value) { |
| | | return value == null ? BigDecimal.ZERO : value.max(BigDecimal.ZERO); |
| | | } |
| | | |
| | | private boolean canSettleRefund(String refundStatus) { |
| | | return refundStatus == null |
| | | || refundStatus.trim().isEmpty() |
| | | || RefundStatus.NONE.matches(refundStatus) |
| | | || RefundStatus.PARTIAL.matches(refundStatus) |
| | | || RefundStatus.REFUND_FAILED.matches(refundStatus); |
| | | } |
| | | } |