liujie
2026-09-09 39f6fca28e3f78abe48f08e474ec011abb990b36
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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);
    }
}