|
|
|
@ -9,9 +9,15 @@ import java.util.List; |
|
|
|
/** |
|
|
|
/** |
|
|
|
* 退款命令。 |
|
|
|
* 退款命令。 |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>按平台退货单发起退款。平台侧的退款通常细到<b>退货行 × 费用项</b> |
|
|
|
* <p>按平台退货单发起退款。各平台表达「退多少」的方式不同:</p> |
|
|
|
* (沃尔玛 {@code refundLines[].refundCharges[]}),所以这里不是「退多少钱」, |
|
|
|
* <ul> |
|
|
|
* 而是逐行逐费用给金额。</p> |
|
|
|
* <li><b>按数量</b>(沃尔玛当前 API):给 {@code lineId} + {@code quantity}, |
|
|
|
|
|
|
|
* 金额由平台按单价算;{@code charges} 会被忽略。</li> |
|
|
|
|
|
|
|
* <li><b>按费用项</b>(部分平台/旧接口):给 {@code lineId} + {@code charges} 金额明细。</li> |
|
|
|
|
|
|
|
* </ul> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>所以 {@code charges} 与 {@code quantity} 都是可选的,由适配器按平台要求取用; |
|
|
|
|
|
|
|
* 两者都不给时,适配器按「整行全退」处理。</p> |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>调用前应先查售后详情核对 {@code refundedQty} / {@code cancellableQty}, |
|
|
|
* <p>调用前应先查售后详情核对 {@code refundedQty} / {@code cancellableQty}, |
|
|
|
* 避免超退——各平台超额规则不同,适配器只做格式校验,不做余额校验。</p> |
|
|
|
* 避免超退——各平台超额规则不同,适配器只做格式校验,不做余额校验。</p> |
|
|
|
@ -21,6 +27,14 @@ public final class RefundCommand { |
|
|
|
/** 平台退货单号;必填。 */ |
|
|
|
/** 平台退货单号;必填。 */ |
|
|
|
private final String afterSaleId; |
|
|
|
private final String afterSaleId; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* 平台客户订单号;可选。 |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>沃尔玛退款接口把它列为<b>必填</b>({@code customerOrderId}), |
|
|
|
|
|
|
|
* 其他平台可以不用。为空时由适配器决定是报错还是从别处补。</p> |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
private final String customerOrderId; |
|
|
|
|
|
|
|
|
|
|
|
/** 退款行;不可变,至少一行。 */ |
|
|
|
/** 退款行;不可变,至少一行。 */ |
|
|
|
private final List<Line> lines; |
|
|
|
private final List<Line> lines; |
|
|
|
|
|
|
|
|
|
|
|
@ -32,6 +46,7 @@ public final class RefundCommand { |
|
|
|
throw new IllegalArgumentException("refund requires at least one line"); |
|
|
|
throw new IllegalArgumentException("refund requires at least one line"); |
|
|
|
} |
|
|
|
} |
|
|
|
this.afterSaleId = b.afterSaleId.trim(); |
|
|
|
this.afterSaleId = b.afterSaleId.trim(); |
|
|
|
|
|
|
|
this.customerOrderId = b.customerOrderId == null ? null : b.customerOrderId.trim(); |
|
|
|
this.lines = Collections.unmodifiableList(new ArrayList<Line>(b.lines)); |
|
|
|
this.lines = Collections.unmodifiableList(new ArrayList<Line>(b.lines)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -45,6 +60,11 @@ public final class RefundCommand { |
|
|
|
return afterSaleId; |
|
|
|
return afterSaleId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 平台客户订单号;可空。 */ |
|
|
|
|
|
|
|
public String customerOrderId() { |
|
|
|
|
|
|
|
return customerOrderId; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 退款行;不可变,至少一行。 */ |
|
|
|
/** 退款行;不可变,至少一行。 */ |
|
|
|
public List<Line> lines() { |
|
|
|
public List<Line> lines() { |
|
|
|
return lines; |
|
|
|
return lines; |
|
|
|
@ -66,23 +86,27 @@ public final class RefundCommand { |
|
|
|
* |
|
|
|
* |
|
|
|
* <p>{@code lineId} 是<b>平台退货行号</b>(沃尔玛 {@code returnOrderLineNumber}), |
|
|
|
* <p>{@code lineId} 是<b>平台退货行号</b>(沃尔玛 {@code returnOrderLineNumber}), |
|
|
|
* 不是统一模型的 {@code afterSaleId()};后者是「退货单号:行号」的拼接。</p> |
|
|
|
* 不是统一模型的 {@code afterSaleId()};后者是「退货单号:行号」的拼接。</p> |
|
|
|
|
|
|
|
* |
|
|
|
|
|
|
|
* <p>{@code quantity} 为空表示「整行全退」;{@code charges} 为空表示 |
|
|
|
|
|
|
|
* 「金额由平台计算」——沃尔玛当前接口就是这种。</p> |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public static final class Line { |
|
|
|
public static final class Line { |
|
|
|
|
|
|
|
|
|
|
|
/** 平台退货行号;必填。 */ |
|
|
|
/** 平台退货行号;必填。 */ |
|
|
|
private final String lineId; |
|
|
|
private final String lineId; |
|
|
|
|
|
|
|
|
|
|
|
/** 费用明细;不可变,至少一条。 */ |
|
|
|
/** 退款数量;可空,空表示整行。 */ |
|
|
|
|
|
|
|
private final Integer quantity; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 费用明细;可空(按数量退款的平台不需要)。 */ |
|
|
|
private final List<Charge> charges; |
|
|
|
private final List<Charge> charges; |
|
|
|
|
|
|
|
|
|
|
|
private Line(Builder b) { |
|
|
|
private Line(Builder b) { |
|
|
|
if (isBlank(b.lineId)) { |
|
|
|
if (isBlank(b.lineId)) { |
|
|
|
throw new IllegalArgumentException("refund lineId must not be blank"); |
|
|
|
throw new IllegalArgumentException("refund lineId must not be blank"); |
|
|
|
} |
|
|
|
} |
|
|
|
if (b.charges.isEmpty()) { |
|
|
|
|
|
|
|
throw new IllegalArgumentException("refund line requires at least one charge"); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
this.lineId = b.lineId.trim(); |
|
|
|
this.lineId = b.lineId.trim(); |
|
|
|
|
|
|
|
this.quantity = b.quantity; |
|
|
|
this.charges = Collections.unmodifiableList(new ArrayList<Charge>(b.charges)); |
|
|
|
this.charges = Collections.unmodifiableList(new ArrayList<Charge>(b.charges)); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -96,7 +120,12 @@ public final class RefundCommand { |
|
|
|
return lineId; |
|
|
|
return lineId; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 费用明细。 */ |
|
|
|
/** 退款数量;可空(空 = 整行)。 */ |
|
|
|
|
|
|
|
public Integer quantity() { |
|
|
|
|
|
|
|
return quantity; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 费用明细;可能为空。 */ |
|
|
|
public List<Charge> charges() { |
|
|
|
public List<Charge> charges() { |
|
|
|
return charges; |
|
|
|
return charges; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -106,6 +135,8 @@ public final class RefundCommand { |
|
|
|
|
|
|
|
|
|
|
|
/** 平台退货行号。 */ |
|
|
|
/** 平台退货行号。 */ |
|
|
|
private String lineId; |
|
|
|
private String lineId; |
|
|
|
|
|
|
|
/** 退款数量;空表示整行。 */ |
|
|
|
|
|
|
|
private Integer quantity; |
|
|
|
/** 费用明细。 */ |
|
|
|
/** 费用明细。 */ |
|
|
|
private final List<Charge> charges = new ArrayList<Charge>(); |
|
|
|
private final List<Charge> charges = new ArrayList<Charge>(); |
|
|
|
|
|
|
|
|
|
|
|
@ -115,6 +146,12 @@ public final class RefundCommand { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 设置退款数量;不设表示整行全退。 */ |
|
|
|
|
|
|
|
public Builder quantity(Integer quantity) { |
|
|
|
|
|
|
|
this.quantity = quantity; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 追加一条费用明细。 */ |
|
|
|
/** 追加一条费用明细。 */ |
|
|
|
public Builder charge(Charge charge) { |
|
|
|
public Builder charge(Charge charge) { |
|
|
|
if (charge != null) { |
|
|
|
if (charge != null) { |
|
|
|
@ -236,6 +273,8 @@ public final class RefundCommand { |
|
|
|
|
|
|
|
|
|
|
|
/** 平台退货单号。 */ |
|
|
|
/** 平台退货单号。 */ |
|
|
|
private String afterSaleId; |
|
|
|
private String afterSaleId; |
|
|
|
|
|
|
|
/** 平台客户订单号;沃尔玛必填。 */ |
|
|
|
|
|
|
|
private String customerOrderId; |
|
|
|
/** 退款行。 */ |
|
|
|
/** 退款行。 */ |
|
|
|
private final List<Line> lines = new ArrayList<Line>(); |
|
|
|
private final List<Line> lines = new ArrayList<Line>(); |
|
|
|
|
|
|
|
|
|
|
|
@ -245,6 +284,12 @@ public final class RefundCommand { |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** 设置平台客户订单号;沃尔玛退款必填,其他平台可不用。 */ |
|
|
|
|
|
|
|
public Builder customerOrderId(String customerOrderId) { |
|
|
|
|
|
|
|
this.customerOrderId = customerOrderId; |
|
|
|
|
|
|
|
return this; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** 追加一条退款行。 */ |
|
|
|
/** 追加一条退款行。 */ |
|
|
|
public Builder line(Line line) { |
|
|
|
public Builder line(Line line) { |
|
|
|
if (line != null) { |
|
|
|
if (line != null) { |
|
|
|
|