package com.tourguide.modules.order.domain;
|
|
import com.tourguide.modules.order.entity.TourOrder;
|
|
import java.math.BigDecimal;
|
|
/** 统一计算订单实付、累计退款和剩余可退款金额,兼容累计字段上线前的历史订单。 */
|
public final class RefundAmountCalculator {
|
private RefundAmountCalculator() {
|
}
|
|
public static BigDecimal paidAmount(TourOrder order) {
|
if (order == null) return BigDecimal.ZERO;
|
BigDecimal amount = order.getPaymentAmount() == null ? order.getAmount() : order.getPaymentAmount();
|
return amount == null ? BigDecimal.ZERO : amount.max(BigDecimal.ZERO);
|
}
|
|
public static BigDecimal refundedAmount(TourOrder order) {
|
if (order == null) return BigDecimal.ZERO;
|
if (order.getRefundedAmount() != null) return order.getRefundedAmount().max(BigDecimal.ZERO);
|
if (order.getRefundAmount() != null
|
&& (RefundStatus.REFUNDED.matches(order.getRefundStatus())
|
|| RefundStatus.PARTIAL.matches(order.getRefundStatus())
|
|| OrderStatus.REFUNDED.matches(order.getStatus()))) {
|
return order.getRefundAmount().max(BigDecimal.ZERO);
|
}
|
return BigDecimal.ZERO;
|
}
|
|
public static BigDecimal refundableAmount(TourOrder order) {
|
return paidAmount(order).subtract(refundedAmount(order)).max(BigDecimal.ZERO);
|
}
|
}
|