@pisell/pisellos 0.10.8 → 0.10.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. package/dist/core/index.js +0 -1
  2. package/dist/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  3. package/dist/model/strategy/adapter/dataVariant/evaluator.js +287 -101
  4. package/dist/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  5. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  6. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -2
  7. package/dist/model/strategy/adapter/walletPass/type.d.ts +5 -0
  8. package/dist/model/strategy/adapter/walletPass/utils.js +57 -26
  9. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +7 -3
  10. package/dist/modules/BookingContext/utils/productExtend.js +5 -9
  11. package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
  12. package/dist/modules/Customer/index.d.ts +4 -0
  13. package/dist/modules/Customer/index.js +91 -59
  14. package/dist/modules/Customer/types.d.ts +2 -0
  15. package/dist/modules/Discount/index.d.ts +2 -0
  16. package/dist/modules/Discount/index.js +38 -5
  17. package/dist/modules/Discount/types.d.ts +11 -0
  18. package/dist/modules/Order/index.d.ts +20 -1
  19. package/dist/modules/Order/index.js +976 -730
  20. package/dist/modules/Order/types.d.ts +6 -1
  21. package/dist/modules/Order/utils/virtualSettlement.d.ts +56 -0
  22. package/dist/modules/Order/utils/virtualSettlement.js +271 -0
  23. package/dist/modules/Order/utils.js +89 -48
  24. package/dist/modules/Payment/types.d.ts +2 -0
  25. package/dist/modules/Payment/utils.js +4 -1
  26. package/dist/modules/Payment/walletpass.d.ts +11 -0
  27. package/dist/modules/Payment/walletpass.js +235 -60
  28. package/dist/modules/Product/types.d.ts +23 -0
  29. package/dist/modules/ProductList/index.d.ts +15 -2
  30. package/dist/modules/ProductList/index.js +92 -13
  31. package/dist/modules/SalesSummary/index.d.ts +1 -0
  32. package/dist/modules/SalesSummary/index.js +4 -3
  33. package/dist/modules/SalesSummary/types.d.ts +1 -0
  34. package/dist/modules/SalesSummary/utils.d.ts +1 -0
  35. package/dist/modules/SalesSummary/utils.js +21 -1
  36. package/dist/server/index.d.ts +9 -0
  37. package/dist/server/index.js +90 -58
  38. package/dist/server/modules/order/index.d.ts +1 -0
  39. package/dist/server/modules/order/index.js +252 -94
  40. package/dist/server/utils/small-ticket.js +2 -1
  41. package/dist/solution/BaseSales/index.d.ts +26 -2
  42. package/dist/solution/BaseSales/index.js +1310 -931
  43. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  44. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +78 -12
  45. package/dist/solution/BookingByStep/index.d.ts +3 -3
  46. package/dist/solution/BookingTicket/index.d.ts +5 -1
  47. package/dist/solution/BookingTicket/index.js +221 -159
  48. package/dist/solution/BookingTicket/utils/addProductDecision.js +2 -1
  49. package/dist/solution/ScanOrder/index.js +25 -64
  50. package/lib/core/index.js +0 -1
  51. package/lib/model/strategy/adapter/dataVariant/evaluator.d.ts +18 -2
  52. package/lib/model/strategy/adapter/dataVariant/evaluator.js +170 -7
  53. package/lib/model/strategy/adapter/dataVariant/type.d.ts +25 -0
  54. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -2
  55. package/lib/model/strategy/adapter/walletPass/type.d.ts +5 -0
  56. package/lib/model/strategy/adapter/walletPass/utils.js +62 -11
  57. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -0
  58. package/lib/modules/BookingContext/utils/productExtend.js +4 -3
  59. package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
  60. package/lib/modules/Customer/index.d.ts +4 -0
  61. package/lib/modules/Customer/index.js +11 -0
  62. package/lib/modules/Customer/types.d.ts +2 -0
  63. package/lib/modules/Discount/index.d.ts +2 -0
  64. package/lib/modules/Discount/index.js +37 -3
  65. package/lib/modules/Discount/types.d.ts +11 -0
  66. package/lib/modules/Order/index.d.ts +20 -1
  67. package/lib/modules/Order/index.js +393 -128
  68. package/lib/modules/Order/types.d.ts +6 -1
  69. package/lib/modules/Order/utils/virtualSettlement.d.ts +56 -0
  70. package/lib/modules/Order/utils/virtualSettlement.js +300 -0
  71. package/lib/modules/Order/utils.js +65 -21
  72. package/lib/modules/Payment/types.d.ts +2 -0
  73. package/lib/modules/Payment/utils.js +5 -1
  74. package/lib/modules/Payment/walletpass.d.ts +11 -0
  75. package/lib/modules/Payment/walletpass.js +198 -17
  76. package/lib/modules/Product/types.d.ts +23 -0
  77. package/lib/modules/ProductList/index.d.ts +15 -2
  78. package/lib/modules/ProductList/index.js +85 -3
  79. package/lib/modules/SalesSummary/index.d.ts +1 -0
  80. package/lib/modules/SalesSummary/index.js +10 -2
  81. package/lib/modules/SalesSummary/types.d.ts +1 -0
  82. package/lib/modules/SalesSummary/utils.d.ts +1 -0
  83. package/lib/modules/SalesSummary/utils.js +25 -1
  84. package/lib/server/index.d.ts +9 -0
  85. package/lib/server/index.js +54 -14
  86. package/lib/server/modules/order/index.d.ts +1 -0
  87. package/lib/server/modules/order/index.js +66 -2
  88. package/lib/server/utils/small-ticket.js +1 -1
  89. package/lib/solution/BaseSales/index.d.ts +26 -2
  90. package/lib/solution/BaseSales/index.js +261 -23
  91. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  92. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +61 -11
  93. package/lib/solution/BookingByStep/index.d.ts +3 -3
  94. package/lib/solution/BookingTicket/index.d.ts +5 -1
  95. package/lib/solution/BookingTicket/index.js +30 -2
  96. package/lib/solution/BookingTicket/utils/addProductDecision.js +2 -1
  97. package/lib/solution/ScanOrder/index.js +17 -54
  98. package/package.json +1 -1
@@ -40,6 +40,7 @@ var import_decimal = __toESM(require("decimal.js"));
40
40
  var import_lodash_es = require("lodash-es");
41
41
  var import_types2 = require("../BookingByStep/types");
42
42
  var import_utils = require("../../modules/Order/utils");
43
+ var import_virtualSettlement = require("../../modules/Order/utils/virtualSettlement");
43
44
  var import_payment_utils = require("../../modules/Order/payment-utils");
44
45
  var import_payment_number = require("../../utils/payment-number");
45
46
  var import_orderCollectionIdentity = require("../../modules/Order/utils/orderCollectionIdentity");
@@ -734,8 +735,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
734
735
  if (businessCode !== void 0 && businessCode !== null && String(businessCode).trim() !== "") {
735
736
  strategyContext.business_code = String(businessCode).trim();
736
737
  }
738
+ const availableWalletIds = this.getAvailableWalletIds();
739
+ if (availableWalletIds.length > 0 && !Array.isArray(strategyContext.available_wallet_ids)) {
740
+ strategyContext.available_wallet_ids = availableWalletIds;
741
+ }
737
742
  return strategyContext;
738
743
  }
744
+ /**
745
+ * 子类可在商品重报价前准备客户维度的策略上下文,例如等待 Wallet/优惠资产加载。
746
+ */
747
+ async prepareProductPriceQueryContext(_customerId) {
748
+ }
749
+ /**
750
+ * 默认保留 BaseSales 的 legacy quotation 行为;已由 /product/query 统一完成
751
+ * 智能定价与报价合并的业务可在子类中覆盖,避免二次覆盖权威价格。
752
+ */
753
+ preferAuthoritativeProductQueryPrice() {
754
+ return false;
755
+ }
739
756
  getPriceQuerySchedule(params) {
740
757
  const booking = params.booking || {};
741
758
  if (typeof booking.start_date === "string" && booking.start_date.trim()) {
@@ -1016,11 +1033,26 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1016
1033
  }
1017
1034
  return (0, import_payment_number.resolvePaymentNumberDevicePrefix)((key) => this.getAppData(key));
1018
1035
  }
1036
+ isMultiCurrencySettlementEnabled() {
1037
+ var _a;
1038
+ return ((_a = this.otherParams) == null ? void 0 : _a.enableMultiCurrencySettlement) === true;
1039
+ }
1040
+ isActiveVirtualSettlementOrder(tempOrder) {
1041
+ return this.isMultiCurrencySettlementEnabled() && (0, import_virtualSettlement.isVirtualSettlementOrder)(tempOrder);
1042
+ }
1043
+ isHistoricalVirtualSettlementOrder(tempOrder) {
1044
+ var _a, _b;
1045
+ return ((_b = (_a = tempOrder == null ? void 0 : tempOrder.metadata) == null ? void 0 : _a.currency_settlement_config) == null ? void 0 : _b.settlement_type) === "virtual_currency";
1046
+ }
1019
1047
  syncAppDataToTempOrder(tempOrder) {
1048
+ var _a, _b, _c;
1020
1049
  const isPriceIncludeTax = this.getAppData("is_price_include_tax");
1021
1050
  const taxCountryCode = this.getAppData("tax_country_code");
1022
1051
  const currencyCode = this.getAppData("shop_currency_code");
1023
1052
  const currencySymbol = this.getAppData("shop_symbol");
1053
+ const isHistoricalVirtualSettlement = this.isHistoricalVirtualSettlementOrder(tempOrder);
1054
+ const isVirtualSettlement = this.isActiveVirtualSettlementOrder(tempOrder) || isHistoricalVirtualSettlement;
1055
+ const shouldManageLegalCurrencySnapshot = this.isMultiCurrencySettlementEnabled() || isHistoricalVirtualSettlement;
1024
1056
  let isChanged = false;
1025
1057
  if (isPriceIncludeTax !== void 0) {
1026
1058
  const nextIsPriceIncludeTax = Number(isPriceIncludeTax);
@@ -1036,14 +1068,32 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1036
1068
  isChanged = true;
1037
1069
  }
1038
1070
  }
1039
- if (currencyCode !== void 0) {
1071
+ tempOrder.metadata = tempOrder.metadata || {};
1072
+ if (shouldManageLegalCurrencySnapshot) {
1073
+ const legalCurrencySnapshot = {
1074
+ currency_code: String(
1075
+ currencyCode ?? ((_a = tempOrder.metadata.legal_currency_snapshot) == null ? void 0 : _a.currency_code) ?? tempOrder.currency_code ?? ""
1076
+ ),
1077
+ currency_symbol: String(
1078
+ currencySymbol ?? ((_b = tempOrder.metadata.legal_currency_snapshot) == null ? void 0 : _b.currency_symbol) ?? tempOrder.currency_symbol ?? ""
1079
+ ),
1080
+ currency_format: String(
1081
+ ((_c = tempOrder.metadata.legal_currency_snapshot) == null ? void 0 : _c.currency_format) || (isVirtualSettlement ? "symbol_first" : tempOrder.currency_format) || "symbol_first"
1082
+ )
1083
+ };
1084
+ if (JSON.stringify(tempOrder.metadata.legal_currency_snapshot || {}) !== JSON.stringify(legalCurrencySnapshot)) {
1085
+ tempOrder.metadata.legal_currency_snapshot = legalCurrencySnapshot;
1086
+ isChanged = true;
1087
+ }
1088
+ }
1089
+ if (!isVirtualSettlement && currencyCode !== void 0) {
1040
1090
  const nextCurrencyCode = String(currencyCode || "");
1041
1091
  if (tempOrder.currency_code !== nextCurrencyCode) {
1042
1092
  tempOrder.currency_code = nextCurrencyCode;
1043
1093
  isChanged = true;
1044
1094
  }
1045
1095
  }
1046
- if (currencySymbol !== void 0) {
1096
+ if (!isVirtualSettlement && currencySymbol !== void 0) {
1047
1097
  const nextCurrencySymbol = String(currencySymbol || "");
1048
1098
  if (tempOrder.currency_symbol !== nextCurrencySymbol) {
1049
1099
  tempOrder.currency_symbol = nextCurrencySymbol;
@@ -1395,6 +1445,24 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1395
1445
  throw error;
1396
1446
  }
1397
1447
  }
1448
+ /** 切换法币 / WalletPass 单位时清空商品、折扣与支付状态,保留客户。 */
1449
+ async clearOrderForSettlementSwitch() {
1450
+ if (!this.store.order)
1451
+ throw new Error("order 模块未初始化");
1452
+ const tempOrder = await this.store.order.clearOrderForSettlementSwitch();
1453
+ if (this.currentSalesDetail) {
1454
+ this.currentSalesDetail = {
1455
+ ...this.currentSalesDetail,
1456
+ products: [],
1457
+ bookings: [],
1458
+ rootBooking: null,
1459
+ bookingsByProductUid: {},
1460
+ discount_list: [],
1461
+ payments: []
1462
+ };
1463
+ }
1464
+ return tempOrder;
1465
+ }
1398
1466
  getOrderProducts() {
1399
1467
  if (!this.store.order)
1400
1468
  throw new Error("order 模块未初始化");
@@ -1521,7 +1589,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1521
1589
  });
1522
1590
  }
1523
1591
  async loadDiscountConfig(params) {
1524
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
1592
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
1525
1593
  if (!this.store.order)
1526
1594
  throw new Error("order 模块未初始化");
1527
1595
  const tempOrder = this.store.order.ensureTempOrder();
@@ -1543,7 +1611,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1543
1611
  ].join(":");
1544
1612
  let preparedDiscountList = [];
1545
1613
  if (customerId && customerId !== 1) {
1546
- if (this.discountConfigCacheKey === discountConfigCacheKey) {
1614
+ if (!(params == null ? void 0 : params.force) && this.discountConfigCacheKey === discountConfigCacheKey) {
1547
1615
  preparedDiscountList = originalDiscountList;
1548
1616
  } else {
1549
1617
  preparedDiscountList = await this.store.order.loadDiscountConfig({
@@ -1556,15 +1624,28 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1556
1624
  await ((_j = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _j.call(discountModule, preparedDiscountList));
1557
1625
  }
1558
1626
  }
1627
+ if (this.isActiveVirtualSettlementOrder(tempOrder)) {
1628
+ await ((_k = discountModule == null ? void 0 : discountModule.setOriginalDiscountList) == null ? void 0 : _k.call(discountModule, []));
1629
+ await ((_l = discountModule == null ? void 0 : discountModule.setDiscountList) == null ? void 0 : _l.call(discountModule, []));
1630
+ tempOrder.discount_list = [];
1631
+ tempOrder.shop_discount = "0.00";
1632
+ return {
1633
+ productList: tempOrder.products || [],
1634
+ discountList: [],
1635
+ availableWalletIds: this.getAvailableWalletIds(),
1636
+ virtualCurrencyList: this.store.order.getVirtualCurrencyList()
1637
+ };
1638
+ }
1559
1639
  if (hasManualDiscountSelection && currentDiscountList.length) {
1560
1640
  return {
1561
1641
  productList: tempOrder.products || [],
1562
1642
  discountList: currentDiscountList,
1563
- availableWalletIds: this.getAvailableWalletIds()
1643
+ availableWalletIds: this.getAvailableWalletIds(),
1644
+ virtualCurrencyList: this.store.order.getVirtualCurrencyList()
1564
1645
  };
1565
1646
  }
1566
1647
  let nextDiscountList = this.mergeHistoricalDiscountList(
1567
- preparedDiscountList || ((_k = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _k.call(discountModule)) || [],
1648
+ preparedDiscountList || ((_m = discountModule == null ? void 0 : discountModule.getDiscountList) == null ? void 0 : _m.call(discountModule)) || [],
1568
1649
  tempOrder.products || []
1569
1650
  );
1570
1651
  nextDiscountList = this.mergeCurrentDiscountSelectionState(
@@ -1590,11 +1671,12 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1590
1671
  return {
1591
1672
  productList: tempOrder.products || [],
1592
1673
  discountList: nextDiscountList,
1593
- availableWalletIds: this.getAvailableWalletIds()
1674
+ availableWalletIds: this.getAvailableWalletIds(),
1675
+ virtualCurrencyList: this.store.order.getVirtualCurrencyList()
1594
1676
  };
1595
1677
  }
1596
1678
  if (rulesModule) {
1597
- const orderTotalAmount = Number(((_l = orderStore.summary) == null ? void 0 : _l.total_amount) || 0);
1679
+ const orderTotalAmount = Number(((_n = orderStore.summary) == null ? void 0 : _n.total_amount) || 0);
1598
1680
  console.log("[BaseSales.applyDiscountConfig.calcDiscount]");
1599
1681
  const result = rulesModule.calcDiscount({
1600
1682
  productList: tempOrder.products,
@@ -1610,8 +1692,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1610
1692
  );
1611
1693
  }
1612
1694
  for (const product of tempOrder.products || []) {
1613
- const productUid = (_m = product.metadata) == null ? void 0 : _m.unique_identification_number;
1614
- const runtimeOrigin = productUid ? (_p = (_o = (_n = tempOrder._extend) == null ? void 0 : _n.productsByUid) == null ? void 0 : _o[productUid]) == null ? void 0 : _p.origin : void 0;
1695
+ const productUid = (_o = product.metadata) == null ? void 0 : _o.unique_identification_number;
1696
+ const runtimeOrigin = productUid ? (_r = (_q = (_p = tempOrder._extend) == null ? void 0 : _p.productsByUid) == null ? void 0 : _q[productUid]) == null ? void 0 : _r.origin : void 0;
1615
1697
  if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
1616
1698
  continue;
1617
1699
  const totalPerUnitDiscount = (product.discount_list || []).reduce(
@@ -1619,7 +1701,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1619
1701
  0
1620
1702
  );
1621
1703
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
1622
- const sourcePrice = ((_q = product.metadata) == null ? void 0 : _q.source_product_price) ?? (((_r = product.metadata) == null ? void 0 : _r.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
1704
+ const sourcePrice = ((_s = product.metadata) == null ? void 0 : _s.source_product_price) ?? (((_t = product.metadata) == null ? void 0 : _t.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
1623
1705
  const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1624
1706
  const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1625
1707
  if (product.metadata) {
@@ -1652,7 +1734,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1652
1734
  return {
1653
1735
  productList: tempOrder.products || [],
1654
1736
  discountList: nextDiscountList,
1655
- availableWalletIds: this.getAvailableWalletIds()
1737
+ availableWalletIds: this.getAvailableWalletIds(),
1738
+ virtualCurrencyList: this.store.order.getVirtualCurrencyList()
1656
1739
  };
1657
1740
  }
1658
1741
  getAvailableWalletIds() {
@@ -1661,11 +1744,25 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1661
1744
  return [];
1662
1745
  return this.store.order.getAvailableWalletIds();
1663
1746
  }
1747
+ getVirtualCurrencyList() {
1748
+ var _a;
1749
+ if (!((_a = this.store.order) == null ? void 0 : _a.getVirtualCurrencyList))
1750
+ return [];
1751
+ return this.store.order.getVirtualCurrencyList();
1752
+ }
1664
1753
  async bestDiscount(cb) {
1665
1754
  var _a, _b, _c;
1666
1755
  if (!this.store.order)
1667
1756
  throw new Error("order 模块未初始化");
1668
1757
  const tempOrder = this.store.order.ensureTempOrder();
1758
+ if (this.isActiveVirtualSettlementOrder(tempOrder)) {
1759
+ const result2 = {
1760
+ productList: tempOrder.products || [],
1761
+ discountList: []
1762
+ };
1763
+ cb == null ? void 0 : cb(result2);
1764
+ return result2;
1765
+ }
1669
1766
  const orderStore = this.store.order.store || {};
1670
1767
  const discountModule = orderStore.discount;
1671
1768
  const rulesModule = orderStore.rules;
@@ -1779,10 +1876,19 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1779
1876
  }
1780
1877
  // TODO 需要优化,这段逻辑太长了,里面应该有些历史遗留问题
1781
1878
  async setDiscountSelected(params) {
1782
- var _a, _b, _c, _d, _e, _f, _g;
1879
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
1783
1880
  try {
1784
1881
  if (!this.store.order)
1785
1882
  throw new Error("order 模块未初始化");
1883
+ const currentOrder = this.store.order.ensureTempOrder();
1884
+ if (this.isActiveVirtualSettlementOrder(currentOrder)) {
1885
+ currentOrder.discount_list = [];
1886
+ currentOrder.shop_discount = "0.00";
1887
+ await ((_c = (_b = (_a = this.store.order.store) == null ? void 0 : _a.discount) == null ? void 0 : _b.setDiscountList) == null ? void 0 : _c.call(_b, []));
1888
+ await this.store.order.recalculateSummary({ createIfMissing: true });
1889
+ this.store.order.persistTempOrder();
1890
+ return;
1891
+ }
1786
1892
  const list = this.store.order.getDiscountList();
1787
1893
  const updated = list.map(
1788
1894
  (d) => d.id === params.discountId && !isBaseSalesHistoricalDiscountEntry(d) ? {
@@ -1799,7 +1905,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1799
1905
  let nextDiscountList = updated;
1800
1906
  await (discountModule == null ? void 0 : discountModule.setDiscountList(updated));
1801
1907
  if (rulesModule) {
1802
- const orderTotalAmount = Number(((_a = orderStore.summary) == null ? void 0 : _a.total_amount) || 0);
1908
+ const orderTotalAmount = Number(((_d = orderStore.summary) == null ? void 0 : _d.total_amount) || 0);
1803
1909
  console.log("[BaseSales.setDiscountSelected.calcDiscount]");
1804
1910
  const result = rulesModule.calcDiscount(
1805
1911
  {
@@ -1845,8 +1951,8 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1845
1951
  return rid != null && selectedResourceIds.has(rid);
1846
1952
  });
1847
1953
  for (const product of tempOrder.products) {
1848
- const productUid = (_b = product.metadata) == null ? void 0 : _b.unique_identification_number;
1849
- const runtimeOrigin = productUid ? (_e = (_d = (_c = tempOrder._extend) == null ? void 0 : _c.productsByUid) == null ? void 0 : _d[productUid]) == null ? void 0 : _e.origin : void 0;
1954
+ const productUid = (_e = product.metadata) == null ? void 0 : _e.unique_identification_number;
1955
+ const runtimeOrigin = productUid ? (_h = (_g = (_f = tempOrder._extend) == null ? void 0 : _f.productsByUid) == null ? void 0 : _g[productUid]) == null ? void 0 : _h.origin : void 0;
1850
1956
  if ((runtimeOrigin == null ? void 0 : runtimeOrigin.isManualDiscount) || isBaseSalesManualProductDiscountProduct(product))
1851
1957
  continue;
1852
1958
  product.discount_list = filterSelectedDiscountDetails(product.discount_list);
@@ -1870,7 +1976,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1870
1976
  0
1871
1977
  );
1872
1978
  const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
1873
- const sourcePrice = ((_f = product.metadata) == null ? void 0 : _f.source_product_price) ?? (((_g = product.metadata) == null ? void 0 : _g.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
1979
+ const sourcePrice = ((_i = product.metadata) == null ? void 0 : _i.source_product_price) ?? (((_j = product.metadata) == null ? void 0 : _j.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
1874
1980
  const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
1875
1981
  const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
1876
1982
  if (product.metadata) {
@@ -1937,6 +2043,88 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1937
2043
  async submitScanOrder(params) {
1938
2044
  return this.submitSalesOrder(params);
1939
2045
  }
2046
+ async buildVirtualSettlementSubmitData() {
2047
+ var _a, _b, _c;
2048
+ if (!this.store.order)
2049
+ return null;
2050
+ const tempOrder = this.store.order.getTempOrder();
2051
+ if (!this.isActiveVirtualSettlementOrder(tempOrder))
2052
+ return null;
2053
+ const snapshot = (0, import_virtualSettlement.getTempOrderSettlementSnapshot)(tempOrder);
2054
+ const currencyProductId = Number(
2055
+ ((_c = (_b = (_a = tempOrder == null ? void 0 : tempOrder.metadata) == null ? void 0 : _a.currency_settlement_config) == null ? void 0 : _b.settlement_ids) == null ? void 0 : _c[0]) ?? (snapshot == null ? void 0 : snapshot.currency_product_id)
2056
+ );
2057
+ if (!snapshot || !Number.isFinite(currencyProductId) || currencyProductId <= 0) {
2058
+ throw new Error("Virtual currency settlement configuration is invalid.");
2059
+ }
2060
+ const summary = await this.store.order.recalculateSummary({ createIfMissing: true });
2061
+ const amount = new import_decimal.default(
2062
+ (summary == null ? void 0 : summary.total_amount) || 0
2063
+ ).toDecimalPlaces(2);
2064
+ const customerId = Number((tempOrder == null ? void 0 : tempOrder.customer_id) || 0);
2065
+ if (amount.gt(0) && customerId > 0 && customerId !== 1) {
2066
+ await this.store.order.loadDiscountConfig({
2067
+ customerId,
2068
+ action: (tempOrder == null ? void 0 : tempOrder.order_id) ? "edit" : "create",
2069
+ orderId: Number(tempOrder == null ? void 0 : tempOrder.order_id) || void 0,
2070
+ apply: false
2071
+ });
2072
+ }
2073
+ const asset = this.store.order.getVirtualCurrencyList().find(
2074
+ (item) => Number(item == null ? void 0 : item.product_id) === currencyProductId
2075
+ );
2076
+ const currencyCode = String((tempOrder == null ? void 0 : tempOrder.currency_code) || "");
2077
+ const currencySymbol = String((tempOrder == null ? void 0 : tempOrder.currency_symbol) || "");
2078
+ const currencyFormat = String((tempOrder == null ? void 0 : tempOrder.currency_format) || "symbol_first");
2079
+ if (amount.lte(0)) {
2080
+ return {
2081
+ payments: [],
2082
+ snapshot,
2083
+ currencyProductId,
2084
+ currencyCode,
2085
+ currencySymbol,
2086
+ currencyFormat
2087
+ };
2088
+ }
2089
+ if (!asset) {
2090
+ throw new Error("No matching virtual currency card is available.");
2091
+ }
2092
+ const balance = new import_decimal.default(asset.balance || 0);
2093
+ if (balance.lt(amount)) {
2094
+ throw new Error("Insufficient virtual currency balance.");
2095
+ }
2096
+ const paymentMethods = await this.getPaymentMethodsAsync();
2097
+ const paymentMethod = paymentMethods.find(
2098
+ (method) => String(method.code || "").toUpperCase() === "PRODUCTVOUCHER"
2099
+ );
2100
+ if (!paymentMethod) {
2101
+ throw new Error("PRODUCTVOUCHER payment method is unavailable.");
2102
+ }
2103
+ const amountText = amount.toFixed(2);
2104
+ const payment = {
2105
+ payment_number: `LOCAL_${(0, import_utils.createUuidV4)()}`,
2106
+ amount: amountText,
2107
+ origin_amount: amountText,
2108
+ code: paymentMethod.code,
2109
+ custom_payment_id: paymentMethod.id,
2110
+ custom_payment_type: paymentMethod.custom_payment_type ?? paymentMethod.type,
2111
+ name: paymentMethod.name,
2112
+ type: "normal",
2113
+ voucher_id: asset.id,
2114
+ order_payment_type: "normal",
2115
+ wallet_pass_usage_unit: { price: 1, points: 1 },
2116
+ wallet_pass_use_value: amountText,
2117
+ metadata: {}
2118
+ };
2119
+ return {
2120
+ payments: [payment],
2121
+ snapshot,
2122
+ currencyProductId,
2123
+ currencyCode,
2124
+ currencySymbol,
2125
+ currencyFormat
2126
+ };
2127
+ }
1940
2128
  /**
1941
2129
  * 提交当前 Sales 订单。
1942
2130
  *
@@ -1948,6 +2136,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1948
2136
  if (!this.store.order) {
1949
2137
  throw new Error("BaseSales 解决方案需要 order 模块支持");
1950
2138
  }
2139
+ const virtualSettlement = await this.buildVirtualSettlementSubmitData();
1951
2140
  const inferredPaymentStatus = this.getSubmitPaymentStatus(params == null ? void 0 : params.paymentStatus);
1952
2141
  const smallTicketDataFlag = (params == null ? void 0 : params.smallTicketDataFlag) ?? this.getDefaultCheckoutSmallTicketDataFlag();
1953
2142
  const submitParams = {
@@ -1957,11 +2146,30 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
1957
2146
  channel: this.getSubmitOrderSalesChannel(),
1958
2147
  type: (_d = this.otherParams) == null ? void 0 : _d.type,
1959
2148
  request_unique_idempotency_token: this.store.order.generateIdempotencyToken(),
1960
- ...(params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
2149
+ ...virtualSettlement ? { payments: virtualSettlement.payments } : (params == null ? void 0 : params.payments) !== void 0 ? { payments: params.payments } : {},
1961
2150
  ...inferredPaymentStatus !== void 0 ? { paymentStatus: inferredPaymentStatus } : {},
1962
2151
  ...smallTicketDataFlag !== void 0 ? { smallTicketDataFlag } : {},
1963
- ...(params == null ? void 0 : params.confirmPendingVoucherPayments) !== void 0 ? { confirmPendingVoucherPayments: params.confirmPendingVoucherPayments } : {},
1964
- ...(params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
2152
+ ...virtualSettlement ? {
2153
+ confirmPendingVoucherPayments: false
2154
+ } : (params == null ? void 0 : params.confirmPendingVoucherPayments) !== void 0 ? { confirmPendingVoucherPayments: params.confirmPendingVoucherPayments } : {},
2155
+ ...virtualSettlement ? {
2156
+ enhancePayload: (payload, ctx) => {
2157
+ const callerPayload = (params == null ? void 0 : params.enhancePayload) ? params.enhancePayload(payload, ctx) : payload;
2158
+ return {
2159
+ ...callerPayload,
2160
+ metadata: {
2161
+ ...callerPayload.metadata || {},
2162
+ currency_settlement_config: {
2163
+ settlement_type: "virtual_currency",
2164
+ settlement_ids: [virtualSettlement.currencyProductId]
2165
+ }
2166
+ },
2167
+ currency_code: virtualSettlement.currencyCode,
2168
+ currency_symbol: virtualSettlement.currencySymbol,
2169
+ currency_format: virtualSettlement.currencyFormat
2170
+ };
2171
+ }
2172
+ } : (params == null ? void 0 : params.enhancePayload) !== void 0 ? { enhancePayload: params.enhancePayload } : {}
1965
2173
  };
1966
2174
  return this.shouldUseCheckoutSyncTask() ? this.store.order.submitTempOrder(submitParams) : this.store.order.submitTempOrderAsync(submitParams);
1967
2175
  }
@@ -2670,11 +2878,27 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
2670
2878
  await this.syncSelectedWalletAssets(state);
2671
2879
  return this.publishWalletAssetsState(state);
2672
2880
  }
2881
+ /** 更新已选钱包资产的手动使用金额,并同步 pending payment。 */
2882
+ async updateWalletAssetAmount(params) {
2883
+ if (!this.store.payment)
2884
+ throw new Error("payment 模块未初始化");
2885
+ const state = this.store.payment.wallet.updateWalletAssetAmount(
2886
+ params.assetId,
2887
+ params.amount
2888
+ );
2889
+ await this.syncSelectedWalletAssets(state);
2890
+ return this.publishWalletAssetsState(state);
2891
+ }
2673
2892
  /** 扫码精确查券;仅可用资产会被自动选中。 */
2674
2893
  async scanWalletAsset(code) {
2675
2894
  if (!this.store.payment)
2676
2895
  throw new Error("payment 模块未初始化");
2677
- const result = await this.store.payment.wallet.scanWalletAssetAsync(code);
2896
+ const wallet = this.store.payment.wallet;
2897
+ const businessData = this.buildWalletInitBusinessData();
2898
+ if (businessData) {
2899
+ wallet.generateWalletParams(businessData);
2900
+ }
2901
+ const result = await wallet.scanWalletAssetAsync(code);
2678
2902
  if (result.type === "normalCode") {
2679
2903
  await this.syncSelectedWalletAssets(result.state);
2680
2904
  await this.publishWalletAssetsState(result.state);
@@ -3113,6 +3337,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
3113
3337
  async calculateProductBookingPrice(params) {
3114
3338
  const quotation = this.store.quotation;
3115
3339
  const customerId = params.customer_id ?? this.getCurrentOrderCustomerId();
3340
+ await this.prepareProductPriceQueryContext(customerId);
3116
3341
  const authoritativeProduct = await this.loadProductForPriceQuery(params, customerId);
3117
3342
  const product = this.mergeProductForPriceQuery(params.product, authoritativeProduct);
3118
3343
  await this.loadQuotationForPriceQuery({
@@ -3125,7 +3350,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
3125
3350
  product,
3126
3351
  fallback_price: authoritativeProduct ? void 0 : params.fallback_price,
3127
3352
  customer_id: customerId,
3128
- quotation
3353
+ quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? void 0 : quotation
3129
3354
  });
3130
3355
  }
3131
3356
  getQuotationCustomerScopeInfo() {
@@ -3162,11 +3387,23 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
3162
3387
  quotationScopes
3163
3388
  };
3164
3389
  }
3390
+ hasSmartPricingStrategies() {
3391
+ var _a, _b;
3392
+ const evaluator = (_b = (_a = this.core) == null ? void 0 : _a.context) == null ? void 0 : _b.dataVariantEvaluator;
3393
+ if (!evaluator || typeof evaluator.getStrategyConfigs !== "function") {
3394
+ return false;
3395
+ }
3396
+ const configs = evaluator.getStrategyConfigs();
3397
+ return Array.isArray(configs) && configs.length > 0;
3398
+ }
3165
3399
  shouldRecalculateProductBookingPricesForContextChange(params) {
3166
3400
  const scopeInfo = this.getQuotationCustomerScopeInfo();
3167
3401
  const scopedCustomerIds = new Set(scopeInfo.customerIds.map((id) => String(id)));
3168
3402
  const previousCustomerId = this.normalizePriceContextCustomerId(params.previousCustomerId);
3169
3403
  const nextCustomerId = this.normalizePriceContextCustomerId(params.nextCustomerId);
3404
+ if (this.hasSmartPricingStrategies()) {
3405
+ return previousCustomerId !== nextCustomerId;
3406
+ }
3170
3407
  const previousInScope = previousCustomerId ? scopedCustomerIds.has(previousCustomerId) : false;
3171
3408
  const nextInScope = nextCustomerId ? scopedCustomerIds.has(nextCustomerId) : false;
3172
3409
  let shouldRecalculate = false;
@@ -3187,6 +3424,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
3187
3424
  return [];
3188
3425
  const quotation = this.store.quotation;
3189
3426
  const customerId = ((_a = paramsList[0]) == null ? void 0 : _a.customer_id) ?? this.getCurrentOrderCustomerId();
3427
+ await this.prepareProductPriceQueryContext(customerId);
3190
3428
  const productMapsByGroup = /* @__PURE__ */ new Map();
3191
3429
  const groups = /* @__PURE__ */ new Map();
3192
3430
  paramsList.forEach((params) => {
@@ -3244,7 +3482,7 @@ var BaseSalesImpl = class extends import_BaseModule.BaseModule {
3244
3482
  product,
3245
3483
  fallback_price: authoritativeProduct ? void 0 : params.fallback_price,
3246
3484
  customer_id: customerId,
3247
- quotation
3485
+ quotation: authoritativeProduct && this.preferAuthoritativeProductQueryPrice() ? void 0 : quotation
3248
3486
  });
3249
3487
  });
3250
3488
  }
@@ -43,6 +43,7 @@ export interface BaseProductDetailPayload {
43
43
  original_price?: number | string;
44
44
  tax_fee?: number | string;
45
45
  is_charge_tax?: number;
46
+ metadata?: Record<string, any>;
46
47
  note?: string;
47
48
  [key: string]: any;
48
49
  }
@@ -56,6 +56,25 @@ function isBlankValue(value) {
56
56
  function firstNonBlank(...values) {
57
57
  return values.find((value) => !isBlankValue(value));
58
58
  }
59
+ function cloneFirstDataVariantIds(...values) {
60
+ const ids = values.find((value) => Array.isArray(value));
61
+ return Array.isArray(ids) ? [...ids] : void 0;
62
+ }
63
+ function appendDataVariantIds(base, ...values) {
64
+ const result = Array.isArray(base) ? [...base] : [];
65
+ const seen = new Set(result.map((id) => String(id)));
66
+ for (const value of values) {
67
+ const candidates = Array.isArray(value) ? value : [value];
68
+ for (const candidate of candidates) {
69
+ const id = Number(candidate);
70
+ if (!Number.isFinite(id) || id <= 0 || seen.has(String(id)))
71
+ continue;
72
+ result.push(id);
73
+ seen.add(String(id));
74
+ }
75
+ }
76
+ return Array.isArray(base) || result.length ? result : void 0;
77
+ }
59
78
  function normalizeOptionItems(optionItems) {
60
79
  if (!Array.isArray(optionItems))
61
80
  return [];
@@ -112,7 +131,7 @@ function findVariantById(origin, variantId) {
112
131
  return variants.find((variant) => Number(variant == null ? void 0 : variant.id) === variantId) || null;
113
132
  }
114
133
  function transformBaseProductToOrderProduct(params) {
115
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
134
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C;
116
135
  const { payload, fallbackProductId = null } = params;
117
136
  if (!payload || typeof payload !== "object")
118
137
  return null;
@@ -131,6 +150,32 @@ function transformBaseProductToOrderProduct(params) {
131
150
  ...sourceProduct || {},
132
151
  ...callbackOrigin || {}
133
152
  };
153
+ const authoritativeDataVariantIds = cloneFirstDataVariantIds(
154
+ (_c = payload.metadata) == null ? void 0 : _c.data_variant_ids,
155
+ (_d = sourceProduct == null ? void 0 : sourceProduct.metadata) == null ? void 0 : _d.data_variant_ids,
156
+ (_e = callbackOrigin == null ? void 0 : callbackOrigin.metadata) == null ? void 0 : _e.data_variant_ids,
157
+ (_f = origin == null ? void 0 : origin.metadata) == null ? void 0 : _f.data_variant_ids
158
+ );
159
+ const selectedSettlementSnapshot = firstNonBlank(
160
+ payload.selected_settlement_snapshot,
161
+ (_g = payload.metadata) == null ? void 0 : _g.selected_settlement_snapshot,
162
+ (_i = (_h = payload._extend) == null ? void 0 : _h.metadata) == null ? void 0 : _i.selected_settlement_snapshot,
163
+ (_j = sourceProduct == null ? void 0 : sourceProduct.metadata) == null ? void 0 : _j.selected_settlement_snapshot,
164
+ (_l = (_k = sourceProduct == null ? void 0 : sourceProduct._extend) == null ? void 0 : _k.metadata) == null ? void 0 : _l.selected_settlement_snapshot,
165
+ (_m = callbackOrigin == null ? void 0 : callbackOrigin.metadata) == null ? void 0 : _m.selected_settlement_snapshot,
166
+ (_o = (_n = callbackOrigin == null ? void 0 : callbackOrigin._extend) == null ? void 0 : _n.metadata) == null ? void 0 : _o.selected_settlement_snapshot
167
+ );
168
+ const locallyAppliedVariantIds = authoritativeDataVariantIds === void 0 ? cloneFirstDataVariantIds(
169
+ (_p = payload._dataVariant) == null ? void 0 : _p.appliedVariantIds,
170
+ (_q = sourceProduct == null ? void 0 : sourceProduct._dataVariant) == null ? void 0 : _q.appliedVariantIds,
171
+ (_r = callbackOrigin == null ? void 0 : callbackOrigin._dataVariant) == null ? void 0 : _r.appliedVariantIds,
172
+ (_s = origin == null ? void 0 : origin._dataVariant) == null ? void 0 : _s.appliedVariantIds
173
+ ) : void 0;
174
+ const dataVariantIds = appendDataVariantIds(
175
+ authoritativeDataVariantIds,
176
+ locallyAppliedVariantIds,
177
+ selectedSettlementSnapshot == null ? void 0 : selectedSettlementSnapshot.data_variant_id
178
+ );
134
179
  const matchedVariant = findVariantById(callbackOrigin, productVariantId) ?? findVariantById(sourceProduct, productVariantId) ?? findVariantById(origin, productVariantId);
135
180
  const hasPriceOverride = payload.price_override !== void 0 && payload.price_override !== null && payload.price_override !== "";
136
181
  const catalogSourcePrice = (matchedVariant == null ? void 0 : matchedVariant.price) ?? (matchedVariant == null ? void 0 : matchedVariant.base_price) ?? (origin == null ? void 0 : origin.price) ?? (origin == null ? void 0 : origin.base_price) ?? (sourceProduct == null ? void 0 : sourceProduct.price) ?? (sourceProduct == null ? void 0 : sourceProduct.selling_price) ?? (sourceProduct == null ? void 0 : sourceProduct.base_price);
@@ -138,12 +183,12 @@ function transformBaseProductToOrderProduct(params) {
138
183
  hasPriceOverride ? catalogSourcePrice ?? payload.price ?? payload.selling_price : payload.price ?? payload.selling_price ?? catalogSourcePrice,
139
184
  "0.00"
140
185
  );
141
- const explicitLineTotal = payload.line_total ?? payload.total ?? ((_c = payload._extend) == null ? void 0 : _c.total);
186
+ const explicitLineTotal = payload.line_total ?? payload.total ?? ((_t = payload._extend) == null ? void 0 : _t.total);
142
187
  const hasExplicitLineTotal = Number.isFinite(Number(explicitLineTotal));
143
188
  const lineCompositeTotal = toPriceString(explicitLineTotal, sourceProductPrice);
144
189
  const productOptionItem = (0, import_utils.normalizeProductSkuOptions)(
145
190
  normalizeOptionItems(
146
- ((_d = payload.product_sku) == null ? void 0 : _d.option) ?? payload.option ?? payload.options ?? payload.product_option_item
191
+ ((_u = payload.product_sku) == null ? void 0 : _u.option) ?? payload.option ?? payload.options ?? payload.product_option_item
147
192
  )
148
193
  );
149
194
  const productBundle = normalizeBundleItems(
@@ -154,19 +199,19 @@ function transformBaseProductToOrderProduct(params) {
154
199
  const resolvedQuantity = toSafePositiveInt(payload.quantity ?? payload.num, 1);
155
200
  const originTotal = (0, import_manualProductDiscount.resolveManualDiscountOriginTotal)({
156
201
  originTotal: payload.origin_total,
157
- extendOriginTotal: (_e = payload._extend) == null ? void 0 : _e.origin_total,
158
- originExtendOriginTotal: (_f = origin == null ? void 0 : origin._extend) == null ? void 0 : _f.origin_total,
159
- sourceExtendOriginTotal: (_g = sourceProduct == null ? void 0 : sourceProduct._extend) == null ? void 0 : _g.origin_total,
202
+ extendOriginTotal: (_v = payload._extend) == null ? void 0 : _v.origin_total,
203
+ originExtendOriginTotal: (_w = origin == null ? void 0 : origin._extend) == null ? void 0 : _w.origin_total,
204
+ sourceExtendOriginTotal: (_x = sourceProduct == null ? void 0 : sourceProduct._extend) == null ? void 0 : _x.origin_total,
160
205
  catalogUnitPrice: (origin == null ? void 0 : origin.base_price) ?? (origin == null ? void 0 : origin.price) ?? (sourceProduct == null ? void 0 : sourceProduct.base_price) ?? (sourceProduct == null ? void 0 : sourceProduct.price),
161
206
  quantity: resolvedQuantity
162
207
  });
163
208
  const sellingTotal = Number(
164
- payload.line_total ?? payload.total ?? ((_h = payload._extend) == null ? void 0 : _h.total) ?? lineCompositeTotal
209
+ payload.line_total ?? payload.total ?? ((_y = payload._extend) == null ? void 0 : _y.total) ?? lineCompositeTotal
165
210
  );
166
211
  const discountReason = (0, import_manualProductDiscount.resolveManualDiscountReasonFromSources)({
167
212
  discountReason: payload.discount_reason,
168
- extendDiscountReason: (_i = payload._extend) == null ? void 0 : _i.discount_reason,
169
- originExtendDiscountReason: (_j = origin == null ? void 0 : origin._extend) == null ? void 0 : _j.discount_reason
213
+ extendDiscountReason: (_z = payload._extend) == null ? void 0 : _z.discount_reason,
214
+ originExtendDiscountReason: (_A = origin == null ? void 0 : origin._extend) == null ? void 0 : _A.discount_reason
170
215
  });
171
216
  const lineOriginalPrice = hasPriceOverride && Number.isFinite(originTotal) ? toPriceString(originTotal) : lineCompositeTotal;
172
217
  const manualDiscountList = (0, import_manualProductDiscount.shouldBuildManualProductDiscount)({
@@ -180,8 +225,8 @@ function transformBaseProductToOrderProduct(params) {
180
225
  sellingTotal: Number.isFinite(sellingTotal) ? sellingTotal : Number(lineCompositeTotal),
181
226
  quantity: resolvedQuantity,
182
227
  message: discountReason,
183
- discountway: (_k = payload._extend) == null ? void 0 : _k.discountway,
184
- discount_per: (_l = payload._extend) == null ? void 0 : _l.discount_per
228
+ discountway: (_B = payload._extend) == null ? void 0 : _B.discountway,
229
+ discount_per: (_C = payload._extend) == null ? void 0 : _C.discount_per
185
230
  })
186
231
  ) : payload.discount_list || [];
187
232
  const optionSum = (0, import_utils.sumOptionUnitPrice)(productOptionItem).toNumber();
@@ -206,6 +251,10 @@ function transformBaseProductToOrderProduct(params) {
206
251
  main_product_original_price: mainProductOriginalPrice,
207
252
  price_schema_version: 2,
208
253
  holder_config: sourceProduct == null ? void 0 : sourceProduct.holder_config,
254
+ ...dataVariantIds !== void 0 ? { data_variant_ids: dataVariantIds } : {},
255
+ ...selectedSettlementSnapshot ? {
256
+ selected_settlement_snapshot: selectedSettlementSnapshot
257
+ } : {},
209
258
  ...hasPriceOverride ? {
210
259
  price_override: String(payload.price_override),
211
260
  is_manual_discount: 1
@@ -230,6 +279,7 @@ function transformBaseProductToOrderProduct(params) {
230
279
  },
231
280
  product_bundle: productBundle,
232
281
  discount_list: manualDiscountList,
282
+ ...payload.bundle_edit !== void 0 ? { bundle_edit: payload.bundle_edit } : {},
233
283
  // 折后行价由 normalizeOrderProduct 按 main + bundle 合成;手动改价时 bundle 已为分摊后单价
234
284
  selling_price: lineCompositeTotal,
235
285
  original_price: lineOriginalPrice,