@pisell/pisellos 2.3.28 → 2.3.30

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 (57) hide show
  1. package/dist/modules/Order/index.d.ts +32 -8
  2. package/dist/modules/Order/index.js +883 -521
  3. package/dist/modules/Order/payment-utils.d.ts +23 -0
  4. package/dist/modules/Order/payment-utils.js +203 -0
  5. package/dist/modules/Order/types.d.ts +33 -1
  6. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  7. package/dist/modules/Order/utils/orderCollectionIdentity.js +405 -0
  8. package/dist/modules/Order/utils.d.ts +2 -1
  9. package/dist/modules/Order/utils.js +6 -12
  10. package/dist/modules/Payment/index.d.ts +2 -0
  11. package/dist/modules/Payment/index.js +78 -49
  12. package/dist/modules/Payment/types.d.ts +26 -24
  13. package/dist/modules/Payment/types.js +2 -0
  14. package/dist/modules/Product/index.d.ts +1 -1
  15. package/dist/server/index.d.ts +14 -0
  16. package/dist/server/index.js +1826 -1000
  17. package/dist/server/modules/order/index.d.ts +47 -4
  18. package/dist/server/modules/order/index.js +1415 -711
  19. package/dist/server/modules/order/types.d.ts +11 -3
  20. package/dist/server/modules/order/types.js +1 -1
  21. package/dist/solution/BaseSales/index.d.ts +40 -4
  22. package/dist/solution/BaseSales/index.js +1268 -749
  23. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  24. package/dist/solution/BaseSales/utils/parseSalesResponse.js +6 -8
  25. package/dist/solution/BookingByStep/index.d.ts +1 -1
  26. package/dist/solution/BookingTicket/index.d.ts +13 -1
  27. package/dist/solution/BookingTicket/index.js +2 -1
  28. package/dist/utils/payment-number.d.ts +9 -0
  29. package/dist/utils/payment-number.js +69 -0
  30. package/lib/modules/Order/index.d.ts +32 -8
  31. package/lib/modules/Order/index.js +270 -64
  32. package/lib/modules/Order/payment-utils.d.ts +23 -0
  33. package/lib/modules/Order/payment-utils.js +193 -0
  34. package/lib/modules/Order/types.d.ts +33 -1
  35. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +53 -0
  36. package/lib/modules/Order/utils/orderCollectionIdentity.js +415 -0
  37. package/lib/modules/Order/utils.d.ts +2 -1
  38. package/lib/modules/Order/utils.js +6 -14
  39. package/lib/modules/Payment/index.d.ts +2 -0
  40. package/lib/modules/Payment/index.js +33 -12
  41. package/lib/modules/Payment/types.d.ts +26 -24
  42. package/lib/modules/Product/index.d.ts +1 -1
  43. package/lib/server/index.d.ts +14 -0
  44. package/lib/server/index.js +604 -8
  45. package/lib/server/modules/order/index.d.ts +47 -4
  46. package/lib/server/modules/order/index.js +578 -116
  47. package/lib/server/modules/order/types.d.ts +11 -3
  48. package/lib/solution/BaseSales/index.d.ts +40 -4
  49. package/lib/solution/BaseSales/index.js +363 -37
  50. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +9 -4
  51. package/lib/solution/BaseSales/utils/parseSalesResponse.js +4 -5
  52. package/lib/solution/BookingByStep/index.d.ts +1 -1
  53. package/lib/solution/BookingTicket/index.d.ts +13 -1
  54. package/lib/solution/BookingTicket/index.js +2 -1
  55. package/lib/utils/payment-number.d.ts +9 -0
  56. package/lib/utils/payment-number.js +64 -0
  57. package/package.json +1 -1
@@ -35,10 +35,13 @@ import { OrderHooks } from "./types";
35
35
  import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, mergeOrderProductDisplayFields, resolveIsFormSubject } from "./utils";
36
36
  import { isNormalProduct } from "../Product/utils";
37
37
  import dayjs from 'dayjs';
38
+ import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
39
+ import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
38
40
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
39
41
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
40
42
  import { syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
41
43
  import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
44
+ import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
42
45
  import { DiscountModule } from "../Discount";
43
46
  import { RulesModule } from "../Rules";
44
47
  import { UnavailableReason } from "../Rules/types";
@@ -96,6 +99,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
96
99
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
97
100
  // LoggerManager 实例
98
101
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
102
+ _defineProperty(_assertThisInitialized(_this), "appPlugin", void 0);
99
103
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
100
104
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
101
105
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
@@ -283,7 +287,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
283
287
  value: function () {
284
288
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
285
289
  var _otherParams$rules, _otherParams$order, _otherParams$hooks;
286
- var appPlugin, app, otherParams;
290
+ var app, otherParams;
287
291
  return _regeneratorRuntime().wrap(function _callee$(_context) {
288
292
  while (1) switch (_context.prev = _context.next) {
289
293
  case 0:
@@ -296,14 +300,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
296
300
  this.store.summary = createEmptySummary();
297
301
  }
298
302
  this.request = this.core.getPlugin('request');
299
- appPlugin = this.core.getPlugin('app');
300
- if (appPlugin) {
303
+ this.appPlugin = this.core.getPlugin('app');
304
+ if (this.appPlugin) {
301
305
  _context.next = 8;
302
306
  break;
303
307
  }
304
308
  throw new Error('Order 模块需要 app 插件支持');
305
309
  case 8:
306
- app = appPlugin.getApp();
310
+ app = this.appPlugin.getApp();
307
311
  this.logger = app.logger;
308
312
  this.window = this.core.getPlugin('window');
309
313
  otherParams = options.otherParams || {};
@@ -1497,19 +1501,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1497
1501
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1498
1502
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1499
1503
  }
1504
+ }, {
1505
+ key: "getPaymentNumberAppData",
1506
+ value: function getPaymentNumberAppData(key) {
1507
+ var _appPlugin$getData, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
1508
+ var appPlugin = this.appPlugin;
1509
+ if (!appPlugin) return undefined;
1510
+ var getData = (_appPlugin$getData = appPlugin.getData) === null || _appPlugin$getData === void 0 ? void 0 : _appPlugin$getData.call(appPlugin);
1511
+ if (typeof getData === 'function') return getData(key);
1512
+ var app = appPlugin.getApp();
1513
+ var coreData = app === null || app === void 0 || (_app$models = app.models) === null || _app$models === void 0 || (_app$models$getStore = _app$models.getStore) === null || _app$models$getStore === void 0 || (_app$models$getStore$ = (_app$models$getStore$2 = _app$models$getStore.call(_app$models)).getDataByModel) === null || _app$models$getStore$ === void 0 ? void 0 : _app$models$getStore$.call(_app$models$getStore$2, 'core', 'core');
1514
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1515
+ }
1516
+ }, {
1517
+ key: "getPaymentNumberDevicePrefixSync",
1518
+ value: function getPaymentNumberDevicePrefixSync() {
1519
+ var _this7 = this;
1520
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1521
+ return _this7.getPaymentNumberAppData(key);
1522
+ });
1523
+ }
1524
+ }, {
1525
+ key: "getPaymentNumberDevicePrefixAsync",
1526
+ value: function getPaymentNumberDevicePrefixAsync() {
1527
+ var _this8 = this;
1528
+ return resolvePaymentNumberDevicePrefix(function (key) {
1529
+ return _this8.getPaymentNumberAppData(key);
1530
+ });
1531
+ }
1500
1532
  }, {
1501
1533
  key: "normalizePaymentSource",
1502
1534
  value: function normalizePaymentSource(payment, options) {
1503
1535
  var _ref19, _paymentRecord$origin;
1504
1536
  var paymentRecord = payment;
1505
1537
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1506
- if (!metadata.unique_payment_number) {
1507
- metadata.unique_payment_number = createUuidV4();
1508
- }
1509
- var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
1538
+ var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1510
1539
  metadata: metadata,
1511
1540
  origin_amount: (_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : '0.00'
1512
- });
1541
+ }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1513
1542
  if (paymentRecord.status !== undefined) {
1514
1543
  normalized.status = paymentRecord.status;
1515
1544
  } else if ((options === null || options === void 0 ? void 0 : options.defaultPaid) !== false) {
@@ -1627,16 +1656,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1627
1656
  }, {
1628
1657
  key: "calculatePaidPaymentSummary",
1629
1658
  value: function calculatePaidPaymentSummary(payments) {
1630
- var _this7 = this;
1659
+ var _this9 = this;
1631
1660
  return (payments || []).reduce(function (summary, payment) {
1632
1661
  var paymentRecord = payment;
1633
1662
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
1634
1663
  return {
1635
1664
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1636
- orderPaidAmount: summary.orderPaidAmount.plus(_this7.calculatePaymentOrderAmount(paymentRecord)),
1637
- gapPaidAmount: summary.gapPaidAmount.plus(_this7.calculatePaymentGapAmount(paymentRecord)),
1638
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this7.calculatePaymentServiceFee(paymentRecord)),
1639
- roundingAmount: summary.roundingAmount.plus(_this7.calculatePaymentRoundingAmount(paymentRecord))
1665
+ orderPaidAmount: summary.orderPaidAmount.plus(_this9.calculatePaymentOrderAmount(paymentRecord)),
1666
+ gapPaidAmount: summary.gapPaidAmount.plus(_this9.calculatePaymentGapAmount(paymentRecord)),
1667
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this9.calculatePaymentServiceFee(paymentRecord)),
1668
+ roundingAmount: summary.roundingAmount.plus(_this9.calculatePaymentRoundingAmount(paymentRecord))
1640
1669
  };
1641
1670
  }, {
1642
1671
  customerPaidAmount: new Decimal(0),
@@ -1838,15 +1867,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1838
1867
  }, {
1839
1868
  key: "normalizeFingerprintValue",
1840
1869
  value: function normalizeFingerprintValue(value) {
1841
- var _this8 = this;
1870
+ var _this10 = this;
1842
1871
  if (Array.isArray(value)) {
1843
1872
  return value.map(function (item) {
1844
- return _this8.normalizeFingerprintValue(item);
1873
+ return _this10.normalizeFingerprintValue(item);
1845
1874
  });
1846
1875
  }
1847
1876
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
1848
1877
  return Object.keys(value).sort().reduce(function (result, key) {
1849
- result[key] = _this8.normalizeFingerprintValue(value[key]);
1878
+ result[key] = _this10.normalizeFingerprintValue(value[key]);
1850
1879
  return result;
1851
1880
  }, {});
1852
1881
  }
@@ -1861,7 +1890,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1861
1890
  _sku$barcode,
1862
1891
  _ref20,
1863
1892
  _sku$variant_id,
1864
- _this9 = this;
1893
+ _this11 = this;
1865
1894
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1866
1895
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1867
1896
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1895,7 +1924,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1895
1924
  option_group_id: (_option$option_group_ = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_ !== void 0 ? _option$option_group_ : null,
1896
1925
  option_group_item_id: (_ref22 = (_option$option_group_2 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_2 !== void 0 ? _option$option_group_2 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref22 !== void 0 ? _ref22 : null,
1897
1926
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1898
- add_price: _this9.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
1927
+ add_price: _this11.normalizeFingerprintMoney((_option$add_price = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price !== void 0 ? _option$add_price : option === null || option === void 0 ? void 0 : option.price)
1899
1928
  };
1900
1929
  })
1901
1930
  }),
@@ -1905,8 +1934,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1905
1934
  bundle_product_id: (_ref23 = (_ref24 = (_bundle$bundle_produc = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_product_id) !== null && _bundle$bundle_produc !== void 0 ? _bundle$bundle_produc : bundle === null || bundle === void 0 ? void 0 : bundle._bundle_product_id) !== null && _ref24 !== void 0 ? _ref24 : bundle === null || bundle === void 0 ? void 0 : bundle.product_id) !== null && _ref23 !== void 0 ? _ref23 : null,
1906
1935
  bundle_variant_id: (_ref25 = (_bundle$bundle_varian = bundle === null || bundle === void 0 ? void 0 : bundle.bundle_variant_id) !== null && _bundle$bundle_varian !== void 0 ? _bundle$bundle_varian : bundle === null || bundle === void 0 ? void 0 : bundle.product_variant_id) !== null && _ref25 !== void 0 ? _ref25 : 0,
1907
1936
  num: getSafeProductNum((_bundle$num = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num !== void 0 ? _bundle$num : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
1908
- price: _this9.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1909
- bundle_selling_price: _this9.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1937
+ price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1938
+ bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1910
1939
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
1911
1940
  price_type_ext: (_bundle$price_type_ex = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex !== void 0 ? _bundle$price_type_ex : ''
1912
1941
  };
@@ -1916,7 +1945,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1916
1945
  return {
1917
1946
  type: (_ref26 = (_discount$type2 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type2 !== void 0 ? _discount$type2 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref26 !== void 0 ? _ref26 : '',
1918
1947
  discount_id: (_ref27 = (_ref28 = (_discount$discount_id = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id !== void 0 ? _discount$discount_id : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref28 !== void 0 ? _ref28 : discount === null || discount === void 0 || (_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) !== null && _ref27 !== void 0 ? _ref27 : null,
1919
- amount: _this9.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1948
+ amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1920
1949
  };
1921
1950
  }))
1922
1951
  };
@@ -1924,9 +1953,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1924
1953
  }, {
1925
1954
  key: "buildOrderProductsFingerprint",
1926
1955
  value: function buildOrderProductsFingerprint(products) {
1927
- var _this10 = this;
1956
+ var _this12 = this;
1928
1957
  var items = (products || []).map(function (product) {
1929
- return _this10.buildProductFingerprintItem(product);
1958
+ return _this12.buildProductFingerprintItem(product);
1930
1959
  });
1931
1960
  items.sort(function (left, right) {
1932
1961
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -1948,7 +1977,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1948
1977
  _sku$barcode2,
1949
1978
  _ref30,
1950
1979
  _sku$variant_id2,
1951
- _this11 = this;
1980
+ _this13 = this;
1952
1981
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1953
1982
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1954
1983
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1979,7 +2008,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1979
2008
  option_group_id: (_option$option_group_3 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_3 !== void 0 ? _option$option_group_3 : null,
1980
2009
  option_group_item_id: (_ref32 = (_option$option_group_4 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_4 !== void 0 ? _option$option_group_4 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref32 !== void 0 ? _ref32 : null,
1981
2010
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
1982
- add_price: _this11.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
2011
+ add_price: _this13.normalizeFingerprintMoney((_option$add_price2 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price2 !== void 0 ? _option$add_price2 : option === null || option === void 0 ? void 0 : option.price)
1983
2012
  };
1984
2013
  })
1985
2014
  }),
@@ -1993,14 +2022,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1993
2022
  num: getSafeProductNum((_bundle$num2 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num2 !== void 0 ? _bundle$num2 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity),
1994
2023
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
1995
2024
  price_type_ext: (_bundle$price_type_ex2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type_ext) !== null && _bundle$price_type_ex2 !== void 0 ? _bundle$price_type_ex2 : '',
1996
- option: _this11.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2025
+ option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
1997
2026
  var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
1998
2027
  return {
1999
2028
  id: (_ref38 = (_option$id3 = option === null || option === void 0 ? void 0 : option.id) !== null && _option$id3 !== void 0 ? _option$id3 : option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _ref38 !== void 0 ? _ref38 : null,
2000
2029
  option_group_id: (_option$option_group_5 = option === null || option === void 0 ? void 0 : option.option_group_id) !== null && _option$option_group_5 !== void 0 ? _option$option_group_5 : null,
2001
2030
  option_group_item_id: (_ref39 = (_option$option_group_6 = option === null || option === void 0 ? void 0 : option.option_group_item_id) !== null && _option$option_group_6 !== void 0 ? _option$option_group_6 : option === null || option === void 0 ? void 0 : option.id) !== null && _ref39 !== void 0 ? _ref39 : null,
2002
2031
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2003
- add_price: _this11.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2032
+ add_price: _this13.normalizeFingerprintMoney((_option$add_price3 = option === null || option === void 0 ? void 0 : option.add_price) !== null && _option$add_price3 !== void 0 ? _option$add_price3 : option === null || option === void 0 ? void 0 : option.price)
2004
2033
  };
2005
2034
  }))
2006
2035
  };
@@ -2010,7 +2039,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2010
2039
  return {
2011
2040
  type: (_ref40 = (_discount$type4 = discount === null || discount === void 0 ? void 0 : discount.type) !== null && _discount$type4 !== void 0 ? _discount$type4 : discount === null || discount === void 0 ? void 0 : discount.tag) !== null && _ref40 !== void 0 ? _ref40 : '',
2012
2041
  discount_id: (_ref41 = (_ref42 = (_discount$discount_id2 = discount === null || discount === void 0 ? void 0 : discount.discount_id) !== null && _discount$discount_id2 !== void 0 ? _discount$discount_id2 : discount === null || discount === void 0 ? void 0 : discount.order_discount_id) !== null && _ref42 !== void 0 ? _ref42 : discount === null || discount === void 0 || (_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) !== null && _ref41 !== void 0 ? _ref41 : null,
2013
- amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2042
+ amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2014
2043
  };
2015
2044
  }))
2016
2045
  };
@@ -2018,9 +2047,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2018
2047
  }, {
2019
2048
  key: "buildOrderProductsStructuralFingerprint",
2020
2049
  value: function buildOrderProductsStructuralFingerprint(products) {
2021
- var _this12 = this;
2050
+ var _this14 = this;
2022
2051
  var items = (products || []).map(function (product) {
2023
- return _this12.buildProductStructuralFingerprintItem(product);
2052
+ return _this14.buildProductStructuralFingerprintItem(product);
2024
2053
  });
2025
2054
  items.sort(function (left, right) {
2026
2055
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2448,9 +2477,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2448
2477
  }, {
2449
2478
  key: "sanitizeTempOrderProducts",
2450
2479
  value: function sanitizeTempOrderProducts(tempOrder) {
2451
- var _this13 = this;
2480
+ var _this15 = this;
2452
2481
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2453
- return _this13.sanitizeOrderProductForTempOrder(product);
2482
+ return _this15.sanitizeOrderProductForTempOrder(product);
2454
2483
  });
2455
2484
  }
2456
2485
  }, {
@@ -2553,7 +2582,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2553
2582
  }, {
2554
2583
  key: "syncLinkedBookingHoldersToProducts",
2555
2584
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2556
- var _this14 = this;
2585
+ var _this16 = this;
2557
2586
  var bookings = tempOrder.bookings || [];
2558
2587
  var products = tempOrder.products || [];
2559
2588
  if (!bookings.length || !products.length) return;
@@ -2578,7 +2607,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2578
2607
  var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2579
2608
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2580
2609
  if (linkedBooking) {
2581
- _this14.setProductHolderFromBooking(product, linkedBooking);
2610
+ _this16.setProductHolderFromBooking(product, linkedBooking);
2582
2611
  }
2583
2612
  });
2584
2613
  }
@@ -2706,9 +2735,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2706
2735
  }, {
2707
2736
  key: "findBookingIndexByUniqueIdentificationNumber",
2708
2737
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
2709
- var _this15 = this;
2738
+ var _this17 = this;
2710
2739
  return (tempOrder.bookings || []).findIndex(function (booking) {
2711
- return _this15.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2740
+ return _this17.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2712
2741
  });
2713
2742
  }
2714
2743
  }, {
@@ -2716,12 +2745,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2716
2745
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2717
2746
  var _product$metadata7,
2718
2747
  _product$metadata8,
2719
- _this16 = this;
2748
+ _this18 = this;
2720
2749
  var productUid = (product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
2721
2750
  var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata8 = product.metadata) === null || _product$metadata8 === void 0 ? void 0 : _product$metadata8.booking_uid);
2722
2751
  if (!productUid && !bookingUid) return;
2723
2752
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2724
- var currentBookingUid = _this16.getBookingUniqueIdentificationNumber(booking);
2753
+ var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
2725
2754
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2726
2755
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
2727
2756
  return true;
@@ -3054,15 +3083,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3054
3083
  }, {
3055
3084
  key: "productHasCustomerBoundDiscount",
3056
3085
  value: function productHasCustomerBoundDiscount(product) {
3057
- var _this17 = this;
3086
+ var _this19 = this;
3058
3087
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3059
- return _this17.isCustomerBoundDiscount(discount);
3088
+ return _this19.isCustomerBoundDiscount(discount);
3060
3089
  })) {
3061
3090
  return true;
3062
3091
  }
3063
3092
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3064
3093
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3065
- return _this17.isCustomerBoundDiscount(discount);
3094
+ return _this19.isCustomerBoundDiscount(discount);
3066
3095
  });
3067
3096
  });
3068
3097
  }
@@ -3071,18 +3100,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3071
3100
  value: function shouldSkipDiscountCalculation(tempOrder) {
3072
3101
  var _this$store$discount17,
3073
3102
  _this$store$discount18,
3074
- _this18 = this;
3103
+ _this20 = this;
3075
3104
  if (this.hasActiveCustomerBoundDiscount) return false;
3076
3105
  var discountList = ((_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 || (_this$store$discount18 = _this$store$discount17.getDiscountList) === null || _this$store$discount18 === void 0 ? void 0 : _this$store$discount18.call(_this$store$discount17)) || [];
3077
3106
  if (discountList.length > 0) return false;
3078
3107
  return !(tempOrder.products || []).some(function (product) {
3079
- return _this18.productHasCustomerBoundDiscount(product);
3108
+ return _this20.productHasCustomerBoundDiscount(product);
3080
3109
  });
3081
3110
  }
3082
3111
  }, {
3083
3112
  key: "clearCustomerBoundDiscounts",
3084
3113
  value: function clearCustomerBoundDiscounts(tempOrder) {
3085
- var _this19 = this,
3114
+ var _this21 = this,
3086
3115
  _discountModule$getDi,
3087
3116
  _discountModule$getOr,
3088
3117
  _discountModule$setDi,
@@ -3091,7 +3120,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3091
3120
  var filterDiscountList = function filterDiscountList(discountList) {
3092
3121
  if (!Array.isArray(discountList)) return [];
3093
3122
  return discountList.filter(function (discount) {
3094
- var shouldRemove = _this19.isCustomerBoundDiscount(discount);
3123
+ var shouldRemove = _this21.isCustomerBoundDiscount(discount);
3095
3124
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3096
3125
  return !shouldRemove;
3097
3126
  });
@@ -3118,12 +3147,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3118
3147
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3119
3148
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3120
3149
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3121
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3122
- return !_this19.isCustomerBoundDiscount(discount);
3150
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3151
+ return !_this21.isCustomerBoundDiscount(discount);
3123
3152
  });
3124
3153
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3125
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3126
- return !_this19.isCustomerBoundDiscount(discount);
3154
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3155
+ return !_this21.isCustomerBoundDiscount(discount);
3127
3156
  });
3128
3157
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3129
3158
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3275,23 +3304,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3275
3304
  * 用一组支付来源覆盖当前订单支付项。
3276
3305
  *
3277
3306
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
3278
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
3307
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
3279
3308
  * isSynced 等运行态字段不会进入 tempOrder.payments。
3280
3309
  */
3281
3310
  }, {
3282
3311
  key: "setOrderPayments",
3283
3312
  value: function setOrderPayments(payments) {
3313
+ var _this22 = this;
3284
3314
  var tempOrder = this.ensureTempOrder();
3285
- tempOrder.payments = mapPaymentItemsToOrderPayments(payments);
3315
+ tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
3316
+ return _this22.normalizePaymentSource(payment, {
3317
+ defaultPaid: false
3318
+ });
3319
+ }));
3286
3320
  this.persistTempOrder();
3287
3321
  return tempOrder.payments;
3288
3322
  }
3289
3323
 
3290
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
3324
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
3291
3325
  }, {
3292
3326
  key: "addOrderPayment",
3293
3327
  value: function addOrderPayment(payment) {
3294
- var _this20 = this;
3328
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3329
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3330
+ }
3331
+
3332
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
3333
+ }, {
3334
+ key: "addOrderPaymentAsync",
3335
+ value: (function () {
3336
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(payment) {
3337
+ var hasPaymentNumber, devicePrefix;
3338
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3339
+ while (1) switch (_context17.prev = _context17.next) {
3340
+ case 0:
3341
+ hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3342
+ if (!hasPaymentNumber) {
3343
+ _context17.next = 5;
3344
+ break;
3345
+ }
3346
+ _context17.t0 = 'LOCAL';
3347
+ _context17.next = 8;
3348
+ break;
3349
+ case 5:
3350
+ _context17.next = 7;
3351
+ return this.getPaymentNumberDevicePrefixAsync();
3352
+ case 7:
3353
+ _context17.t0 = _context17.sent;
3354
+ case 8:
3355
+ devicePrefix = _context17.t0;
3356
+ return _context17.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3357
+ case 10:
3358
+ case "end":
3359
+ return _context17.stop();
3360
+ }
3361
+ }, _callee15, this);
3362
+ }));
3363
+ function addOrderPaymentAsync(_x14) {
3364
+ return _addOrderPaymentAsync.apply(this, arguments);
3365
+ }
3366
+ return addOrderPaymentAsync;
3367
+ }())
3368
+ }, {
3369
+ key: "addOrderPaymentWithDevicePrefix",
3370
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3371
+ var _this23 = this;
3295
3372
  this.logInfo('addOrderPayment', {
3296
3373
  payment: payment
3297
3374
  });
@@ -3301,14 +3378,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3301
3378
  type: orderPaymentType,
3302
3379
  order_payment_type: orderPaymentType
3303
3380
  }), {
3304
- defaultPaid: true
3381
+ defaultPaid: true,
3382
+ devicePrefix: devicePrefix
3305
3383
  })]);
3306
3384
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
3307
3385
  this.persistTempOrder();
3308
3386
  void this.recalculateSummary({
3309
3387
  createIfMissing: true
3310
3388
  }).catch(function (error) {
3311
- _this20.logError('recalculate summary after addOrderPayment failed', {
3389
+ _this23.logError('recalculate summary after addOrderPayment failed', {
3312
3390
  error: error instanceof Error ? error.message : String(error)
3313
3391
  });
3314
3392
  });
@@ -3316,49 +3394,80 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3316
3394
  }
3317
3395
 
3318
3396
  /**
3319
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
3320
- *
3321
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
3322
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
3397
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
3398
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
3323
3399
  */
3324
3400
  }, {
3325
3401
  key: "updateOrderPayment",
3326
- value: function updateOrderPayment(paymentIdentity, updates) {
3327
- var tempOrder = this.ensureTempOrder();
3328
- var identity = String(paymentIdentity);
3329
- tempOrder.payments = (tempOrder.payments || []).map(function (payment) {
3330
- var _payment$metadata;
3331
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.unique_payment_number;
3332
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3333
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3334
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3335
- var matched = [uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3336
- return value !== undefined && String(value) === identity;
3337
- });
3338
- if (!matched) return payment;
3339
- return _objectSpread(_objectSpread(_objectSpread({}, payment), updates), {}, {
3340
- metadata: _objectSpread(_objectSpread({}, payment.metadata || {}), updates.metadata || {})
3341
- });
3342
- });
3343
- this.persistTempOrder();
3344
- return tempOrder.payments;
3345
- }
3346
-
3347
- /** 从当前订单支付项中移除指定支付项。 */
3402
+ value: (function () {
3403
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentIdentity, updates) {
3404
+ var options,
3405
+ tempOrder,
3406
+ identity,
3407
+ matchMode,
3408
+ matchedPayment,
3409
+ updatedPayment,
3410
+ summary,
3411
+ payments,
3412
+ _args18 = arguments;
3413
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3414
+ while (1) switch (_context18.prev = _context18.next) {
3415
+ case 0:
3416
+ options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
3417
+ tempOrder = this.ensureTempOrder();
3418
+ identity = String(paymentIdentity);
3419
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3420
+ matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
3421
+ if (matchedPayment) {
3422
+ _context18.next = 7;
3423
+ break;
3424
+ }
3425
+ throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
3426
+ case 7:
3427
+ updatedPayment = null;
3428
+ tempOrder.payments = (tempOrder.payments || []).map(function (payment, index) {
3429
+ if (index !== matchedPayment.index) return payment;
3430
+ var nextPayment = mergeOrderPaymentRecord(payment, _objectSpread(_objectSpread({}, updates), {}, {
3431
+ updated_at: updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
3432
+ }));
3433
+ updatedPayment = nextPayment;
3434
+ return nextPayment;
3435
+ });
3436
+ this.persistTempOrder();
3437
+ _context18.next = 12;
3438
+ return this.recalculateSummary({
3439
+ createIfMissing: true
3440
+ });
3441
+ case 12:
3442
+ summary = _context18.sent;
3443
+ this.persistTempOrder();
3444
+ payments = tempOrder.payments;
3445
+ return _context18.abrupt("return", {
3446
+ updated: true,
3447
+ payment: payments[matchedPayment.index] || updatedPayment,
3448
+ payments: payments,
3449
+ summary: summary
3450
+ });
3451
+ case 16:
3452
+ case "end":
3453
+ return _context18.stop();
3454
+ }
3455
+ }, _callee16, this);
3456
+ }));
3457
+ function updateOrderPayment(_x15, _x16) {
3458
+ return _updateOrderPayment.apply(this, arguments);
3459
+ }
3460
+ return updateOrderPayment;
3461
+ }() /** 从当前订单支付项中移除指定支付项。 */)
3348
3462
  }, {
3349
3463
  key: "deleteOrderPayment",
3350
3464
  value: function deleteOrderPayment(paymentIdentity) {
3351
3465
  var tempOrder = this.ensureTempOrder();
3352
3466
  var identity = String(paymentIdentity);
3353
- tempOrder.payments = (tempOrder.payments || []).filter(function (payment) {
3354
- var _payment$metadata2;
3355
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata2 = payment.metadata) === null || _payment$metadata2 === void 0 ? void 0 : _payment$metadata2.unique_payment_number;
3356
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3357
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3358
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3359
- return ![uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3360
- return value !== undefined && String(value) === identity;
3361
- });
3467
+ var matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, 'compat');
3468
+ if (!matchedPayment) return tempOrder.payments;
3469
+ tempOrder.payments = (tempOrder.payments || []).filter(function (_, index) {
3470
+ return index !== matchedPayment.index;
3362
3471
  });
3363
3472
  this.persistTempOrder();
3364
3473
  return tempOrder.payments;
@@ -3390,7 +3499,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3390
3499
  }, {
3391
3500
  key: "applyPaymentLifecycleChange",
3392
3501
  value: function applyPaymentLifecycleChange(tempOrder, options) {
3393
- var _this21 = this;
3502
+ var _this24 = this;
3394
3503
  this.updateTempOrderPaymentStatus(tempOrder);
3395
3504
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3396
3505
  this.persistTempOrder();
@@ -3400,7 +3509,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3400
3509
  void this.recalculateSummary({
3401
3510
  createIfMissing: true
3402
3511
  }).catch(function (error) {
3403
- _this21.logError("recalculate summary after ".concat(logContext, " failed"), {
3512
+ _this24.logError("recalculate summary after ".concat(logContext, " failed"), {
3404
3513
  error: error instanceof Error ? error.message : String(error)
3405
3514
  });
3406
3515
  });
@@ -3444,7 +3553,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3444
3553
  }, {
3445
3554
  key: "updateVoucherOrderPayments",
3446
3555
  value: function updateVoucherOrderPayments(payments, options) {
3447
- var _this22 = this;
3556
+ var _this25 = this;
3448
3557
  var tempOrder = this.ensureTempOrder();
3449
3558
  var isOrderPaymentType = function isOrderPaymentType(value) {
3450
3559
  return value === 'normal' || value === 'deposit';
@@ -3479,8 +3588,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3479
3588
  });
3480
3589
  };
3481
3590
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3482
- return _this22.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3483
- defaultPaid: false
3591
+ return _this25.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3592
+ defaultPaid: false,
3593
+ devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
3484
3594
  });
3485
3595
  })).filter(function (payment) {
3486
3596
  return isVoucherPaymentRecord(payment);
@@ -3528,54 +3638,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3528
3638
  void this.recalculateSummary({
3529
3639
  createIfMissing: true
3530
3640
  }).catch(function (error) {
3531
- _this22.logError('recalculate summary after updateVoucherOrderPayments failed', {
3641
+ _this25.logError('recalculate summary after updateVoucherOrderPayments failed', {
3532
3642
  error: error instanceof Error ? error.message : String(error)
3533
3643
  });
3534
3644
  });
3535
3645
  return tempOrder.payments;
3536
3646
  }
3647
+ }, {
3648
+ key: "updateVoucherOrderPaymentsAsync",
3649
+ value: function () {
3650
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(payments, options) {
3651
+ var needsPaymentNumber, devicePrefix;
3652
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3653
+ while (1) switch (_context19.prev = _context19.next) {
3654
+ case 0:
3655
+ needsPaymentNumber = (payments || []).some(function (payment) {
3656
+ return String(payment.payment_number || '').trim() === '';
3657
+ });
3658
+ if (!needsPaymentNumber) {
3659
+ _context19.next = 7;
3660
+ break;
3661
+ }
3662
+ _context19.next = 4;
3663
+ return this.getPaymentNumberDevicePrefixAsync();
3664
+ case 4:
3665
+ _context19.t0 = _context19.sent;
3666
+ _context19.next = 8;
3667
+ break;
3668
+ case 7:
3669
+ _context19.t0 = 'LOCAL';
3670
+ case 8:
3671
+ devicePrefix = _context19.t0;
3672
+ return _context19.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
3673
+ devicePrefix: devicePrefix
3674
+ })));
3675
+ case 10:
3676
+ case "end":
3677
+ return _context19.stop();
3678
+ }
3679
+ }, _callee17, this);
3680
+ }));
3681
+ function updateVoucherOrderPaymentsAsync(_x17, _x18) {
3682
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3683
+ }
3684
+ return updateVoucherOrderPaymentsAsync;
3685
+ }()
3537
3686
  }, {
3538
3687
  key: "shouldMergeProductToOrder",
3539
3688
  value: function () {
3540
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
3689
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3541
3690
  var _this$orderHooks;
3542
3691
  var onBeforeMergeProductToOrder, result;
3543
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3544
- while (1) switch (_context17.prev = _context17.next) {
3692
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3693
+ while (1) switch (_context20.prev = _context20.next) {
3545
3694
  case 0:
3546
3695
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3547
3696
  if (onBeforeMergeProductToOrder) {
3548
- _context17.next = 3;
3697
+ _context20.next = 3;
3549
3698
  break;
3550
3699
  }
3551
- return _context17.abrupt("return", true);
3700
+ return _context20.abrupt("return", true);
3552
3701
  case 3:
3553
- _context17.next = 5;
3702
+ _context20.next = 5;
3554
3703
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3555
3704
  defaultShouldMerge: true
3556
3705
  }));
3557
3706
  case 5:
3558
- result = _context17.sent;
3707
+ result = _context20.sent;
3559
3708
  if (!(typeof result === 'boolean')) {
3560
- _context17.next = 8;
3709
+ _context20.next = 8;
3561
3710
  break;
3562
3711
  }
3563
- return _context17.abrupt("return", result);
3712
+ return _context20.abrupt("return", result);
3564
3713
  case 8:
3565
3714
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3566
- _context17.next = 10;
3715
+ _context20.next = 10;
3567
3716
  break;
3568
3717
  }
3569
- return _context17.abrupt("return", result.shouldMerge);
3718
+ return _context20.abrupt("return", result.shouldMerge);
3570
3719
  case 10:
3571
- return _context17.abrupt("return", true);
3720
+ return _context20.abrupt("return", true);
3572
3721
  case 11:
3573
3722
  case "end":
3574
- return _context17.stop();
3723
+ return _context20.stop();
3575
3724
  }
3576
- }, _callee15, this);
3725
+ }, _callee18, this);
3577
3726
  }));
3578
- function shouldMergeProductToOrder(_x14) {
3727
+ function shouldMergeProductToOrder(_x19) {
3579
3728
  return _shouldMergeProductToOrder.apply(this, arguments);
3580
3729
  }
3581
3730
  return shouldMergeProductToOrder;
@@ -3611,30 +3760,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3611
3760
  }, {
3612
3761
  key: "finalizeProductOrderMutation",
3613
3762
  value: function () {
3614
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, options) {
3615
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3616
- while (1) switch (_context18.prev = _context18.next) {
3763
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3764
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3765
+ while (1) switch (_context21.prev = _context21.next) {
3617
3766
  case 0:
3618
3767
  this.syncTempOrderHolderFromBookings(tempOrder);
3619
3768
  if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3620
- _context18.next = 4;
3769
+ _context21.next = 4;
3621
3770
  break;
3622
3771
  }
3623
- _context18.next = 4;
3772
+ _context21.next = 4;
3624
3773
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3625
3774
  case 4:
3626
3775
  if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3627
- _context18.next = 7;
3776
+ _context21.next = 7;
3628
3777
  break;
3629
3778
  }
3630
- _context18.next = 7;
3779
+ _context21.next = 7;
3631
3780
  return this.applyPromotion();
3632
3781
  case 7:
3633
3782
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
3634
3783
  this.applyDiscount();
3635
3784
  }
3636
3785
  this.sanitizeTempOrderProducts(tempOrder);
3637
- _context18.next = 11;
3786
+ _context21.next = 11;
3638
3787
  return this.recalculateSummary({
3639
3788
  createIfMissing: true
3640
3789
  });
@@ -3642,11 +3791,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3642
3791
  this.persistTempOrder();
3643
3792
  case 12:
3644
3793
  case "end":
3645
- return _context18.stop();
3794
+ return _context21.stop();
3646
3795
  }
3647
- }, _callee16, this);
3796
+ }, _callee19, this);
3648
3797
  }));
3649
- function finalizeProductOrderMutation(_x15, _x16) {
3798
+ function finalizeProductOrderMutation(_x20, _x21) {
3650
3799
  return _finalizeProductOrderMutation.apply(this, arguments);
3651
3800
  }
3652
3801
  return finalizeProductOrderMutation;
@@ -3661,13 +3810,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3661
3810
  }, {
3662
3811
  key: "appendProductLineToTempOrder",
3663
3812
  value: (function () {
3664
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(tempOrder, product, booking) {
3813
+ var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking) {
3665
3814
  var _booking_uid,
3666
3815
  _metadata,
3667
- _this23 = this;
3816
+ _this26 = this;
3668
3817
  var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3669
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3670
- while (1) switch (_context19.prev = _context19.next) {
3818
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3819
+ while (1) switch (_context22.prev = _context22.next) {
3671
3820
  case 0:
3672
3821
  linked = booking ? this.createLinkedProductAndBooking({
3673
3822
  product: product,
@@ -3689,8 +3838,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3689
3838
  hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3690
3839
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3691
3840
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3692
- if (_this23.hasGoodPassDiscount(item)) return false;
3693
- if (_this23.hasOrderProductLineNote(item)) return false;
3841
+ if (_this26.hasGoodPassDiscount(item)) return false;
3842
+ if (_this26.hasOrderProductLineNote(item)) return false;
3694
3843
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3695
3844
  if (item.product_id !== productToAdd.product_id) return false;
3696
3845
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
@@ -3700,10 +3849,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3700
3849
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3701
3850
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3702
3851
  if (!matchedProduct) {
3703
- _context19.next = 20;
3852
+ _context22.next = 20;
3704
3853
  break;
3705
3854
  }
3706
- _context19.next = 17;
3855
+ _context22.next = 17;
3707
3856
  return this.shouldMergeProductToOrder({
3708
3857
  incomingProduct: productToAdd,
3709
3858
  normalizedIncoming: normalizedIncoming,
@@ -3715,13 +3864,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3715
3864
  booking: booking
3716
3865
  });
3717
3866
  case 17:
3718
- _context19.t0 = _context19.sent;
3719
- _context19.next = 21;
3867
+ _context22.t0 = _context22.sent;
3868
+ _context22.next = 21;
3720
3869
  break;
3721
3870
  case 20:
3722
- _context19.t0 = false;
3871
+ _context22.t0 = false;
3723
3872
  case 21:
3724
- shouldMerge = _context19.t0;
3873
+ shouldMerge = _context22.t0;
3725
3874
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3726
3875
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
3727
3876
  if (linked) {
@@ -3775,11 +3924,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3775
3924
  }
3776
3925
  case 24:
3777
3926
  case "end":
3778
- return _context19.stop();
3927
+ return _context22.stop();
3779
3928
  }
3780
- }, _callee17, this);
3929
+ }, _callee20, this);
3781
3930
  }));
3782
- function appendProductLineToTempOrder(_x17, _x18, _x19) {
3931
+ function appendProductLineToTempOrder(_x22, _x23, _x24) {
3783
3932
  return _appendProductLineToTempOrder.apply(this, arguments);
3784
3933
  }
3785
3934
  return appendProductLineToTempOrder;
@@ -3795,61 +3944,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3795
3944
  }, {
3796
3945
  key: "addProductToOrder",
3797
3946
  value: (function () {
3798
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(product, booking) {
3947
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking) {
3799
3948
  var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3800
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3801
- while (1) switch (_context20.prev = _context20.next) {
3949
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
3950
+ while (1) switch (_context23.prev = _context23.next) {
3802
3951
  case 0:
3803
3952
  tempOrder = this.ensureTempOrder();
3804
3953
  if (!booking) {
3805
- _context20.next = 18;
3954
+ _context23.next = 18;
3806
3955
  break;
3807
3956
  }
3808
3957
  productRecord = product;
3809
3958
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3810
3959
  if (!(splitCount > 1)) {
3811
- _context20.next = 18;
3960
+ _context23.next = 18;
3812
3961
  break;
3813
3962
  }
3814
3963
  i = 0;
3815
3964
  case 6:
3816
3965
  if (!(i < splitCount)) {
3817
- _context20.next = 15;
3966
+ _context23.next = 15;
3818
3967
  break;
3819
3968
  }
3820
3969
  singleLine = cloneDeep(productRecord);
3821
3970
  singleLine.num = 1;
3822
3971
  delete singleLine.product_quantity;
3823
- _context20.next = 12;
3972
+ _context23.next = 12;
3824
3973
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3825
3974
  case 12:
3826
3975
  i += 1;
3827
- _context20.next = 6;
3976
+ _context23.next = 6;
3828
3977
  break;
3829
3978
  case 15:
3830
- _context20.next = 17;
3979
+ _context23.next = 17;
3831
3980
  return this.finalizeProductOrderMutation(tempOrder);
3832
3981
  case 17:
3833
- return _context20.abrupt("return", tempOrder.products);
3982
+ return _context23.abrupt("return", tempOrder.products);
3834
3983
  case 18:
3835
- _context20.next = 20;
3984
+ _context23.next = 20;
3836
3985
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3837
3986
  case 20:
3838
- _context20.next = 22;
3987
+ _context23.next = 22;
3839
3988
  return this.finalizeProductOrderMutation(tempOrder);
3840
3989
  case 22:
3841
3990
  this.logInfo('addProductToOrder success', {
3842
3991
  product_id: product.product_id,
3843
3992
  with_booking: !!booking
3844
3993
  });
3845
- return _context20.abrupt("return", tempOrder.products);
3994
+ return _context23.abrupt("return", tempOrder.products);
3846
3995
  case 24:
3847
3996
  case "end":
3848
- return _context20.stop();
3997
+ return _context23.stop();
3849
3998
  }
3850
- }, _callee18, this);
3999
+ }, _callee21, this);
3851
4000
  }));
3852
- function addProductToOrder(_x20, _x21) {
4001
+ function addProductToOrder(_x25, _x26) {
3853
4002
  return _addProductToOrder.apply(this, arguments);
3854
4003
  }
3855
4004
  return addProductToOrder;
@@ -3867,93 +4016,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3867
4016
  }, {
3868
4017
  key: "addProductsToOrder",
3869
4018
  value: (function () {
3870
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(items, options) {
4019
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
3871
4020
  var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3872
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3873
- while (1) switch (_context21.prev = _context21.next) {
4021
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4022
+ while (1) switch (_context24.prev = _context24.next) {
3874
4023
  case 0:
3875
4024
  tempOrder = this.ensureTempOrder();
3876
4025
  if (!(!Array.isArray(items) || items.length === 0)) {
3877
- _context21.next = 3;
4026
+ _context24.next = 3;
3878
4027
  break;
3879
4028
  }
3880
- return _context21.abrupt("return", tempOrder.products);
4029
+ return _context24.abrupt("return", tempOrder.products);
3881
4030
  case 3:
3882
4031
  _iterator20 = _createForOfIteratorHelper(items || []);
3883
- _context21.prev = 4;
4032
+ _context24.prev = 4;
3884
4033
  _iterator20.s();
3885
4034
  case 6:
3886
4035
  if ((_step20 = _iterator20.n()).done) {
3887
- _context21.next = 30;
4036
+ _context24.next = 30;
3888
4037
  break;
3889
4038
  }
3890
4039
  item = _step20.value;
3891
4040
  product = item.product, booking = item.booking;
3892
4041
  if (product) {
3893
- _context21.next = 11;
4042
+ _context24.next = 11;
3894
4043
  break;
3895
4044
  }
3896
- return _context21.abrupt("continue", 28);
4045
+ return _context24.abrupt("continue", 28);
3897
4046
  case 11:
3898
4047
  if (!booking) {
3899
- _context21.next = 26;
4048
+ _context24.next = 26;
3900
4049
  break;
3901
4050
  }
3902
4051
  productRecord = product;
3903
4052
  splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3904
4053
  if (!(splitCount > 1)) {
3905
- _context21.next = 26;
4054
+ _context24.next = 26;
3906
4055
  break;
3907
4056
  }
3908
4057
  i = 0;
3909
4058
  case 16:
3910
4059
  if (!(i < splitCount)) {
3911
- _context21.next = 25;
4060
+ _context24.next = 25;
3912
4061
  break;
3913
4062
  }
3914
4063
  singleLine = cloneDeep(productRecord);
3915
4064
  singleLine.num = 1;
3916
4065
  delete singleLine.product_quantity;
3917
- _context21.next = 22;
4066
+ _context24.next = 22;
3918
4067
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3919
4068
  case 22:
3920
4069
  i += 1;
3921
- _context21.next = 16;
4070
+ _context24.next = 16;
3922
4071
  break;
3923
4072
  case 25:
3924
- return _context21.abrupt("continue", 28);
4073
+ return _context24.abrupt("continue", 28);
3925
4074
  case 26:
3926
- _context21.next = 28;
4075
+ _context24.next = 28;
3927
4076
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3928
4077
  case 28:
3929
- _context21.next = 6;
4078
+ _context24.next = 6;
3930
4079
  break;
3931
4080
  case 30:
3932
- _context21.next = 35;
4081
+ _context24.next = 35;
3933
4082
  break;
3934
4083
  case 32:
3935
- _context21.prev = 32;
3936
- _context21.t0 = _context21["catch"](4);
3937
- _iterator20.e(_context21.t0);
4084
+ _context24.prev = 32;
4085
+ _context24.t0 = _context24["catch"](4);
4086
+ _iterator20.e(_context24.t0);
3938
4087
  case 35:
3939
- _context21.prev = 35;
4088
+ _context24.prev = 35;
3940
4089
  _iterator20.f();
3941
- return _context21.finish(35);
4090
+ return _context24.finish(35);
3942
4091
  case 38:
3943
- _context21.next = 40;
4092
+ _context24.next = 40;
3944
4093
  return this.finalizeProductOrderMutation(tempOrder, options);
3945
4094
  case 40:
3946
4095
  this.logInfo('addProductsToOrder success', {
3947
4096
  itemsCount: items.length
3948
4097
  });
3949
- return _context21.abrupt("return", tempOrder.products);
4098
+ return _context24.abrupt("return", tempOrder.products);
3950
4099
  case 42:
3951
4100
  case "end":
3952
- return _context21.stop();
4101
+ return _context24.stop();
3953
4102
  }
3954
- }, _callee19, this, [[4, 32, 35, 38]]);
4103
+ }, _callee22, this, [[4, 32, 35, 38]]);
3955
4104
  }));
3956
- function addProductsToOrder(_x22, _x23) {
4105
+ function addProductsToOrder(_x27, _x28) {
3957
4106
  return _addProductsToOrder.apply(this, arguments);
3958
4107
  }
3959
4108
  return addProductsToOrder;
@@ -3987,17 +4136,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3987
4136
  }, {
3988
4137
  key: "preservePersistedBundlePriceFields",
3989
4138
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
3990
- var _this24 = this;
4139
+ var _this27 = this;
3991
4140
  if (!Array.isArray(nextBundles)) return nextBundles;
3992
4141
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
3993
4142
  var previousByIdentity = new Map();
3994
4143
  previousBundles.forEach(function (bundle) {
3995
- var identity = _this24.getBundleRuntimeIdentity(bundle);
4144
+ var identity = _this27.getBundleRuntimeIdentity(bundle);
3996
4145
  if (identity) previousByIdentity.set(identity, bundle);
3997
4146
  });
3998
4147
  return nextBundles.map(function (bundle, index) {
3999
4148
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4000
- var previous = previousByIdentity.get(_this24.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4149
+ var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4001
4150
  if (!previous || _typeof(previous) !== 'object') return bundle;
4002
4151
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4003
4152
  cover: previous.cover
@@ -4150,21 +4299,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4150
4299
  }, {
4151
4300
  key: "updateOrderProduct",
4152
4301
  value: function () {
4153
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
4302
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4154
4303
  var tempOrder, updatedProductUid;
4155
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4156
- while (1) switch (_context22.prev = _context22.next) {
4304
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4305
+ while (1) switch (_context25.prev = _context25.next) {
4157
4306
  case 0:
4158
4307
  tempOrder = this.ensureTempOrder();
4159
4308
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4160
- _context22.next = 4;
4309
+ _context25.next = 4;
4161
4310
  return this.applyPromotion();
4162
4311
  case 4:
4163
4312
  this.applyDiscount({
4164
4313
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4165
4314
  });
4166
4315
  this.sanitizeTempOrderProducts(tempOrder);
4167
- _context22.next = 8;
4316
+ _context25.next = 8;
4168
4317
  return this.recalculateSummary({
4169
4318
  createIfMissing: true
4170
4319
  });
@@ -4173,14 +4322,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4173
4322
  this.logInfo('updateOrderProduct success', {
4174
4323
  params: params
4175
4324
  });
4176
- return _context22.abrupt("return", tempOrder.products);
4325
+ return _context25.abrupt("return", tempOrder.products);
4177
4326
  case 11:
4178
4327
  case "end":
4179
- return _context22.stop();
4328
+ return _context25.stop();
4180
4329
  }
4181
- }, _callee20, this);
4330
+ }, _callee23, this);
4182
4331
  }));
4183
- function updateOrderProduct(_x24) {
4332
+ function updateOrderProduct(_x29) {
4184
4333
  return _updateOrderProduct.apply(this, arguments);
4185
4334
  }
4186
4335
  return updateOrderProduct;
@@ -4188,28 +4337,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4188
4337
  }, {
4189
4338
  key: "updateOrderProducts",
4190
4339
  value: function () {
4191
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(paramsList) {
4192
- var _this25 = this;
4340
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4341
+ var _this28 = this;
4193
4342
  var tempOrder, reapplyBookingDiscountProductUids;
4194
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4195
- while (1) switch (_context23.prev = _context23.next) {
4343
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4344
+ while (1) switch (_context26.prev = _context26.next) {
4196
4345
  case 0:
4197
4346
  tempOrder = this.ensureTempOrder();
4198
4347
  if (paramsList.length) {
4199
- _context23.next = 3;
4348
+ _context26.next = 3;
4200
4349
  break;
4201
4350
  }
4202
- return _context23.abrupt("return", tempOrder.products);
4351
+ return _context26.abrupt("return", tempOrder.products);
4203
4352
  case 3:
4204
4353
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4205
- var updatedProductUid = _this25.applyOrderProductUpdateToTempOrder(tempOrder, params);
4354
+ var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4206
4355
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4207
4356
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4208
4357
  acc.push(String(updatedProductUid));
4209
4358
  }
4210
4359
  return acc;
4211
4360
  }, []);
4212
- _context23.next = 6;
4361
+ _context26.next = 6;
4213
4362
  return this.finalizeAfterProductsMutation(tempOrder, {
4214
4363
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4215
4364
  });
@@ -4217,14 +4366,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4217
4366
  this.logInfo('updateOrderProduct success', {
4218
4367
  paramsList: paramsList
4219
4368
  });
4220
- return _context23.abrupt("return", tempOrder.products);
4369
+ return _context26.abrupt("return", tempOrder.products);
4221
4370
  case 8:
4222
4371
  case "end":
4223
- return _context23.stop();
4372
+ return _context26.stop();
4224
4373
  }
4225
- }, _callee21, this);
4374
+ }, _callee24, this);
4226
4375
  }));
4227
- function updateOrderProducts(_x25) {
4376
+ function updateOrderProducts(_x30) {
4228
4377
  return _updateOrderProducts.apply(this, arguments);
4229
4378
  }
4230
4379
  return updateOrderProducts;
@@ -4232,11 +4381,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4232
4381
  }, {
4233
4382
  key: "updateOrderProductQuantity",
4234
4383
  value: function () {
4235
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
4384
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4236
4385
  var _targetProduct$metada10;
4237
4386
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4238
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4239
- while (1) switch (_context24.prev = _context24.next) {
4387
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4388
+ while (1) switch (_context27.prev = _context27.next) {
4240
4389
  case 0:
4241
4390
  product_id = params.product_id, product_variant_id = params.product_variant_id, num = params.num, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_sku = params.product_sku, product_bundle = params.product_bundle;
4242
4391
  tempOrder = this.ensureTempOrder();
@@ -4265,7 +4414,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4265
4414
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4266
4415
  }
4267
4416
  if (!(productIndex === -1)) {
4268
- _context24.next = 12;
4417
+ _context27.next = 12;
4269
4418
  break;
4270
4419
  }
4271
4420
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -4279,12 +4428,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4279
4428
  }));
4280
4429
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4281
4430
  tempOrder.products[productIndex] = normalizedProduct;
4282
- _context24.next = 18;
4431
+ _context27.next = 18;
4283
4432
  return this.applyPromotion();
4284
4433
  case 18:
4285
4434
  this.applyDiscount();
4286
4435
  this.sanitizeTempOrderProducts(tempOrder);
4287
- _context24.next = 22;
4436
+ _context27.next = 22;
4288
4437
  return this.recalculateSummary({
4289
4438
  createIfMissing: true
4290
4439
  });
@@ -4293,14 +4442,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4293
4442
  this.logInfo('updateOrderProductQuantity success', {
4294
4443
  params: params
4295
4444
  });
4296
- return _context24.abrupt("return", tempOrder.products);
4445
+ return _context27.abrupt("return", tempOrder.products);
4297
4446
  case 25:
4298
4447
  case "end":
4299
- return _context24.stop();
4448
+ return _context27.stop();
4300
4449
  }
4301
- }, _callee22, this);
4450
+ }, _callee25, this);
4302
4451
  }));
4303
- function updateOrderProductQuantity(_x26) {
4452
+ function updateOrderProductQuantity(_x31) {
4304
4453
  return _updateOrderProductQuantity.apply(this, arguments);
4305
4454
  }
4306
4455
  return updateOrderProductQuantity;
@@ -4341,19 +4490,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4341
4490
  }, {
4342
4491
  key: "finalizeAfterProductsMutation",
4343
4492
  value: (function () {
4344
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(tempOrder, options) {
4345
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4346
- while (1) switch (_context25.prev = _context25.next) {
4493
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4494
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4495
+ while (1) switch (_context28.prev = _context28.next) {
4347
4496
  case 0:
4348
4497
  this.syncTempOrderHolderFromBookings(tempOrder);
4349
- _context25.next = 3;
4498
+ _context28.next = 3;
4350
4499
  return this.applyPromotion();
4351
4500
  case 3:
4352
4501
  this.applyDiscount({
4353
4502
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4354
4503
  });
4355
4504
  this.sanitizeTempOrderProducts(tempOrder);
4356
- _context25.next = 7;
4505
+ _context28.next = 7;
4357
4506
  return this.recalculateSummary({
4358
4507
  createIfMissing: true
4359
4508
  });
@@ -4361,11 +4510,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4361
4510
  this.persistTempOrder();
4362
4511
  case 8:
4363
4512
  case "end":
4364
- return _context25.stop();
4513
+ return _context28.stop();
4365
4514
  }
4366
- }, _callee23, this);
4515
+ }, _callee26, this);
4367
4516
  }));
4368
- function finalizeAfterProductsMutation(_x27, _x28) {
4517
+ function finalizeAfterProductsMutation(_x32, _x33) {
4369
4518
  return _finalizeAfterProductsMutation.apply(this, arguments);
4370
4519
  }
4371
4520
  return finalizeAfterProductsMutation;
@@ -4380,18 +4529,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4380
4529
  }, {
4381
4530
  key: "removeProductsFromOrder",
4382
4531
  value: (function () {
4383
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identities) {
4384
- var _this26 = this;
4532
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities) {
4533
+ var _this29 = this;
4385
4534
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4386
- return _regeneratorRuntime().wrap(function _callee24$(_context27) {
4387
- while (1) switch (_context27.prev = _context27.next) {
4535
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4536
+ while (1) switch (_context30.prev = _context30.next) {
4388
4537
  case 0:
4389
4538
  tempOrder = this.ensureTempOrder();
4390
4539
  if (identities.length) {
4391
- _context27.next = 3;
4540
+ _context30.next = 3;
4392
4541
  break;
4393
4542
  }
4394
- return _context27.abrupt("return", tempOrder.products);
4543
+ return _context30.abrupt("return", tempOrder.products);
4395
4544
  case 3:
4396
4545
  productsBeforeRemove = tempOrder.products || [];
4397
4546
  bookingsBeforeRemove = tempOrder.bookings || [];
@@ -4414,29 +4563,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4414
4563
  }
4415
4564
  linkedBookingUidsToRemove = new Set();
4416
4565
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4417
- _context27.prev = 11;
4566
+ _context30.prev = 11;
4418
4567
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4419
4568
  var _metadata8, _metadata9, _metadata10, _metadata11;
4420
4569
  var product, productUid, productBookingUid, isAddTimeProduct;
4421
- return _regeneratorRuntime().wrap(function _loop3$(_context26) {
4422
- while (1) switch (_context26.prev = _context26.next) {
4570
+ return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4571
+ while (1) switch (_context29.prev = _context29.next) {
4423
4572
  case 0:
4424
4573
  product = _step21.value;
4425
4574
  productUid = (product === null || product === void 0 || (_metadata8 = product.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4426
4575
  productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata9 = product.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.booking_uid);
4427
4576
  isAddTimeProduct = (product === null || product === void 0 || (_metadata10 = product.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.product_add_schedule_time) !== null;
4428
4577
  if (!isAddTimeProduct) {
4429
- _context26.next = 6;
4578
+ _context29.next = 6;
4430
4579
  break;
4431
4580
  }
4432
- return _context26.abrupt("return", 1);
4581
+ return _context29.abrupt("return", 1);
4433
4582
  case 6:
4434
4583
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4435
4584
  linkedBookingUidsToRemove.add(String(productBookingUid));
4436
4585
  }
4437
4586
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4438
4587
  bookingsBeforeRemove.forEach(function (booking) {
4439
- var bookingUid = _this26.getBookingUniqueIdentificationNumber(booking);
4588
+ var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
4440
4589
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4441
4590
  linkedBookingUidsToRemove.add(bookingUid);
4442
4591
  }
@@ -4444,37 +4593,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4444
4593
  }
4445
4594
  case 8:
4446
4595
  case "end":
4447
- return _context26.stop();
4596
+ return _context29.stop();
4448
4597
  }
4449
4598
  }, _loop3);
4450
4599
  });
4451
4600
  _iterator21.s();
4452
4601
  case 14:
4453
4602
  if ((_step21 = _iterator21.n()).done) {
4454
- _context27.next = 20;
4603
+ _context30.next = 20;
4455
4604
  break;
4456
4605
  }
4457
- return _context27.delegateYield(_loop3(), "t0", 16);
4606
+ return _context30.delegateYield(_loop3(), "t0", 16);
4458
4607
  case 16:
4459
- if (!_context27.t0) {
4460
- _context27.next = 18;
4608
+ if (!_context30.t0) {
4609
+ _context30.next = 18;
4461
4610
  break;
4462
4611
  }
4463
- return _context27.abrupt("continue", 18);
4612
+ return _context30.abrupt("continue", 18);
4464
4613
  case 18:
4465
- _context27.next = 14;
4614
+ _context30.next = 14;
4466
4615
  break;
4467
4616
  case 20:
4468
- _context27.next = 25;
4617
+ _context30.next = 25;
4469
4618
  break;
4470
4619
  case 22:
4471
- _context27.prev = 22;
4472
- _context27.t1 = _context27["catch"](11);
4473
- _iterator21.e(_context27.t1);
4620
+ _context30.prev = 22;
4621
+ _context30.t1 = _context30["catch"](11);
4622
+ _iterator21.e(_context30.t1);
4474
4623
  case 25:
4475
- _context27.prev = 25;
4624
+ _context30.prev = 25;
4476
4625
  _iterator21.f();
4477
- return _context27.finish(25);
4626
+ return _context30.finish(25);
4478
4627
  case 28:
4479
4628
  if (linkedBookingUidsToRemove.size > 0) {
4480
4629
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
@@ -4485,20 +4634,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4485
4634
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4486
4635
  });
4487
4636
  }
4488
- _context27.next = 31;
4637
+ _context30.next = 31;
4489
4638
  return this.finalizeAfterProductsMutation(tempOrder);
4490
4639
  case 31:
4491
4640
  this.logInfo('removeProductsFromOrder success', {
4492
4641
  identities: identities
4493
4642
  });
4494
- return _context27.abrupt("return", tempOrder.products);
4643
+ return _context30.abrupt("return", tempOrder.products);
4495
4644
  case 33:
4496
4645
  case "end":
4497
- return _context27.stop();
4646
+ return _context30.stop();
4498
4647
  }
4499
- }, _callee24, this, [[11, 22, 25, 28]]);
4648
+ }, _callee27, this, [[11, 22, 25, 28]]);
4500
4649
  }));
4501
- function removeProductsFromOrder(_x29) {
4650
+ function removeProductsFromOrder(_x34) {
4502
4651
  return _removeProductsFromOrder.apply(this, arguments);
4503
4652
  }
4504
4653
  return removeProductsFromOrder;
@@ -4506,18 +4655,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4506
4655
  }, {
4507
4656
  key: "removeProductFromOrder",
4508
4657
  value: function () {
4509
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identity) {
4510
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4511
- while (1) switch (_context28.prev = _context28.next) {
4658
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
4659
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4660
+ while (1) switch (_context31.prev = _context31.next) {
4512
4661
  case 0:
4513
- return _context28.abrupt("return", this.removeProductsFromOrder([identity]));
4662
+ return _context31.abrupt("return", this.removeProductsFromOrder([identity]));
4514
4663
  case 1:
4515
4664
  case "end":
4516
- return _context28.stop();
4665
+ return _context31.stop();
4517
4666
  }
4518
- }, _callee25, this);
4667
+ }, _callee28, this);
4519
4668
  }));
4520
- function removeProductFromOrder(_x30) {
4669
+ function removeProductFromOrder(_x35) {
4521
4670
  return _removeProductFromOrder.apply(this, arguments);
4522
4671
  }
4523
4672
  return removeProductFromOrder;
@@ -4529,10 +4678,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4529
4678
  }, {
4530
4679
  key: "clearOrderCartLines",
4531
4680
  value: (function () {
4532
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4681
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4533
4682
  var tempOrder;
4534
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4535
- while (1) switch (_context29.prev = _context29.next) {
4683
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4684
+ while (1) switch (_context32.prev = _context32.next) {
4536
4685
  case 0:
4537
4686
  tempOrder = this.ensureTempOrder();
4538
4687
  tempOrder.products = [];
@@ -4543,24 +4692,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4543
4692
  productsByUid: {}
4544
4693
  });
4545
4694
  }
4546
- _context29.next = 7;
4695
+ _context32.next = 7;
4547
4696
  return this.applyPromotion();
4548
4697
  case 7:
4549
4698
  this.applyDiscount();
4550
4699
  this.sanitizeTempOrderProducts(tempOrder);
4551
- _context29.next = 11;
4700
+ _context32.next = 11;
4552
4701
  return this.recalculateSummary({
4553
4702
  createIfMissing: true
4554
4703
  });
4555
4704
  case 11:
4556
4705
  this.persistTempOrder();
4557
4706
  this.logInfo('clearOrderCartLines success', {});
4558
- return _context29.abrupt("return", tempOrder);
4707
+ return _context32.abrupt("return", tempOrder);
4559
4708
  case 14:
4560
4709
  case "end":
4561
- return _context29.stop();
4710
+ return _context32.stop();
4562
4711
  }
4563
- }, _callee26, this);
4712
+ }, _callee29, this);
4564
4713
  }));
4565
4714
  function clearOrderCartLines() {
4566
4715
  return _clearOrderCartLines.apply(this, arguments);
@@ -4598,17 +4747,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4598
4747
  }, {
4599
4748
  key: "applyLocalPrintOrderNumbers",
4600
4749
  value: function () {
4601
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order) {
4750
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
4602
4751
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4603
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4604
- while (1) switch (_context30.prev = _context30.next) {
4752
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4753
+ while (1) switch (_context33.prev = _context33.next) {
4605
4754
  case 0:
4606
4755
  tempOrder = this.ensureTempOrder();
4607
4756
  if (!(!order || _typeof(order) !== 'object')) {
4608
- _context30.next = 3;
4757
+ _context33.next = 3;
4609
4758
  break;
4610
4759
  }
4611
- return _context30.abrupt("return", tempOrder);
4760
+ return _context33.abrupt("return", tempOrder);
4612
4761
  case 3:
4613
4762
  shopOrderNumber = order.shop_order_number;
4614
4763
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4619,21 +4768,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4619
4768
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4620
4769
  }
4621
4770
  this.persistTempOrder();
4622
- _context30.next = 10;
4771
+ _context33.next = 10;
4623
4772
  return this.saveDraft();
4624
4773
  case 10:
4625
- return _context30.abrupt("return", tempOrder);
4774
+ return _context33.abrupt("return", tempOrder);
4626
4775
  case 11:
4627
4776
  case "end":
4628
- return _context30.stop();
4777
+ return _context33.stop();
4629
4778
  }
4630
- }, _callee27, this);
4779
+ }, _callee30, this);
4631
4780
  }));
4632
- function applyLocalPrintOrderNumbers(_x31) {
4781
+ function applyLocalPrintOrderNumbers(_x36) {
4633
4782
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4634
4783
  }
4635
4784
  return applyLocalPrintOrderNumbers;
4636
4785
  }()
4786
+ }, {
4787
+ key: "saveTempOrderAsDraft",
4788
+ value: function () {
4789
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4790
+ var _params$cacheId2, _this$otherParams6, _ref72, _params$businessCode2, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4791
+ var tempOrder, latestSummary, payload;
4792
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4793
+ while (1) switch (_context34.prev = _context34.next) {
4794
+ case 0:
4795
+ tempOrder = this.ensureTempOrder();
4796
+ this.ensureExternalSaleNumber(tempOrder);
4797
+ this.persistTempOrder();
4798
+ _context34.next = 5;
4799
+ return this.recalculateSummary({
4800
+ createIfMissing: true
4801
+ });
4802
+ case 5:
4803
+ _context34.t1 = _context34.sent;
4804
+ if (_context34.t1) {
4805
+ _context34.next = 8;
4806
+ break;
4807
+ }
4808
+ _context34.t1 = this.store.summary;
4809
+ case 8:
4810
+ _context34.t0 = _context34.t1;
4811
+ if (_context34.t0) {
4812
+ _context34.next = 11;
4813
+ break;
4814
+ }
4815
+ _context34.t0 = createEmptySummary();
4816
+ case 11:
4817
+ latestSummary = _context34.t0;
4818
+ payload = buildSubmitPayload({
4819
+ tempOrder: tempOrder,
4820
+ cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
4821
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4822
+ businessCode: (_ref72 = (_params$businessCode2 = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode2 !== void 0 ? _params$businessCode2 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref72 !== void 0 ? _ref72 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4823
+ channel: params === null || params === void 0 ? void 0 : params.channel,
4824
+ type: (_params$type = params === null || params === void 0 ? void 0 : params.type) !== null && _params$type !== void 0 ? _params$type : (_this$otherParams9 = this.otherParams) === null || _this$otherParams9 === void 0 ? void 0 : _this$otherParams9.type,
4825
+ summary: latestSummary,
4826
+ enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
4827
+ });
4828
+ if (!payload.created_at) {
4829
+ payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4830
+ }
4831
+ payload.need_sync = 0;
4832
+ payload.is_draft_order = 1;
4833
+ this.logInfo('saveTempOrderAsDraft calling sales draft', {
4834
+ orderId: payload.order_id,
4835
+ externalSaleNumber: payload.external_sale_number,
4836
+ productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
4837
+ });
4838
+ return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
4839
+ osServer: true,
4840
+ customToast: function customToast() {}
4841
+ }));
4842
+ case 18:
4843
+ case "end":
4844
+ return _context34.stop();
4845
+ }
4846
+ }, _callee31, this);
4847
+ }));
4848
+ function saveTempOrderAsDraft(_x37) {
4849
+ return _saveTempOrderAsDraft.apply(this, arguments);
4850
+ }
4851
+ return saveTempOrderAsDraft;
4852
+ }()
4637
4853
  /**
4638
4854
  * 提交当前 Sales tempOrder。
4639
4855
  *
@@ -4643,18 +4859,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4643
4859
  }, {
4644
4860
  key: "submitTempOrder",
4645
4861
  value: (function () {
4646
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
4647
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4648
- while (1) switch (_context31.prev = _context31.next) {
4862
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
4863
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
4864
+ while (1) switch (_context35.prev = _context35.next) {
4649
4865
  case 0:
4650
- return _context31.abrupt("return", this.runSubmitTempOrder(params));
4866
+ return _context35.abrupt("return", this.runSubmitTempOrder(params));
4651
4867
  case 1:
4652
4868
  case "end":
4653
- return _context31.stop();
4869
+ return _context35.stop();
4654
4870
  }
4655
- }, _callee28, this);
4871
+ }, _callee32, this);
4656
4872
  }));
4657
- function submitTempOrder(_x32) {
4873
+ function submitTempOrder(_x38) {
4658
4874
  return _submitTempOrder.apply(this, arguments);
4659
4875
  }
4660
4876
  return submitTempOrder;
@@ -4662,20 +4878,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4662
4878
  }, {
4663
4879
  key: "submitTempOrderAsync",
4664
4880
  value: function () {
4665
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4666
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4667
- while (1) switch (_context32.prev = _context32.next) {
4881
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
4882
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
4883
+ while (1) switch (_context36.prev = _context36.next) {
4668
4884
  case 0:
4669
- return _context32.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4885
+ return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4670
4886
  syncMode: true
4671
4887
  })));
4672
4888
  case 1:
4673
4889
  case "end":
4674
- return _context32.stop();
4890
+ return _context36.stop();
4675
4891
  }
4676
- }, _callee29, this);
4892
+ }, _callee33, this);
4677
4893
  }));
4678
- function submitTempOrderAsync(_x33) {
4894
+ function submitTempOrderAsync(_x39) {
4679
4895
  return _submitTempOrderAsync.apply(this, arguments);
4680
4896
  }
4681
4897
  return submitTempOrderAsync;
@@ -4683,11 +4899,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4683
4899
  }, {
4684
4900
  key: "runSubmitTempOrder",
4685
4901
  value: function () {
4686
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
4687
- var _params$cacheId2, _this$otherParams6, _ref72, _ref73, _submitSnapshot$busin, _this$otherParams7, _this$otherParams8, _submitSnapshot$type;
4902
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
4903
+ var _params$cacheId3, _this$otherParams10, _ref73, _ref74, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4688
4904
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4689
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4690
- while (1) switch (_context33.prev = _context33.next) {
4905
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
4906
+ while (1) switch (_context37.prev = _context37.next) {
4691
4907
  case 0:
4692
4908
  tempOrder = this.ensureTempOrder();
4693
4909
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -4707,27 +4923,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4707
4923
  }
4708
4924
  }
4709
4925
  this.persistTempOrder();
4710
- _context33.next = 8;
4926
+ _context37.next = 8;
4711
4927
  return this.recalculateSummary({
4712
4928
  createIfMissing: true
4713
4929
  });
4714
4930
  case 8:
4715
- _context33.t1 = _context33.sent;
4716
- if (_context33.t1) {
4717
- _context33.next = 11;
4931
+ _context37.t1 = _context37.sent;
4932
+ if (_context37.t1) {
4933
+ _context37.next = 11;
4718
4934
  break;
4719
4935
  }
4720
- _context33.t1 = this.store.summary;
4936
+ _context37.t1 = this.store.summary;
4721
4937
  case 11:
4722
- _context33.t0 = _context33.t1;
4723
- if (_context33.t0) {
4724
- _context33.next = 14;
4938
+ _context37.t0 = _context37.t1;
4939
+ if (_context37.t0) {
4940
+ _context37.next = 14;
4725
4941
  break;
4726
4942
  }
4727
- _context33.t0 = createEmptySummary();
4943
+ _context37.t0 = createEmptySummary();
4728
4944
  case 14:
4729
- latestSummary = _context33.t0;
4730
- effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
4945
+ latestSummary = _context37.t0;
4946
+ effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
4731
4947
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4732
4948
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4733
4949
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
@@ -4745,8 +4961,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4745
4961
  payload = buildSubmitPayload({
4746
4962
  tempOrder: tempOrder,
4747
4963
  cacheId: effectiveCacheId,
4748
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4749
- businessCode: (_ref72 = (_ref73 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref72 !== void 0 ? _ref72 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4964
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
4965
+ businessCode: (_ref73 = (_ref74 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
4750
4966
  channel: params === null || params === void 0 ? void 0 : params.channel,
4751
4967
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4752
4968
  summary: latestSummary,
@@ -4761,10 +4977,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4761
4977
  if (!payload.created_at) {
4762
4978
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4763
4979
  }
4764
- _context33.next = 26;
4980
+ _context37.next = 26;
4765
4981
  return this.saveDraft();
4766
4982
  case 26:
4767
- _context33.prev = 26;
4983
+ _context37.prev = 26;
4768
4984
  this.logInfo('submitTempOrder calling sales checkout', {
4769
4985
  orderId: payload.order_id,
4770
4986
  externalSaleNumber: payload.external_sale_number,
@@ -4774,43 +4990,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4774
4990
  smallTicketDataFlag: payload.small_ticket_data_flag,
4775
4991
  syncMode: payload.sync_mode
4776
4992
  });
4777
- _context33.next = 30;
4993
+ _context37.next = 30;
4778
4994
  return this.submitSalesOrder({
4779
4995
  query: payload
4780
4996
  });
4781
4997
  case 30:
4782
- result = _context33.sent;
4783
- _context33.next = 43;
4998
+ result = _context37.sent;
4999
+ _context37.next = 43;
4784
5000
  break;
4785
5001
  case 33:
4786
- _context33.prev = 33;
4787
- _context33.t2 = _context33["catch"](26);
4788
- backendErrorResponse = this.extractSubmitErrorResponse(_context33.t2);
5002
+ _context37.prev = 33;
5003
+ _context37.t2 = _context37["catch"](26);
5004
+ backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
4789
5005
  if (!backendErrorResponse) {
4790
- _context33.next = 40;
5006
+ _context37.next = 40;
4791
5007
  break;
4792
5008
  }
4793
5009
  this.store.syncState = 'failed';
4794
5010
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4795
- return _context33.abrupt("return", backendErrorResponse);
5011
+ return _context37.abrupt("return", backendErrorResponse);
4796
5012
  case 40:
4797
5013
  this.store.syncState = 'failed';
4798
5014
  this.logError('submitTempOrder failed', {
4799
- error: _context33.t2 instanceof Error ? _context33.t2.message : String(_context33.t2),
5015
+ error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
4800
5016
  orderId: payload.order_id,
4801
5017
  externalSaleNumber: payload.external_sale_number,
4802
5018
  paymentStatus: payload.payment_status,
4803
5019
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4804
5020
  });
4805
- throw _context33.t2;
5021
+ throw _context37.t2;
4806
5022
  case 43:
4807
5023
  if (!this.isSubmitResponseRejected(result)) {
4808
- _context33.next = 47;
5024
+ _context37.next = 47;
4809
5025
  break;
4810
5026
  }
4811
5027
  this.store.syncState = 'failed';
4812
5028
  this.logSubmitBackendRejected(result, payload);
4813
- return _context33.abrupt("return", result);
5029
+ return _context37.abrupt("return", result);
4814
5030
  case 47:
4815
5031
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4816
5032
  this.logInfo('runSubmitTempOrder: 提交成功', {
@@ -4821,15 +5037,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4821
5037
  })
4822
5038
  });
4823
5039
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4824
- _context33.next = 56;
5040
+ _context37.next = 56;
4825
5041
  break;
4826
5042
  }
4827
5043
  tempOrder.order_id = submittedOrderId;
4828
5044
  resultRecord = result;
4829
- _context33.next = 54;
5045
+ _context37.next = 54;
4830
5046
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4831
5047
  case 54:
4832
- _context33.next = 57;
5048
+ _context37.next = 57;
4833
5049
  break;
4834
5050
  case 56:
4835
5051
  if (this.isLocalPendingSubmitResult(result)) {
@@ -4838,14 +5054,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4838
5054
  this.store.syncState = 'submitted';
4839
5055
  }
4840
5056
  case 57:
4841
- return _context33.abrupt("return", result);
5057
+ return _context37.abrupt("return", result);
4842
5058
  case 58:
4843
5059
  case "end":
4844
- return _context33.stop();
5060
+ return _context37.stop();
4845
5061
  }
4846
- }, _callee30, this, [[26, 33]]);
5062
+ }, _callee34, this, [[26, 33]]);
4847
5063
  }));
4848
- function runSubmitTempOrder(_x34) {
5064
+ function runSubmitTempOrder(_x40) {
4849
5065
  return _runSubmitTempOrder.apply(this, arguments);
4850
5066
  }
4851
5067
  return runSubmitTempOrder;
@@ -4853,10 +5069,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4853
5069
  }, {
4854
5070
  key: "markLocalOrderSynced",
4855
5071
  value: function () {
4856
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderId, remoteOrder) {
5072
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
4857
5073
  var tempOrder;
4858
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4859
- while (1) switch (_context34.prev = _context34.next) {
5074
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5075
+ while (1) switch (_context38.prev = _context38.next) {
4860
5076
  case 0:
4861
5077
  tempOrder = this.ensureTempOrder();
4862
5078
  tempOrder.order_id = orderId;
@@ -4864,15 +5080,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4864
5080
  this.store.lastOrderInfo = remoteOrder;
4865
5081
  this.store.syncState = 'submitted';
4866
5082
  this.persistTempOrder();
4867
- _context34.next = 8;
5083
+ _context38.next = 8;
4868
5084
  return this.saveDraft();
4869
5085
  case 8:
4870
5086
  case "end":
4871
- return _context34.stop();
5087
+ return _context38.stop();
4872
5088
  }
4873
- }, _callee31, this);
5089
+ }, _callee35, this);
4874
5090
  }));
4875
- function markLocalOrderSynced(_x35, _x36) {
5091
+ function markLocalOrderSynced(_x41, _x42) {
4876
5092
  return _markLocalOrderSynced.apply(this, arguments);
4877
5093
  }
4878
5094
  return markLocalOrderSynced;
@@ -4915,10 +5131,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4915
5131
  value: function extractSubmitErrorResponse(error) {
4916
5132
  var _error$response,
4917
5133
  _error$response2,
4918
- _this27 = this;
5134
+ _this30 = this;
4919
5135
  var candidates = [error === null || error === void 0 || (_error$response = error.response) === null || _error$response === void 0 ? void 0 : _error$response.data, error === null || error === void 0 ? void 0 : error.data, error === null || error === void 0 || (_error$response2 = error.response) === null || _error$response2 === void 0 ? void 0 : _error$response2.body, error === null || error === void 0 ? void 0 : error.body];
4920
5136
  return candidates.find(function (candidate) {
4921
- return _this27.isSubmitErrorResponse(candidate);
5137
+ return _this30.isSubmitErrorResponse(candidate);
4922
5138
  }) || null;
4923
5139
  }
4924
5140
  }, {
@@ -4945,14 +5161,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4945
5161
  }, {
4946
5162
  key: "syncPaymentsToOrder",
4947
5163
  value: function () {
4948
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
4949
- var _params$confirmPendin;
4950
- var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
4951
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
4952
- while (1) switch (_context35.prev = _context35.next) {
5164
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5165
+ var _this31 = this,
5166
+ _params$confirmPendin;
5167
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
5168
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5169
+ while (1) switch (_context39.prev = _context39.next) {
4953
5170
  case 0:
4954
5171
  tempOrder = this.ensureTempOrder();
4955
- mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
5172
+ needsPaymentNumber = (params.payments || []).some(function (payment) {
5173
+ return String(payment.payment_number || '').trim() === '';
5174
+ });
5175
+ if (!needsPaymentNumber) {
5176
+ _context39.next = 8;
5177
+ break;
5178
+ }
5179
+ _context39.next = 5;
5180
+ return this.getPaymentNumberDevicePrefixAsync();
5181
+ case 5:
5182
+ _context39.t0 = _context39.sent;
5183
+ _context39.next = 9;
5184
+ break;
5185
+ case 8:
5186
+ _context39.t0 = 'LOCAL';
5187
+ case 9:
5188
+ devicePrefix = _context39.t0;
5189
+ mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5190
+ return _this31.normalizePaymentSource(payment, {
5191
+ defaultPaid: false,
5192
+ devicePrefix: devicePrefix
5193
+ });
5194
+ }));
4956
5195
  shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
4957
5196
  effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
4958
5197
  completion = this.getPaymentCompletion(effectivePayments);
@@ -4961,24 +5200,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4961
5200
  tempOrder.payments = effectivePayments;
4962
5201
  tempOrder.payment_status = paymentStatus;
4963
5202
  this.persistTempOrder();
4964
- _context35.next = 12;
5203
+ _context39.next = 21;
4965
5204
  return this.saveDraft();
4966
- case 12:
5205
+ case 21:
4967
5206
  if (params.submitWhenPaid) {
4968
- _context35.next = 14;
5207
+ _context39.next = 23;
4969
5208
  break;
4970
5209
  }
4971
- return _context35.abrupt("return", completion);
4972
- case 14:
5210
+ return _context39.abrupt("return", completion);
5211
+ case 23:
4973
5212
  if (!(this.store.syncState === 'submitting')) {
4974
- _context35.next = 16;
5213
+ _context39.next = 25;
4975
5214
  break;
4976
5215
  }
4977
- return _context35.abrupt("return", completion);
4978
- case 16:
5216
+ return _context39.abrupt("return", completion);
5217
+ case 25:
4979
5218
  this.store.syncState = 'submitting';
4980
5219
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
4981
- _context35.next = 20;
5220
+ _context39.next = 29;
4982
5221
  return this.submitTempOrder({
4983
5222
  payments: effectivePayments,
4984
5223
  paymentStatus: paymentStatus,
@@ -4993,18 +5232,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4993
5232
  return nextPayload;
4994
5233
  }
4995
5234
  });
4996
- case 20:
4997
- submitResult = _context35.sent;
4998
- return _context35.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5235
+ case 29:
5236
+ submitResult = _context39.sent;
5237
+ return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
4999
5238
  submitResult: submitResult
5000
5239
  }));
5001
- case 22:
5240
+ case 31:
5002
5241
  case "end":
5003
- return _context35.stop();
5242
+ return _context39.stop();
5004
5243
  }
5005
- }, _callee32, this);
5244
+ }, _callee36, this);
5006
5245
  }));
5007
- function syncPaymentsToOrder(_x37) {
5246
+ function syncPaymentsToOrder(_x43) {
5008
5247
  return _syncPaymentsToOrder.apply(this, arguments);
5009
5248
  }
5010
5249
  return syncPaymentsToOrder;
@@ -5093,11 +5332,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5093
5332
  }, {
5094
5333
  key: "submitOrder",
5095
5334
  value: function () {
5096
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
5335
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5097
5336
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5098
5337
  var url, query, fetchUrl, params;
5099
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5100
- while (1) switch (_context36.prev = _context36.next) {
5338
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5339
+ while (1) switch (_context40.prev = _context40.next) {
5101
5340
  case 0:
5102
5341
  this.logInfo('submitOrder called', {
5103
5342
  url: order.url,
@@ -5117,14 +5356,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5117
5356
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5118
5357
  scheduleDate: params.schedule_date
5119
5358
  });
5120
- return _context36.abrupt("return", this.request.post(fetchUrl, params));
5359
+ return _context40.abrupt("return", this.request.post(fetchUrl, params));
5121
5360
  case 6:
5122
5361
  case "end":
5123
- return _context36.stop();
5362
+ return _context40.stop();
5124
5363
  }
5125
- }, _callee33, this);
5364
+ }, _callee37, this);
5126
5365
  }));
5127
- function submitOrder(_x38) {
5366
+ function submitOrder(_x44) {
5128
5367
  return _submitOrder.apply(this, arguments);
5129
5368
  }
5130
5369
  return submitOrder;
@@ -5132,13 +5371,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5132
5371
  }, {
5133
5372
  key: "cancelOrder",
5134
5373
  value: function () {
5135
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5374
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5136
5375
  var payload;
5137
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5138
- while (1) switch (_context37.prev = _context37.next) {
5376
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5377
+ while (1) switch (_context41.prev = _context41.next) {
5139
5378
  case 0:
5140
5379
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5141
- _context37.next = 2;
5380
+ _context41.next = 2;
5142
5381
  break;
5143
5382
  }
5144
5383
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5154,16 +5393,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5154
5393
  method: 'PUT',
5155
5394
  orderIdsCount: params.order_ids.length
5156
5395
  });
5157
- return _context37.abrupt("return", this.request.put('/order/update-status', payload, {
5396
+ return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5158
5397
  isShopApi: true
5159
5398
  }));
5160
5399
  case 5:
5161
5400
  case "end":
5162
- return _context37.stop();
5401
+ return _context41.stop();
5163
5402
  }
5164
- }, _callee34, this);
5403
+ }, _callee38, this);
5165
5404
  }));
5166
- function cancelOrder(_x39) {
5405
+ function cancelOrder(_x45) {
5167
5406
  return _cancelOrder.apply(this, arguments);
5168
5407
  }
5169
5408
  return cancelOrder;
@@ -5171,19 +5410,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5171
5410
  }, {
5172
5411
  key: "changeBookingStatus",
5173
5412
  value: function () {
5174
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5413
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5175
5414
  var url, payload;
5176
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5177
- while (1) switch (_context38.prev = _context38.next) {
5415
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5416
+ while (1) switch (_context42.prev = _context42.next) {
5178
5417
  case 0:
5179
5418
  if (params.booking_id) {
5180
- _context38.next = 2;
5419
+ _context42.next = 2;
5181
5420
  break;
5182
5421
  }
5183
5422
  throw new Error('变更预约状态失败:booking_id 不能为空');
5184
5423
  case 2:
5185
5424
  if (params.appointment_status) {
5186
- _context38.next = 4;
5425
+ _context42.next = 4;
5187
5426
  break;
5188
5427
  }
5189
5428
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5198,16 +5437,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5198
5437
  bookingId: params.booking_id,
5199
5438
  appointmentStatus: params.appointment_status
5200
5439
  });
5201
- return _context38.abrupt("return", this.request.put(url, payload, {
5440
+ return _context42.abrupt("return", this.request.put(url, payload, {
5202
5441
  isShopApi: true
5203
5442
  }));
5204
5443
  case 8:
5205
5444
  case "end":
5206
- return _context38.stop();
5445
+ return _context42.stop();
5207
5446
  }
5208
- }, _callee35, this);
5447
+ }, _callee39, this);
5209
5448
  }));
5210
- function changeBookingStatus(_x40) {
5449
+ function changeBookingStatus(_x46) {
5211
5450
  return _changeBookingStatus.apply(this, arguments);
5212
5451
  }
5213
5452
  return changeBookingStatus;
@@ -5225,11 +5464,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5225
5464
  }, {
5226
5465
  key: "createOrderByCheckout",
5227
5466
  value: (function () {
5228
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5467
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5229
5468
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5230
5469
  var onlineStorePaymentCodeList, _orderData$payments, _orderData$bookings, _orderData$relation_p, _orderData$payments2, _orderData$payments3, _orderData$bookings2, _orderData$relation_p2, _orderData$payments4, _orderData$payments5, _response$data, orderData, response;
5231
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5232
- while (1) switch (_context39.prev = _context39.next) {
5470
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5471
+ while (1) switch (_context43.prev = _context43.next) {
5233
5472
  case 0:
5234
5473
  // 过滤掉由在线店铺下单的 payment 支付数据
5235
5474
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5263,7 +5502,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5263
5502
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5264
5503
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5265
5504
  });
5266
- _context39.prev = 4;
5505
+ _context43.prev = 4;
5267
5506
  // 构建订单数据,设置默认值并允许 params 覆盖
5268
5507
  orderData = _objectSpread({
5269
5508
  sales_channel: 'my_pisel',
@@ -5325,13 +5564,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5325
5564
  hasOrderId: !!orderData.order_id,
5326
5565
  smallTicketDataFlag: orderData.small_ticket_data_flag
5327
5566
  });
5328
- _context39.next = 12;
5567
+ _context43.next = 12;
5329
5568
  return this.request.post('/order/checkout', orderData, {
5330
5569
  osServer: true,
5331
5570
  customToast: function customToast() {}
5332
5571
  });
5333
5572
  case 12:
5334
- response = _context39.sent;
5573
+ response = _context43.sent;
5335
5574
  this.logInfo('Order API called successfully', {
5336
5575
  response: response
5337
5576
  });
@@ -5339,22 +5578,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5339
5578
  success: !!response,
5340
5579
  hasOrderId: !!(response !== null && response !== void 0 && (_response$data = response.data) !== null && _response$data !== void 0 && _response$data.order_id || response !== null && response !== void 0 && response.order_id)
5341
5580
  });
5342
- return _context39.abrupt("return", response);
5581
+ return _context43.abrupt("return", response);
5343
5582
  case 18:
5344
- _context39.prev = 18;
5345
- _context39.t0 = _context39["catch"](4);
5346
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context39.t0);
5583
+ _context43.prev = 18;
5584
+ _context43.t0 = _context43["catch"](4);
5585
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
5347
5586
  this.logInfo('Order API called failed', {
5348
- error: _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0)
5587
+ error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
5349
5588
  });
5350
- throw _context39.t0;
5589
+ throw _context43.t0;
5351
5590
  case 23:
5352
5591
  case "end":
5353
- return _context39.stop();
5592
+ return _context43.stop();
5354
5593
  }
5355
- }, _callee36, this, [[4, 18]]);
5594
+ }, _callee40, this, [[4, 18]]);
5356
5595
  }));
5357
- function createOrderByCheckout(_x41) {
5596
+ function createOrderByCheckout(_x47) {
5358
5597
  return _createOrderByCheckout.apply(this, arguments);
5359
5598
  }
5360
5599
  return createOrderByCheckout;
@@ -5362,24 +5601,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5362
5601
  }, {
5363
5602
  key: "submitSalesOrder",
5364
5603
  value: function () {
5365
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5604
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5366
5605
  var url, query, fetchUrl;
5367
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5368
- while (1) switch (_context40.prev = _context40.next) {
5606
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5607
+ while (1) switch (_context44.prev = _context44.next) {
5369
5608
  case 0:
5370
5609
  url = params.url, query = params.query;
5371
5610
  fetchUrl = url || '/order/sales/checkout';
5372
- return _context40.abrupt("return", this.request.post(fetchUrl, query, {
5611
+ return _context44.abrupt("return", this.request.post(fetchUrl, query, {
5373
5612
  osServer: true,
5374
5613
  customToast: function customToast() {}
5375
5614
  }));
5376
5615
  case 3:
5377
5616
  case "end":
5378
- return _context40.stop();
5617
+ return _context44.stop();
5379
5618
  }
5380
- }, _callee37, this);
5619
+ }, _callee41, this);
5381
5620
  }));
5382
- function submitSalesOrder(_x42) {
5621
+ function submitSalesOrder(_x48) {
5383
5622
  return _submitSalesOrder.apply(this, arguments);
5384
5623
  }
5385
5624
  return submitSalesOrder;
@@ -5393,37 +5632,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5393
5632
  }, {
5394
5633
  key: "sendCustomerPayLink",
5395
5634
  value: (function () {
5396
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5635
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5397
5636
  var _params$emails;
5398
5637
  var orderIds;
5399
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5400
- while (1) switch (_context41.prev = _context41.next) {
5638
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5639
+ while (1) switch (_context45.prev = _context45.next) {
5401
5640
  case 0:
5402
5641
  orderIds = params.order_ids || params.orderIds || [];
5403
5642
  if (orderIds.length) {
5404
- _context41.next = 3;
5643
+ _context45.next = 3;
5405
5644
  break;
5406
5645
  }
5407
5646
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5408
5647
  case 3:
5409
5648
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5410
- _context41.next = 5;
5649
+ _context45.next = 5;
5411
5650
  break;
5412
5651
  }
5413
5652
  throw new Error('发送支付链接需要至少一个邮箱');
5414
5653
  case 5:
5415
- return _context41.abrupt("return", this.request.post('/order/batch-email', {
5654
+ return _context45.abrupt("return", this.request.post('/order/batch-email', {
5416
5655
  order_ids: orderIds,
5417
5656
  notify_action: params.notify_action || 'order_payment_reminder',
5418
5657
  emails: params.emails
5419
5658
  }));
5420
5659
  case 6:
5421
5660
  case "end":
5422
- return _context41.stop();
5661
+ return _context45.stop();
5423
5662
  }
5424
- }, _callee38, this);
5663
+ }, _callee42, this);
5425
5664
  }));
5426
- function sendCustomerPayLink(_x43) {
5665
+ function sendCustomerPayLink(_x49) {
5427
5666
  return _sendCustomerPayLink.apply(this, arguments);
5428
5667
  }
5429
5668
  return sendCustomerPayLink;
@@ -5431,14 +5670,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5431
5670
  }, {
5432
5671
  key: "getSalesOrderByLookup",
5433
5672
  value: function () {
5434
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5673
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5435
5674
  var lookup, res;
5436
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5437
- while (1) switch (_context42.prev = _context42.next) {
5675
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5676
+ while (1) switch (_context46.prev = _context46.next) {
5438
5677
  case 0:
5439
5678
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5440
5679
  if (lookup) {
5441
- _context42.next = 3;
5680
+ _context46.next = 3;
5442
5681
  break;
5443
5682
  }
5444
5683
  throw new Error('加载销售详情需要 lookup');
@@ -5447,7 +5686,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5447
5686
  if (lookup.startsWith('LOCAL_')) {
5448
5687
  params.forceRemote = false;
5449
5688
  }
5450
- _context42.next = 6;
5689
+ _context46.next = 6;
5451
5690
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5452
5691
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
5453
5692
  }, params.forceRemote ? {
@@ -5456,18 +5695,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5456
5695
  osServer: true
5457
5696
  });
5458
5697
  case 6:
5459
- res = _context42.sent;
5698
+ res = _context46.sent;
5460
5699
  if (res.code === 200) {
5461
5700
  this.store.lastOrderInfo = res.data;
5462
5701
  }
5463
- return _context42.abrupt("return", res);
5702
+ return _context46.abrupt("return", res);
5464
5703
  case 9:
5465
5704
  case "end":
5466
- return _context42.stop();
5705
+ return _context46.stop();
5467
5706
  }
5468
- }, _callee39, this);
5707
+ }, _callee43, this);
5469
5708
  }));
5470
- function getSalesOrderByLookup(_x44) {
5709
+ function getSalesOrderByLookup(_x50) {
5471
5710
  return _getSalesOrderByLookup.apply(this, arguments);
5472
5711
  }
5473
5712
  return getSalesOrderByLookup;
@@ -5481,16 +5720,42 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5481
5720
  }, {
5482
5721
  key: "hydrateTempOrderFromRecord",
5483
5722
  value: (function () {
5484
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(record, options) {
5723
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5485
5724
  var _this$store$discount19;
5486
- var raw, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount20, _this$store$discount21;
5487
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5488
- while (1) switch (_context43.prev = _context43.next) {
5725
+ var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount20, _this$store$discount21;
5726
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5727
+ while (1) switch (_context47.prev = _context47.next) {
5489
5728
  case 0:
5490
- raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5729
+ sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5730
+ identityReadySource = this.seedAnonymousBookingUidsFromProducts(sourceRaw);
5731
+ normalizedCollections = normalizeOrderCollections(identityReadySource);
5732
+ raw = normalizedCollections.order;
5733
+ hasIdentityChanges = Object.values(normalizedCollections.stats).some(function (stats) {
5734
+ return stats.backfilledUidCount > 0 || stats.collapsedDuplicateCount > 0 || stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
5735
+ });
5736
+ if (hasIdentityChanges) {
5737
+ identityLogMetadata = {
5738
+ collections: normalizedCollections.stats,
5739
+ uidRemapCount: normalizedCollections.uidRemaps.length
5740
+ };
5741
+ hasIdentityWarnings = Object.values(normalizedCollections.stats).some(function (stats) {
5742
+ return stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
5743
+ });
5744
+ if (hasIdentityWarnings) {
5745
+ this.logWarning('Normalized hydrated order collection identities', identityLogMetadata);
5746
+ } else {
5747
+ this.logInfo('Normalized hydrated order collection identities', identityLogMetadata);
5748
+ }
5749
+ }
5491
5750
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
5492
5751
  makeEditMark: true
5493
- });
5752
+ }); // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
5753
+ sourceLastOrderInfo = raw.lastOrderInfo || raw;
5754
+ isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
5755
+ syntheticIdentityOptions = {
5756
+ isDraftOrder: isDraftOrder,
5757
+ externalSaleNumber: nextTempOrder.external_sale_number
5758
+ };
5494
5759
  rawSummary = raw.summary && _typeof(raw.summary) === 'object' ? raw.summary : {};
5495
5760
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
5496
5761
  return _objectSpread({}, s || {});
@@ -5503,13 +5768,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5503
5768
  originalSalesSnapshot: {
5504
5769
  summary: cloneDeep(this.store.summary),
5505
5770
  products: cloneDeep(nextTempOrder.products || []),
5771
+ bookings: cloneDeep(nextTempOrder.bookings || []),
5506
5772
  payments: cloneDeep(nextTempOrder.payments || []),
5507
5773
  surcharges: cloneDeep(nextTempOrder.surcharges || []),
5508
5774
  shop_discount: nextTempOrder.shop_discount || '0.00',
5509
5775
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
5510
5776
  }
5511
5777
  });
5512
- this.store.lastOrderInfo = raw.lastOrderInfo || raw;
5778
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5779
+ hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5780
+ if (hadSyntheticDraftOrderId && this.store.syncState !== 'submitting') {
5781
+ this.store.syncState = 'local';
5782
+ }
5513
5783
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
5514
5784
  currentDiscounts = typeof ((_this$store$discount19 = this.store.discount) === null || _this$store$discount19 === void 0 ? void 0 : _this$store$discount19.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5515
5785
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
@@ -5524,34 +5794,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5524
5794
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
5525
5795
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
5526
5796
  if (shouldSkipEmptyDiscountSync) {
5527
- _context43.next = 21;
5797
+ _context47.next = 31;
5528
5798
  break;
5529
5799
  }
5530
5800
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
5531
- _context43.next = 19;
5801
+ _context47.next = 29;
5532
5802
  return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(nextDiscounts);
5533
- case 19:
5534
- _context43.next = 21;
5803
+ case 29:
5804
+ _context47.next = 31;
5535
5805
  return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(nextDiscounts);
5536
- case 21:
5806
+ case 31:
5537
5807
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5538
- _context43.next = 24;
5808
+ _context47.next = 34;
5539
5809
  break;
5540
5810
  }
5541
- _context43.next = 24;
5811
+ _context47.next = 34;
5542
5812
  return this.recalculateSummary({
5543
5813
  createIfMissing: false
5544
5814
  });
5545
- case 24:
5815
+ case 34:
5546
5816
  this.persistTempOrder();
5547
- return _context43.abrupt("return", nextTempOrder);
5548
- case 26:
5817
+ return _context47.abrupt("return", nextTempOrder);
5818
+ case 36:
5549
5819
  case "end":
5550
- return _context43.stop();
5820
+ return _context47.stop();
5551
5821
  }
5552
- }, _callee40, this);
5822
+ }, _callee44, this);
5553
5823
  }));
5554
- function hydrateTempOrderFromRecord(_x45, _x46) {
5824
+ function hydrateTempOrderFromRecord(_x51, _x52) {
5555
5825
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5556
5826
  }
5557
5827
  return hydrateTempOrderFromRecord;
@@ -5589,14 +5859,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5589
5859
  }
5590
5860
  return next;
5591
5861
  }
5862
+
5863
+ /**
5864
+ * 匿名 booking 没有服务端行 ID 时,商品侧已有的 booking_uid 就是唯一可用的强引用。
5865
+ * 在统一规范化生成 UUID 前先复用它;已落库 booking 仍按 schedule_event_id 派生稳定 UID。
5866
+ */
5867
+ }, {
5868
+ key: "seedAnonymousBookingUidsFromProducts",
5869
+ value: function seedAnonymousBookingUidsFromProducts(raw) {
5870
+ if (!raw || _typeof(raw) !== 'object') return {};
5871
+ if (!Array.isArray(raw.bookings) || !Array.isArray(raw.products)) return raw;
5872
+ var bookingUidsByProductUid = new Map();
5873
+ var _iterator22 = _createForOfIteratorHelper(raw.products),
5874
+ _step22;
5875
+ try {
5876
+ for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
5877
+ var _product$metadata10;
5878
+ var product = _step22.value;
5879
+ var productUid = getOrderCollectionUid('product', product);
5880
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.booking_uid);
5881
+ if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
5882
+ continue;
5883
+ }
5884
+ var candidates = bookingUidsByProductUid.get(productUid) || new Set();
5885
+ candidates.add(String(bookingUid));
5886
+ bookingUidsByProductUid.set(productUid, candidates);
5887
+ }
5888
+ } catch (err) {
5889
+ _iterator22.e(err);
5890
+ } finally {
5891
+ _iterator22.f();
5892
+ }
5893
+ if (bookingUidsByProductUid.size === 0) return raw;
5894
+ var anonymousBookingCountByProductUid = new Map();
5895
+ var _iterator23 = _createForOfIteratorHelper(raw.bookings),
5896
+ _step23;
5897
+ try {
5898
+ for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
5899
+ var _booking$metadata7;
5900
+ var booking = _step23.value;
5901
+ if (getOrderCollectionPersistentId('booking', booking) || getOrderCollectionUid('booking', booking)) {
5902
+ continue;
5903
+ }
5904
+ var _productUid = (booking === null || booking === void 0 ? void 0 : booking.product_uid) || (booking === null || booking === void 0 || (_booking$metadata7 = booking.metadata) === null || _booking$metadata7 === void 0 ? void 0 : _booking$metadata7.product_uid);
5905
+ if (_productUid === undefined || _productUid === null || _productUid === '') continue;
5906
+ var key = String(_productUid);
5907
+ anonymousBookingCountByProductUid.set(key, (anonymousBookingCountByProductUid.get(key) || 0) + 1);
5908
+ }
5909
+ } catch (err) {
5910
+ _iterator23.e(err);
5911
+ } finally {
5912
+ _iterator23.f();
5913
+ }
5914
+ return _objectSpread(_objectSpread({}, raw), {}, {
5915
+ bookings: raw.bookings.map(function (booking) {
5916
+ var _booking$metadata6;
5917
+ if (getOrderCollectionPersistentId('booking', booking) || getOrderCollectionUid('booking', booking)) {
5918
+ return booking;
5919
+ }
5920
+ var productUid = (booking === null || booking === void 0 ? void 0 : booking.product_uid) || (booking === null || booking === void 0 || (_booking$metadata6 = booking.metadata) === null || _booking$metadata6 === void 0 ? void 0 : _booking$metadata6.product_uid);
5921
+ if (productUid === undefined || productUid === null || productUid === '') {
5922
+ return booking;
5923
+ }
5924
+ var productUidKey = String(productUid);
5925
+ // 多条匿名 booking 共用同一商品引用时身份仍然不明确,不能借商品字段猜测合并。
5926
+ if (anonymousBookingCountByProductUid.get(productUidKey) !== 1) {
5927
+ return booking;
5928
+ }
5929
+ var bookingUidCandidates = bookingUidsByProductUid.get(productUidKey);
5930
+ var bookingUid = (bookingUidCandidates === null || bookingUidCandidates === void 0 ? void 0 : bookingUidCandidates.size) === 1 ? _toConsumableArray(bookingUidCandidates)[0] : null;
5931
+ return bookingUid ? setOrderCollectionUid('booking', booking, bookingUid) : booking;
5932
+ })
5933
+ });
5934
+ }
5592
5935
  }, {
5593
5936
  key: "normalizeTempOrderForRuntime",
5594
5937
  value: function normalizeTempOrderForRuntime(raw, options) {
5595
- var _this28 = this;
5596
- var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
5938
+ var _this32 = this;
5939
+ var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
5940
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
5597
5941
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5598
- if ((nextTempOrder.order_id === undefined || nextTempOrder.order_id === null) && (raw === null || raw === void 0 ? void 0 : raw.id) !== undefined && (raw === null || raw === void 0 ? void 0 : raw.id) !== null) {
5599
- nextTempOrder.order_id = raw.id;
5942
+ if ((nextTempOrder.order_id === undefined || nextTempOrder.order_id === null) && (runtimeRaw === null || runtimeRaw === void 0 ? void 0 : runtimeRaw.id) !== undefined && (runtimeRaw === null || runtimeRaw === void 0 ? void 0 : runtimeRaw.id) !== null) {
5943
+ nextTempOrder.order_id = runtimeRaw.id;
5600
5944
  }
5601
5945
  delete nextTempOrder.summary;
5602
5946
  delete nextTempOrder.lastOrderInfo;
@@ -5615,12 +5959,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5615
5959
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5616
5960
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5617
5961
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5618
- return _this28.normalizeHydratedOrderProduct(p, {
5962
+ return _this32.normalizeHydratedOrderProduct(p, {
5619
5963
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
5620
5964
  });
5621
5965
  }) : [];
5622
5966
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5623
- var booking = _this28.normalizeHydratedBookingHolder(b || {});
5967
+ var booking = _this32.normalizeHydratedBookingHolder(b || {});
5624
5968
  return _objectSpread(_objectSpread({}, booking), {}, {
5625
5969
  is_all: normalizeBookingIsAll(booking),
5626
5970
  sub_type: normalizeBookingSubType(booking)
@@ -5646,19 +5990,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5646
5990
  };
5647
5991
  var tempOrderExtend = nextTempOrder._extend;
5648
5992
  var productsByUid = tempOrderExtend.productsByUid || {};
5649
- var _iterator22 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
5650
- _step22;
5993
+ var _iterator24 = _createForOfIteratorHelper(nextTempOrder.products.entries()),
5994
+ _step24;
5651
5995
  try {
5652
- for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
5653
- var _product$metadata10, _ref74, _ref75, _existed$origin, _rawProduct$metadata;
5654
- var _step22$value = _slicedToArray(_step22.value, 2),
5655
- index = _step22$value[0],
5656
- product = _step22$value[1];
5657
- var uid = (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number;
5996
+ for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
5997
+ var _product$metadata11, _ref75, _ref76, _existed$origin, _rawProduct$metadata;
5998
+ var _step24$value = _slicedToArray(_step24.value, 2),
5999
+ index = _step24$value[0],
6000
+ product = _step24$value[1];
6001
+ var uid = (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number;
5658
6002
  if (!uid) continue;
5659
6003
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
5660
6004
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
5661
- var origin = (_ref74 = (_ref75 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref75 !== void 0 ? _ref75 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref74 !== void 0 ? _ref74 : rawProduct;
6005
+ var origin = (_ref75 = (_ref76 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref76 !== void 0 ? _ref76 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref75 !== void 0 ? _ref75 : rawProduct;
5662
6006
  var originSnapshot = cloneDeep(origin);
5663
6007
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
5664
6008
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -5674,9 +6018,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5674
6018
  });
5675
6019
  }
5676
6020
  } catch (err) {
5677
- _iterator22.e(err);
6021
+ _iterator24.e(err);
5678
6022
  } finally {
5679
- _iterator22.f();
6023
+ _iterator24.f();
5680
6024
  }
5681
6025
  tempOrderExtend.productsByUid = productsByUid;
5682
6026
  this.hydrateLinkedBookingIdentity(nextTempOrder);
@@ -5686,14 +6030,31 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5686
6030
  nextTempOrder.vouchers = raw.vouchers || [];
5687
6031
  return nextTempOrder;
5688
6032
  }
6033
+ }, {
6034
+ key: "isSyntheticDraftOrderIdForRuntime",
6035
+ value: function isSyntheticDraftOrderIdForRuntime(record, options) {
6036
+ var _options$isDraftOrder, _record$external_sale;
6037
+ var isDraftOrder = (_options$isDraftOrder = options === null || options === void 0 ? void 0 : options.isDraftOrder) !== null && _options$isDraftOrder !== void 0 ? _options$isDraftOrder : Number((record === null || record === void 0 ? void 0 : record.is_draft_order) || 0) === 1;
6038
+ var externalSaleNumber = (_record$external_sale = record === null || record === void 0 ? void 0 : record.external_sale_number) !== null && _record$external_sale !== void 0 ? _record$external_sale : options === null || options === void 0 ? void 0 : options.externalSaleNumber;
6039
+ var orderId = record === null || record === void 0 ? void 0 : record.order_id;
6040
+ return Boolean(isDraftOrder && orderId !== undefined && orderId !== null && orderId !== '' && externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '' && String(orderId) === String(externalSaleNumber));
6041
+ }
6042
+ }, {
6043
+ key: "withoutSyntheticDraftOrderIdForRuntime",
6044
+ value: function withoutSyntheticDraftOrderIdForRuntime(record, options) {
6045
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options)) return record;
6046
+ return _objectSpread(_objectSpread({}, record), {}, {
6047
+ order_id: null
6048
+ });
6049
+ }
5689
6050
  }, {
5690
6051
  key: "hydrateLinkedBookingIdentity",
5691
6052
  value: function hydrateLinkedBookingIdentity(tempOrder) {
5692
6053
  var bookingUidByProductUid = new Map();
5693
6054
  var productByUid = new Map();
5694
6055
  (tempOrder.products || []).forEach(function (product) {
5695
- var _product$metadata11;
5696
- var productUid = (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6056
+ var _product$metadata12;
6057
+ var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5697
6058
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
5698
6059
  productByUid.set(String(productUid), product);
5699
6060
  }
@@ -5714,15 +6075,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5714
6075
  bookingUidByProductUid.set(String(productUid), bookingUid);
5715
6076
  });
5716
6077
  (tempOrder.products || []).forEach(function (product) {
5717
- var _product$metadata12;
5718
- var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6078
+ var _product$metadata13;
6079
+ var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
5719
6080
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
5720
6081
  var bookingUid = bookingUidByProductUid.get(String(productUid));
5721
6082
  if (!bookingUid) return;
5722
6083
  if (!product.metadata || _typeof(product.metadata) !== 'object') {
5723
6084
  product.metadata = {};
5724
6085
  }
5725
- var linkedBookingUid = String(product.booking_uid || product.metadata.booking_uid || bookingUid);
6086
+ // booking 已经过统一身份规范化;以它为准同步商品侧旧引用,避免两侧 UID 断链。
6087
+ var linkedBookingUid = String(bookingUid);
5726
6088
  product.booking_uid = linkedBookingUid;
5727
6089
  product.metadata.booking_uid = linkedBookingUid;
5728
6090
  });
@@ -5750,18 +6112,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5750
6112
  var segments = [];
5751
6113
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
5752
6114
  if (Array.isArray(sku.variant)) {
5753
- var _iterator23 = _createForOfIteratorHelper(sku.variant),
5754
- _step23;
6115
+ var _iterator25 = _createForOfIteratorHelper(sku.variant),
6116
+ _step25;
5755
6117
  try {
5756
- for (_iterator23.s(); !(_step23 = _iterator23.n()).done;) {
5757
- var variant = _step23.value;
6118
+ for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
6119
+ var variant = _step25.value;
5758
6120
  var segment = this.formatHydratedNamePair(variant === null || variant === void 0 ? void 0 : variant.group, variant === null || variant === void 0 ? void 0 : variant.item);
5759
6121
  if (segment) segments.push(segment);
5760
6122
  }
5761
6123
  } catch (err) {
5762
- _iterator23.e(err);
6124
+ _iterator25.e(err);
5763
6125
  } finally {
5764
- _iterator23.f();
6126
+ _iterator25.f();
5765
6127
  }
5766
6128
  }
5767
6129
  return segments.join(', ');
@@ -5769,10 +6131,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5769
6131
  }, {
5770
6132
  key: "normalizeHydratedProductOptionItem",
5771
6133
  value: function normalizeHydratedProductOptionItem(optionItem) {
5772
- var _ref76, _optionItem$num, _ref77, _optionItem$add_price;
5773
- var rawNum = (_ref76 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref76 !== void 0 ? _ref76 : 1;
6134
+ var _ref77, _optionItem$num, _ref78, _optionItem$add_price;
6135
+ var rawNum = (_ref77 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref77 !== void 0 ? _ref77 : 1;
5774
6136
  var parsedNum = Number(rawNum);
5775
- var rawPrice = (_ref77 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref77 !== void 0 ? _ref77 : 0;
6137
+ var rawPrice = (_ref78 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref78 !== void 0 ? _ref78 : 0;
5776
6138
  var parsedPrice = Number(rawPrice);
5777
6139
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
5778
6140
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -5789,7 +6151,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5789
6151
  }, {
5790
6152
  key: "normalizeHydratedOrderProduct",
5791
6153
  value: function normalizeHydratedOrderProduct(product, options) {
5792
- var _this29 = this;
6154
+ var _this33 = this;
5793
6155
  var row = _objectSpread({}, product || {});
5794
6156
  if (row.num === undefined && row.product_quantity !== undefined) {
5795
6157
  row.num = row.product_quantity;
@@ -5797,7 +6159,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5797
6159
  var productSku = ensureProductSku(row);
5798
6160
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5799
6161
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5800
- return _this29.normalizeHydratedProductOptionItem(optionItem || {});
6162
+ return _this33.normalizeHydratedProductOptionItem(optionItem || {});
5801
6163
  }))
5802
6164
  });
5803
6165
  delete row["product_".concat('option', "_item")];
@@ -5834,27 +6196,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5834
6196
  }, {
5835
6197
  key: "getOrderInfo",
5836
6198
  value: function () {
5837
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(order_id) {
6199
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
5838
6200
  var res;
5839
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5840
- while (1) switch (_context44.prev = _context44.next) {
6201
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6202
+ while (1) switch (_context48.prev = _context48.next) {
5841
6203
  case 0:
5842
- _context44.next = 2;
6204
+ _context48.next = 2;
5843
6205
  return this.request.get("/order/sales/".concat(order_id), {
5844
6206
  with: ['products', 'bookings']
5845
6207
  }, {
5846
6208
  osServer: true
5847
6209
  });
5848
6210
  case 2:
5849
- res = _context44.sent;
5850
- return _context44.abrupt("return", res);
6211
+ res = _context48.sent;
6212
+ return _context48.abrupt("return", res);
5851
6213
  case 4:
5852
6214
  case "end":
5853
- return _context44.stop();
6215
+ return _context48.stop();
5854
6216
  }
5855
- }, _callee41, this);
6217
+ }, _callee45, this);
5856
6218
  }));
5857
- function getOrderInfo(_x47) {
6219
+ function getOrderInfo(_x53) {
5858
6220
  return _getOrderInfo.apply(this, arguments);
5859
6221
  }
5860
6222
  return getOrderInfo;
@@ -5890,70 +6252,70 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5890
6252
  addDiscountAmount(savedMap, discountKey, amount);
5891
6253
  addDiscountAmount(isPersistedProduct || discount.order_discount_id != null ? editModeSavedMap : runtimeSavedMap, discountKey, amount);
5892
6254
  };
5893
- var _iterator24 = _createForOfIteratorHelper(productList),
5894
- _step24;
6255
+ var _iterator26 = _createForOfIteratorHelper(productList),
6256
+ _step26;
5895
6257
  try {
5896
- for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
5897
- var product = _step24.value;
6258
+ for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
6259
+ var product = _step26.value;
5898
6260
  var qty = product.num || 1;
5899
6261
  var isPersistedProduct = Boolean(product.order_detail_id || product.orderDetailId || product.booking_id);
5900
- var _iterator26 = _createForOfIteratorHelper(product.discount_list || []),
5901
- _step26;
6262
+ var _iterator28 = _createForOfIteratorHelper(product.discount_list || []),
6263
+ _step28;
5902
6264
  try {
5903
- for (_iterator26.s(); !(_step26 = _iterator26.n()).done;) {
5904
- var pd = _step26.value;
6265
+ for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
6266
+ var pd = _step28.value;
5905
6267
  addProductDiscountAmount(pd, qty, isPersistedProduct);
5906
6268
  }
5907
6269
  } catch (err) {
5908
- _iterator26.e(err);
6270
+ _iterator28.e(err);
5909
6271
  } finally {
5910
- _iterator26.f();
6272
+ _iterator28.f();
5911
6273
  }
5912
- var _iterator27 = _createForOfIteratorHelper(product.product_bundle || []),
5913
- _step27;
6274
+ var _iterator29 = _createForOfIteratorHelper(product.product_bundle || []),
6275
+ _step29;
5914
6276
  try {
5915
- for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
5916
- var _ref78, _bundle$num3;
5917
- var bundle = _step27.value;
6277
+ for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
6278
+ var _ref79, _bundle$num3;
6279
+ var bundle = _step29.value;
5918
6280
  var isPersistedBundleProduct = isPersistedProduct || Boolean((bundle === null || bundle === void 0 ? void 0 : bundle.order_detail_id) || (bundle === null || bundle === void 0 ? void 0 : bundle.orderDetailId) || (bundle === null || bundle === void 0 ? void 0 : bundle.booking_id));
5919
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref78 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref78 !== void 0 ? _ref78 : 1) || 1).toNumber();
5920
- var _iterator28 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
5921
- _step28;
6281
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref79 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref79 !== void 0 ? _ref79 : 1) || 1).toNumber();
6282
+ var _iterator30 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
6283
+ _step30;
5922
6284
  try {
5923
- for (_iterator28.s(); !(_step28 = _iterator28.n()).done;) {
5924
- var _pd = _step28.value;
6285
+ for (_iterator30.s(); !(_step30 = _iterator30.n()).done;) {
6286
+ var _pd = _step30.value;
5925
6287
  addProductDiscountAmount(_pd, bundleQty, isPersistedBundleProduct);
5926
6288
  }
5927
6289
  } catch (err) {
5928
- _iterator28.e(err);
6290
+ _iterator30.e(err);
5929
6291
  } finally {
5930
- _iterator28.f();
6292
+ _iterator30.f();
5931
6293
  }
5932
6294
  }
5933
6295
  } catch (err) {
5934
- _iterator27.e(err);
6296
+ _iterator29.e(err);
5935
6297
  } finally {
5936
- _iterator27.f();
6298
+ _iterator29.f();
5937
6299
  }
5938
6300
  }
5939
6301
  } catch (err) {
5940
- _iterator24.e(err);
6302
+ _iterator26.e(err);
5941
6303
  } finally {
5942
- _iterator24.f();
6304
+ _iterator26.f();
5943
6305
  }
5944
- var _iterator25 = _createForOfIteratorHelper(discountList),
5945
- _step25;
6306
+ var _iterator27 = _createForOfIteratorHelper(discountList),
6307
+ _step27;
5946
6308
  try {
5947
- for (_iterator25.s(); !(_step25 = _iterator25.n()).done;) {
5948
- var d = _step25.value;
6309
+ for (_iterator27.s(); !(_step27 = _iterator27.n()).done;) {
6310
+ var d = _step27.value;
5949
6311
  var key = d.id;
5950
6312
  var sourceMap = d.isEditMode ? editModeSavedMap : editModeDiscountKeys.has(key) ? runtimeSavedMap : savedMap;
5951
6313
  d.savedAmount = d.isSelected && key != null && sourceMap.has(key) ? sourceMap.get(key).toNumber() : 0;
5952
6314
  }
5953
6315
  } catch (err) {
5954
- _iterator25.e(err);
6316
+ _iterator27.e(err);
5955
6317
  } finally {
5956
- _iterator25.f();
6318
+ _iterator27.f();
5957
6319
  }
5958
6320
  }
5959
6321
  }]);