@pisell/pisellos 2.2.189 → 2.2.191

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 (65) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  3. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -7
  4. package/dist/modules/Cart/utils/cartProduct.js +13 -2
  5. package/dist/modules/Order/index.d.ts +1 -3
  6. package/dist/modules/Order/index.js +88 -114
  7. package/dist/modules/Order/types.d.ts +10 -6
  8. package/dist/modules/Order/utils.d.ts +9 -2
  9. package/dist/modules/Order/utils.js +36 -13
  10. package/dist/modules/SalesSummary/types.d.ts +3 -1
  11. package/dist/modules/SalesSummary/utils.js +7 -3
  12. package/dist/server/modules/order/index.d.ts +126 -6
  13. package/dist/server/modules/order/index.js +1204 -285
  14. package/dist/server/modules/order/types.d.ts +0 -2
  15. package/dist/server/modules/products/index.d.ts +90 -6
  16. package/dist/server/modules/products/index.js +1017 -361
  17. package/dist/solution/BaseSales/index.js +54 -39
  18. package/dist/solution/BaseSales/types.d.ts +8 -5
  19. package/dist/solution/BaseSales/types.js +2 -3
  20. package/dist/solution/BaseSales/utils/cartPromotion.js +7 -7
  21. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  22. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +29 -14
  23. package/dist/solution/BaseSales/utils.d.ts +1 -1
  24. package/dist/solution/BaseSales/utils.js +22 -19
  25. package/dist/solution/BookingByStep/index.d.ts +1 -1
  26. package/dist/solution/ScanOrder/index.js +7 -5
  27. package/dist/solution/ScanOrder/types.d.ts +8 -5
  28. package/dist/solution/ScanOrder/types.js +2 -3
  29. package/dist/solution/ScanOrder/utils.d.ts +1 -1
  30. package/dist/solution/ScanOrder/utils.js +26 -23
  31. package/dist/solution/VenueBooking/index.js +5 -3
  32. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  33. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  34. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  35. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  36. package/lib/modules/Cart/utils/cartProduct.js +9 -2
  37. package/lib/modules/Order/index.d.ts +1 -3
  38. package/lib/modules/Order/index.js +50 -63
  39. package/lib/modules/Order/types.d.ts +10 -6
  40. package/lib/modules/Order/utils.d.ts +9 -2
  41. package/lib/modules/Order/utils.js +41 -10
  42. package/lib/modules/SalesSummary/types.d.ts +3 -1
  43. package/lib/modules/SalesSummary/utils.js +5 -3
  44. package/lib/server/modules/order/index.d.ts +126 -6
  45. package/lib/server/modules/order/index.js +722 -42
  46. package/lib/server/modules/order/types.d.ts +0 -2
  47. package/lib/server/modules/products/index.d.ts +90 -6
  48. package/lib/server/modules/products/index.js +492 -30
  49. package/lib/solution/BaseSales/index.js +26 -8
  50. package/lib/solution/BaseSales/types.d.ts +8 -5
  51. package/lib/solution/BaseSales/utils/cartPromotion.js +6 -6
  52. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.d.ts +1 -0
  53. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +32 -16
  54. package/lib/solution/BaseSales/utils.d.ts +1 -1
  55. package/lib/solution/BaseSales/utils.js +11 -7
  56. package/lib/solution/BookingByStep/index.d.ts +1 -1
  57. package/lib/solution/ScanOrder/index.js +4 -4
  58. package/lib/solution/ScanOrder/types.d.ts +8 -5
  59. package/lib/solution/ScanOrder/utils.d.ts +1 -1
  60. package/lib/solution/ScanOrder/utils.js +12 -8
  61. package/lib/solution/VenueBooking/index.js +2 -2
  62. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -2
  63. package/package.json +1 -1
  64. package/dist/solution/Checkout/appointmentDemo.json +0 -1
  65. package/lib/solution/Checkout/appointmentDemo.json +0 -1
@@ -109,7 +109,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
109
109
  if ((_a = product.metadata) == null ? void 0 : _a.is_manual_discount)
110
110
  return product;
111
111
  const totalPerUnitDiscount = (0, import_utils.resolveEffectivePerUnitDiscount)(product);
112
- const optionSum = (0, import_utils.sumOptionUnitPrice)(product.product_option_item);
112
+ const optionSum = (0, import_utils.sumOptionUnitPrice)((0, import_utils.getProductSkuOptions)(product));
113
113
  const sourcePrice = ((_b = product.metadata) == null ? void 0 : _b.source_product_price) ?? (((_c = product.metadata) == null ? void 0 : _c.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");
114
114
  const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
115
115
  const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
@@ -1445,12 +1445,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1445
1445
  // ─── TempOrder: 商品 CRUD ───
1446
1446
  async addProductToOrder(product, booking) {
1447
1447
  var _a;
1448
- debugger;
1449
1448
  const tempOrder = this.ensureTempOrder();
1450
1449
  const linked = booking ? this.createLinkedProductAndBooking({ product, booking }) : null;
1451
1450
  const productToAdd = (linked == null ? void 0 : linked.product) || product;
1452
1451
  const incomingFingerprint = (0, import_utils3.buildProductLineFingerprint)(
1453
- productToAdd.product_option_item,
1452
+ (0, import_utils.getProductSkuOptions)(productToAdd),
1454
1453
  productToAdd.product_bundle
1455
1454
  );
1456
1455
  const normalizedIncoming = (0, import_utils.mergeOrderProductDisplayFields)(
@@ -1472,14 +1471,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1472
1471
  if (item.product_variant_id !== productToAdd.product_variant_id)
1473
1472
  return false;
1474
1473
  const existedFingerprint2 = (0, import_utils3.buildProductLineFingerprint)(
1475
- item.product_option_item,
1474
+ (0, import_utils.getProductSkuOptions)(item),
1476
1475
  item.product_bundle
1477
1476
  );
1478
1477
  return existedFingerprint2 === incomingFingerprint;
1479
1478
  });
1480
1479
  const matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
1481
1480
  const existedFingerprint = matchedProduct ? (0, import_utils3.buildProductLineFingerprint)(
1482
- matchedProduct.product_option_item,
1481
+ (0, import_utils.getProductSkuOptions)(matchedProduct),
1483
1482
  matchedProduct.product_bundle
1484
1483
  ) : "";
1485
1484
  const shouldMerge = matchedProduct ? await this.shouldMergeProductToOrder({
@@ -1530,6 +1529,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1530
1529
  ...normalizedProduct.metadata || {},
1531
1530
  unique_identification_number: targetUid
1532
1531
  },
1532
+ product_sku: {
1533
+ ...targetProduct.product_sku || { option: [] },
1534
+ ...normalizedProduct.product_sku || { option: [] },
1535
+ option: (0, import_utils.getProductSkuOptions)(normalizedProduct)
1536
+ },
1533
1537
  note: targetProduct.note,
1534
1538
  order_detail_id: targetProduct.order_detail_id,
1535
1539
  num: (0, import_utils3.getSafeProductNum)(targetProduct.num + normalizedProduct.num)
@@ -1569,14 +1573,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1569
1573
  );
1570
1574
  }
1571
1575
  async updateOrderProduct(params) {
1572
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p;
1576
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
1573
1577
  const {
1574
1578
  product_id,
1575
1579
  product_variant_id,
1576
1580
  updates,
1577
1581
  unique_identification_number,
1578
1582
  identity_key,
1579
- product_option_item,
1583
+ product_sku,
1580
1584
  product_bundle,
1581
1585
  booking
1582
1586
  } = params;
@@ -1594,8 +1598,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1594
1598
  if (identity_key !== void 0) {
1595
1599
  identityLookup.identity_key = identity_key;
1596
1600
  }
1597
- if (product_option_item !== void 0)
1598
- identityLookup.product_option_item = product_option_item;
1601
+ if (product_sku !== void 0)
1602
+ identityLookup.product_sku = product_sku;
1599
1603
  if (product_bundle !== void 0)
1600
1604
  identityLookup.product_bundle = product_bundle;
1601
1605
  let productIndex = -1;
@@ -1624,23 +1628,28 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1624
1628
  ...targetProduct.metadata || {},
1625
1629
  ...(updates == null ? void 0 : updates.metadata) || {},
1626
1630
  unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
1631
+ },
1632
+ product_sku: {
1633
+ ...targetProduct.product_sku || { option: [] },
1634
+ ...(updates == null ? void 0 : updates.product_sku) && typeof updates.product_sku === "object" ? updates.product_sku : {},
1635
+ option: Array.isArray((_b = updates == null ? void 0 : updates.product_sku) == null ? void 0 : _b.option) ? updates.product_sku.option : (0, import_utils.getProductSkuOptions)(targetProduct)
1627
1636
  }
1628
1637
  };
1629
1638
  nextProduct.num = (0, import_utils3.getSafeProductNum)(nextProduct.num);
1630
1639
  const callerUpdatesTopPrice = Object.prototype.hasOwnProperty.call(updates || {}, "selling_price") || Object.prototype.hasOwnProperty.call(updates || {}, "original_price");
1631
- const callerUpdatesMainMeta = ((_b = updates == null ? void 0 : updates.metadata) == null ? void 0 : _b.main_product_selling_price) !== void 0 || ((_c = updates == null ? void 0 : updates.metadata) == null ? void 0 : _c.main_product_original_price) !== void 0 || ((_d = updates == null ? void 0 : updates.metadata) == null ? void 0 : _d.source_product_price) !== void 0;
1640
+ const callerUpdatesMainMeta = ((_c = updates == null ? void 0 : updates.metadata) == null ? void 0 : _c.main_product_selling_price) !== void 0 || ((_d = updates == null ? void 0 : updates.metadata) == null ? void 0 : _d.main_product_original_price) !== void 0 || ((_e = updates == null ? void 0 : updates.metadata) == null ? void 0 : _e.source_product_price) !== void 0;
1632
1641
  const isPersistedOrderLine = targetProduct.order_detail_id !== void 0 && targetProduct.order_detail_id !== null;
1633
- const callerUpdatesManualPrice = ((_e = updates == null ? void 0 : updates.metadata) == null ? void 0 : _e.price_override) !== void 0 || ((_f = updates == null ? void 0 : updates.metadata) == null ? void 0 : _f.is_manual_discount) !== void 0 || ((_g = updates == null ? void 0 : updates.metadata) == null ? void 0 : _g.product_discount_reason) !== void 0 || Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0;
1642
+ const callerUpdatesManualPrice = ((_f = updates == null ? void 0 : updates.metadata) == null ? void 0 : _f.price_override) !== void 0 || ((_g = updates == null ? void 0 : updates.metadata) == null ? void 0 : _g.is_manual_discount) !== void 0 || ((_h = updates == null ? void 0 : updates.metadata) == null ? void 0 : _h.product_discount_reason) !== void 0 || Array.isArray(updates == null ? void 0 : updates.discount_list) && updates.discount_list.length > 0;
1634
1643
  if (isPersistedOrderLine && !callerUpdatesManualPrice) {
1635
1644
  nextProduct.selling_price = targetProduct.selling_price;
1636
1645
  nextProduct.original_price = targetProduct.original_price;
1637
1646
  nextProduct.payment_price = targetProduct.payment_price;
1638
1647
  nextProduct.metadata = {
1639
1648
  ...nextProduct.metadata || {},
1640
- source_product_price: (_h = targetProduct.metadata) == null ? void 0 : _h.source_product_price,
1641
- main_product_selling_price: (_i = targetProduct.metadata) == null ? void 0 : _i.main_product_selling_price,
1642
- main_product_original_price: (_j = targetProduct.metadata) == null ? void 0 : _j.main_product_original_price,
1643
- price_schema_version: (_k = targetProduct.metadata) == null ? void 0 : _k.price_schema_version
1649
+ source_product_price: (_i = targetProduct.metadata) == null ? void 0 : _i.source_product_price,
1650
+ main_product_selling_price: (_j = targetProduct.metadata) == null ? void 0 : _j.main_product_selling_price,
1651
+ main_product_original_price: (_k = targetProduct.metadata) == null ? void 0 : _k.main_product_original_price,
1652
+ price_schema_version: (_l = targetProduct.metadata) == null ? void 0 : _l.price_schema_version
1644
1653
  };
1645
1654
  } else if (callerUpdatesTopPrice && !callerUpdatesMainMeta) {
1646
1655
  const existedMeta = nextProduct.metadata || {};
@@ -1657,7 +1666,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1657
1666
  normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
1658
1667
  normalizedProduct.discount_list
1659
1668
  );
1660
- const preservedBookingUid = nextProduct.booking_uid || ((_l = nextProduct.metadata) == null ? void 0 : _l.booking_uid) || targetProduct.booking_uid || ((_m = targetProduct.metadata) == null ? void 0 : _m.booking_uid);
1669
+ const preservedBookingUid = nextProduct.booking_uid || ((_m = nextProduct.metadata) == null ? void 0 : _m.booking_uid) || targetProduct.booking_uid || ((_n = targetProduct.metadata) == null ? void 0 : _n.booking_uid);
1661
1670
  if (!booking && preservedBookingUid) {
1662
1671
  normalizedProduct.booking_uid = preservedBookingUid;
1663
1672
  normalizedProduct.metadata = {
@@ -1667,7 +1676,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1667
1676
  }
1668
1677
  if (booking) {
1669
1678
  const productUid = String(
1670
- ((_n = normalizedProduct.metadata) == null ? void 0 : _n.unique_identification_number) || ((_o = targetProduct.metadata) == null ? void 0 : _o.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
1679
+ ((_o = normalizedProduct.metadata) == null ? void 0 : _o.unique_identification_number) || ((_p = targetProduct.metadata) == null ? void 0 : _p.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
1671
1680
  );
1672
1681
  normalizedProduct.metadata = {
1673
1682
  ...normalizedProduct.metadata || {},
@@ -1697,7 +1706,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1697
1706
  tempOrder,
1698
1707
  updates,
1699
1708
  tempOrder.products[productIndex],
1700
- (_p = tempOrder.products[productIndex].metadata) == null ? void 0 : _p.unique_identification_number
1709
+ (_q = tempOrder.products[productIndex].metadata) == null ? void 0 : _q.unique_identification_number
1701
1710
  );
1702
1711
  await this.applyPromotion();
1703
1712
  this.applyDiscount();
@@ -1713,7 +1722,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1713
1722
  num,
1714
1723
  unique_identification_number,
1715
1724
  identity_key,
1716
- product_option_item,
1725
+ product_sku,
1717
1726
  product_bundle
1718
1727
  } = params;
1719
1728
  const tempOrder = this.ensureTempOrder();
@@ -1729,8 +1738,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1729
1738
  }
1730
1739
  if (identity_key !== void 0)
1731
1740
  identityLookup.identity_key = identity_key;
1732
- if (product_option_item !== void 0)
1733
- identityLookup.product_option_item = product_option_item;
1741
+ if (product_sku !== void 0)
1742
+ identityLookup.product_sku = product_sku;
1734
1743
  if (product_bundle !== void 0)
1735
1744
  identityLookup.product_bundle = product_bundle;
1736
1745
  let productIndex = -1;
@@ -1841,7 +1850,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1841
1850
  * 应传 1,确保 /order/sales/checkout 返回打印所需数据。
1842
1851
  */
1843
1852
  async submitTempOrder(params) {
1844
- var _a, _b, _c;
1853
+ var _a, _b, _c, _d, _e;
1845
1854
  const tempOrder = this.ensureTempOrder();
1846
1855
  this.persistTempOrder();
1847
1856
  const effectiveCacheId = (params == null ? void 0 : params.cacheId) ?? this.cacheId;
@@ -1866,7 +1875,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1866
1875
  tempOrder,
1867
1876
  cacheId: effectiveCacheId,
1868
1877
  platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
1869
- businessCode: params == null ? void 0 : params.businessCode,
1878
+ businessCode: (params == null ? void 0 : params.businessCode) ?? ((_b = this.otherParams) == null ? void 0 : _b.businessCode) ?? ((_c = this.otherParams) == null ? void 0 : _c.business_code),
1870
1879
  channel: params == null ? void 0 : params.channel,
1871
1880
  type: params == null ? void 0 : params.type,
1872
1881
  enhance: enhancePayload
@@ -1880,7 +1889,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1880
1889
  externalSaleNumber: payload.external_sale_number,
1881
1890
  requestUniqueIdempotencyToken: payload.request_unique_idempotency_token,
1882
1891
  paymentStatus: payload.payment_status,
1883
- paymentsCount: ((_b = payload.payments) == null ? void 0 : _b.length) || 0,
1892
+ paymentsCount: ((_d = payload.payments) == null ? void 0 : _d.length) || 0,
1884
1893
  smallTicketDataFlag: payload.small_ticket_data_flag
1885
1894
  });
1886
1895
  result = await this.submitSalesOrder({
@@ -1899,7 +1908,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1899
1908
  orderId: payload.order_id,
1900
1909
  externalSaleNumber: payload.external_sale_number,
1901
1910
  paymentStatus: payload.payment_status,
1902
- paymentsCount: ((_c = payload.payments) == null ? void 0 : _c.length) || 0
1911
+ paymentsCount: ((_e = payload.payments) == null ? void 0 : _e.length) || 0
1903
1912
  });
1904
1913
  throw error;
1905
1914
  }
@@ -1988,6 +1997,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1988
1997
  payments: mappedPayments,
1989
1998
  paymentStatus,
1990
1999
  smallTicketDataFlag: params.smallTicketDataFlag,
2000
+ businessCode: params.businessCode,
1991
2001
  channel: params.channel,
1992
2002
  enhancePayload: (payload) => {
1993
2003
  const nextPayload = {
@@ -2404,14 +2414,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2404
2414
  normalizeHydratedProductOptionItem(optionItem) {
2405
2415
  const rawNum = (optionItem == null ? void 0 : optionItem.num) ?? (optionItem == null ? void 0 : optionItem.quantity) ?? 1;
2406
2416
  const parsedNum = Number(rawNum);
2407
- const rawPrice = (optionItem == null ? void 0 : optionItem.price) ?? (optionItem == null ? void 0 : optionItem.add_price) ?? 0;
2417
+ const rawPrice = (optionItem == null ? void 0 : optionItem.add_price) ?? (optionItem == null ? void 0 : optionItem.price) ?? 0;
2408
2418
  const parsedPrice = Number(rawPrice);
2409
2419
  const normalized = {
2420
+ ...optionItem,
2410
2421
  option_group_item_id: optionItem == null ? void 0 : optionItem.option_group_item_id,
2411
2422
  option_group_id: optionItem == null ? void 0 : optionItem.option_group_id,
2412
2423
  num: Number.isFinite(parsedNum) && parsedNum > 0 ? parsedNum : 1,
2413
- price: Number.isFinite(parsedPrice) ? parsedPrice : 0
2424
+ add_price: Number.isFinite(parsedPrice) ? parsedPrice : 0
2414
2425
  };
2426
+ delete normalized.price;
2415
2427
  if ((optionItem == null ? void 0 : optionItem.name) !== void 0)
2416
2428
  normalized.name = optionItem.name;
2417
2429
  if ((optionItem == null ? void 0 : optionItem.group_name) !== void 0)
@@ -2420,46 +2432,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2420
2432
  normalized.id = optionItem.id;
2421
2433
  return normalized;
2422
2434
  }
2423
- mergeHydratedProductOptionDisplayFields(options, skuOptions) {
2424
- if (!Array.isArray(skuOptions) || skuOptions.length === 0)
2425
- return options;
2426
- const displayByItemId = /* @__PURE__ */ new Map();
2427
- for (const option of skuOptions) {
2428
- const key = option == null ? void 0 : option.option_group_item_id;
2429
- if (key === void 0 || key === null || key === "")
2430
- continue;
2431
- displayByItemId.set(String(key), option);
2432
- }
2433
- return options.map((option) => {
2434
- const display = displayByItemId.get(String((option == null ? void 0 : option.option_group_item_id) ?? ""));
2435
- if (!display)
2436
- return option;
2437
- return {
2438
- ...option,
2439
- ...option.name === void 0 && display.name !== void 0 ? { name: display.name } : {},
2440
- ...option.group_name === void 0 && display.group_name !== void 0 ? { group_name: display.group_name } : {},
2441
- ...option.id === void 0 && display.id !== void 0 ? { id: display.id } : {}
2442
- };
2443
- });
2444
- }
2445
- resolveHydratedProductOptions(row) {
2446
- var _a;
2447
- const skuOptions = (_a = row.product_sku) == null ? void 0 : _a.option;
2448
- if (Array.isArray(row.product_option_item) && row.product_option_item.length > 0) {
2449
- return this.mergeHydratedProductOptionDisplayFields(row.product_option_item, skuOptions);
2450
- }
2451
- if (!Array.isArray(skuOptions))
2452
- return [];
2453
- return skuOptions.map(
2454
- (optionItem) => this.normalizeHydratedProductOptionItem(optionItem || {})
2455
- );
2456
- }
2457
2435
  normalizeHydratedOrderProduct(product) {
2458
2436
  const row = { ...product || {} };
2459
2437
  if (row.num === void 0 && row.product_quantity !== void 0) {
2460
2438
  row.num = row.product_quantity;
2461
2439
  }
2462
- row.product_option_item = this.resolveHydratedProductOptions(row);
2440
+ const productSku = (0, import_utils.ensureProductSku)(row);
2441
+ row.product_sku = {
2442
+ ...productSku,
2443
+ option: (0, import_utils.normalizeProductSkuOptions)(
2444
+ productSku.option.map(
2445
+ (optionItem) => this.normalizeHydratedProductOptionItem(optionItem || {})
2446
+ )
2447
+ )
2448
+ };
2449
+ delete row[`product_${"option"}_item`];
2463
2450
  if (!Array.isArray(row.product_bundle))
2464
2451
  row.product_bundle = [];
2465
2452
  if (!row.metadata || typeof row.metadata !== "object")
@@ -2478,7 +2465,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2478
2465
  const result = {
2479
2466
  ...row,
2480
2467
  ...normalized,
2481
- product_sku: row.product_sku,
2468
+ product_sku: normalized.product_sku,
2482
2469
  metadata: {
2483
2470
  ...row.metadata,
2484
2471
  ...normalized.metadata
@@ -161,15 +161,18 @@ export interface OrderProductIdentity {
161
161
  product_id: number | null;
162
162
  product_variant_id: number;
163
163
  unique_identification_number?: string;
164
- product_option_item?: any[];
164
+ product_sku?: OrderProductSku;
165
165
  product_bundle?: any[];
166
166
  }
167
+ export interface OrderProductSku {
168
+ option: any[];
169
+ [key: string]: any;
170
+ }
167
171
  export interface OrderProduct extends OrderProductIdentity {
168
172
  order_detail_id: number | null;
169
173
  num: number;
170
174
  bundle_edit?: number;
171
- product_option_item: any[];
172
- product_sku?: Record<string, any>;
175
+ product_sku: OrderProductSku;
173
176
  gift_card?: number;
174
177
  selling_price: string;
175
178
  original_price: string;
@@ -262,10 +265,10 @@ export interface OrderTempOrder {
262
265
  [key: string]: any;
263
266
  };
264
267
  }
265
- export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identification_number' | 'num' | 'product_option_item'> {
268
+ export interface OrderSubmitProduct extends Omit<OrderProduct, 'unique_identification_number' | 'num'> {
266
269
  product_quantity: number;
267
270
  payment_price: string;
268
- product_sku: Record<string, any>;
271
+ product_sku: OrderProductSku;
269
272
  }
270
273
  export interface OrderSubmitPayload extends Omit<OrderTempOrder, 'platform' | 'products' | '_extend' | 'customer' | 'discount_list' | 'created_at'> {
271
274
  platform: string;
@@ -300,7 +303,7 @@ export interface UpdateOrderProductParams {
300
303
  updates: Partial<OrderProduct>;
301
304
  unique_identification_number?: string;
302
305
  identity_key?: string;
303
- product_option_item?: any[];
306
+ product_sku?: OrderProductSku;
304
307
  product_bundle?: any[];
305
308
  booking?: AddProductBookingInput;
306
309
  }
@@ -479,6 +482,7 @@ export interface SyncPaymentsToOrderParams {
479
482
  paymentStatus?: SubmitSalesOrderParams['query']['payment_status'];
480
483
  submitWhenPaid?: boolean;
481
484
  smallTicketDataFlag?: number;
485
+ businessCode?: string;
482
486
  channel?: string;
483
487
  }
484
488
  export interface SyncPaymentsToOrderResult<T = any> {
@@ -28,11 +28,18 @@ export declare function composeLinePrice(params: {
28
28
  }> | null;
29
29
  useOriginalBundle?: boolean;
30
30
  }): string;
31
+ export declare function normalizeProductSkuOptions(options?: unknown): Record<string, any>[];
32
+ export declare function ensureProductSku(product?: Record<string, any> | null): Record<string, any> & {
33
+ option: Record<string, any>[];
34
+ };
35
+ export declare function getProductSkuOptions(product?: Record<string, any> | null): Record<string, any>[];
31
36
  /**
32
- * 计算 option 单价合计:Σ(option.price × option.num)。
37
+ * 计算 option 单价合计:Σ(option.add_price × option.num)。
38
+ * 兼容入参仍带旧 `price` 的调用方,但运行时归一化后只维护 `add_price`。
33
39
  * 在新语义 v2 下,main_product_original_price = source_product_price + 本函数结果。
34
40
  */
35
41
  export declare function sumOptionUnitPrice(options?: Array<{
42
+ add_price?: any;
36
43
  price?: any;
37
44
  num?: any;
38
45
  }> | null): Decimal;
@@ -162,7 +169,7 @@ export declare function mapPaymentItemsToOrderPayments(paymentItems: OrderPaymen
162
169
  export declare function formatV1Product(products: OrderSubmitProduct[]): {
163
170
  bundle: any[];
164
171
  key: number | null;
165
- option: any;
172
+ option: any[];
166
173
  product_id: number | null;
167
174
  product_variant_id: number;
168
175
  num: number;
@@ -38,12 +38,14 @@ __export(utils_exports, {
38
38
  createEmptySummary: () => import_utils2.createEmptySummary,
39
39
  createUuidV4: () => createUuidV4,
40
40
  ensureManualProductDiscountList: () => import_manualProductDiscount.ensureManualProductDiscountList,
41
+ ensureProductSku: () => ensureProductSku,
41
42
  findManualProductDiscountItem: () => import_manualProductDiscount.findManualProductDiscountItem,
42
43
  formatDateTime: () => formatDateTime,
43
44
  formatV1Product: () => formatV1Product,
44
45
  generateDuration: () => generateDuration,
45
46
  getAllDiscountList: () => getAllDiscountList,
46
47
  getOrderProductLineUid: () => getOrderProductLineUid,
48
+ getProductSkuOptions: () => getProductSkuOptions,
47
49
  hasAssignedHolderId: () => hasAssignedHolderId,
48
50
  indexOrderProductsByUid: () => indexOrderProductsByUid,
49
51
  isEmptyOrderProductDisplayValue: () => isEmptyOrderProductDisplayValue,
@@ -56,6 +58,7 @@ __export(utils_exports, {
56
58
  normalizeBookingIsAll: () => normalizeBookingIsAll,
57
59
  normalizeBookingSubType: () => normalizeBookingSubType,
58
60
  normalizeOrderProductDiscountList: () => normalizeOrderProductDiscountList,
61
+ normalizeProductSkuOptions: () => normalizeProductSkuOptions,
59
62
  normalizeSubmitBooking: () => normalizeSubmitBooking,
60
63
  normalizeSubmitCollectPaxValue: () => normalizeSubmitCollectPaxValue,
61
64
  resolveEffectivePerUnitDiscount: () => resolveEffectivePerUnitDiscount,
@@ -91,12 +94,36 @@ function composeLinePrice(params) {
91
94
  }
92
95
  return total.toDecimalPlaces(2).toFixed(2);
93
96
  }
97
+ function normalizeProductSkuOptions(options) {
98
+ if (!Array.isArray(options))
99
+ return [];
100
+ return options.map((option) => {
101
+ const normalized = {
102
+ ...option && typeof option === "object" ? option : {}
103
+ };
104
+ const addPrice = normalized.add_price ?? normalized.price;
105
+ if (addPrice !== void 0)
106
+ normalized.add_price = addPrice;
107
+ delete normalized.price;
108
+ return normalized;
109
+ });
110
+ }
111
+ function ensureProductSku(product) {
112
+ const rawSku = (product == null ? void 0 : product.product_sku) && typeof product.product_sku === "object" ? product.product_sku : {};
113
+ return {
114
+ ...rawSku,
115
+ option: normalizeProductSkuOptions(rawSku.option)
116
+ };
117
+ }
118
+ function getProductSkuOptions(product) {
119
+ return ensureProductSku(product).option;
120
+ }
94
121
  function sumOptionUnitPrice(options) {
95
122
  let total = new import_decimal.default(0);
96
123
  if (!Array.isArray(options))
97
124
  return total;
98
125
  for (const opt of options) {
99
- const price = new import_decimal.default(Number(opt == null ? void 0 : opt.price) || 0);
126
+ const price = new import_decimal.default(Number((opt == null ? void 0 : opt.add_price) ?? (opt == null ? void 0 : opt.price)) || 0);
100
127
  const num = new import_decimal.default(Number(opt == null ? void 0 : opt.num) || 0);
101
128
  total = total.plus(price.times(num));
102
129
  }
@@ -184,7 +211,7 @@ function resolveEffectivePerUnitDiscount(product) {
184
211
  if (hasPromoDiscountItem)
185
212
  return fromList;
186
213
  const metadata = (product == null ? void 0 : product.metadata) || {};
187
- const optionSum = sumOptionUnitPrice(product == null ? void 0 : product.product_option_item).toNumber();
214
+ const optionSum = sumOptionUnitPrice(getProductSkuOptions(product)).toNumber();
188
215
  if (metadata.source_product_price != null && metadata.main_product_selling_price != null) {
189
216
  const source = Number(metadata.source_product_price);
190
217
  const selling = Number(metadata.main_product_selling_price) - optionSum;
@@ -246,7 +273,7 @@ function createDefaultOrderRulesHooks() {
246
273
  getProduct: (product) => {
247
274
  var _a, _b, _c, _d, _e, _f;
248
275
  const metadataAny = product.metadata || {};
249
- const optionSum = sumOptionUnitPrice(product.product_option_item);
276
+ const optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
250
277
  let sourcePrice;
251
278
  if (metadataAny.source_product_price !== void 0) {
252
279
  sourcePrice = String(metadataAny.source_product_price);
@@ -274,7 +301,7 @@ function createDefaultOrderRulesHooks() {
274
301
  // 不透明 identity 契约下,normalizeOrderProduct / hydrate 已保证唯一值存在;
275
302
  // 留 fingerprint 分支仅作 Rules 单测里直接传裸 product 时的兜底。
276
303
  _id: ((_a = product.metadata) == null ? void 0 : _a.unique_identification_number) ? `${product.product_id}_${product.product_variant_id}_${product.metadata.unique_identification_number}` : `${product.product_id}_${product.product_variant_id}_${(0, import_utils.buildProductLineFingerprint)(
277
- product.product_option_item,
304
+ getProductSkuOptions(product),
278
305
  product.product_bundle
279
306
  )}`,
280
307
  // Rules 内部 getProductTotalPrice / getProductOriginTotalPrice 会各自再叠加 bundle + option,
@@ -306,7 +333,7 @@ function createDefaultOrderRulesHooks() {
306
333
  const nextNum = Number(values.quantity ?? product.num ?? 1) || 1;
307
334
  const metadataAny = product.metadata || {};
308
335
  const existedSource = metadataAny.source_product_price ?? product.selling_price ?? "0";
309
- const nextOptions = product.product_option_item;
336
+ const nextOptions = getProductSkuOptions(product);
310
337
  const optionSum = sumOptionUnitPrice(nextOptions);
311
338
  const nextSourceSellingPrice = values.main_product_selling_price !== void 0 ? String(values.main_product_selling_price) : values.price !== void 0 ? String(values.price) : values.total !== void 0 ? toUnitPriceString(values.total, nextNum) : String(existedSource);
312
339
  const nextSourceOriginalPrice = values.original_price !== void 0 ? String(values.original_price) : String(existedSource);
@@ -415,6 +442,7 @@ function formatSubmitOptionItems(options) {
415
442
  return [];
416
443
  return options.map((d) => {
417
444
  const option = {
445
+ ...d && typeof d === "object" ? d : {},
418
446
  num: d == null ? void 0 : d.num,
419
447
  option_group_item_id: d == null ? void 0 : d.option_group_item_id,
420
448
  option_group_id: d == null ? void 0 : d.option_group_id
@@ -422,6 +450,7 @@ function formatSubmitOptionItems(options) {
422
450
  const addPrice = (d == null ? void 0 : d.add_price) ?? (d == null ? void 0 : d.price);
423
451
  if (addPrice !== void 0)
424
452
  option.add_price = String(addPrice);
453
+ delete option.price;
425
454
  return option;
426
455
  });
427
456
  }
@@ -485,7 +514,6 @@ function normalizeSubmitProduct(product) {
485
514
  const { unique_identification_number: _runtimeUid, ...submitProduct } = product;
486
515
  const {
487
516
  num,
488
- product_option_item: productOptionItem,
489
517
  surcharge_fee: _productSurchargeFee,
490
518
  discount_amount: _deprecatedDiscountAmount,
491
519
  discount_type: _deprecatedDiscountType,
@@ -494,6 +522,7 @@ function normalizeSubmitProduct(product) {
494
522
  discount_per: _deprecatedDiscountPer,
495
523
  ...productRest
496
524
  } = submitProduct;
525
+ delete productRest[`product_${"option"}_item`];
497
526
  const rawMetadata = submitProduct.metadata || {};
498
527
  const bookingUid = rawMetadata.booking_uid;
499
528
  const cleanMetadata = {};
@@ -527,9 +556,7 @@ function normalizeSubmitProduct(product) {
527
556
  }
528
557
  const productSku = {
529
558
  ...submitProduct.product_sku && typeof submitProduct.product_sku === "object" ? submitProduct.product_sku : {},
530
- option: formatSubmitOptionItems(
531
- (productOptionItem == null ? void 0 : productOptionItem.length) ? productOptionItem : (_a = submitProduct.product_sku) == null ? void 0 : _a.option
532
- )
559
+ option: formatSubmitOptionItems((_a = submitProduct.product_sku) == null ? void 0 : _a.option)
533
560
  };
534
561
  return {
535
562
  ...productRest,
@@ -872,7 +899,8 @@ function mergeOrderProductDisplayFields(previous, next) {
872
899
  "product_cover",
873
900
  "cover",
874
901
  "variant_title",
875
- "product_sku"
902
+ "product_sku",
903
+ "payment_price"
876
904
  ];
877
905
  displayFields.forEach((field) => {
878
906
  if (isEmptyOrderProductDisplayValue(merged[field]) && !isEmptyOrderProductDisplayValue(previous[field])) {
@@ -919,12 +947,14 @@ function indexOrderProductsByUid(products) {
919
947
  createEmptySummary,
920
948
  createUuidV4,
921
949
  ensureManualProductDiscountList,
950
+ ensureProductSku,
922
951
  findManualProductDiscountItem,
923
952
  formatDateTime,
924
953
  formatV1Product,
925
954
  generateDuration,
926
955
  getAllDiscountList,
927
956
  getOrderProductLineUid,
957
+ getProductSkuOptions,
928
958
  hasAssignedHolderId,
929
959
  indexOrderProductsByUid,
930
960
  isEmptyOrderProductDisplayValue,
@@ -937,6 +967,7 @@ function indexOrderProductsByUid(products) {
937
967
  normalizeBookingIsAll,
938
968
  normalizeBookingSubType,
939
969
  normalizeOrderProductDiscountList,
970
+ normalizeProductSkuOptions,
940
971
  normalizeSubmitBooking,
941
972
  normalizeSubmitCollectPaxValue,
942
973
  resolveEffectivePerUnitDiscount,
@@ -8,7 +8,9 @@ export interface SalesSummaryProduct {
8
8
  original_price: string;
9
9
  tax_fee: string;
10
10
  is_charge_tax?: number;
11
- product_option_item?: any[];
11
+ product_sku?: Record<string, any> & {
12
+ option?: any[];
13
+ };
12
14
  discount_list?: any[];
13
15
  product_bundle?: any[];
14
16
  metadata?: Record<string, any>;
@@ -35,6 +35,7 @@ __export(utils_exports, {
35
35
  module.exports = __toCommonJS(utils_exports);
36
36
  var import_decimal = __toESM(require("decimal.js"));
37
37
  var import_utils = require("../Summary/utils");
38
+ var import_utils2 = require("../Order/utils");
38
39
  function toDecimal(value) {
39
40
  return new import_decimal.default(value || 0);
40
41
  }
@@ -75,6 +76,7 @@ function buildSurchargeServiceItems(products) {
75
76
  var _a, _b;
76
77
  const quantity = getSafeNum(product.num);
77
78
  const unitTotal = getUnitPaymentTotal(product);
79
+ const options = (0, import_utils2.getProductSkuOptions)(product);
78
80
  return {
79
81
  id: product.product_id,
80
82
  num: quantity,
@@ -86,12 +88,12 @@ function buildSurchargeServiceItems(products) {
86
88
  product: {
87
89
  discount_list: product.discount_list || [],
88
90
  product_bundle: product.product_bundle || [],
89
- product_option_item: product.product_option_item || []
91
+ product_sku: product.product_sku || { option: options }
90
92
  }
91
93
  },
92
94
  bundle: product.product_bundle || [],
93
- option: product.product_option_item || [],
94
- options: product.product_option_item || [],
95
+ option: options,
96
+ options,
95
97
  relation_details: [],
96
98
  metadata: product.metadata || {},
97
99
  start_date: ((_a = product.metadata) == null ? void 0 : _a.start_date) || "",