@pisell/pisellos 2.2.263 → 2.2.265

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 (52) hide show
  1. package/dist/modules/Order/index.d.ts +27 -8
  2. package/dist/modules/Order/index.js +736 -473
  3. package/dist/modules/Order/payment-utils.d.ts +26 -0
  4. package/dist/modules/Order/payment-utils.js +225 -0
  5. package/dist/modules/Order/types.d.ts +33 -1
  6. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  7. package/dist/modules/Order/utils.js +8 -5
  8. package/dist/modules/Payment/index.d.ts +2 -0
  9. package/dist/modules/Payment/index.js +78 -49
  10. package/dist/modules/Payment/types.d.ts +26 -24
  11. package/dist/modules/Payment/types.js +2 -0
  12. package/dist/server/index.d.ts +16 -0
  13. package/dist/server/index.js +1940 -1043
  14. package/dist/server/modules/order/index.d.ts +49 -4
  15. package/dist/server/modules/order/index.js +1577 -698
  16. package/dist/server/modules/order/types.d.ts +11 -3
  17. package/dist/server/modules/order/types.js +1 -1
  18. package/dist/solution/BaseSales/index.d.ts +33 -3
  19. package/dist/solution/BaseSales/index.js +653 -340
  20. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  21. package/dist/solution/BookingByStep/index.d.ts +1 -1
  22. package/dist/solution/BookingTicket/index.js +2 -1
  23. package/dist/solution/Sales/index.d.ts +1 -0
  24. package/dist/solution/Sales/index.js +10 -2
  25. package/dist/utils/payment-number.d.ts +9 -0
  26. package/dist/utils/payment-number.js +69 -0
  27. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  28. package/lib/modules/Order/index.d.ts +27 -8
  29. package/lib/modules/Order/index.js +180 -60
  30. package/lib/modules/Order/payment-utils.d.ts +26 -0
  31. package/lib/modules/Order/payment-utils.js +224 -0
  32. package/lib/modules/Order/types.d.ts +33 -1
  33. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  34. package/lib/modules/Order/utils.js +5 -3
  35. package/lib/modules/Payment/index.d.ts +2 -0
  36. package/lib/modules/Payment/index.js +33 -12
  37. package/lib/modules/Payment/types.d.ts +26 -24
  38. package/lib/server/index.d.ts +16 -0
  39. package/lib/server/index.js +670 -18
  40. package/lib/server/modules/order/index.d.ts +49 -4
  41. package/lib/server/modules/order/index.js +657 -66
  42. package/lib/server/modules/order/types.d.ts +11 -3
  43. package/lib/solution/BaseSales/index.d.ts +33 -3
  44. package/lib/solution/BaseSales/index.js +193 -9
  45. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  46. package/lib/solution/BookingByStep/index.d.ts +1 -1
  47. package/lib/solution/BookingTicket/index.js +2 -1
  48. package/lib/solution/Sales/index.d.ts +1 -0
  49. package/lib/solution/Sales/index.js +5 -3
  50. package/lib/utils/payment-number.d.ts +9 -0
  51. package/lib/utils/payment-number.js +64 -0
  52. package/package.json +1 -1
@@ -35,6 +35,8 @@ 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";
@@ -97,6 +99,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
97
99
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
98
100
  // LoggerManager 实例
99
101
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
102
+ _defineProperty(_assertThisInitialized(_this), "appPlugin", void 0);
100
103
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
101
104
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
102
105
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
@@ -284,7 +287,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
284
287
  value: function () {
285
288
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
286
289
  var _otherParams$rules, _otherParams$order, _otherParams$hooks;
287
- var appPlugin, app, otherParams;
290
+ var app, otherParams;
288
291
  return _regeneratorRuntime().wrap(function _callee$(_context) {
289
292
  while (1) switch (_context.prev = _context.next) {
290
293
  case 0:
@@ -300,14 +303,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
300
303
  this.store.availableWalletIds = [];
301
304
  }
302
305
  this.request = this.core.getPlugin('request');
303
- appPlugin = this.core.getPlugin('app');
304
- if (appPlugin) {
306
+ this.appPlugin = this.core.getPlugin('app');
307
+ if (this.appPlugin) {
305
308
  _context.next = 9;
306
309
  break;
307
310
  }
308
311
  throw new Error('Order 模块需要 app 插件支持');
309
312
  case 9:
310
- app = appPlugin.getApp();
313
+ app = this.appPlugin.getApp();
311
314
  this.logger = app.logger;
312
315
  this.window = this.core.getPlugin('window');
313
316
  otherParams = options.otherParams || {};
@@ -1510,19 +1513,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1510
1513
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1511
1514
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1512
1515
  }
1516
+ }, {
1517
+ key: "getPaymentNumberAppData",
1518
+ value: function getPaymentNumberAppData(key) {
1519
+ var _appPlugin$getData, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
1520
+ var appPlugin = this.appPlugin;
1521
+ if (!appPlugin) return undefined;
1522
+ var getData = (_appPlugin$getData = appPlugin.getData) === null || _appPlugin$getData === void 0 ? void 0 : _appPlugin$getData.call(appPlugin);
1523
+ if (typeof getData === 'function') return getData(key);
1524
+ var app = appPlugin.getApp();
1525
+ 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');
1526
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1527
+ }
1528
+ }, {
1529
+ key: "getPaymentNumberDevicePrefixSync",
1530
+ value: function getPaymentNumberDevicePrefixSync() {
1531
+ var _this7 = this;
1532
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1533
+ return _this7.getPaymentNumberAppData(key);
1534
+ });
1535
+ }
1536
+ }, {
1537
+ key: "getPaymentNumberDevicePrefixAsync",
1538
+ value: function getPaymentNumberDevicePrefixAsync() {
1539
+ var _this8 = this;
1540
+ return resolvePaymentNumberDevicePrefix(function (key) {
1541
+ return _this8.getPaymentNumberAppData(key);
1542
+ });
1543
+ }
1513
1544
  }, {
1514
1545
  key: "normalizePaymentSource",
1515
1546
  value: function normalizePaymentSource(payment, options) {
1516
1547
  var _ref19, _paymentRecord$origin;
1517
1548
  var paymentRecord = payment;
1518
1549
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1519
- if (!metadata.unique_payment_number) {
1520
- metadata.unique_payment_number = createUuidV4();
1521
- }
1522
- var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
1550
+ var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1523
1551
  metadata: metadata,
1524
1552
  origin_amount: (_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : '0.00'
1525
- });
1553
+ }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1526
1554
  if (paymentRecord.status !== undefined) {
1527
1555
  normalized.status = paymentRecord.status;
1528
1556
  } else if ((options === null || options === void 0 ? void 0 : options.defaultPaid) !== false) {
@@ -1640,16 +1668,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1640
1668
  }, {
1641
1669
  key: "calculatePaidPaymentSummary",
1642
1670
  value: function calculatePaidPaymentSummary(payments) {
1643
- var _this7 = this;
1671
+ var _this9 = this;
1644
1672
  return (payments || []).reduce(function (summary, payment) {
1645
1673
  var paymentRecord = payment;
1646
1674
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
1647
1675
  return {
1648
1676
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1649
- orderPaidAmount: summary.orderPaidAmount.plus(_this7.calculatePaymentOrderAmount(paymentRecord)),
1650
- gapPaidAmount: summary.gapPaidAmount.plus(_this7.calculatePaymentGapAmount(paymentRecord)),
1651
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this7.calculatePaymentServiceFee(paymentRecord)),
1652
- roundingAmount: summary.roundingAmount.plus(_this7.calculatePaymentRoundingAmount(paymentRecord))
1677
+ orderPaidAmount: summary.orderPaidAmount.plus(_this9.calculatePaymentOrderAmount(paymentRecord)),
1678
+ gapPaidAmount: summary.gapPaidAmount.plus(_this9.calculatePaymentGapAmount(paymentRecord)),
1679
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this9.calculatePaymentServiceFee(paymentRecord)),
1680
+ roundingAmount: summary.roundingAmount.plus(_this9.calculatePaymentRoundingAmount(paymentRecord))
1653
1681
  };
1654
1682
  }, {
1655
1683
  customerPaidAmount: new Decimal(0),
@@ -1851,15 +1879,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1851
1879
  }, {
1852
1880
  key: "normalizeFingerprintValue",
1853
1881
  value: function normalizeFingerprintValue(value) {
1854
- var _this8 = this;
1882
+ var _this10 = this;
1855
1883
  if (Array.isArray(value)) {
1856
1884
  return value.map(function (item) {
1857
- return _this8.normalizeFingerprintValue(item);
1885
+ return _this10.normalizeFingerprintValue(item);
1858
1886
  });
1859
1887
  }
1860
1888
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
1861
1889
  return Object.keys(value).sort().reduce(function (result, key) {
1862
- result[key] = _this8.normalizeFingerprintValue(value[key]);
1890
+ result[key] = _this10.normalizeFingerprintValue(value[key]);
1863
1891
  return result;
1864
1892
  }, {});
1865
1893
  }
@@ -1874,7 +1902,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1874
1902
  _sku$barcode,
1875
1903
  _ref20,
1876
1904
  _sku$variant_id,
1877
- _this9 = this;
1905
+ _this11 = this;
1878
1906
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1879
1907
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1880
1908
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1908,7 +1936,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1908
1936
  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,
1909
1937
  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,
1910
1938
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1911
- 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)
1939
+ 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)
1912
1940
  };
1913
1941
  })
1914
1942
  }),
@@ -1918,8 +1946,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1918
1946
  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,
1919
1947
  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,
1920
1948
  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),
1921
- price: _this9.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1922
- bundle_selling_price: _this9.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1949
+ price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1950
+ bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1923
1951
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
1924
1952
  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 : ''
1925
1953
  };
@@ -1929,7 +1957,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1929
1957
  return {
1930
1958
  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 : '',
1931
1959
  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,
1932
- amount: _this9.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1960
+ amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1933
1961
  };
1934
1962
  }))
1935
1963
  };
@@ -1937,9 +1965,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1937
1965
  }, {
1938
1966
  key: "buildOrderProductsFingerprint",
1939
1967
  value: function buildOrderProductsFingerprint(products) {
1940
- var _this10 = this;
1968
+ var _this12 = this;
1941
1969
  var items = (products || []).map(function (product) {
1942
- return _this10.buildProductFingerprintItem(product);
1970
+ return _this12.buildProductFingerprintItem(product);
1943
1971
  });
1944
1972
  items.sort(function (left, right) {
1945
1973
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -1961,7 +1989,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1961
1989
  _sku$barcode2,
1962
1990
  _ref30,
1963
1991
  _sku$variant_id2,
1964
- _this11 = this;
1992
+ _this13 = this;
1965
1993
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1966
1994
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1967
1995
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1992,7 +2020,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1992
2020
  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,
1993
2021
  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,
1994
2022
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
1995
- 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)
2023
+ 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)
1996
2024
  };
1997
2025
  })
1998
2026
  }),
@@ -2006,14 +2034,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2006
2034
  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),
2007
2035
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
2008
2036
  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 : '',
2009
- option: _this11.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2037
+ option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2010
2038
  var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
2011
2039
  return {
2012
2040
  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,
2013
2041
  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,
2014
2042
  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,
2015
2043
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2016
- 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)
2044
+ 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)
2017
2045
  };
2018
2046
  }))
2019
2047
  };
@@ -2023,7 +2051,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2023
2051
  return {
2024
2052
  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 : '',
2025
2053
  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,
2026
- amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2054
+ amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2027
2055
  };
2028
2056
  }))
2029
2057
  };
@@ -2031,9 +2059,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2031
2059
  }, {
2032
2060
  key: "buildOrderProductsStructuralFingerprint",
2033
2061
  value: function buildOrderProductsStructuralFingerprint(products) {
2034
- var _this12 = this;
2062
+ var _this14 = this;
2035
2063
  var items = (products || []).map(function (product) {
2036
- return _this12.buildProductStructuralFingerprintItem(product);
2064
+ return _this14.buildProductStructuralFingerprintItem(product);
2037
2065
  });
2038
2066
  items.sort(function (left, right) {
2039
2067
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2461,9 +2489,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2461
2489
  }, {
2462
2490
  key: "sanitizeTempOrderProducts",
2463
2491
  value: function sanitizeTempOrderProducts(tempOrder) {
2464
- var _this13 = this;
2492
+ var _this15 = this;
2465
2493
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2466
- return _this13.sanitizeOrderProductForTempOrder(product);
2494
+ return _this15.sanitizeOrderProductForTempOrder(product);
2467
2495
  });
2468
2496
  }
2469
2497
  }, {
@@ -2566,7 +2594,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2566
2594
  }, {
2567
2595
  key: "syncLinkedBookingHoldersToProducts",
2568
2596
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2569
- var _this14 = this;
2597
+ var _this16 = this;
2570
2598
  var bookings = tempOrder.bookings || [];
2571
2599
  var products = tempOrder.products || [];
2572
2600
  if (!bookings.length || !products.length) return;
@@ -2591,7 +2619,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2591
2619
  var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2592
2620
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2593
2621
  if (linkedBooking) {
2594
- _this14.setProductHolderFromBooking(product, linkedBooking);
2622
+ _this16.setProductHolderFromBooking(product, linkedBooking);
2595
2623
  }
2596
2624
  });
2597
2625
  }
@@ -2719,9 +2747,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2719
2747
  }, {
2720
2748
  key: "findBookingIndexByUniqueIdentificationNumber",
2721
2749
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
2722
- var _this15 = this;
2750
+ var _this17 = this;
2723
2751
  return (tempOrder.bookings || []).findIndex(function (booking) {
2724
- return _this15.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2752
+ return _this17.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2725
2753
  });
2726
2754
  }
2727
2755
  }, {
@@ -2729,12 +2757,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2729
2757
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2730
2758
  var _product$metadata7,
2731
2759
  _product$metadata8,
2732
- _this16 = this;
2760
+ _this18 = this;
2733
2761
  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);
2734
2762
  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);
2735
2763
  if (!productUid && !bookingUid) return;
2736
2764
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2737
- var currentBookingUid = _this16.getBookingUniqueIdentificationNumber(booking);
2765
+ var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
2738
2766
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2739
2767
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
2740
2768
  return true;
@@ -3067,15 +3095,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3067
3095
  }, {
3068
3096
  key: "productHasCustomerBoundDiscount",
3069
3097
  value: function productHasCustomerBoundDiscount(product) {
3070
- var _this17 = this;
3098
+ var _this19 = this;
3071
3099
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3072
- return _this17.isCustomerBoundDiscount(discount);
3100
+ return _this19.isCustomerBoundDiscount(discount);
3073
3101
  })) {
3074
3102
  return true;
3075
3103
  }
3076
3104
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3077
3105
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3078
- return _this17.isCustomerBoundDiscount(discount);
3106
+ return _this19.isCustomerBoundDiscount(discount);
3079
3107
  });
3080
3108
  });
3081
3109
  }
@@ -3084,18 +3112,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3084
3112
  value: function shouldSkipDiscountCalculation(tempOrder) {
3085
3113
  var _this$store$discount17,
3086
3114
  _this$store$discount18,
3087
- _this18 = this;
3115
+ _this20 = this;
3088
3116
  if (this.hasActiveCustomerBoundDiscount) return false;
3089
3117
  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)) || [];
3090
3118
  if (discountList.length > 0) return false;
3091
3119
  return !(tempOrder.products || []).some(function (product) {
3092
- return _this18.productHasCustomerBoundDiscount(product);
3120
+ return _this20.productHasCustomerBoundDiscount(product);
3093
3121
  });
3094
3122
  }
3095
3123
  }, {
3096
3124
  key: "clearCustomerBoundDiscounts",
3097
3125
  value: function clearCustomerBoundDiscounts(tempOrder) {
3098
- var _this19 = this,
3126
+ var _this21 = this,
3099
3127
  _discountModule$getDi,
3100
3128
  _discountModule$getOr,
3101
3129
  _discountModule$setDi,
@@ -3104,7 +3132,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3104
3132
  var filterDiscountList = function filterDiscountList(discountList) {
3105
3133
  if (!Array.isArray(discountList)) return [];
3106
3134
  return discountList.filter(function (discount) {
3107
- var shouldRemove = _this19.isCustomerBoundDiscount(discount);
3135
+ var shouldRemove = _this21.isCustomerBoundDiscount(discount);
3108
3136
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3109
3137
  return !shouldRemove;
3110
3138
  });
@@ -3131,12 +3159,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3131
3159
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3132
3160
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3133
3161
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3134
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3135
- return !_this19.isCustomerBoundDiscount(discount);
3162
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3163
+ return !_this21.isCustomerBoundDiscount(discount);
3136
3164
  });
3137
3165
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3138
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3139
- return !_this19.isCustomerBoundDiscount(discount);
3166
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3167
+ return !_this21.isCustomerBoundDiscount(discount);
3140
3168
  });
3141
3169
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3142
3170
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3290,23 +3318,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3290
3318
  * 用一组支付来源覆盖当前订单支付项。
3291
3319
  *
3292
3320
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
3293
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
3321
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
3294
3322
  * isSynced 等运行态字段不会进入 tempOrder.payments。
3295
3323
  */
3296
3324
  }, {
3297
3325
  key: "setOrderPayments",
3298
3326
  value: function setOrderPayments(payments) {
3327
+ var _this22 = this;
3299
3328
  var tempOrder = this.ensureTempOrder();
3300
- tempOrder.payments = mapPaymentItemsToOrderPayments(payments);
3329
+ tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
3330
+ return _this22.normalizePaymentSource(payment, {
3331
+ defaultPaid: false
3332
+ });
3333
+ }));
3301
3334
  this.persistTempOrder();
3302
3335
  return tempOrder.payments;
3303
3336
  }
3304
3337
 
3305
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
3338
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
3306
3339
  }, {
3307
3340
  key: "addOrderPayment",
3308
3341
  value: function addOrderPayment(payment) {
3309
- var _this20 = this;
3342
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3343
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3344
+ }
3345
+
3346
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
3347
+ }, {
3348
+ key: "addOrderPaymentAsync",
3349
+ value: (function () {
3350
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(payment) {
3351
+ var hasPaymentNumber, devicePrefix;
3352
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3353
+ while (1) switch (_context17.prev = _context17.next) {
3354
+ case 0:
3355
+ hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3356
+ if (!hasPaymentNumber) {
3357
+ _context17.next = 5;
3358
+ break;
3359
+ }
3360
+ _context17.t0 = 'LOCAL';
3361
+ _context17.next = 8;
3362
+ break;
3363
+ case 5:
3364
+ _context17.next = 7;
3365
+ return this.getPaymentNumberDevicePrefixAsync();
3366
+ case 7:
3367
+ _context17.t0 = _context17.sent;
3368
+ case 8:
3369
+ devicePrefix = _context17.t0;
3370
+ return _context17.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3371
+ case 10:
3372
+ case "end":
3373
+ return _context17.stop();
3374
+ }
3375
+ }, _callee15, this);
3376
+ }));
3377
+ function addOrderPaymentAsync(_x14) {
3378
+ return _addOrderPaymentAsync.apply(this, arguments);
3379
+ }
3380
+ return addOrderPaymentAsync;
3381
+ }())
3382
+ }, {
3383
+ key: "addOrderPaymentWithDevicePrefix",
3384
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3385
+ var _this23 = this;
3310
3386
  this.logInfo('addOrderPayment', {
3311
3387
  payment: payment
3312
3388
  });
@@ -3316,14 +3392,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3316
3392
  type: orderPaymentType,
3317
3393
  order_payment_type: orderPaymentType
3318
3394
  }), {
3319
- defaultPaid: true
3395
+ defaultPaid: true,
3396
+ devicePrefix: devicePrefix
3320
3397
  })]);
3321
3398
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
3322
3399
  this.persistTempOrder();
3323
3400
  void this.recalculateSummary({
3324
3401
  createIfMissing: true
3325
3402
  }).catch(function (error) {
3326
- _this20.logError('recalculate summary after addOrderPayment failed', {
3403
+ _this23.logError('recalculate summary after addOrderPayment failed', {
3327
3404
  error: error instanceof Error ? error.message : String(error)
3328
3405
  });
3329
3406
  });
@@ -3331,49 +3408,80 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3331
3408
  }
3332
3409
 
3333
3410
  /**
3334
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
3335
- *
3336
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
3337
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
3411
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
3412
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
3338
3413
  */
3339
3414
  }, {
3340
3415
  key: "updateOrderPayment",
3341
- value: function updateOrderPayment(paymentIdentity, updates) {
3342
- var tempOrder = this.ensureTempOrder();
3343
- var identity = String(paymentIdentity);
3344
- tempOrder.payments = (tempOrder.payments || []).map(function (payment) {
3345
- var _payment$metadata;
3346
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.unique_payment_number;
3347
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3348
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3349
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3350
- var matched = [uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3351
- return value !== undefined && String(value) === identity;
3352
- });
3353
- if (!matched) return payment;
3354
- return _objectSpread(_objectSpread(_objectSpread({}, payment), updates), {}, {
3355
- metadata: _objectSpread(_objectSpread({}, payment.metadata || {}), updates.metadata || {})
3356
- });
3357
- });
3358
- this.persistTempOrder();
3359
- return tempOrder.payments;
3360
- }
3361
-
3362
- /** 从当前订单支付项中移除指定支付项。 */
3416
+ value: (function () {
3417
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentIdentity, updates) {
3418
+ var options,
3419
+ tempOrder,
3420
+ identity,
3421
+ matchMode,
3422
+ matchedPayment,
3423
+ updatedPayment,
3424
+ summary,
3425
+ payments,
3426
+ _args18 = arguments;
3427
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3428
+ while (1) switch (_context18.prev = _context18.next) {
3429
+ case 0:
3430
+ options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
3431
+ tempOrder = this.ensureTempOrder();
3432
+ identity = String(paymentIdentity);
3433
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3434
+ matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
3435
+ if (matchedPayment) {
3436
+ _context18.next = 7;
3437
+ break;
3438
+ }
3439
+ throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
3440
+ case 7:
3441
+ updatedPayment = null;
3442
+ tempOrder.payments = (tempOrder.payments || []).map(function (payment, index) {
3443
+ if (index !== matchedPayment.index) return payment;
3444
+ var nextPayment = mergeOrderPaymentRecord(payment, _objectSpread(_objectSpread({}, updates), {}, {
3445
+ updated_at: updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
3446
+ }));
3447
+ updatedPayment = nextPayment;
3448
+ return nextPayment;
3449
+ });
3450
+ this.persistTempOrder();
3451
+ _context18.next = 12;
3452
+ return this.recalculateSummary({
3453
+ createIfMissing: true
3454
+ });
3455
+ case 12:
3456
+ summary = _context18.sent;
3457
+ this.persistTempOrder();
3458
+ payments = tempOrder.payments;
3459
+ return _context18.abrupt("return", {
3460
+ updated: true,
3461
+ payment: payments[matchedPayment.index] || updatedPayment,
3462
+ payments: payments,
3463
+ summary: summary
3464
+ });
3465
+ case 16:
3466
+ case "end":
3467
+ return _context18.stop();
3468
+ }
3469
+ }, _callee16, this);
3470
+ }));
3471
+ function updateOrderPayment(_x15, _x16) {
3472
+ return _updateOrderPayment.apply(this, arguments);
3473
+ }
3474
+ return updateOrderPayment;
3475
+ }() /** 从当前订单支付项中移除指定支付项。 */)
3363
3476
  }, {
3364
3477
  key: "deleteOrderPayment",
3365
3478
  value: function deleteOrderPayment(paymentIdentity) {
3366
3479
  var tempOrder = this.ensureTempOrder();
3367
3480
  var identity = String(paymentIdentity);
3368
- tempOrder.payments = (tempOrder.payments || []).filter(function (payment) {
3369
- var _payment$metadata2;
3370
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata2 = payment.metadata) === null || _payment$metadata2 === void 0 ? void 0 : _payment$metadata2.unique_payment_number;
3371
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3372
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3373
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3374
- return ![uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3375
- return value !== undefined && String(value) === identity;
3376
- });
3481
+ var matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, 'compat');
3482
+ if (!matchedPayment) return tempOrder.payments;
3483
+ tempOrder.payments = (tempOrder.payments || []).filter(function (_, index) {
3484
+ return index !== matchedPayment.index;
3377
3485
  });
3378
3486
  this.persistTempOrder();
3379
3487
  return tempOrder.payments;
@@ -3405,7 +3513,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3405
3513
  }, {
3406
3514
  key: "applyPaymentLifecycleChange",
3407
3515
  value: function applyPaymentLifecycleChange(tempOrder, options) {
3408
- var _this21 = this;
3516
+ var _this24 = this;
3409
3517
  this.updateTempOrderPaymentStatus(tempOrder);
3410
3518
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3411
3519
  this.persistTempOrder();
@@ -3415,7 +3523,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3415
3523
  void this.recalculateSummary({
3416
3524
  createIfMissing: true
3417
3525
  }).catch(function (error) {
3418
- _this21.logError("recalculate summary after ".concat(logContext, " failed"), {
3526
+ _this24.logError("recalculate summary after ".concat(logContext, " failed"), {
3419
3527
  error: error instanceof Error ? error.message : String(error)
3420
3528
  });
3421
3529
  });
@@ -3459,7 +3567,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3459
3567
  }, {
3460
3568
  key: "updateVoucherOrderPayments",
3461
3569
  value: function updateVoucherOrderPayments(payments, options) {
3462
- var _this22 = this;
3570
+ var _this25 = this;
3463
3571
  var tempOrder = this.ensureTempOrder();
3464
3572
  var isOrderPaymentType = function isOrderPaymentType(value) {
3465
3573
  return value === 'normal' || value === 'deposit';
@@ -3494,8 +3602,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3494
3602
  });
3495
3603
  };
3496
3604
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3497
- return _this22.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3498
- defaultPaid: false
3605
+ return _this25.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3606
+ defaultPaid: false,
3607
+ devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
3499
3608
  });
3500
3609
  })).filter(function (payment) {
3501
3610
  return isVoucherPaymentRecord(payment);
@@ -3543,54 +3652,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3543
3652
  void this.recalculateSummary({
3544
3653
  createIfMissing: true
3545
3654
  }).catch(function (error) {
3546
- _this22.logError('recalculate summary after updateVoucherOrderPayments failed', {
3655
+ _this25.logError('recalculate summary after updateVoucherOrderPayments failed', {
3547
3656
  error: error instanceof Error ? error.message : String(error)
3548
3657
  });
3549
3658
  });
3550
3659
  return tempOrder.payments;
3551
3660
  }
3661
+ }, {
3662
+ key: "updateVoucherOrderPaymentsAsync",
3663
+ value: function () {
3664
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(payments, options) {
3665
+ var needsPaymentNumber, devicePrefix;
3666
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3667
+ while (1) switch (_context19.prev = _context19.next) {
3668
+ case 0:
3669
+ needsPaymentNumber = (payments || []).some(function (payment) {
3670
+ return String(payment.payment_number || '').trim() === '';
3671
+ });
3672
+ if (!needsPaymentNumber) {
3673
+ _context19.next = 7;
3674
+ break;
3675
+ }
3676
+ _context19.next = 4;
3677
+ return this.getPaymentNumberDevicePrefixAsync();
3678
+ case 4:
3679
+ _context19.t0 = _context19.sent;
3680
+ _context19.next = 8;
3681
+ break;
3682
+ case 7:
3683
+ _context19.t0 = 'LOCAL';
3684
+ case 8:
3685
+ devicePrefix = _context19.t0;
3686
+ return _context19.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
3687
+ devicePrefix: devicePrefix
3688
+ })));
3689
+ case 10:
3690
+ case "end":
3691
+ return _context19.stop();
3692
+ }
3693
+ }, _callee17, this);
3694
+ }));
3695
+ function updateVoucherOrderPaymentsAsync(_x17, _x18) {
3696
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3697
+ }
3698
+ return updateVoucherOrderPaymentsAsync;
3699
+ }()
3552
3700
  }, {
3553
3701
  key: "shouldMergeProductToOrder",
3554
3702
  value: function () {
3555
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
3703
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3556
3704
  var _this$orderHooks;
3557
3705
  var onBeforeMergeProductToOrder, result;
3558
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3559
- while (1) switch (_context17.prev = _context17.next) {
3706
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3707
+ while (1) switch (_context20.prev = _context20.next) {
3560
3708
  case 0:
3561
3709
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3562
3710
  if (onBeforeMergeProductToOrder) {
3563
- _context17.next = 3;
3711
+ _context20.next = 3;
3564
3712
  break;
3565
3713
  }
3566
- return _context17.abrupt("return", true);
3714
+ return _context20.abrupt("return", true);
3567
3715
  case 3:
3568
- _context17.next = 5;
3716
+ _context20.next = 5;
3569
3717
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3570
3718
  defaultShouldMerge: true
3571
3719
  }));
3572
3720
  case 5:
3573
- result = _context17.sent;
3721
+ result = _context20.sent;
3574
3722
  if (!(typeof result === 'boolean')) {
3575
- _context17.next = 8;
3723
+ _context20.next = 8;
3576
3724
  break;
3577
3725
  }
3578
- return _context17.abrupt("return", result);
3726
+ return _context20.abrupt("return", result);
3579
3727
  case 8:
3580
3728
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3581
- _context17.next = 10;
3729
+ _context20.next = 10;
3582
3730
  break;
3583
3731
  }
3584
- return _context17.abrupt("return", result.shouldMerge);
3732
+ return _context20.abrupt("return", result.shouldMerge);
3585
3733
  case 10:
3586
- return _context17.abrupt("return", true);
3734
+ return _context20.abrupt("return", true);
3587
3735
  case 11:
3588
3736
  case "end":
3589
- return _context17.stop();
3737
+ return _context20.stop();
3590
3738
  }
3591
- }, _callee15, this);
3739
+ }, _callee18, this);
3592
3740
  }));
3593
- function shouldMergeProductToOrder(_x14) {
3741
+ function shouldMergeProductToOrder(_x19) {
3594
3742
  return _shouldMergeProductToOrder.apply(this, arguments);
3595
3743
  }
3596
3744
  return shouldMergeProductToOrder;
@@ -3626,30 +3774,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3626
3774
  }, {
3627
3775
  key: "finalizeProductOrderMutation",
3628
3776
  value: function () {
3629
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, options) {
3630
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3631
- while (1) switch (_context18.prev = _context18.next) {
3777
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3778
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3779
+ while (1) switch (_context21.prev = _context21.next) {
3632
3780
  case 0:
3633
3781
  this.syncTempOrderHolderFromBookings(tempOrder);
3634
3782
  if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3635
- _context18.next = 4;
3783
+ _context21.next = 4;
3636
3784
  break;
3637
3785
  }
3638
- _context18.next = 4;
3786
+ _context21.next = 4;
3639
3787
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3640
3788
  case 4:
3641
3789
  if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3642
- _context18.next = 7;
3790
+ _context21.next = 7;
3643
3791
  break;
3644
3792
  }
3645
- _context18.next = 7;
3793
+ _context21.next = 7;
3646
3794
  return this.applyPromotion();
3647
3795
  case 7:
3648
3796
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
3649
3797
  this.applyDiscount();
3650
3798
  }
3651
3799
  this.sanitizeTempOrderProducts(tempOrder);
3652
- _context18.next = 11;
3800
+ _context21.next = 11;
3653
3801
  return this.recalculateSummary({
3654
3802
  createIfMissing: true
3655
3803
  });
@@ -3657,11 +3805,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3657
3805
  this.persistTempOrder();
3658
3806
  case 12:
3659
3807
  case "end":
3660
- return _context18.stop();
3808
+ return _context21.stop();
3661
3809
  }
3662
- }, _callee16, this);
3810
+ }, _callee19, this);
3663
3811
  }));
3664
- function finalizeProductOrderMutation(_x15, _x16) {
3812
+ function finalizeProductOrderMutation(_x20, _x21) {
3665
3813
  return _finalizeProductOrderMutation.apply(this, arguments);
3666
3814
  }
3667
3815
  return finalizeProductOrderMutation;
@@ -3676,13 +3824,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3676
3824
  }, {
3677
3825
  key: "appendProductLineToTempOrder",
3678
3826
  value: (function () {
3679
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(tempOrder, product, booking) {
3827
+ var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking) {
3680
3828
  var _booking_uid,
3681
3829
  _metadata,
3682
- _this23 = this;
3830
+ _this26 = this;
3683
3831
  var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3684
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3685
- while (1) switch (_context19.prev = _context19.next) {
3832
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3833
+ while (1) switch (_context22.prev = _context22.next) {
3686
3834
  case 0:
3687
3835
  linked = booking ? this.createLinkedProductAndBooking({
3688
3836
  product: product,
@@ -3705,8 +3853,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3705
3853
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3706
3854
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3707
3855
  var _item$metadata3;
3708
- if (_this23.hasGoodPassDiscount(item)) return false;
3709
- if (_this23.hasOrderProductLineNote(item)) return false;
3856
+ if (_this26.hasGoodPassDiscount(item)) return false;
3857
+ if (_this26.hasOrderProductLineNote(item)) return false;
3710
3858
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3711
3859
  if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
3712
3860
  if (item.product_id !== productToAdd.product_id) return false;
@@ -3717,10 +3865,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3717
3865
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3718
3866
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3719
3867
  if (!matchedProduct) {
3720
- _context19.next = 20;
3868
+ _context22.next = 20;
3721
3869
  break;
3722
3870
  }
3723
- _context19.next = 17;
3871
+ _context22.next = 17;
3724
3872
  return this.shouldMergeProductToOrder({
3725
3873
  incomingProduct: productToAdd,
3726
3874
  normalizedIncoming: normalizedIncoming,
@@ -3732,13 +3880,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3732
3880
  booking: booking
3733
3881
  });
3734
3882
  case 17:
3735
- _context19.t0 = _context19.sent;
3736
- _context19.next = 21;
3883
+ _context22.t0 = _context22.sent;
3884
+ _context22.next = 21;
3737
3885
  break;
3738
3886
  case 20:
3739
- _context19.t0 = false;
3887
+ _context22.t0 = false;
3740
3888
  case 21:
3741
- shouldMerge = _context19.t0;
3889
+ shouldMerge = _context22.t0;
3742
3890
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3743
3891
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
3744
3892
  if (linked) {
@@ -3792,11 +3940,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3792
3940
  }
3793
3941
  case 24:
3794
3942
  case "end":
3795
- return _context19.stop();
3943
+ return _context22.stop();
3796
3944
  }
3797
- }, _callee17, this);
3945
+ }, _callee20, this);
3798
3946
  }));
3799
- function appendProductLineToTempOrder(_x17, _x18, _x19) {
3947
+ function appendProductLineToTempOrder(_x22, _x23, _x24) {
3800
3948
  return _appendProductLineToTempOrder.apply(this, arguments);
3801
3949
  }
3802
3950
  return appendProductLineToTempOrder;
@@ -3812,61 +3960,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3812
3960
  }, {
3813
3961
  key: "addProductToOrder",
3814
3962
  value: (function () {
3815
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(product, booking) {
3963
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking) {
3816
3964
  var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3817
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3818
- while (1) switch (_context20.prev = _context20.next) {
3965
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
3966
+ while (1) switch (_context23.prev = _context23.next) {
3819
3967
  case 0:
3820
3968
  tempOrder = this.ensureTempOrder();
3821
3969
  if (!booking) {
3822
- _context20.next = 18;
3970
+ _context23.next = 18;
3823
3971
  break;
3824
3972
  }
3825
3973
  productRecord = product;
3826
3974
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3827
3975
  if (!(splitCount > 1)) {
3828
- _context20.next = 18;
3976
+ _context23.next = 18;
3829
3977
  break;
3830
3978
  }
3831
3979
  i = 0;
3832
3980
  case 6:
3833
3981
  if (!(i < splitCount)) {
3834
- _context20.next = 15;
3982
+ _context23.next = 15;
3835
3983
  break;
3836
3984
  }
3837
3985
  singleLine = cloneDeep(productRecord);
3838
3986
  singleLine.num = 1;
3839
3987
  delete singleLine.product_quantity;
3840
- _context20.next = 12;
3988
+ _context23.next = 12;
3841
3989
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3842
3990
  case 12:
3843
3991
  i += 1;
3844
- _context20.next = 6;
3992
+ _context23.next = 6;
3845
3993
  break;
3846
3994
  case 15:
3847
- _context20.next = 17;
3995
+ _context23.next = 17;
3848
3996
  return this.finalizeProductOrderMutation(tempOrder);
3849
3997
  case 17:
3850
- return _context20.abrupt("return", tempOrder.products);
3998
+ return _context23.abrupt("return", tempOrder.products);
3851
3999
  case 18:
3852
- _context20.next = 20;
4000
+ _context23.next = 20;
3853
4001
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3854
4002
  case 20:
3855
- _context20.next = 22;
4003
+ _context23.next = 22;
3856
4004
  return this.finalizeProductOrderMutation(tempOrder);
3857
4005
  case 22:
3858
4006
  this.logInfo('addProductToOrder success', {
3859
4007
  product_id: product.product_id,
3860
4008
  with_booking: !!booking
3861
4009
  });
3862
- return _context20.abrupt("return", tempOrder.products);
4010
+ return _context23.abrupt("return", tempOrder.products);
3863
4011
  case 24:
3864
4012
  case "end":
3865
- return _context20.stop();
4013
+ return _context23.stop();
3866
4014
  }
3867
- }, _callee18, this);
4015
+ }, _callee21, this);
3868
4016
  }));
3869
- function addProductToOrder(_x20, _x21) {
4017
+ function addProductToOrder(_x25, _x26) {
3870
4018
  return _addProductToOrder.apply(this, arguments);
3871
4019
  }
3872
4020
  return addProductToOrder;
@@ -3884,93 +4032,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3884
4032
  }, {
3885
4033
  key: "addProductsToOrder",
3886
4034
  value: (function () {
3887
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(items, options) {
4035
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
3888
4036
  var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3889
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3890
- while (1) switch (_context21.prev = _context21.next) {
4037
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4038
+ while (1) switch (_context24.prev = _context24.next) {
3891
4039
  case 0:
3892
4040
  tempOrder = this.ensureTempOrder();
3893
4041
  if (!(!Array.isArray(items) || items.length === 0)) {
3894
- _context21.next = 3;
4042
+ _context24.next = 3;
3895
4043
  break;
3896
4044
  }
3897
- return _context21.abrupt("return", tempOrder.products);
4045
+ return _context24.abrupt("return", tempOrder.products);
3898
4046
  case 3:
3899
4047
  _iterator20 = _createForOfIteratorHelper(items || []);
3900
- _context21.prev = 4;
4048
+ _context24.prev = 4;
3901
4049
  _iterator20.s();
3902
4050
  case 6:
3903
4051
  if ((_step20 = _iterator20.n()).done) {
3904
- _context21.next = 30;
4052
+ _context24.next = 30;
3905
4053
  break;
3906
4054
  }
3907
4055
  item = _step20.value;
3908
4056
  product = item.product, booking = item.booking;
3909
4057
  if (product) {
3910
- _context21.next = 11;
4058
+ _context24.next = 11;
3911
4059
  break;
3912
4060
  }
3913
- return _context21.abrupt("continue", 28);
4061
+ return _context24.abrupt("continue", 28);
3914
4062
  case 11:
3915
4063
  if (!booking) {
3916
- _context21.next = 26;
4064
+ _context24.next = 26;
3917
4065
  break;
3918
4066
  }
3919
4067
  productRecord = product;
3920
4068
  splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3921
4069
  if (!(splitCount > 1)) {
3922
- _context21.next = 26;
4070
+ _context24.next = 26;
3923
4071
  break;
3924
4072
  }
3925
4073
  i = 0;
3926
4074
  case 16:
3927
4075
  if (!(i < splitCount)) {
3928
- _context21.next = 25;
4076
+ _context24.next = 25;
3929
4077
  break;
3930
4078
  }
3931
4079
  singleLine = cloneDeep(productRecord);
3932
4080
  singleLine.num = 1;
3933
4081
  delete singleLine.product_quantity;
3934
- _context21.next = 22;
4082
+ _context24.next = 22;
3935
4083
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3936
4084
  case 22:
3937
4085
  i += 1;
3938
- _context21.next = 16;
4086
+ _context24.next = 16;
3939
4087
  break;
3940
4088
  case 25:
3941
- return _context21.abrupt("continue", 28);
4089
+ return _context24.abrupt("continue", 28);
3942
4090
  case 26:
3943
- _context21.next = 28;
4091
+ _context24.next = 28;
3944
4092
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3945
4093
  case 28:
3946
- _context21.next = 6;
4094
+ _context24.next = 6;
3947
4095
  break;
3948
4096
  case 30:
3949
- _context21.next = 35;
4097
+ _context24.next = 35;
3950
4098
  break;
3951
4099
  case 32:
3952
- _context21.prev = 32;
3953
- _context21.t0 = _context21["catch"](4);
3954
- _iterator20.e(_context21.t0);
4100
+ _context24.prev = 32;
4101
+ _context24.t0 = _context24["catch"](4);
4102
+ _iterator20.e(_context24.t0);
3955
4103
  case 35:
3956
- _context21.prev = 35;
4104
+ _context24.prev = 35;
3957
4105
  _iterator20.f();
3958
- return _context21.finish(35);
4106
+ return _context24.finish(35);
3959
4107
  case 38:
3960
- _context21.next = 40;
4108
+ _context24.next = 40;
3961
4109
  return this.finalizeProductOrderMutation(tempOrder, options);
3962
4110
  case 40:
3963
4111
  this.logInfo('addProductsToOrder success', {
3964
4112
  itemsCount: items.length
3965
4113
  });
3966
- return _context21.abrupt("return", tempOrder.products);
4114
+ return _context24.abrupt("return", tempOrder.products);
3967
4115
  case 42:
3968
4116
  case "end":
3969
- return _context21.stop();
4117
+ return _context24.stop();
3970
4118
  }
3971
- }, _callee19, this, [[4, 32, 35, 38]]);
4119
+ }, _callee22, this, [[4, 32, 35, 38]]);
3972
4120
  }));
3973
- function addProductsToOrder(_x22, _x23) {
4121
+ function addProductsToOrder(_x27, _x28) {
3974
4122
  return _addProductsToOrder.apply(this, arguments);
3975
4123
  }
3976
4124
  return addProductsToOrder;
@@ -4004,17 +4152,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4004
4152
  }, {
4005
4153
  key: "preservePersistedBundlePriceFields",
4006
4154
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4007
- var _this24 = this;
4155
+ var _this27 = this;
4008
4156
  if (!Array.isArray(nextBundles)) return nextBundles;
4009
4157
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4010
4158
  var previousByIdentity = new Map();
4011
4159
  previousBundles.forEach(function (bundle) {
4012
- var identity = _this24.getBundleRuntimeIdentity(bundle);
4160
+ var identity = _this27.getBundleRuntimeIdentity(bundle);
4013
4161
  if (identity) previousByIdentity.set(identity, bundle);
4014
4162
  });
4015
4163
  return nextBundles.map(function (bundle, index) {
4016
4164
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4017
- var previous = previousByIdentity.get(_this24.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4165
+ var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4018
4166
  if (!previous || _typeof(previous) !== 'object') return bundle;
4019
4167
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4020
4168
  cover: previous.cover
@@ -4215,21 +4363,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4215
4363
  }, {
4216
4364
  key: "updateOrderProduct",
4217
4365
  value: function () {
4218
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
4366
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4219
4367
  var tempOrder, updatedProductUid;
4220
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4221
- while (1) switch (_context22.prev = _context22.next) {
4368
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4369
+ while (1) switch (_context25.prev = _context25.next) {
4222
4370
  case 0:
4223
4371
  tempOrder = this.ensureTempOrder();
4224
4372
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4225
- _context22.next = 4;
4373
+ _context25.next = 4;
4226
4374
  return this.applyPromotion();
4227
4375
  case 4:
4228
4376
  this.applyDiscount({
4229
4377
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4230
4378
  });
4231
4379
  this.sanitizeTempOrderProducts(tempOrder);
4232
- _context22.next = 8;
4380
+ _context25.next = 8;
4233
4381
  return this.recalculateSummary({
4234
4382
  createIfMissing: true
4235
4383
  });
@@ -4238,14 +4386,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4238
4386
  this.logInfo('updateOrderProduct success', {
4239
4387
  params: params
4240
4388
  });
4241
- return _context22.abrupt("return", tempOrder.products);
4389
+ return _context25.abrupt("return", tempOrder.products);
4242
4390
  case 11:
4243
4391
  case "end":
4244
- return _context22.stop();
4392
+ return _context25.stop();
4245
4393
  }
4246
- }, _callee20, this);
4394
+ }, _callee23, this);
4247
4395
  }));
4248
- function updateOrderProduct(_x24) {
4396
+ function updateOrderProduct(_x29) {
4249
4397
  return _updateOrderProduct.apply(this, arguments);
4250
4398
  }
4251
4399
  return updateOrderProduct;
@@ -4253,28 +4401,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4253
4401
  }, {
4254
4402
  key: "updateOrderProducts",
4255
4403
  value: function () {
4256
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(paramsList) {
4257
- var _this25 = this;
4404
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4405
+ var _this28 = this;
4258
4406
  var tempOrder, reapplyBookingDiscountProductUids;
4259
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4260
- while (1) switch (_context23.prev = _context23.next) {
4407
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4408
+ while (1) switch (_context26.prev = _context26.next) {
4261
4409
  case 0:
4262
4410
  tempOrder = this.ensureTempOrder();
4263
4411
  if (paramsList.length) {
4264
- _context23.next = 3;
4412
+ _context26.next = 3;
4265
4413
  break;
4266
4414
  }
4267
- return _context23.abrupt("return", tempOrder.products);
4415
+ return _context26.abrupt("return", tempOrder.products);
4268
4416
  case 3:
4269
4417
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4270
- var updatedProductUid = _this25.applyOrderProductUpdateToTempOrder(tempOrder, params);
4418
+ var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4271
4419
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4272
4420
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4273
4421
  acc.push(String(updatedProductUid));
4274
4422
  }
4275
4423
  return acc;
4276
4424
  }, []);
4277
- _context23.next = 6;
4425
+ _context26.next = 6;
4278
4426
  return this.finalizeAfterProductsMutation(tempOrder, {
4279
4427
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4280
4428
  });
@@ -4282,14 +4430,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4282
4430
  this.logInfo('updateOrderProduct success', {
4283
4431
  paramsList: paramsList
4284
4432
  });
4285
- return _context23.abrupt("return", tempOrder.products);
4433
+ return _context26.abrupt("return", tempOrder.products);
4286
4434
  case 8:
4287
4435
  case "end":
4288
- return _context23.stop();
4436
+ return _context26.stop();
4289
4437
  }
4290
- }, _callee21, this);
4438
+ }, _callee24, this);
4291
4439
  }));
4292
- function updateOrderProducts(_x25) {
4440
+ function updateOrderProducts(_x30) {
4293
4441
  return _updateOrderProducts.apply(this, arguments);
4294
4442
  }
4295
4443
  return updateOrderProducts;
@@ -4297,11 +4445,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4297
4445
  }, {
4298
4446
  key: "updateOrderProductQuantity",
4299
4447
  value: function () {
4300
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
4448
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4301
4449
  var _targetProduct$metada17;
4302
4450
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4303
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4304
- while (1) switch (_context24.prev = _context24.next) {
4451
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4452
+ while (1) switch (_context27.prev = _context27.next) {
4305
4453
  case 0:
4306
4454
  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;
4307
4455
  tempOrder = this.ensureTempOrder();
@@ -4330,7 +4478,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4330
4478
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4331
4479
  }
4332
4480
  if (!(productIndex === -1)) {
4333
- _context24.next = 12;
4481
+ _context27.next = 12;
4334
4482
  break;
4335
4483
  }
4336
4484
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -4344,12 +4492,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4344
4492
  }));
4345
4493
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4346
4494
  tempOrder.products[productIndex] = normalizedProduct;
4347
- _context24.next = 18;
4495
+ _context27.next = 18;
4348
4496
  return this.applyPromotion();
4349
4497
  case 18:
4350
4498
  this.applyDiscount();
4351
4499
  this.sanitizeTempOrderProducts(tempOrder);
4352
- _context24.next = 22;
4500
+ _context27.next = 22;
4353
4501
  return this.recalculateSummary({
4354
4502
  createIfMissing: true
4355
4503
  });
@@ -4358,14 +4506,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4358
4506
  this.logInfo('updateOrderProductQuantity success', {
4359
4507
  params: params
4360
4508
  });
4361
- return _context24.abrupt("return", tempOrder.products);
4509
+ return _context27.abrupt("return", tempOrder.products);
4362
4510
  case 25:
4363
4511
  case "end":
4364
- return _context24.stop();
4512
+ return _context27.stop();
4365
4513
  }
4366
- }, _callee22, this);
4514
+ }, _callee25, this);
4367
4515
  }));
4368
- function updateOrderProductQuantity(_x26) {
4516
+ function updateOrderProductQuantity(_x31) {
4369
4517
  return _updateOrderProductQuantity.apply(this, arguments);
4370
4518
  }
4371
4519
  return updateOrderProductQuantity;
@@ -4406,19 +4554,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4406
4554
  }, {
4407
4555
  key: "finalizeAfterProductsMutation",
4408
4556
  value: (function () {
4409
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(tempOrder, options) {
4410
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4411
- while (1) switch (_context25.prev = _context25.next) {
4557
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4558
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4559
+ while (1) switch (_context28.prev = _context28.next) {
4412
4560
  case 0:
4413
4561
  this.syncTempOrderHolderFromBookings(tempOrder);
4414
- _context25.next = 3;
4562
+ _context28.next = 3;
4415
4563
  return this.applyPromotion();
4416
4564
  case 3:
4417
4565
  this.applyDiscount({
4418
4566
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4419
4567
  });
4420
4568
  this.sanitizeTempOrderProducts(tempOrder);
4421
- _context25.next = 7;
4569
+ _context28.next = 7;
4422
4570
  return this.recalculateSummary({
4423
4571
  createIfMissing: true
4424
4572
  });
@@ -4426,11 +4574,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4426
4574
  this.persistTempOrder();
4427
4575
  case 8:
4428
4576
  case "end":
4429
- return _context25.stop();
4577
+ return _context28.stop();
4430
4578
  }
4431
- }, _callee23, this);
4579
+ }, _callee26, this);
4432
4580
  }));
4433
- function finalizeAfterProductsMutation(_x27, _x28) {
4581
+ function finalizeAfterProductsMutation(_x32, _x33) {
4434
4582
  return _finalizeAfterProductsMutation.apply(this, arguments);
4435
4583
  }
4436
4584
  return finalizeAfterProductsMutation;
@@ -4445,18 +4593,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4445
4593
  }, {
4446
4594
  key: "removeProductsFromOrder",
4447
4595
  value: (function () {
4448
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identities) {
4449
- var _this26 = this;
4596
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities) {
4597
+ var _this29 = this;
4450
4598
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4451
- return _regeneratorRuntime().wrap(function _callee24$(_context27) {
4452
- while (1) switch (_context27.prev = _context27.next) {
4599
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4600
+ while (1) switch (_context30.prev = _context30.next) {
4453
4601
  case 0:
4454
4602
  tempOrder = this.ensureTempOrder();
4455
4603
  if (identities.length) {
4456
- _context27.next = 3;
4604
+ _context30.next = 3;
4457
4605
  break;
4458
4606
  }
4459
- return _context27.abrupt("return", tempOrder.products);
4607
+ return _context30.abrupt("return", tempOrder.products);
4460
4608
  case 3:
4461
4609
  productsBeforeRemove = tempOrder.products || [];
4462
4610
  bookingsBeforeRemove = tempOrder.bookings || [];
@@ -4479,29 +4627,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4479
4627
  }
4480
4628
  linkedBookingUidsToRemove = new Set();
4481
4629
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4482
- _context27.prev = 11;
4630
+ _context30.prev = 11;
4483
4631
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4484
4632
  var _metadata11, _metadata12, _metadata13, _metadata14;
4485
4633
  var product, productUid, productBookingUid, isAddTimeProduct;
4486
- return _regeneratorRuntime().wrap(function _loop3$(_context26) {
4487
- while (1) switch (_context26.prev = _context26.next) {
4634
+ return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4635
+ while (1) switch (_context29.prev = _context29.next) {
4488
4636
  case 0:
4489
4637
  product = _step21.value;
4490
4638
  productUid = (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4491
4639
  productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata12 = product.metadata) === null || _metadata12 === void 0 ? void 0 : _metadata12.booking_uid);
4492
4640
  isAddTimeProduct = (product === null || product === void 0 || (_metadata13 = product.metadata) === null || _metadata13 === void 0 ? void 0 : _metadata13.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata14 = product.metadata) === null || _metadata14 === void 0 ? void 0 : _metadata14.product_add_schedule_time) !== null;
4493
4641
  if (!isAddTimeProduct) {
4494
- _context26.next = 6;
4642
+ _context29.next = 6;
4495
4643
  break;
4496
4644
  }
4497
- return _context26.abrupt("return", 1);
4645
+ return _context29.abrupt("return", 1);
4498
4646
  case 6:
4499
4647
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4500
4648
  linkedBookingUidsToRemove.add(String(productBookingUid));
4501
4649
  }
4502
4650
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4503
4651
  bookingsBeforeRemove.forEach(function (booking) {
4504
- var bookingUid = _this26.getBookingUniqueIdentificationNumber(booking);
4652
+ var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
4505
4653
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4506
4654
  linkedBookingUidsToRemove.add(bookingUid);
4507
4655
  }
@@ -4509,37 +4657,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4509
4657
  }
4510
4658
  case 8:
4511
4659
  case "end":
4512
- return _context26.stop();
4660
+ return _context29.stop();
4513
4661
  }
4514
4662
  }, _loop3);
4515
4663
  });
4516
4664
  _iterator21.s();
4517
4665
  case 14:
4518
4666
  if ((_step21 = _iterator21.n()).done) {
4519
- _context27.next = 20;
4667
+ _context30.next = 20;
4520
4668
  break;
4521
4669
  }
4522
- return _context27.delegateYield(_loop3(), "t0", 16);
4670
+ return _context30.delegateYield(_loop3(), "t0", 16);
4523
4671
  case 16:
4524
- if (!_context27.t0) {
4525
- _context27.next = 18;
4672
+ if (!_context30.t0) {
4673
+ _context30.next = 18;
4526
4674
  break;
4527
4675
  }
4528
- return _context27.abrupt("continue", 18);
4676
+ return _context30.abrupt("continue", 18);
4529
4677
  case 18:
4530
- _context27.next = 14;
4678
+ _context30.next = 14;
4531
4679
  break;
4532
4680
  case 20:
4533
- _context27.next = 25;
4681
+ _context30.next = 25;
4534
4682
  break;
4535
4683
  case 22:
4536
- _context27.prev = 22;
4537
- _context27.t1 = _context27["catch"](11);
4538
- _iterator21.e(_context27.t1);
4684
+ _context30.prev = 22;
4685
+ _context30.t1 = _context30["catch"](11);
4686
+ _iterator21.e(_context30.t1);
4539
4687
  case 25:
4540
- _context27.prev = 25;
4688
+ _context30.prev = 25;
4541
4689
  _iterator21.f();
4542
- return _context27.finish(25);
4690
+ return _context30.finish(25);
4543
4691
  case 28:
4544
4692
  if (linkedBookingUidsToRemove.size > 0) {
4545
4693
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
@@ -4550,20 +4698,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4550
4698
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4551
4699
  });
4552
4700
  }
4553
- _context27.next = 31;
4701
+ _context30.next = 31;
4554
4702
  return this.finalizeAfterProductsMutation(tempOrder);
4555
4703
  case 31:
4556
4704
  this.logInfo('removeProductsFromOrder success', {
4557
4705
  identities: identities
4558
4706
  });
4559
- return _context27.abrupt("return", tempOrder.products);
4707
+ return _context30.abrupt("return", tempOrder.products);
4560
4708
  case 33:
4561
4709
  case "end":
4562
- return _context27.stop();
4710
+ return _context30.stop();
4563
4711
  }
4564
- }, _callee24, this, [[11, 22, 25, 28]]);
4712
+ }, _callee27, this, [[11, 22, 25, 28]]);
4565
4713
  }));
4566
- function removeProductsFromOrder(_x29) {
4714
+ function removeProductsFromOrder(_x34) {
4567
4715
  return _removeProductsFromOrder.apply(this, arguments);
4568
4716
  }
4569
4717
  return removeProductsFromOrder;
@@ -4571,18 +4719,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4571
4719
  }, {
4572
4720
  key: "removeProductFromOrder",
4573
4721
  value: function () {
4574
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identity) {
4575
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4576
- while (1) switch (_context28.prev = _context28.next) {
4722
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
4723
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4724
+ while (1) switch (_context31.prev = _context31.next) {
4577
4725
  case 0:
4578
- return _context28.abrupt("return", this.removeProductsFromOrder([identity]));
4726
+ return _context31.abrupt("return", this.removeProductsFromOrder([identity]));
4579
4727
  case 1:
4580
4728
  case "end":
4581
- return _context28.stop();
4729
+ return _context31.stop();
4582
4730
  }
4583
- }, _callee25, this);
4731
+ }, _callee28, this);
4584
4732
  }));
4585
- function removeProductFromOrder(_x30) {
4733
+ function removeProductFromOrder(_x35) {
4586
4734
  return _removeProductFromOrder.apply(this, arguments);
4587
4735
  }
4588
4736
  return removeProductFromOrder;
@@ -4594,10 +4742,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4594
4742
  }, {
4595
4743
  key: "clearOrderCartLines",
4596
4744
  value: (function () {
4597
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4745
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4598
4746
  var tempOrder;
4599
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4600
- while (1) switch (_context29.prev = _context29.next) {
4747
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4748
+ while (1) switch (_context32.prev = _context32.next) {
4601
4749
  case 0:
4602
4750
  tempOrder = this.ensureTempOrder();
4603
4751
  tempOrder.products = [];
@@ -4608,24 +4756,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4608
4756
  productsByUid: {}
4609
4757
  });
4610
4758
  }
4611
- _context29.next = 7;
4759
+ _context32.next = 7;
4612
4760
  return this.applyPromotion();
4613
4761
  case 7:
4614
4762
  this.applyDiscount();
4615
4763
  this.sanitizeTempOrderProducts(tempOrder);
4616
- _context29.next = 11;
4764
+ _context32.next = 11;
4617
4765
  return this.recalculateSummary({
4618
4766
  createIfMissing: true
4619
4767
  });
4620
4768
  case 11:
4621
4769
  this.persistTempOrder();
4622
4770
  this.logInfo('clearOrderCartLines success', {});
4623
- return _context29.abrupt("return", tempOrder);
4771
+ return _context32.abrupt("return", tempOrder);
4624
4772
  case 14:
4625
4773
  case "end":
4626
- return _context29.stop();
4774
+ return _context32.stop();
4627
4775
  }
4628
- }, _callee26, this);
4776
+ }, _callee29, this);
4629
4777
  }));
4630
4778
  function clearOrderCartLines() {
4631
4779
  return _clearOrderCartLines.apply(this, arguments);
@@ -4663,17 +4811,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4663
4811
  }, {
4664
4812
  key: "applyLocalPrintOrderNumbers",
4665
4813
  value: function () {
4666
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order) {
4814
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
4667
4815
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4668
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4669
- while (1) switch (_context30.prev = _context30.next) {
4816
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4817
+ while (1) switch (_context33.prev = _context33.next) {
4670
4818
  case 0:
4671
4819
  tempOrder = this.ensureTempOrder();
4672
4820
  if (!(!order || _typeof(order) !== 'object')) {
4673
- _context30.next = 3;
4821
+ _context33.next = 3;
4674
4822
  break;
4675
4823
  }
4676
- return _context30.abrupt("return", tempOrder);
4824
+ return _context33.abrupt("return", tempOrder);
4677
4825
  case 3:
4678
4826
  shopOrderNumber = order.shop_order_number;
4679
4827
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4684,21 +4832,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4684
4832
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4685
4833
  }
4686
4834
  this.persistTempOrder();
4687
- _context30.next = 10;
4835
+ _context33.next = 10;
4688
4836
  return this.saveDraft();
4689
4837
  case 10:
4690
- return _context30.abrupt("return", tempOrder);
4838
+ return _context33.abrupt("return", tempOrder);
4691
4839
  case 11:
4692
4840
  case "end":
4693
- return _context30.stop();
4841
+ return _context33.stop();
4694
4842
  }
4695
- }, _callee27, this);
4843
+ }, _callee30, this);
4696
4844
  }));
4697
- function applyLocalPrintOrderNumbers(_x31) {
4845
+ function applyLocalPrintOrderNumbers(_x36) {
4698
4846
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4699
4847
  }
4700
4848
  return applyLocalPrintOrderNumbers;
4701
4849
  }()
4850
+ }, {
4851
+ key: "saveTempOrderAsDraft",
4852
+ value: function () {
4853
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4854
+ var _params$cacheId2, _this$otherParams6, _ref74, _params$businessCode2, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4855
+ var tempOrder, latestSummary, payload;
4856
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4857
+ while (1) switch (_context34.prev = _context34.next) {
4858
+ case 0:
4859
+ tempOrder = this.ensureTempOrder();
4860
+ this.ensureExternalSaleNumber(tempOrder);
4861
+ this.persistTempOrder();
4862
+ _context34.next = 5;
4863
+ return this.recalculateSummary({
4864
+ createIfMissing: true
4865
+ });
4866
+ case 5:
4867
+ _context34.t1 = _context34.sent;
4868
+ if (_context34.t1) {
4869
+ _context34.next = 8;
4870
+ break;
4871
+ }
4872
+ _context34.t1 = this.store.summary;
4873
+ case 8:
4874
+ _context34.t0 = _context34.t1;
4875
+ if (_context34.t0) {
4876
+ _context34.next = 11;
4877
+ break;
4878
+ }
4879
+ _context34.t0 = createEmptySummary();
4880
+ case 11:
4881
+ latestSummary = _context34.t0;
4882
+ payload = buildSubmitPayload({
4883
+ tempOrder: tempOrder,
4884
+ cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
4885
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4886
+ businessCode: (_ref74 = (_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 && _ref74 !== void 0 ? _ref74 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4887
+ channel: params === null || params === void 0 ? void 0 : params.channel,
4888
+ 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,
4889
+ summary: latestSummary,
4890
+ enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
4891
+ });
4892
+ if (!payload.created_at) {
4893
+ payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4894
+ }
4895
+ payload.need_sync = 0;
4896
+ payload.is_draft_order = 1;
4897
+ this.logInfo('saveTempOrderAsDraft calling sales draft', {
4898
+ orderId: payload.order_id,
4899
+ externalSaleNumber: payload.external_sale_number,
4900
+ productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
4901
+ });
4902
+ return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
4903
+ osServer: true,
4904
+ customToast: function customToast() {}
4905
+ }));
4906
+ case 18:
4907
+ case "end":
4908
+ return _context34.stop();
4909
+ }
4910
+ }, _callee31, this);
4911
+ }));
4912
+ function saveTempOrderAsDraft(_x37) {
4913
+ return _saveTempOrderAsDraft.apply(this, arguments);
4914
+ }
4915
+ return saveTempOrderAsDraft;
4916
+ }()
4702
4917
  /**
4703
4918
  * 提交当前 Sales tempOrder。
4704
4919
  *
@@ -4708,18 +4923,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4708
4923
  }, {
4709
4924
  key: "submitTempOrder",
4710
4925
  value: (function () {
4711
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
4712
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4713
- while (1) switch (_context31.prev = _context31.next) {
4926
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
4927
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
4928
+ while (1) switch (_context35.prev = _context35.next) {
4714
4929
  case 0:
4715
- return _context31.abrupt("return", this.runSubmitTempOrder(params));
4930
+ return _context35.abrupt("return", this.runSubmitTempOrder(params));
4716
4931
  case 1:
4717
4932
  case "end":
4718
- return _context31.stop();
4933
+ return _context35.stop();
4719
4934
  }
4720
- }, _callee28, this);
4935
+ }, _callee32, this);
4721
4936
  }));
4722
- function submitTempOrder(_x32) {
4937
+ function submitTempOrder(_x38) {
4723
4938
  return _submitTempOrder.apply(this, arguments);
4724
4939
  }
4725
4940
  return submitTempOrder;
@@ -4727,20 +4942,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4727
4942
  }, {
4728
4943
  key: "submitTempOrderAsync",
4729
4944
  value: function () {
4730
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4731
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4732
- while (1) switch (_context32.prev = _context32.next) {
4945
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
4946
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
4947
+ while (1) switch (_context36.prev = _context36.next) {
4733
4948
  case 0:
4734
- return _context32.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4949
+ return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4735
4950
  syncMode: true
4736
4951
  })));
4737
4952
  case 1:
4738
4953
  case "end":
4739
- return _context32.stop();
4954
+ return _context36.stop();
4740
4955
  }
4741
- }, _callee29, this);
4956
+ }, _callee33, this);
4742
4957
  }));
4743
- function submitTempOrderAsync(_x33) {
4958
+ function submitTempOrderAsync(_x39) {
4744
4959
  return _submitTempOrderAsync.apply(this, arguments);
4745
4960
  }
4746
4961
  return submitTempOrderAsync;
@@ -4748,11 +4963,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4748
4963
  }, {
4749
4964
  key: "runSubmitTempOrder",
4750
4965
  value: function () {
4751
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
4752
- var _params$cacheId2, _this$otherParams6, _ref74, _ref75, _submitSnapshot$busin, _this$otherParams7, _this$otherParams8, _submitSnapshot$type;
4966
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
4967
+ var _params$cacheId3, _this$otherParams10, _ref75, _ref76, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4753
4968
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4754
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4755
- while (1) switch (_context33.prev = _context33.next) {
4969
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
4970
+ while (1) switch (_context37.prev = _context37.next) {
4756
4971
  case 0:
4757
4972
  tempOrder = this.ensureTempOrder();
4758
4973
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -4772,27 +4987,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4772
4987
  }
4773
4988
  }
4774
4989
  this.persistTempOrder();
4775
- _context33.next = 8;
4990
+ _context37.next = 8;
4776
4991
  return this.recalculateSummary({
4777
4992
  createIfMissing: true
4778
4993
  });
4779
4994
  case 8:
4780
- _context33.t1 = _context33.sent;
4781
- if (_context33.t1) {
4782
- _context33.next = 11;
4995
+ _context37.t1 = _context37.sent;
4996
+ if (_context37.t1) {
4997
+ _context37.next = 11;
4783
4998
  break;
4784
4999
  }
4785
- _context33.t1 = this.store.summary;
5000
+ _context37.t1 = this.store.summary;
4786
5001
  case 11:
4787
- _context33.t0 = _context33.t1;
4788
- if (_context33.t0) {
4789
- _context33.next = 14;
5002
+ _context37.t0 = _context37.t1;
5003
+ if (_context37.t0) {
5004
+ _context37.next = 14;
4790
5005
  break;
4791
5006
  }
4792
- _context33.t0 = createEmptySummary();
5007
+ _context37.t0 = createEmptySummary();
4793
5008
  case 14:
4794
- latestSummary = _context33.t0;
4795
- effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
5009
+ latestSummary = _context37.t0;
5010
+ effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
4796
5011
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4797
5012
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4798
5013
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
@@ -4810,8 +5025,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4810
5025
  payload = buildSubmitPayload({
4811
5026
  tempOrder: tempOrder,
4812
5027
  cacheId: effectiveCacheId,
4813
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4814
- businessCode: (_ref74 = (_ref75 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
5028
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
5029
+ businessCode: (_ref75 = (_ref76 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref76 !== void 0 ? _ref76 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
4815
5030
  channel: params === null || params === void 0 ? void 0 : params.channel,
4816
5031
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4817
5032
  summary: latestSummary,
@@ -4826,10 +5041,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4826
5041
  if (!payload.created_at) {
4827
5042
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4828
5043
  }
4829
- _context33.next = 26;
5044
+ _context37.next = 26;
4830
5045
  return this.saveDraft();
4831
5046
  case 26:
4832
- _context33.prev = 26;
5047
+ _context37.prev = 26;
4833
5048
  this.logInfo('submitTempOrder calling sales checkout', {
4834
5049
  orderId: payload.order_id,
4835
5050
  externalSaleNumber: payload.external_sale_number,
@@ -4839,43 +5054,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4839
5054
  smallTicketDataFlag: payload.small_ticket_data_flag,
4840
5055
  syncMode: payload.sync_mode
4841
5056
  });
4842
- _context33.next = 30;
5057
+ _context37.next = 30;
4843
5058
  return this.submitSalesOrder({
4844
5059
  query: payload
4845
5060
  });
4846
5061
  case 30:
4847
- result = _context33.sent;
4848
- _context33.next = 43;
5062
+ result = _context37.sent;
5063
+ _context37.next = 43;
4849
5064
  break;
4850
5065
  case 33:
4851
- _context33.prev = 33;
4852
- _context33.t2 = _context33["catch"](26);
4853
- backendErrorResponse = this.extractSubmitErrorResponse(_context33.t2);
5066
+ _context37.prev = 33;
5067
+ _context37.t2 = _context37["catch"](26);
5068
+ backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
4854
5069
  if (!backendErrorResponse) {
4855
- _context33.next = 40;
5070
+ _context37.next = 40;
4856
5071
  break;
4857
5072
  }
4858
5073
  this.store.syncState = 'failed';
4859
5074
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4860
- return _context33.abrupt("return", backendErrorResponse);
5075
+ return _context37.abrupt("return", backendErrorResponse);
4861
5076
  case 40:
4862
5077
  this.store.syncState = 'failed';
4863
5078
  this.logError('submitTempOrder failed', {
4864
- error: _context33.t2 instanceof Error ? _context33.t2.message : String(_context33.t2),
5079
+ error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
4865
5080
  orderId: payload.order_id,
4866
5081
  externalSaleNumber: payload.external_sale_number,
4867
5082
  paymentStatus: payload.payment_status,
4868
5083
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4869
5084
  });
4870
- throw _context33.t2;
5085
+ throw _context37.t2;
4871
5086
  case 43:
4872
5087
  if (!this.isSubmitResponseRejected(result)) {
4873
- _context33.next = 47;
5088
+ _context37.next = 47;
4874
5089
  break;
4875
5090
  }
4876
5091
  this.store.syncState = 'failed';
4877
5092
  this.logSubmitBackendRejected(result, payload);
4878
- return _context33.abrupt("return", result);
5093
+ return _context37.abrupt("return", result);
4879
5094
  case 47:
4880
5095
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4881
5096
  this.logInfo('runSubmitTempOrder: 提交成功', {
@@ -4886,15 +5101,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4886
5101
  })
4887
5102
  });
4888
5103
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4889
- _context33.next = 56;
5104
+ _context37.next = 56;
4890
5105
  break;
4891
5106
  }
4892
5107
  tempOrder.order_id = submittedOrderId;
4893
5108
  resultRecord = result;
4894
- _context33.next = 54;
5109
+ _context37.next = 54;
4895
5110
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4896
5111
  case 54:
4897
- _context33.next = 57;
5112
+ _context37.next = 57;
4898
5113
  break;
4899
5114
  case 56:
4900
5115
  if (this.isLocalPendingSubmitResult(result)) {
@@ -4903,14 +5118,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4903
5118
  this.store.syncState = 'submitted';
4904
5119
  }
4905
5120
  case 57:
4906
- return _context33.abrupt("return", result);
5121
+ return _context37.abrupt("return", result);
4907
5122
  case 58:
4908
5123
  case "end":
4909
- return _context33.stop();
5124
+ return _context37.stop();
4910
5125
  }
4911
- }, _callee30, this, [[26, 33]]);
5126
+ }, _callee34, this, [[26, 33]]);
4912
5127
  }));
4913
- function runSubmitTempOrder(_x34) {
5128
+ function runSubmitTempOrder(_x40) {
4914
5129
  return _runSubmitTempOrder.apply(this, arguments);
4915
5130
  }
4916
5131
  return runSubmitTempOrder;
@@ -4918,10 +5133,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4918
5133
  }, {
4919
5134
  key: "markLocalOrderSynced",
4920
5135
  value: function () {
4921
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderId, remoteOrder) {
5136
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
4922
5137
  var tempOrder;
4923
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4924
- while (1) switch (_context34.prev = _context34.next) {
5138
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5139
+ while (1) switch (_context38.prev = _context38.next) {
4925
5140
  case 0:
4926
5141
  tempOrder = this.ensureTempOrder();
4927
5142
  tempOrder.order_id = orderId;
@@ -4929,15 +5144,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4929
5144
  this.store.lastOrderInfo = remoteOrder;
4930
5145
  this.store.syncState = 'submitted';
4931
5146
  this.persistTempOrder();
4932
- _context34.next = 8;
5147
+ _context38.next = 8;
4933
5148
  return this.saveDraft();
4934
5149
  case 8:
4935
5150
  case "end":
4936
- return _context34.stop();
5151
+ return _context38.stop();
4937
5152
  }
4938
- }, _callee31, this);
5153
+ }, _callee35, this);
4939
5154
  }));
4940
- function markLocalOrderSynced(_x35, _x36) {
5155
+ function markLocalOrderSynced(_x41, _x42) {
4941
5156
  return _markLocalOrderSynced.apply(this, arguments);
4942
5157
  }
4943
5158
  return markLocalOrderSynced;
@@ -4980,10 +5195,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4980
5195
  value: function extractSubmitErrorResponse(error) {
4981
5196
  var _error$response,
4982
5197
  _error$response2,
4983
- _this27 = this;
5198
+ _this30 = this;
4984
5199
  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];
4985
5200
  return candidates.find(function (candidate) {
4986
- return _this27.isSubmitErrorResponse(candidate);
5201
+ return _this30.isSubmitErrorResponse(candidate);
4987
5202
  }) || null;
4988
5203
  }
4989
5204
  }, {
@@ -5010,14 +5225,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5010
5225
  }, {
5011
5226
  key: "syncPaymentsToOrder",
5012
5227
  value: function () {
5013
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5014
- var _params$confirmPendin;
5015
- var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
5016
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5017
- while (1) switch (_context35.prev = _context35.next) {
5228
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5229
+ var _this31 = this,
5230
+ _params$confirmPendin;
5231
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
5232
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5233
+ while (1) switch (_context39.prev = _context39.next) {
5018
5234
  case 0:
5019
5235
  tempOrder = this.ensureTempOrder();
5020
- mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
5236
+ needsPaymentNumber = (params.payments || []).some(function (payment) {
5237
+ return String(payment.payment_number || '').trim() === '';
5238
+ });
5239
+ if (!needsPaymentNumber) {
5240
+ _context39.next = 8;
5241
+ break;
5242
+ }
5243
+ _context39.next = 5;
5244
+ return this.getPaymentNumberDevicePrefixAsync();
5245
+ case 5:
5246
+ _context39.t0 = _context39.sent;
5247
+ _context39.next = 9;
5248
+ break;
5249
+ case 8:
5250
+ _context39.t0 = 'LOCAL';
5251
+ case 9:
5252
+ devicePrefix = _context39.t0;
5253
+ mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5254
+ return _this31.normalizePaymentSource(payment, {
5255
+ defaultPaid: false,
5256
+ devicePrefix: devicePrefix
5257
+ });
5258
+ }));
5021
5259
  shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
5022
5260
  effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
5023
5261
  completion = this.getPaymentCompletion(effectivePayments);
@@ -5026,24 +5264,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5026
5264
  tempOrder.payments = effectivePayments;
5027
5265
  tempOrder.payment_status = paymentStatus;
5028
5266
  this.persistTempOrder();
5029
- _context35.next = 12;
5267
+ _context39.next = 21;
5030
5268
  return this.saveDraft();
5031
- case 12:
5269
+ case 21:
5032
5270
  if (params.submitWhenPaid) {
5033
- _context35.next = 14;
5271
+ _context39.next = 23;
5034
5272
  break;
5035
5273
  }
5036
- return _context35.abrupt("return", completion);
5037
- case 14:
5274
+ return _context39.abrupt("return", completion);
5275
+ case 23:
5038
5276
  if (!(this.store.syncState === 'submitting')) {
5039
- _context35.next = 16;
5277
+ _context39.next = 25;
5040
5278
  break;
5041
5279
  }
5042
- return _context35.abrupt("return", completion);
5043
- case 16:
5280
+ return _context39.abrupt("return", completion);
5281
+ case 25:
5044
5282
  this.store.syncState = 'submitting';
5045
5283
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
5046
- _context35.next = 20;
5284
+ _context39.next = 29;
5047
5285
  return this.submitTempOrder({
5048
5286
  payments: effectivePayments,
5049
5287
  paymentStatus: paymentStatus,
@@ -5058,18 +5296,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5058
5296
  return nextPayload;
5059
5297
  }
5060
5298
  });
5061
- case 20:
5062
- submitResult = _context35.sent;
5063
- return _context35.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5299
+ case 29:
5300
+ submitResult = _context39.sent;
5301
+ return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5064
5302
  submitResult: submitResult
5065
5303
  }));
5066
- case 22:
5304
+ case 31:
5067
5305
  case "end":
5068
- return _context35.stop();
5306
+ return _context39.stop();
5069
5307
  }
5070
- }, _callee32, this);
5308
+ }, _callee36, this);
5071
5309
  }));
5072
- function syncPaymentsToOrder(_x37) {
5310
+ function syncPaymentsToOrder(_x43) {
5073
5311
  return _syncPaymentsToOrder.apply(this, arguments);
5074
5312
  }
5075
5313
  return syncPaymentsToOrder;
@@ -5158,11 +5396,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5158
5396
  }, {
5159
5397
  key: "submitOrder",
5160
5398
  value: function () {
5161
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
5399
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5162
5400
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5163
5401
  var url, query, fetchUrl, params;
5164
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5165
- while (1) switch (_context36.prev = _context36.next) {
5402
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5403
+ while (1) switch (_context40.prev = _context40.next) {
5166
5404
  case 0:
5167
5405
  this.logInfo('submitOrder called', {
5168
5406
  url: order.url,
@@ -5182,14 +5420,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5182
5420
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5183
5421
  scheduleDate: params.schedule_date
5184
5422
  });
5185
- return _context36.abrupt("return", this.request.post(fetchUrl, params));
5423
+ return _context40.abrupt("return", this.request.post(fetchUrl, params));
5186
5424
  case 6:
5187
5425
  case "end":
5188
- return _context36.stop();
5426
+ return _context40.stop();
5189
5427
  }
5190
- }, _callee33, this);
5428
+ }, _callee37, this);
5191
5429
  }));
5192
- function submitOrder(_x38) {
5430
+ function submitOrder(_x44) {
5193
5431
  return _submitOrder.apply(this, arguments);
5194
5432
  }
5195
5433
  return submitOrder;
@@ -5197,13 +5435,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5197
5435
  }, {
5198
5436
  key: "cancelOrder",
5199
5437
  value: function () {
5200
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5438
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5201
5439
  var payload;
5202
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5203
- while (1) switch (_context37.prev = _context37.next) {
5440
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5441
+ while (1) switch (_context41.prev = _context41.next) {
5204
5442
  case 0:
5205
5443
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5206
- _context37.next = 2;
5444
+ _context41.next = 2;
5207
5445
  break;
5208
5446
  }
5209
5447
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5219,16 +5457,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5219
5457
  method: 'PUT',
5220
5458
  orderIdsCount: params.order_ids.length
5221
5459
  });
5222
- return _context37.abrupt("return", this.request.put('/order/update-status', payload, {
5460
+ return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5223
5461
  isShopApi: true
5224
5462
  }));
5225
5463
  case 5:
5226
5464
  case "end":
5227
- return _context37.stop();
5465
+ return _context41.stop();
5228
5466
  }
5229
- }, _callee34, this);
5467
+ }, _callee38, this);
5230
5468
  }));
5231
- function cancelOrder(_x39) {
5469
+ function cancelOrder(_x45) {
5232
5470
  return _cancelOrder.apply(this, arguments);
5233
5471
  }
5234
5472
  return cancelOrder;
@@ -5236,19 +5474,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5236
5474
  }, {
5237
5475
  key: "changeBookingStatus",
5238
5476
  value: function () {
5239
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5477
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5240
5478
  var url, payload;
5241
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5242
- while (1) switch (_context38.prev = _context38.next) {
5479
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5480
+ while (1) switch (_context42.prev = _context42.next) {
5243
5481
  case 0:
5244
5482
  if (params.booking_id) {
5245
- _context38.next = 2;
5483
+ _context42.next = 2;
5246
5484
  break;
5247
5485
  }
5248
5486
  throw new Error('变更预约状态失败:booking_id 不能为空');
5249
5487
  case 2:
5250
5488
  if (params.appointment_status) {
5251
- _context38.next = 4;
5489
+ _context42.next = 4;
5252
5490
  break;
5253
5491
  }
5254
5492
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5263,16 +5501,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5263
5501
  bookingId: params.booking_id,
5264
5502
  appointmentStatus: params.appointment_status
5265
5503
  });
5266
- return _context38.abrupt("return", this.request.put(url, payload, {
5504
+ return _context42.abrupt("return", this.request.put(url, payload, {
5267
5505
  isShopApi: true
5268
5506
  }));
5269
5507
  case 8:
5270
5508
  case "end":
5271
- return _context38.stop();
5509
+ return _context42.stop();
5272
5510
  }
5273
- }, _callee35, this);
5511
+ }, _callee39, this);
5274
5512
  }));
5275
- function changeBookingStatus(_x40) {
5513
+ function changeBookingStatus(_x46) {
5276
5514
  return _changeBookingStatus.apply(this, arguments);
5277
5515
  }
5278
5516
  return changeBookingStatus;
@@ -5290,11 +5528,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5290
5528
  }, {
5291
5529
  key: "createOrderByCheckout",
5292
5530
  value: (function () {
5293
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5531
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5294
5532
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5295
5533
  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;
5296
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5297
- while (1) switch (_context39.prev = _context39.next) {
5534
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5535
+ while (1) switch (_context43.prev = _context43.next) {
5298
5536
  case 0:
5299
5537
  // 过滤掉由在线店铺下单的 payment 支付数据
5300
5538
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5328,7 +5566,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5328
5566
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5329
5567
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5330
5568
  });
5331
- _context39.prev = 4;
5569
+ _context43.prev = 4;
5332
5570
  // 构建订单数据,设置默认值并允许 params 覆盖
5333
5571
  orderData = _objectSpread({
5334
5572
  sales_channel: 'my_pisel',
@@ -5390,13 +5628,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5390
5628
  hasOrderId: !!orderData.order_id,
5391
5629
  smallTicketDataFlag: orderData.small_ticket_data_flag
5392
5630
  });
5393
- _context39.next = 12;
5631
+ _context43.next = 12;
5394
5632
  return this.request.post('/order/checkout', orderData, {
5395
5633
  osServer: true,
5396
5634
  customToast: function customToast() {}
5397
5635
  });
5398
5636
  case 12:
5399
- response = _context39.sent;
5637
+ response = _context43.sent;
5400
5638
  this.logInfo('Order API called successfully', {
5401
5639
  response: response
5402
5640
  });
@@ -5404,22 +5642,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5404
5642
  success: !!response,
5405
5643
  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)
5406
5644
  });
5407
- return _context39.abrupt("return", response);
5645
+ return _context43.abrupt("return", response);
5408
5646
  case 18:
5409
- _context39.prev = 18;
5410
- _context39.t0 = _context39["catch"](4);
5411
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context39.t0);
5647
+ _context43.prev = 18;
5648
+ _context43.t0 = _context43["catch"](4);
5649
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
5412
5650
  this.logInfo('Order API called failed', {
5413
- error: _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0)
5651
+ error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
5414
5652
  });
5415
- throw _context39.t0;
5653
+ throw _context43.t0;
5416
5654
  case 23:
5417
5655
  case "end":
5418
- return _context39.stop();
5656
+ return _context43.stop();
5419
5657
  }
5420
- }, _callee36, this, [[4, 18]]);
5658
+ }, _callee40, this, [[4, 18]]);
5421
5659
  }));
5422
- function createOrderByCheckout(_x41) {
5660
+ function createOrderByCheckout(_x47) {
5423
5661
  return _createOrderByCheckout.apply(this, arguments);
5424
5662
  }
5425
5663
  return createOrderByCheckout;
@@ -5427,24 +5665,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5427
5665
  }, {
5428
5666
  key: "submitSalesOrder",
5429
5667
  value: function () {
5430
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5668
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5431
5669
  var url, query, fetchUrl;
5432
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5433
- while (1) switch (_context40.prev = _context40.next) {
5670
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5671
+ while (1) switch (_context44.prev = _context44.next) {
5434
5672
  case 0:
5435
5673
  url = params.url, query = params.query;
5436
5674
  fetchUrl = url || '/order/sales/checkout';
5437
- return _context40.abrupt("return", this.request.post(fetchUrl, query, {
5675
+ return _context44.abrupt("return", this.request.post(fetchUrl, query, {
5438
5676
  osServer: true,
5439
5677
  customToast: function customToast() {}
5440
5678
  }));
5441
5679
  case 3:
5442
5680
  case "end":
5443
- return _context40.stop();
5681
+ return _context44.stop();
5444
5682
  }
5445
- }, _callee37, this);
5683
+ }, _callee41, this);
5446
5684
  }));
5447
- function submitSalesOrder(_x42) {
5685
+ function submitSalesOrder(_x48) {
5448
5686
  return _submitSalesOrder.apply(this, arguments);
5449
5687
  }
5450
5688
  return submitSalesOrder;
@@ -5458,37 +5696,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5458
5696
  }, {
5459
5697
  key: "sendCustomerPayLink",
5460
5698
  value: (function () {
5461
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5699
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5462
5700
  var _params$emails;
5463
5701
  var orderIds;
5464
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5465
- while (1) switch (_context41.prev = _context41.next) {
5702
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5703
+ while (1) switch (_context45.prev = _context45.next) {
5466
5704
  case 0:
5467
5705
  orderIds = params.order_ids || params.orderIds || [];
5468
5706
  if (orderIds.length) {
5469
- _context41.next = 3;
5707
+ _context45.next = 3;
5470
5708
  break;
5471
5709
  }
5472
5710
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5473
5711
  case 3:
5474
5712
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5475
- _context41.next = 5;
5713
+ _context45.next = 5;
5476
5714
  break;
5477
5715
  }
5478
5716
  throw new Error('发送支付链接需要至少一个邮箱');
5479
5717
  case 5:
5480
- return _context41.abrupt("return", this.request.post('/order/batch-email', {
5718
+ return _context45.abrupt("return", this.request.post('/order/batch-email', {
5481
5719
  order_ids: orderIds,
5482
5720
  notify_action: params.notify_action || 'order_payment_reminder',
5483
5721
  emails: params.emails
5484
5722
  }));
5485
5723
  case 6:
5486
5724
  case "end":
5487
- return _context41.stop();
5725
+ return _context45.stop();
5488
5726
  }
5489
- }, _callee38, this);
5727
+ }, _callee42, this);
5490
5728
  }));
5491
- function sendCustomerPayLink(_x43) {
5729
+ function sendCustomerPayLink(_x49) {
5492
5730
  return _sendCustomerPayLink.apply(this, arguments);
5493
5731
  }
5494
5732
  return sendCustomerPayLink;
@@ -5496,14 +5734,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5496
5734
  }, {
5497
5735
  key: "getSalesOrderByLookup",
5498
5736
  value: function () {
5499
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5737
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5500
5738
  var lookup, res;
5501
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5502
- while (1) switch (_context42.prev = _context42.next) {
5739
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5740
+ while (1) switch (_context46.prev = _context46.next) {
5503
5741
  case 0:
5504
5742
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5505
5743
  if (lookup) {
5506
- _context42.next = 3;
5744
+ _context46.next = 3;
5507
5745
  break;
5508
5746
  }
5509
5747
  throw new Error('加载销售详情需要 lookup');
@@ -5512,7 +5750,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5512
5750
  if (lookup.startsWith('LOCAL_')) {
5513
5751
  params.forceRemote = false;
5514
5752
  }
5515
- _context42.next = 6;
5753
+ _context46.next = 6;
5516
5754
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5517
5755
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
5518
5756
  }, params.forceRemote ? {
@@ -5521,18 +5759,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5521
5759
  osServer: true
5522
5760
  });
5523
5761
  case 6:
5524
- res = _context42.sent;
5762
+ res = _context46.sent;
5525
5763
  if (res.code === 200) {
5526
5764
  this.store.lastOrderInfo = res.data;
5527
5765
  }
5528
- return _context42.abrupt("return", res);
5766
+ return _context46.abrupt("return", res);
5529
5767
  case 9:
5530
5768
  case "end":
5531
- return _context42.stop();
5769
+ return _context46.stop();
5532
5770
  }
5533
- }, _callee39, this);
5771
+ }, _callee43, this);
5534
5772
  }));
5535
- function getSalesOrderByLookup(_x44) {
5773
+ function getSalesOrderByLookup(_x50) {
5536
5774
  return _getSalesOrderByLookup.apply(this, arguments);
5537
5775
  }
5538
5776
  return getSalesOrderByLookup;
@@ -5546,11 +5784,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5546
5784
  }, {
5547
5785
  key: "hydrateTempOrderFromRecord",
5548
5786
  value: (function () {
5549
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(record, options) {
5787
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5550
5788
  var _this$store$discount19;
5551
- var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount20, _this$store$discount21;
5552
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5553
- while (1) switch (_context43.prev = _context43.next) {
5789
+ 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;
5790
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5791
+ while (1) switch (_context47.prev = _context47.next) {
5554
5792
  case 0:
5555
5793
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5556
5794
  identityReadySource = this.seedAnonymousBookingUidsFromProducts(sourceRaw);
@@ -5575,7 +5813,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5575
5813
  }
5576
5814
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
5577
5815
  makeEditMark: true
5578
- });
5816
+ }); // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
5817
+ sourceLastOrderInfo = raw.lastOrderInfo || raw;
5818
+ isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
5819
+ syntheticIdentityOptions = {
5820
+ isDraftOrder: isDraftOrder,
5821
+ externalSaleNumber: nextTempOrder.external_sale_number
5822
+ };
5579
5823
  rawSummary = raw.summary && _typeof(raw.summary) === 'object' ? raw.summary : {};
5580
5824
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
5581
5825
  return _objectSpread({}, s || {});
@@ -5595,10 +5839,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5595
5839
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
5596
5840
  }
5597
5841
  });
5598
- // lastOrderInfo carries the exact backend snapshot used by deposit/type recovery.
5599
- // Runtime collection repair lives in tempOrder/originalSalesSnapshot and must not
5600
- // rewrite this protocol snapshot as a side effect of hydration.
5601
- this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
5842
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5843
+ hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5844
+ if (hadSyntheticDraftOrderId && this.store.syncState !== 'submitting') {
5845
+ this.store.syncState = 'local';
5846
+ }
5602
5847
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
5603
5848
  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() || [] : [];
5604
5849
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
@@ -5613,34 +5858,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5613
5858
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
5614
5859
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
5615
5860
  if (shouldSkipEmptyDiscountSync) {
5616
- _context43.next = 26;
5861
+ _context47.next = 31;
5617
5862
  break;
5618
5863
  }
5619
5864
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
5620
- _context43.next = 24;
5865
+ _context47.next = 29;
5621
5866
  return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(nextDiscounts);
5622
- case 24:
5623
- _context43.next = 26;
5867
+ case 29:
5868
+ _context47.next = 31;
5624
5869
  return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(nextDiscounts);
5625
- case 26:
5870
+ case 31:
5626
5871
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5627
- _context43.next = 29;
5872
+ _context47.next = 34;
5628
5873
  break;
5629
5874
  }
5630
- _context43.next = 29;
5875
+ _context47.next = 34;
5631
5876
  return this.recalculateSummary({
5632
5877
  createIfMissing: false
5633
5878
  });
5634
- case 29:
5879
+ case 34:
5635
5880
  this.persistTempOrder();
5636
- return _context43.abrupt("return", nextTempOrder);
5637
- case 31:
5881
+ return _context47.abrupt("return", nextTempOrder);
5882
+ case 36:
5638
5883
  case "end":
5639
- return _context43.stop();
5884
+ return _context47.stop();
5640
5885
  }
5641
- }, _callee40, this);
5886
+ }, _callee44, this);
5642
5887
  }));
5643
- function hydrateTempOrderFromRecord(_x45, _x46) {
5888
+ function hydrateTempOrderFromRecord(_x51, _x52) {
5644
5889
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5645
5890
  }
5646
5891
  return hydrateTempOrderFromRecord;
@@ -5754,11 +5999,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5754
5999
  }, {
5755
6000
  key: "normalizeTempOrderForRuntime",
5756
6001
  value: function normalizeTempOrderForRuntime(raw, options) {
5757
- var _this28 = this;
5758
- var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
6002
+ var _this32 = this;
6003
+ var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6004
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
5759
6005
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5760
- 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) {
5761
- nextTempOrder.order_id = raw.id;
6006
+ 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) {
6007
+ nextTempOrder.order_id = runtimeRaw.id;
5762
6008
  }
5763
6009
  delete nextTempOrder.summary;
5764
6010
  delete nextTempOrder.lastOrderInfo;
@@ -5777,12 +6023,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5777
6023
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5778
6024
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5779
6025
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5780
- return _this28.normalizeHydratedOrderProduct(p, {
6026
+ return _this32.normalizeHydratedOrderProduct(p, {
5781
6027
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
5782
6028
  });
5783
6029
  }) : [];
5784
6030
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5785
- var booking = _this28.normalizeHydratedBookingHolder(b || {});
6031
+ var booking = _this32.normalizeHydratedBookingHolder(b || {});
5786
6032
  return _objectSpread(_objectSpread({}, booking), {}, {
5787
6033
  is_all: normalizeBookingIsAll(booking),
5788
6034
  sub_type: normalizeBookingSubType(booking)
@@ -5812,7 +6058,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5812
6058
  _step24;
5813
6059
  try {
5814
6060
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
5815
- var _product$metadata11, _ref76, _ref77, _existed$origin, _rawProduct$metadata;
6061
+ var _product$metadata11, _ref77, _ref78, _existed$origin, _rawProduct$metadata;
5816
6062
  var _step24$value = _slicedToArray(_step24.value, 2),
5817
6063
  index = _step24$value[0],
5818
6064
  product = _step24$value[1];
@@ -5820,7 +6066,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5820
6066
  if (!uid) continue;
5821
6067
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
5822
6068
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
5823
- var origin = (_ref76 = (_ref77 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref77 !== void 0 ? _ref77 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref76 !== void 0 ? _ref76 : rawProduct;
6069
+ var origin = (_ref77 = (_ref78 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref78 !== void 0 ? _ref78 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref77 !== void 0 ? _ref77 : rawProduct;
5824
6070
  var originSnapshot = cloneDeep(origin);
5825
6071
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
5826
6072
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -5848,6 +6094,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5848
6094
  nextTempOrder.vouchers = raw.vouchers || [];
5849
6095
  return nextTempOrder;
5850
6096
  }
6097
+ }, {
6098
+ key: "isSyntheticDraftOrderIdForRuntime",
6099
+ value: function isSyntheticDraftOrderIdForRuntime(record, options) {
6100
+ var _options$isDraftOrder, _record$external_sale;
6101
+ 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;
6102
+ 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;
6103
+ var orderId = record === null || record === void 0 ? void 0 : record.order_id;
6104
+ return Boolean(isDraftOrder && orderId !== undefined && orderId !== null && orderId !== '' && externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '' && String(orderId) === String(externalSaleNumber));
6105
+ }
6106
+ }, {
6107
+ key: "withoutSyntheticDraftOrderIdForRuntime",
6108
+ value: function withoutSyntheticDraftOrderIdForRuntime(record, options) {
6109
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options)) return record;
6110
+ return _objectSpread(_objectSpread({}, record), {}, {
6111
+ order_id: null
6112
+ });
6113
+ }
5851
6114
  }, {
5852
6115
  key: "hydrateLinkedBookingIdentity",
5853
6116
  value: function hydrateLinkedBookingIdentity(tempOrder) {
@@ -5932,10 +6195,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5932
6195
  }, {
5933
6196
  key: "normalizeHydratedProductOptionItem",
5934
6197
  value: function normalizeHydratedProductOptionItem(optionItem) {
5935
- var _ref78, _optionItem$num, _ref79, _optionItem$add_price;
5936
- var rawNum = (_ref78 = (_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 && _ref78 !== void 0 ? _ref78 : 1;
6198
+ var _ref79, _optionItem$num, _ref80, _optionItem$add_price;
6199
+ var rawNum = (_ref79 = (_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 && _ref79 !== void 0 ? _ref79 : 1;
5937
6200
  var parsedNum = Number(rawNum);
5938
- var rawPrice = (_ref79 = (_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 && _ref79 !== void 0 ? _ref79 : 0;
6201
+ var rawPrice = (_ref80 = (_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 && _ref80 !== void 0 ? _ref80 : 0;
5939
6202
  var parsedPrice = Number(rawPrice);
5940
6203
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
5941
6204
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -5952,7 +6215,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5952
6215
  }, {
5953
6216
  key: "normalizeHydratedOrderProduct",
5954
6217
  value: function normalizeHydratedOrderProduct(product, options) {
5955
- var _this29 = this;
6218
+ var _this33 = this;
5956
6219
  var row = _objectSpread({}, product || {});
5957
6220
  if (row.num === undefined && row.product_quantity !== undefined) {
5958
6221
  row.num = row.product_quantity;
@@ -5960,7 +6223,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5960
6223
  var productSku = ensureProductSku(row);
5961
6224
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5962
6225
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5963
- return _this29.normalizeHydratedProductOptionItem(optionItem || {});
6226
+ return _this33.normalizeHydratedProductOptionItem(optionItem || {});
5964
6227
  }))
5965
6228
  });
5966
6229
  delete row["product_".concat('option', "_item")];
@@ -5997,27 +6260,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5997
6260
  }, {
5998
6261
  key: "getOrderInfo",
5999
6262
  value: function () {
6000
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(order_id) {
6263
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
6001
6264
  var res;
6002
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6003
- while (1) switch (_context44.prev = _context44.next) {
6265
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6266
+ while (1) switch (_context48.prev = _context48.next) {
6004
6267
  case 0:
6005
- _context44.next = 2;
6268
+ _context48.next = 2;
6006
6269
  return this.request.get("/order/sales/".concat(order_id), {
6007
6270
  with: ['products', 'bookings']
6008
6271
  }, {
6009
6272
  osServer: true
6010
6273
  });
6011
6274
  case 2:
6012
- res = _context44.sent;
6013
- return _context44.abrupt("return", res);
6275
+ res = _context48.sent;
6276
+ return _context48.abrupt("return", res);
6014
6277
  case 4:
6015
6278
  case "end":
6016
- return _context44.stop();
6279
+ return _context48.stop();
6017
6280
  }
6018
- }, _callee41, this);
6281
+ }, _callee45, this);
6019
6282
  }));
6020
- function getOrderInfo(_x47) {
6283
+ function getOrderInfo(_x53) {
6021
6284
  return _getOrderInfo.apply(this, arguments);
6022
6285
  }
6023
6286
  return getOrderInfo;
@@ -6076,10 +6339,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6076
6339
  _step29;
6077
6340
  try {
6078
6341
  for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
6079
- var _ref80, _bundle$num3;
6342
+ var _ref81, _bundle$num3;
6080
6343
  var bundle = _step29.value;
6081
6344
  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));
6082
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref80 = (_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 && _ref80 !== void 0 ? _ref80 : 1) || 1).toNumber();
6345
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref81 = (_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 && _ref81 !== void 0 ? _ref81 : 1) || 1).toNumber();
6083
6346
  var _iterator30 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
6084
6347
  _step30;
6085
6348
  try {