mirror of
https://gitee.com/qqtt-ah/ecom-dmb.git
synced 2026-11-24 01:19:19 +08:00
refactor: 调整订单表
This commit is contained in:
+5
@@ -21,6 +21,7 @@ public class BiStatMetricDelta {
|
||||
private Integer gmvOrderCount;
|
||||
private Integer gmvQuantitySum;
|
||||
private BigDecimal refundAmount;
|
||||
private BigDecimal serviceFee;
|
||||
private BigDecimal productCost;
|
||||
private BigDecimal freightCost;
|
||||
private BigDecimal otherCost;
|
||||
@@ -34,6 +35,7 @@ public class BiStatMetricDelta {
|
||||
.gmvOrderCount(0)
|
||||
.gmvQuantitySum(0)
|
||||
.refundAmount(BigDecimal.ZERO)
|
||||
.serviceFee(BigDecimal.ZERO)
|
||||
.productCost(BigDecimal.ZERO)
|
||||
.freightCost(BigDecimal.ZERO)
|
||||
.otherCost(BigDecimal.ZERO)
|
||||
@@ -49,6 +51,7 @@ public class BiStatMetricDelta {
|
||||
.gmvOrderCount(-(gmvOrderCount == null ? 0 : gmvOrderCount))
|
||||
.gmvQuantitySum(-(gmvQuantitySum == null ? 0 : gmvQuantitySum))
|
||||
.refundAmount(nz(refundAmount).negate())
|
||||
.serviceFee(nz(serviceFee).negate())
|
||||
.productCost(nz(productCost).negate())
|
||||
.freightCost(nz(freightCost).negate())
|
||||
.otherCost(nz(otherCost).negate())
|
||||
@@ -67,6 +70,7 @@ public class BiStatMetricDelta {
|
||||
.gmvOrderCount(nzi(gmvOrderCount) + nzi(o.gmvOrderCount))
|
||||
.gmvQuantitySum(nzi(gmvQuantitySum) + nzi(o.gmvQuantitySum))
|
||||
.refundAmount(nz(refundAmount).add(nz(o.refundAmount)))
|
||||
.serviceFee(nz(serviceFee).add(nz(o.serviceFee)))
|
||||
.productCost(nz(productCost).add(nz(o.productCost)))
|
||||
.freightCost(nz(freightCost).add(nz(o.freightCost)))
|
||||
.otherCost(nz(otherCost).add(nz(o.otherCost)))
|
||||
@@ -85,6 +89,7 @@ public class BiStatMetricDelta {
|
||||
&& nzi(gmvOrderCount) == 0
|
||||
&& nzi(gmvQuantitySum) == 0
|
||||
&& nz(refundAmount).signum() == 0
|
||||
&& nz(serviceFee).signum() == 0
|
||||
&& nz(productCost).signum() == 0
|
||||
&& nz(freightCost).signum() == 0
|
||||
&& nz(otherCost).signum() == 0;
|
||||
|
||||
+1
@@ -36,6 +36,7 @@ public class BiOrderStatDailyProductDoc {
|
||||
private Integer gmvOrderCount = 0;
|
||||
private Integer gmvQuantitySum = 0;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
private BigDecimal serviceFee = BigDecimal.ZERO;
|
||||
private BigDecimal productCost = BigDecimal.ZERO;
|
||||
private BigDecimal freightCost = BigDecimal.ZERO;
|
||||
private BigDecimal otherCost = BigDecimal.ZERO;
|
||||
|
||||
+1
@@ -33,6 +33,7 @@ public class BiOrderStatDailyShopDoc {
|
||||
private Integer gmvOrderCount = 0;
|
||||
private Integer gmvQuantitySum = 0;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
private BigDecimal serviceFee = BigDecimal.ZERO;
|
||||
private BigDecimal productCost = BigDecimal.ZERO;
|
||||
private BigDecimal freightCost = BigDecimal.ZERO;
|
||||
private BigDecimal otherCost = BigDecimal.ZERO;
|
||||
|
||||
+1
@@ -37,6 +37,7 @@ public class BiOrderStatDailySkuDoc {
|
||||
private Integer gmvOrderCount = 0;
|
||||
private Integer gmvQuantitySum = 0;
|
||||
private BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
private BigDecimal serviceFee = BigDecimal.ZERO;
|
||||
private BigDecimal productCost = BigDecimal.ZERO;
|
||||
private BigDecimal freightCost = BigDecimal.ZERO;
|
||||
private BigDecimal otherCost = BigDecimal.ZERO;
|
||||
|
||||
+4
@@ -166,6 +166,7 @@ public class BiOrderStatDailyRepository {
|
||||
inc(u, "gmvOrderCount", d.getGmvOrderCount());
|
||||
inc(u, "gmvQuantitySum", d.getGmvQuantitySum());
|
||||
inc(u, "refundAmount", d.getRefundAmount());
|
||||
inc(u, "serviceFee", d.getServiceFee());
|
||||
inc(u, "productCost", d.getProductCost());
|
||||
inc(u, "freightCost", d.getFreightCost());
|
||||
inc(u, "otherCost", d.getOtherCost());
|
||||
@@ -200,6 +201,7 @@ public class BiOrderStatDailyRepository {
|
||||
doc.setGmvOrderCount(nzi(d.getGmvOrderCount()));
|
||||
doc.setGmvQuantitySum(nzi(d.getGmvQuantitySum()));
|
||||
doc.setRefundAmount(nz(d.getRefundAmount()));
|
||||
doc.setServiceFee(nz(d.getServiceFee()));
|
||||
doc.setProductCost(nz(d.getProductCost()));
|
||||
doc.setFreightCost(nz(d.getFreightCost()));
|
||||
doc.setOtherCost(nz(d.getOtherCost()));
|
||||
@@ -216,6 +218,7 @@ public class BiOrderStatDailyRepository {
|
||||
doc.setGmvOrderCount(nzi(d.getGmvOrderCount()));
|
||||
doc.setGmvQuantitySum(nzi(d.getGmvQuantitySum()));
|
||||
doc.setRefundAmount(nz(d.getRefundAmount()));
|
||||
doc.setServiceFee(nz(d.getServiceFee()));
|
||||
doc.setProductCost(nz(d.getProductCost()));
|
||||
doc.setFreightCost(nz(d.getFreightCost()));
|
||||
doc.setOtherCost(nz(d.getOtherCost()));
|
||||
@@ -232,6 +235,7 @@ public class BiOrderStatDailyRepository {
|
||||
doc.setGmvOrderCount(nzi(d.getGmvOrderCount()));
|
||||
doc.setGmvQuantitySum(nzi(d.getGmvQuantitySum()));
|
||||
doc.setRefundAmount(nz(d.getRefundAmount()));
|
||||
doc.setServiceFee(nz(d.getServiceFee()));
|
||||
doc.setProductCost(nz(d.getProductCost()));
|
||||
doc.setFreightCost(nz(d.getFreightCost()));
|
||||
doc.setOtherCost(nz(d.getOtherCost()));
|
||||
|
||||
+20
-11
@@ -155,20 +155,22 @@ public class OrderDailyStatComputeService {
|
||||
if (qtySum <= 0 && items.isEmpty()) {
|
||||
qtySum = 1;
|
||||
}
|
||||
BigDecimal pay = nz(order.getPayAmount());
|
||||
BigDecimal received = OrderStatusStatSets.receivedAmount(order);
|
||||
BigDecimal fee = nz(order.getServiceFee());
|
||||
boolean sales = stat.includesSales(order.getStatus());
|
||||
boolean refund = stat.includesRefund(order.getStatus());
|
||||
|
||||
shop.gmvAmount = shop.gmvAmount.add(pay);
|
||||
shop.gmvAmount = shop.gmvAmount.add(received);
|
||||
shop.gmvOrderCount++;
|
||||
shop.gmvQuantitySum += qtySum;
|
||||
shop.serviceFee = shop.serviceFee.add(fee);
|
||||
if (sales) {
|
||||
shop.salesAmount = shop.salesAmount.add(pay);
|
||||
shop.salesAmount = shop.salesAmount.add(received);
|
||||
shop.salesOrderCount++;
|
||||
shop.salesQuantitySum += qtySum;
|
||||
}
|
||||
if (refund) {
|
||||
shop.refundAmount = shop.refundAmount.add(pay);
|
||||
shop.refundAmount = shop.refundAmount.add(received);
|
||||
}
|
||||
|
||||
Set<String> countedProductSales = new HashSet<>();
|
||||
@@ -184,25 +186,27 @@ public class OrderDailyStatComputeService {
|
||||
long categoryId = categoryByProduct.getOrDefault(productId, 0L);
|
||||
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
||||
int qty = OrderStatusStatSets.quantity(item);
|
||||
BigDecimal linePay = allocateLine(pay, item, items);
|
||||
BigDecimal lineReceived = allocateLine(received, item, items);
|
||||
BigDecimal lineFee = allocateLine(fee, item, items);
|
||||
|
||||
String pk = companyId + ":" + shopId + ":" + productId + ":" + categoryId;
|
||||
Metric pm = productMap.computeIfAbsent(pk, k -> new Metric());
|
||||
productKeys.putIfAbsent(pk, new DimKey(productId, categoryId, 0L));
|
||||
pm.gmvAmount = pm.gmvAmount.add(linePay);
|
||||
pm.gmvAmount = pm.gmvAmount.add(lineReceived);
|
||||
pm.gmvQuantitySum += qty;
|
||||
pm.serviceFee = pm.serviceFee.add(lineFee);
|
||||
if (countedProductGmv.add(pk)) {
|
||||
pm.gmvOrderCount++;
|
||||
}
|
||||
if (sales) {
|
||||
pm.salesAmount = pm.salesAmount.add(linePay);
|
||||
pm.salesAmount = pm.salesAmount.add(lineReceived);
|
||||
pm.salesQuantitySum += qty;
|
||||
if (countedProductSales.add(pk)) {
|
||||
pm.salesOrderCount++;
|
||||
}
|
||||
}
|
||||
if (refund) {
|
||||
pm.refundAmount = pm.refundAmount.add(linePay);
|
||||
pm.refundAmount = pm.refundAmount.add(lineReceived);
|
||||
}
|
||||
pm.productCost = pm.productCost.add(stat.productCostForStats(order, item));
|
||||
pm.freightCost = pm.freightCost.add(stat.freightCostForStats(order, item));
|
||||
@@ -211,20 +215,21 @@ public class OrderDailyStatComputeService {
|
||||
String sk = companyId + ":" + shopId + ":" + skuId;
|
||||
Metric sm = skuMap.computeIfAbsent(sk, k -> new Metric());
|
||||
skuKeys.putIfAbsent(sk, new DimKey(productId, 0L, skuId));
|
||||
sm.gmvAmount = sm.gmvAmount.add(linePay);
|
||||
sm.gmvAmount = sm.gmvAmount.add(lineReceived);
|
||||
sm.gmvQuantitySum += qty;
|
||||
sm.serviceFee = sm.serviceFee.add(lineFee);
|
||||
if (countedSkuGmv.add(sk)) {
|
||||
sm.gmvOrderCount++;
|
||||
}
|
||||
if (sales) {
|
||||
sm.salesAmount = sm.salesAmount.add(linePay);
|
||||
sm.salesAmount = sm.salesAmount.add(lineReceived);
|
||||
sm.salesQuantitySum += qty;
|
||||
if (countedSkuSales.add(sk)) {
|
||||
sm.salesOrderCount++;
|
||||
}
|
||||
}
|
||||
if (refund) {
|
||||
sm.refundAmount = sm.refundAmount.add(linePay);
|
||||
sm.refundAmount = sm.refundAmount.add(lineReceived);
|
||||
}
|
||||
sm.productCost = sm.productCost.add(stat.productCostForStats(order, item));
|
||||
sm.freightCost = sm.freightCost.add(stat.freightCostForStats(order, item));
|
||||
@@ -301,6 +306,7 @@ public class OrderDailyStatComputeService {
|
||||
doc.setGmvOrderCount(m.gmvOrderCount);
|
||||
doc.setGmvQuantitySum(m.gmvQuantitySum);
|
||||
doc.setRefundAmount(m.refundAmount);
|
||||
doc.setServiceFee(m.serviceFee);
|
||||
doc.setProductCost(m.productCost);
|
||||
doc.setFreightCost(m.freightCost);
|
||||
doc.setOtherCost(m.otherCost);
|
||||
@@ -314,6 +320,7 @@ public class OrderDailyStatComputeService {
|
||||
doc.setGmvOrderCount(m.gmvOrderCount);
|
||||
doc.setGmvQuantitySum(m.gmvQuantitySum);
|
||||
doc.setRefundAmount(m.refundAmount);
|
||||
doc.setServiceFee(m.serviceFee);
|
||||
doc.setProductCost(m.productCost);
|
||||
doc.setFreightCost(m.freightCost);
|
||||
doc.setOtherCost(m.otherCost);
|
||||
@@ -327,6 +334,7 @@ public class OrderDailyStatComputeService {
|
||||
doc.setGmvOrderCount(m.gmvOrderCount);
|
||||
doc.setGmvQuantitySum(m.gmvQuantitySum);
|
||||
doc.setRefundAmount(m.refundAmount);
|
||||
doc.setServiceFee(m.serviceFee);
|
||||
doc.setProductCost(m.productCost);
|
||||
doc.setFreightCost(m.freightCost);
|
||||
doc.setOtherCost(m.otherCost);
|
||||
@@ -359,6 +367,7 @@ public class OrderDailyStatComputeService {
|
||||
int gmvOrderCount;
|
||||
int gmvQuantitySum;
|
||||
BigDecimal refundAmount = BigDecimal.ZERO;
|
||||
BigDecimal serviceFee = BigDecimal.ZERO;
|
||||
BigDecimal productCost = BigDecimal.ZERO;
|
||||
BigDecimal freightCost = BigDecimal.ZERO;
|
||||
BigDecimal otherCost = BigDecimal.ZERO;
|
||||
|
||||
+16
-11
@@ -43,21 +43,23 @@ public class OrderStatContributionCalculator {
|
||||
if (qtySum <= 0 && safeItems.isEmpty()) {
|
||||
qtySum = 1;
|
||||
}
|
||||
BigDecimal pay = nz(order.getPayAmount());
|
||||
BigDecimal received = OrderStatusStatSets.receivedAmount(order);
|
||||
BigDecimal fee = nz(order.getServiceFee());
|
||||
boolean sales = stat.includesSales(order.getStatus());
|
||||
boolean refund = stat.includesRefund(order.getStatus());
|
||||
|
||||
BiStatMetricDelta shop = BiStatMetricDelta.zeros();
|
||||
shop.setGmvAmount(pay);
|
||||
shop.setGmvAmount(received);
|
||||
shop.setGmvOrderCount(1);
|
||||
shop.setGmvQuantitySum(qtySum);
|
||||
shop.setServiceFee(fee);
|
||||
if (sales) {
|
||||
shop.setSalesAmount(pay);
|
||||
shop.setSalesAmount(received);
|
||||
shop.setSalesOrderCount(1);
|
||||
shop.setSalesQuantitySum(qtySum);
|
||||
}
|
||||
if (refund) {
|
||||
shop.setRefundAmount(pay);
|
||||
shop.setRefundAmount(received);
|
||||
}
|
||||
|
||||
Map<String, BiStatMetricDelta> productMap = new HashMap<>();
|
||||
@@ -72,19 +74,21 @@ public class OrderStatContributionCalculator {
|
||||
long categoryId = categoryByProduct.getOrDefault(productId, 0L);
|
||||
long skuId = item.getProductSkuId() != null ? item.getProductSkuId() : 0L;
|
||||
int qty = OrderStatusStatSets.quantity(item);
|
||||
BigDecimal linePay = allocateLine(pay, item, safeItems);
|
||||
BigDecimal lineReceived = allocateLine(received, item, safeItems);
|
||||
BigDecimal lineFee = allocateLine(fee, item, safeItems);
|
||||
|
||||
String pk = productId + ":" + categoryId;
|
||||
BiStatMetricDelta pm = productMap.computeIfAbsent(pk, k -> BiStatMetricDelta.zeros());
|
||||
productKeys.putIfAbsent(pk, new long[]{productId, categoryId});
|
||||
pm.setGmvAmount(nz(pm.getGmvAmount()).add(linePay));
|
||||
pm.setGmvAmount(nz(pm.getGmvAmount()).add(lineReceived));
|
||||
pm.setGmvQuantitySum(nzi(pm.getGmvQuantitySum()) + qty);
|
||||
pm.setServiceFee(nz(pm.getServiceFee()).add(lineFee));
|
||||
if (sales) {
|
||||
pm.setSalesAmount(nz(pm.getSalesAmount()).add(linePay));
|
||||
pm.setSalesAmount(nz(pm.getSalesAmount()).add(lineReceived));
|
||||
pm.setSalesQuantitySum(nzi(pm.getSalesQuantitySum()) + qty);
|
||||
}
|
||||
if (refund) {
|
||||
pm.setRefundAmount(nz(pm.getRefundAmount()).add(linePay));
|
||||
pm.setRefundAmount(nz(pm.getRefundAmount()).add(lineReceived));
|
||||
}
|
||||
BigDecimal pc = stat.productCostForStats(order, item);
|
||||
BigDecimal fc = stat.freightCostForStats(order, item);
|
||||
@@ -96,14 +100,15 @@ public class OrderStatContributionCalculator {
|
||||
String sk = String.valueOf(skuId);
|
||||
BiStatMetricDelta sm = skuMap.computeIfAbsent(sk, k -> BiStatMetricDelta.zeros());
|
||||
skuKeys.putIfAbsent(sk, new long[]{productId, skuId});
|
||||
sm.setGmvAmount(nz(sm.getGmvAmount()).add(linePay));
|
||||
sm.setGmvAmount(nz(sm.getGmvAmount()).add(lineReceived));
|
||||
sm.setGmvQuantitySum(nzi(sm.getGmvQuantitySum()) + qty);
|
||||
sm.setServiceFee(nz(sm.getServiceFee()).add(lineFee));
|
||||
if (sales) {
|
||||
sm.setSalesAmount(nz(sm.getSalesAmount()).add(linePay));
|
||||
sm.setSalesAmount(nz(sm.getSalesAmount()).add(lineReceived));
|
||||
sm.setSalesQuantitySum(nzi(sm.getSalesQuantitySum()) + qty);
|
||||
}
|
||||
if (refund) {
|
||||
sm.setRefundAmount(nz(sm.getRefundAmount()).add(linePay));
|
||||
sm.setRefundAmount(nz(sm.getRefundAmount()).add(lineReceived));
|
||||
}
|
||||
sm.setProductCost(nz(sm.getProductCost()).add(pc));
|
||||
sm.setFreightCost(nz(sm.getFreightCost()).add(fc));
|
||||
|
||||
+11
-1
@@ -292,12 +292,18 @@ public class PddOrderConvertService {
|
||||
order.setPlatformOrderNo(channel.getOrderSn());
|
||||
order.setSource("sync");
|
||||
order.setSourceOrderId(channel.getId());
|
||||
order.setPayAmount(channel.getPayAmount());
|
||||
order.setPayAmount(nz(channel.getPayAmount()));
|
||||
order.setGoodsAmount(channel.getGoodsAmount());
|
||||
order.setDiscountAmount(channel.getDiscountAmount());
|
||||
order.setPostage(channel.getPostage());
|
||||
order.setPlatformDiscount(channel.getPlatformDiscount());
|
||||
order.setSellerDiscount(channel.getSellerDiscount());
|
||||
// 商家实收 = 实付 - 服务费 + 平台优惠
|
||||
BigDecimal serviceFee = nz(channel.getServiceFee());
|
||||
order.setServiceFee(serviceFee);
|
||||
order.setReceivedAmount(nz(channel.getPayAmount())
|
||||
.subtract(serviceFee)
|
||||
.add(nz(channel.getPlatformDiscount())));
|
||||
order.setLogisticsId(channel.getLogisticsId() != null ? String.valueOf(channel.getLogisticsId()) : null);
|
||||
order.setTrackingNumber(channel.getTrackingNumber());
|
||||
order.setOrderTime(channel.getCreatedTime());
|
||||
@@ -382,4 +388,8 @@ public class PddOrderConvertService {
|
||||
}
|
||||
return item;
|
||||
}
|
||||
|
||||
private static BigDecimal nz(BigDecimal v) {
|
||||
return v != null ? v : BigDecimal.ZERO;
|
||||
}
|
||||
}
|
||||
|
||||
+6
@@ -55,6 +55,12 @@ public class CreatePddOrderDTO {
|
||||
@Schema(description = "商家优惠")
|
||||
private BigDecimal sellerDiscount;
|
||||
|
||||
@Schema(description = "服务费合计")
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@Schema(description = "服务费明细 JSON")
|
||||
private String serviceFeeDetail;
|
||||
|
||||
@Schema(description = "快递公司编码")
|
||||
private Long logisticsId;
|
||||
|
||||
|
||||
+6
@@ -55,6 +55,12 @@ public class UpdatePddOrderDTO {
|
||||
@Schema(description = "商家优惠")
|
||||
private BigDecimal sellerDiscount;
|
||||
|
||||
@Schema(description = "服务费合计")
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@Schema(description = "服务费明细 JSON")
|
||||
private String serviceFeeDetail;
|
||||
|
||||
@Schema(description = "快递公司编码")
|
||||
private Long logisticsId;
|
||||
|
||||
|
||||
+6
@@ -55,6 +55,12 @@ public class PddOrderPO {
|
||||
@TableField("seller_discount")
|
||||
private BigDecimal sellerDiscount;
|
||||
|
||||
@TableField("service_fee")
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@TableField("service_fee_detail")
|
||||
private String serviceFeeDetail;
|
||||
|
||||
@TableField("logistics_id")
|
||||
private Long logisticsId;
|
||||
|
||||
|
||||
+6
@@ -56,6 +56,12 @@ public class PddOrderVO {
|
||||
@Schema(description = "商家优惠")
|
||||
private BigDecimal sellerDiscount;
|
||||
|
||||
@Schema(description = "服务费合计")
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@Schema(description = "服务费明细 JSON")
|
||||
private String serviceFeeDetail;
|
||||
|
||||
@Schema(description = "快递公司编码")
|
||||
private Long logisticsId;
|
||||
|
||||
|
||||
+20
-1
@@ -88,6 +88,7 @@ public class PddOrderUpsertService {
|
||||
order.setPostage(toMoney(snapshot.getPostage()));
|
||||
order.setPlatformDiscount(toMoney(snapshot.getPlatformDiscount()));
|
||||
order.setSellerDiscount(toMoney(snapshot.getSellerDiscount()));
|
||||
applyServiceFee(order, snapshot);
|
||||
order.setLogisticsId(snapshot.getLogisticsId());
|
||||
order.setTrackingNumber(snapshot.getTrackingNumber());
|
||||
order.setCreatedTime(firstNonNull(parseTime(snapshot.getCreatedTime()), LocalDateTime.now(ZONE)));
|
||||
@@ -154,11 +155,29 @@ public class PddOrderUpsertService {
|
||||
}
|
||||
}
|
||||
|
||||
/** 从 service_fee_detail 汇总服务费,并落库明细 JSON */
|
||||
private void applyServiceFee(PddOrderPO order, PddOrderApiSnapshot snapshot) {
|
||||
List<PddOrderApiSnapshot.ServiceFeeDetail> details = snapshot.getServiceFeeDetail();
|
||||
BigDecimal sum = BigDecimal.ZERO.setScale(2, RoundingMode.HALF_UP);
|
||||
if (details != null && !details.isEmpty()) {
|
||||
for (PddOrderApiSnapshot.ServiceFeeDetail d : details) {
|
||||
if (d == null || d.getServiceFee() == null) {
|
||||
continue;
|
||||
}
|
||||
sum = sum.add(toMoney(d.getServiceFee()));
|
||||
}
|
||||
order.setServiceFeeDetail(writeJson(details));
|
||||
} else {
|
||||
order.setServiceFeeDetail(null);
|
||||
}
|
||||
order.setServiceFee(sum);
|
||||
}
|
||||
|
||||
private String writeJson(Object value) {
|
||||
try {
|
||||
return objectMapper.writeValueAsString(value);
|
||||
} catch (JsonProcessingException e) {
|
||||
log.warn("序列化订单 raw_response 失败: {}", e.getMessage());
|
||||
log.warn("序列化订单 JSON 失败: {}", e.getMessage());
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
+9
@@ -24,6 +24,8 @@ public class PddOrderApiSnapshot {
|
||||
private Double postage;
|
||||
private Double platformDiscount;
|
||||
private Double sellerDiscount;
|
||||
/** 服务费明细(SDK:serviceFeeDetail / JSON:service_fee_detail) */
|
||||
private List<ServiceFeeDetail> serviceFeeDetail;
|
||||
private Long logisticsId;
|
||||
private String trackingNumber;
|
||||
private String createdTime;
|
||||
@@ -46,6 +48,13 @@ public class PddOrderApiSnapshot {
|
||||
private Integer groupStatus;
|
||||
private List<Item> itemList;
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class ServiceFeeDetail {
|
||||
private Double serviceFee;
|
||||
private String serviceName;
|
||||
}
|
||||
|
||||
@Data
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public static class Item {
|
||||
|
||||
+12
-2
@@ -706,7 +706,12 @@ public class OrderImportProcessor {
|
||||
|
||||
if (receivedAmountStr != null && !receivedAmountStr.trim().isEmpty()) {
|
||||
try {
|
||||
dto.setReceivedAmount(new BigDecimal(receivedAmountStr.trim()));
|
||||
BigDecimal received = new BigDecimal(receivedAmountStr.trim());
|
||||
dto.setReceivedAmount(received);
|
||||
// 导入仅映射商家实收时,实付同步占位,保证落库非空
|
||||
if (dto.getPayAmount() == null) {
|
||||
dto.setPayAmount(received);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new BusinessException("商家实收金额格式错误: " + receivedAmountStr);
|
||||
}
|
||||
@@ -1440,7 +1445,12 @@ public class OrderImportProcessor {
|
||||
// 解析必填字段
|
||||
if (receivedAmountStr != null && !receivedAmountStr.trim().isEmpty()) {
|
||||
try {
|
||||
dto.setReceivedAmount(new BigDecimal(receivedAmountStr.trim()));
|
||||
BigDecimal received = new BigDecimal(receivedAmountStr.trim());
|
||||
dto.setReceivedAmount(received);
|
||||
// 导入仅映射商家实收时,实付同步占位,保证落库非空
|
||||
if (dto.getPayAmount() == null) {
|
||||
dto.setPayAmount(received);
|
||||
}
|
||||
} catch (NumberFormatException e) {
|
||||
throw new BusinessException("商家实收金额格式错误: " + receivedAmountStr);
|
||||
}
|
||||
|
||||
+8
-13
@@ -1,12 +1,11 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.order.model.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
import jakarta.validation.constraints.Positive;
|
||||
import lombok.Data;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.time.LocalDateTime;
|
||||
@@ -30,11 +29,16 @@ public class CreateOrderDTO {
|
||||
@NotNull(message = "订单状态不能为空")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "实付/商家实收金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "买家实付金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "实付金额不能为空")
|
||||
@JsonAlias("receivedAmount")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
@Schema(description = "商家实收金额(未传时按 实付-服务费+平台优惠 计算)")
|
||||
private BigDecimal receivedAmount;
|
||||
|
||||
@Schema(description = "平台服务费")
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "下单时间不能为空")
|
||||
private LocalDateTime orderTime;
|
||||
@@ -111,13 +115,4 @@ public class CreateOrderDTO {
|
||||
|
||||
@Schema(description = "已存在的订单ID(导入时用于更新)")
|
||||
private Long existingOrderId;
|
||||
|
||||
/** 兼容旧字段名:写入 payAmount */
|
||||
public void setReceivedAmount(BigDecimal receivedAmount) {
|
||||
this.payAmount = receivedAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getReceivedAmount() {
|
||||
return payAmount;
|
||||
}
|
||||
}
|
||||
|
||||
+3
@@ -18,6 +18,9 @@ public class OrderFilterDTO {
|
||||
@Schema(description = "店铺ID")
|
||||
private Long shopId;
|
||||
|
||||
@Schema(description = "平台代码(如 pdd/taobao/jd)")
|
||||
private String platformCode;
|
||||
|
||||
@Schema(description = "平台订单号(默认前缀匹配;含%/_ 时全模糊)")
|
||||
private String platformOrderNo;
|
||||
|
||||
|
||||
+1
@@ -13,6 +13,7 @@ public class OrderListQueryParam {
|
||||
|
||||
private Long companyId;
|
||||
private Long shopId;
|
||||
private String platformCode;
|
||||
private String platformOrderNo;
|
||||
private Boolean platformOrderNoPrefix;
|
||||
private String status;
|
||||
|
||||
+7
-11
@@ -1,6 +1,5 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.order.model.dto;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonAlias;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import jakarta.validation.Valid;
|
||||
import jakarta.validation.constraints.NotNull;
|
||||
@@ -27,11 +26,16 @@ public class UpdateOrderDTO {
|
||||
@Schema(description = "订单状态码")
|
||||
private String status;
|
||||
|
||||
@Schema(description = "实付/商家实收金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@Schema(description = "买家实付金额", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "实付金额不能为空")
|
||||
@JsonAlias("receivedAmount")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
@Schema(description = "商家实收金额(未传时按 实付-服务费+平台优惠 计算)")
|
||||
private BigDecimal receivedAmount;
|
||||
|
||||
@Schema(description = "平台服务费")
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@Schema(description = "下单时间", requiredMode = Schema.RequiredMode.REQUIRED)
|
||||
@NotNull(message = "下单时间不能为空")
|
||||
private LocalDateTime orderTime;
|
||||
@@ -73,12 +77,4 @@ public class UpdateOrderDTO {
|
||||
private BigDecimal otherCost;
|
||||
private String remark;
|
||||
private Integer confirm;
|
||||
|
||||
public void setReceivedAmount(BigDecimal receivedAmount) {
|
||||
this.payAmount = receivedAmount;
|
||||
}
|
||||
|
||||
public BigDecimal getReceivedAmount() {
|
||||
return payAmount;
|
||||
}
|
||||
}
|
||||
|
||||
+8
@@ -42,6 +42,14 @@ public class OrderPO {
|
||||
@TableField("pay_amount")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
/** 商家实收(=实付-服务费+平台优惠) */
|
||||
@TableField("received_amount")
|
||||
private BigDecimal receivedAmount;
|
||||
|
||||
/** 平台服务费 */
|
||||
@TableField("service_fee")
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@TableField("goods_amount")
|
||||
private BigDecimal goodsAmount;
|
||||
|
||||
|
||||
+61
-8
@@ -1,6 +1,5 @@
|
||||
package top.xyquan.ecomdmbbackend.modules.ec.order.model.vo;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.swagger.v3.oas.annotations.media.Schema;
|
||||
import lombok.Data;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopVO;
|
||||
@@ -31,6 +30,9 @@ public class OrderVO {
|
||||
@Schema(description = "平台代码")
|
||||
private String platformCode;
|
||||
|
||||
@Schema(description = "平台名称(由 platformCode 解析)")
|
||||
private String platformLabel;
|
||||
|
||||
@Schema(description = "平台订单号")
|
||||
private String platformOrderNo;
|
||||
|
||||
@@ -46,9 +48,15 @@ public class OrderVO {
|
||||
@Schema(description = "来源")
|
||||
private String source;
|
||||
|
||||
@Schema(description = "实付/商家实收金额")
|
||||
@Schema(description = "买家实付金额")
|
||||
private BigDecimal payAmount;
|
||||
|
||||
@Schema(description = "商家实收金额(=实付-服务费+平台优惠)")
|
||||
private BigDecimal receivedAmount;
|
||||
|
||||
@Schema(description = "平台服务费")
|
||||
private BigDecimal serviceFee;
|
||||
|
||||
@Schema(description = "商品金额合计")
|
||||
private BigDecimal goodsAmount;
|
||||
|
||||
@@ -58,9 +66,54 @@ public class OrderVO {
|
||||
@Schema(description = "邮费")
|
||||
private BigDecimal postage;
|
||||
|
||||
@Schema(description = "平台优惠")
|
||||
private BigDecimal platformDiscount;
|
||||
|
||||
@Schema(description = "商家优惠")
|
||||
private BigDecimal sellerDiscount;
|
||||
|
||||
@Schema(description = "快递公司编码")
|
||||
private String logisticsId;
|
||||
|
||||
@Schema(description = "快递运单号")
|
||||
private String trackingNumber;
|
||||
|
||||
@Schema(description = "下单时间")
|
||||
private LocalDateTime orderTime;
|
||||
|
||||
@Schema(description = "支付时间")
|
||||
private LocalDateTime payTime;
|
||||
|
||||
@Schema(description = "成交时间")
|
||||
private LocalDateTime confirmTime;
|
||||
|
||||
@Schema(description = "发货时间")
|
||||
private LocalDateTime shippingTime;
|
||||
|
||||
@Schema(description = "签收时间")
|
||||
private LocalDateTime receiveTime;
|
||||
|
||||
@Schema(description = "省份")
|
||||
private String province;
|
||||
|
||||
@Schema(description = "城市")
|
||||
private String city;
|
||||
|
||||
@Schema(description = "区县")
|
||||
private String town;
|
||||
|
||||
@Schema(description = "收件人姓名脱敏")
|
||||
private String receiverNameMask;
|
||||
|
||||
@Schema(description = "收件人手机脱敏")
|
||||
private String receiverPhoneMask;
|
||||
|
||||
@Schema(description = "收件地址脱敏")
|
||||
private String receiverAddressMask;
|
||||
|
||||
@Schema(description = "买家留言")
|
||||
private String buyerMemo;
|
||||
|
||||
@Schema(description = "创建时间")
|
||||
private LocalDateTime createTime;
|
||||
|
||||
@@ -82,6 +135,12 @@ public class OrderVO {
|
||||
@Schema(description = "确认(0-否 1-是)")
|
||||
private Integer confirm;
|
||||
|
||||
@Schema(description = "平台侧订单更新时间")
|
||||
private LocalDateTime platformUpdatedAt;
|
||||
|
||||
@Schema(description = "最近一次转换时间")
|
||||
private LocalDateTime lastMappedTime;
|
||||
|
||||
@Schema(description = "明细行数(列表汇总)")
|
||||
private Integer itemCount;
|
||||
|
||||
@@ -93,10 +152,4 @@ public class OrderVO {
|
||||
|
||||
@Schema(description = "关联店铺")
|
||||
private ShopVO shop;
|
||||
|
||||
/** 兼容旧前端字段名 */
|
||||
@JsonProperty("receivedAmount")
|
||||
public BigDecimal getReceivedAmount() {
|
||||
return payAmount;
|
||||
}
|
||||
}
|
||||
|
||||
+20
@@ -30,6 +30,7 @@ import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductSkuVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.model.vo.ProductVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.service.OrderService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.order.status.model.enums.OrderStatus;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.platform.model.enums.PlatformCode;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.shop.model.vo.ShopVO;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductService;
|
||||
import top.xyquan.ecomdmbbackend.modules.ec.product.service.ProductSkuService;
|
||||
@@ -38,6 +39,8 @@ import top.xyquan.ecomdmbbackend.modules.sys.license.LicenseFeature;
|
||||
import top.xyquan.ecomdmbbackend.modules.sys.license.LicenseFeatureGuard;
|
||||
import top.xyquan.ecomdmbbackend.utils.CurrentUserContext;
|
||||
import org.slf4j.Logger;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.time.ZoneId;
|
||||
@@ -139,6 +142,20 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
order.setId(id);
|
||||
order.setCompanyId(companyId);
|
||||
order.setUpdateBy(userId);
|
||||
// 实收未传时按 实付-服务费+平台优惠 重算
|
||||
BigDecimal pay = order.getPayAmount() != null ? order.getPayAmount() : existingOrder.getPayAmount();
|
||||
BigDecimal fee = order.getServiceFee() != null ? order.getServiceFee()
|
||||
: (existingOrder.getServiceFee() != null ? existingOrder.getServiceFee() : BigDecimal.ZERO);
|
||||
BigDecimal platformDiscount = order.getPlatformDiscount() != null ? order.getPlatformDiscount()
|
||||
: (existingOrder.getPlatformDiscount() != null ? existingOrder.getPlatformDiscount() : BigDecimal.ZERO);
|
||||
if (updateOrderDTO.getReceivedAmount() != null) {
|
||||
order.setReceivedAmount(updateOrderDTO.getReceivedAmount());
|
||||
} else {
|
||||
order.setReceivedAmount(pay.subtract(fee).add(platformDiscount));
|
||||
}
|
||||
if (order.getServiceFee() == null) {
|
||||
order.setServiceFee(fee);
|
||||
}
|
||||
this.updateById(order);
|
||||
|
||||
List<CreateOrderItemDTO> itemDtos = OrderDtoSupport.resolveItems(updateOrderDTO);
|
||||
@@ -386,6 +403,9 @@ public class OrderServiceImpl extends ServiceImpl<OrderMapper, OrderPO> implemen
|
||||
OrderVO vo = new OrderVO();
|
||||
BeanCopyUtils.copyProperties(order, vo);
|
||||
fillStatusMeta(vo, order.getStatus());
|
||||
if (order.getPlatformCode() != null && !order.getPlatformCode().isBlank()) {
|
||||
vo.setPlatformLabel(PlatformCode.labelOf(order.getPlatformCode()));
|
||||
}
|
||||
|
||||
if (order.getShopId() != null) {
|
||||
ShopPO shop = shopMap.get(order.getShopId());
|
||||
|
||||
+13
-2
@@ -117,7 +117,7 @@ public final class OrderStatusStatSets {
|
||||
}
|
||||
|
||||
public BigDecimal receivedForSales(OrderPO order) {
|
||||
return includesSales(order.getStatus()) ? nz(order.getPayAmount()) : BigDecimal.ZERO;
|
||||
return includesSales(order.getStatus()) ? receivedAmount(order) : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
public BigDecimal productCostForStats(OrderPO order, OrderItemPO item) {
|
||||
@@ -147,7 +147,18 @@ public final class OrderStatusStatSets {
|
||||
}
|
||||
|
||||
public BigDecimal receivedForRefund(OrderPO order) {
|
||||
return includesRefund(order.getStatus()) ? nz(order.getPayAmount()) : BigDecimal.ZERO;
|
||||
return includesRefund(order.getStatus()) ? receivedAmount(order) : BigDecimal.ZERO;
|
||||
}
|
||||
|
||||
/** 商家实收;历史数据缺省时回退实付 */
|
||||
public static BigDecimal receivedAmount(OrderPO order) {
|
||||
if (order == null) {
|
||||
return BigDecimal.ZERO;
|
||||
}
|
||||
if (order.getReceivedAmount() != null) {
|
||||
return order.getReceivedAmount();
|
||||
}
|
||||
return nz(order.getPayAmount());
|
||||
}
|
||||
|
||||
/** @deprecated 使用 {@link #quantity(OrderItemPO)} */
|
||||
|
||||
+12
-3
@@ -101,12 +101,21 @@ public final class OrderDtoSupport {
|
||||
order.setShopId(dto.getShopId());
|
||||
order.setPlatformOrderNo(dto.getPlatformOrderNo());
|
||||
order.setStatus(dto.getStatus());
|
||||
order.setPayAmount(dto.getPayAmount());
|
||||
BigDecimal pay = nz(dto.getPayAmount());
|
||||
BigDecimal fee = nz(dto.getServiceFee());
|
||||
BigDecimal platformDiscount = nz(dto.getPlatformDiscount());
|
||||
order.setPayAmount(pay);
|
||||
order.setServiceFee(fee);
|
||||
order.setPlatformDiscount(dto.getPlatformDiscount());
|
||||
order.setSellerDiscount(dto.getSellerDiscount());
|
||||
// 未显式传实收时:实付 - 服务费 + 平台优惠
|
||||
BigDecimal received = dto.getReceivedAmount() != null
|
||||
? dto.getReceivedAmount()
|
||||
: pay.subtract(fee).add(platformDiscount);
|
||||
order.setReceivedAmount(received);
|
||||
order.setGoodsAmount(dto.getGoodsAmount());
|
||||
order.setDiscountAmount(dto.getDiscountAmount());
|
||||
order.setPostage(dto.getPostage());
|
||||
order.setPlatformDiscount(dto.getPlatformDiscount());
|
||||
order.setSellerDiscount(dto.getSellerDiscount());
|
||||
order.setOrderTime(dto.getOrderTime());
|
||||
order.setPlatformCode(platformCode != null ? platformCode : dto.getPlatformCode());
|
||||
order.setSource(dto.getSource() != null ? dto.getSource() : "import");
|
||||
|
||||
+5
-2
@@ -22,14 +22,14 @@ public final class OrderPageQuerySupport {
|
||||
public static final int MAX_LIST_DAYS = 366;
|
||||
|
||||
private static final Set<String> ALLOWED_SORT_COLUMNS = Set.of(
|
||||
"order_time", "id", "pay_amount", "shop_id", "status", "create_time"
|
||||
"order_time", "id", "pay_amount", "received_amount", "shop_id", "status", "create_time"
|
||||
);
|
||||
|
||||
private static final Map<String, String> SORT_FIELD_TO_COLUMN = Map.of(
|
||||
"orderTime", "order_time",
|
||||
"id", "id",
|
||||
"payAmount", "pay_amount",
|
||||
"receivedAmount", "pay_amount",
|
||||
"receivedAmount", "received_amount",
|
||||
"shopId", "shop_id",
|
||||
"status", "status",
|
||||
"createTime", "create_time"
|
||||
@@ -74,6 +74,9 @@ public final class OrderPageQuerySupport {
|
||||
OrderListQueryParam p = new OrderListQueryParam();
|
||||
p.setCompanyId(companyId);
|
||||
p.setShopId(filter.getShopId());
|
||||
if (filter.getPlatformCode() != null && !filter.getPlatformCode().isBlank()) {
|
||||
p.setPlatformCode(filter.getPlatformCode().trim());
|
||||
}
|
||||
if (filter.getPlatformOrderNo() != null && !filter.getPlatformOrderNo().trim().isEmpty()) {
|
||||
String raw = filter.getPlatformOrderNo().trim();
|
||||
p.setPlatformOrderNo(raw);
|
||||
|
||||
Reference in New Issue
Block a user