Browse Source

fix(aliexpress): price 单位按分换算为标准金额

接口 price 字段单位为分,统一模型用标准金额(元),除以 100 后输出。

取值优先级:
1. effectiveSupplyPrice(已格式化的字符串,直接可用)
2. price(分)÷ 100
3. 当前生效的 supplyPriceList 条目

文档示例 99990000 与 effectiveSupplyPrice 59.99 不一致,按「单位分」处理;
原始 price 仍保留在 attributes.price。

Co-Authored-By: Claude <noreply@anthropic.com>
feature/supplier-lingxing
chenchuchuan 3 weeks ago
parent
commit
2ff213e3c4
  1. 22
      lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/product/AliexpressProductSource.java

22
lingxing/src/main/java/common/ecommerce/lingxing/platform/aliexpress/product/AliexpressProductSource.java

@ -128,7 +128,9 @@ public final class AliexpressProductSource implements LingxingProductSource {
* <li>imageUrls ← {@code skuImage},为空时用 {@code imageUrls}(父体图)</li> * <li>imageUrls ← {@code skuImage},为空时用 {@code imageUrls}(父体图)</li>
* <li>status ← {@code status}(文档只给了「可售」=2,其余归 UNKNOWN)</li> * <li>status ← {@code status}(文档只给了「可售」=2,其余归 UNKNOWN)</li>
* <li>rawStatus ← {@code statusName} 原值(中文)</li> * <li>rawStatus ← {@code statusName} 原值(中文)</li>
* <li>price ← {@code effectiveSupplyPrice} + {@code currencyCode}</li> * <li>price ← 优先 {@code effectiveSupplyPrice}(已格式化的字符串);
* 缺失时用 {@code price}(<b>单位:分</b>)除以 100 转成标准金额;
* 再缺失时取当前生效的 {@code supplyPriceList} 条目</li>
* <li>listedAt ← {@code createTime}(北京时间,按 UTC 换算)</li> * <li>listedAt ← {@code createTime}(北京时间,按 UTC 换算)</li>
* <li>updatedAt ← 无</li> * <li>updatedAt ← 无</li>
* <li>attributes ← 其余全部原始字段</li> * <li>attributes ← 其余全部原始字段</li>
@ -138,7 +140,10 @@ public final class AliexpressProductSource implements LingxingProductSource {
ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone()); ZoneId zone = ZoneId.of(call.ctx().account().marketplaceZone());
String image = firstNonBlank(dto.getSkuImage(), dto.getImageUrls()); String image = firstNonBlank(dto.getSkuImage(), dto.getImageUrls());
String currency = trimToNull(dto.getCurrencyCode()); String currency = trimToNull(dto.getCurrencyCode());
String price = firstNonBlank(dto.getEffectiveSupplyPrice(), currentSupplyPrice(dto.getSupplyPriceList())); String price = firstNonBlank(
dto.getEffectiveSupplyPrice(),
centsToAmount(dto.getPrice()),
currentSupplyPrice(dto.getSupplyPriceList()));
return ProductListing.builder() return ProductListing.builder()
.platform(call.ctx().platform()) .platform(call.ctx().platform())
@ -157,6 +162,19 @@ public final class AliexpressProductSource implements LingxingProductSource {
.build(); .build();
} }
/**
* 接口的 {@code price} 单位是<b>分</b>,统一模型用标准金额(元),此处除以 100。
*
* <p>文档示例 99990000 与 effectiveSupplyPrice 59.99 不一致,属于文档笔误;
* 以「单位分」为准做换算。</p>
*/
private static String centsToAmount(Long cents) {
if (cents == null) {
return null;
}
return java.math.BigDecimal.valueOf(cents, 2).toPlainString();
}
/** 当前生效供货价:优先 endStr 为空,否则取 beginStr 最大的一条。 */ /** 当前生效供货价:优先 endStr 为空,否则取 beginStr 最大的一条。 */
private static String currentSupplyPrice(List<AliexpressSupplyPriceDto> prices) { private static String currentSupplyPrice(List<AliexpressSupplyPriceDto> prices) {
if (prices == null || prices.isEmpty()) { if (prices == null || prices.isEmpty()) {

Loading…
Cancel
Save