@pisell/pisellos 2.3.29 → 2.3.31

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 (48) 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 +23 -0
  4. package/dist/modules/Order/payment-utils.js +203 -0
  5. package/dist/modules/Order/types.d.ts +33 -1
  6. package/dist/modules/Order/utils.js +4 -4
  7. package/dist/modules/Payment/index.d.ts +2 -0
  8. package/dist/modules/Payment/index.js +78 -49
  9. package/dist/modules/Payment/types.d.ts +26 -24
  10. package/dist/modules/Payment/types.js +2 -0
  11. package/dist/server/index.d.ts +14 -0
  12. package/dist/server/index.js +1850 -1024
  13. package/dist/server/modules/order/index.d.ts +40 -3
  14. package/dist/server/modules/order/index.js +1200 -501
  15. package/dist/server/modules/order/types.d.ts +11 -3
  16. package/dist/server/modules/order/types.js +1 -1
  17. package/dist/solution/BaseSales/index.d.ts +33 -3
  18. package/dist/solution/BaseSales/index.js +609 -322
  19. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  20. package/dist/solution/BookingByStep/index.d.ts +1 -1
  21. package/dist/solution/BookingTicket/index.d.ts +1 -1
  22. package/dist/solution/BookingTicket/index.js +2 -1
  23. package/dist/utils/payment-number.d.ts +9 -0
  24. package/dist/utils/payment-number.js +69 -0
  25. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  26. package/lib/modules/Order/index.d.ts +27 -8
  27. package/lib/modules/Order/index.js +180 -60
  28. package/lib/modules/Order/payment-utils.d.ts +23 -0
  29. package/lib/modules/Order/payment-utils.js +193 -0
  30. package/lib/modules/Order/types.d.ts +33 -1
  31. package/lib/modules/Order/utils.js +2 -3
  32. package/lib/modules/Payment/index.d.ts +2 -0
  33. package/lib/modules/Payment/index.js +33 -12
  34. package/lib/modules/Payment/types.d.ts +26 -24
  35. package/lib/server/index.d.ts +14 -0
  36. package/lib/server/index.js +604 -8
  37. package/lib/server/modules/order/index.d.ts +40 -3
  38. package/lib/server/modules/order/index.js +434 -31
  39. package/lib/server/modules/order/types.d.ts +11 -3
  40. package/lib/solution/BaseSales/index.d.ts +33 -3
  41. package/lib/solution/BaseSales/index.js +167 -7
  42. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  43. package/lib/solution/BookingByStep/index.d.ts +1 -1
  44. package/lib/solution/BookingTicket/index.d.ts +1 -1
  45. package/lib/solution/BookingTicket/index.js +2 -1
  46. package/lib/utils/payment-number.d.ts +9 -0
  47. package/lib/utils/payment-number.js +64 -0
  48. 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,
@@ -3704,8 +3852,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3704
3852
  hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3705
3853
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3706
3854
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3707
- if (_this23.hasGoodPassDiscount(item)) return false;
3708
- if (_this23.hasOrderProductLineNote(item)) return false;
3855
+ if (_this26.hasGoodPassDiscount(item)) return false;
3856
+ if (_this26.hasOrderProductLineNote(item)) return false;
3709
3857
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3710
3858
  if (item.product_id !== productToAdd.product_id) return false;
3711
3859
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
@@ -3715,10 +3863,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3715
3863
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3716
3864
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3717
3865
  if (!matchedProduct) {
3718
- _context19.next = 20;
3866
+ _context22.next = 20;
3719
3867
  break;
3720
3868
  }
3721
- _context19.next = 17;
3869
+ _context22.next = 17;
3722
3870
  return this.shouldMergeProductToOrder({
3723
3871
  incomingProduct: productToAdd,
3724
3872
  normalizedIncoming: normalizedIncoming,
@@ -3730,13 +3878,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3730
3878
  booking: booking
3731
3879
  });
3732
3880
  case 17:
3733
- _context19.t0 = _context19.sent;
3734
- _context19.next = 21;
3881
+ _context22.t0 = _context22.sent;
3882
+ _context22.next = 21;
3735
3883
  break;
3736
3884
  case 20:
3737
- _context19.t0 = false;
3885
+ _context22.t0 = false;
3738
3886
  case 21:
3739
- shouldMerge = _context19.t0;
3887
+ shouldMerge = _context22.t0;
3740
3888
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3741
3889
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
3742
3890
  if (linked) {
@@ -3790,11 +3938,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3790
3938
  }
3791
3939
  case 24:
3792
3940
  case "end":
3793
- return _context19.stop();
3941
+ return _context22.stop();
3794
3942
  }
3795
- }, _callee17, this);
3943
+ }, _callee20, this);
3796
3944
  }));
3797
- function appendProductLineToTempOrder(_x17, _x18, _x19) {
3945
+ function appendProductLineToTempOrder(_x22, _x23, _x24) {
3798
3946
  return _appendProductLineToTempOrder.apply(this, arguments);
3799
3947
  }
3800
3948
  return appendProductLineToTempOrder;
@@ -3810,61 +3958,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3810
3958
  }, {
3811
3959
  key: "addProductToOrder",
3812
3960
  value: (function () {
3813
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(product, booking) {
3961
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking) {
3814
3962
  var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3815
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3816
- while (1) switch (_context20.prev = _context20.next) {
3963
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
3964
+ while (1) switch (_context23.prev = _context23.next) {
3817
3965
  case 0:
3818
3966
  tempOrder = this.ensureTempOrder();
3819
3967
  if (!booking) {
3820
- _context20.next = 18;
3968
+ _context23.next = 18;
3821
3969
  break;
3822
3970
  }
3823
3971
  productRecord = product;
3824
3972
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3825
3973
  if (!(splitCount > 1)) {
3826
- _context20.next = 18;
3974
+ _context23.next = 18;
3827
3975
  break;
3828
3976
  }
3829
3977
  i = 0;
3830
3978
  case 6:
3831
3979
  if (!(i < splitCount)) {
3832
- _context20.next = 15;
3980
+ _context23.next = 15;
3833
3981
  break;
3834
3982
  }
3835
3983
  singleLine = cloneDeep(productRecord);
3836
3984
  singleLine.num = 1;
3837
3985
  delete singleLine.product_quantity;
3838
- _context20.next = 12;
3986
+ _context23.next = 12;
3839
3987
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3840
3988
  case 12:
3841
3989
  i += 1;
3842
- _context20.next = 6;
3990
+ _context23.next = 6;
3843
3991
  break;
3844
3992
  case 15:
3845
- _context20.next = 17;
3993
+ _context23.next = 17;
3846
3994
  return this.finalizeProductOrderMutation(tempOrder);
3847
3995
  case 17:
3848
- return _context20.abrupt("return", tempOrder.products);
3996
+ return _context23.abrupt("return", tempOrder.products);
3849
3997
  case 18:
3850
- _context20.next = 20;
3998
+ _context23.next = 20;
3851
3999
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3852
4000
  case 20:
3853
- _context20.next = 22;
4001
+ _context23.next = 22;
3854
4002
  return this.finalizeProductOrderMutation(tempOrder);
3855
4003
  case 22:
3856
4004
  this.logInfo('addProductToOrder success', {
3857
4005
  product_id: product.product_id,
3858
4006
  with_booking: !!booking
3859
4007
  });
3860
- return _context20.abrupt("return", tempOrder.products);
4008
+ return _context23.abrupt("return", tempOrder.products);
3861
4009
  case 24:
3862
4010
  case "end":
3863
- return _context20.stop();
4011
+ return _context23.stop();
3864
4012
  }
3865
- }, _callee18, this);
4013
+ }, _callee21, this);
3866
4014
  }));
3867
- function addProductToOrder(_x20, _x21) {
4015
+ function addProductToOrder(_x25, _x26) {
3868
4016
  return _addProductToOrder.apply(this, arguments);
3869
4017
  }
3870
4018
  return addProductToOrder;
@@ -3882,93 +4030,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3882
4030
  }, {
3883
4031
  key: "addProductsToOrder",
3884
4032
  value: (function () {
3885
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(items, options) {
4033
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
3886
4034
  var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3887
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3888
- while (1) switch (_context21.prev = _context21.next) {
4035
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4036
+ while (1) switch (_context24.prev = _context24.next) {
3889
4037
  case 0:
3890
4038
  tempOrder = this.ensureTempOrder();
3891
4039
  if (!(!Array.isArray(items) || items.length === 0)) {
3892
- _context21.next = 3;
4040
+ _context24.next = 3;
3893
4041
  break;
3894
4042
  }
3895
- return _context21.abrupt("return", tempOrder.products);
4043
+ return _context24.abrupt("return", tempOrder.products);
3896
4044
  case 3:
3897
4045
  _iterator20 = _createForOfIteratorHelper(items || []);
3898
- _context21.prev = 4;
4046
+ _context24.prev = 4;
3899
4047
  _iterator20.s();
3900
4048
  case 6:
3901
4049
  if ((_step20 = _iterator20.n()).done) {
3902
- _context21.next = 30;
4050
+ _context24.next = 30;
3903
4051
  break;
3904
4052
  }
3905
4053
  item = _step20.value;
3906
4054
  product = item.product, booking = item.booking;
3907
4055
  if (product) {
3908
- _context21.next = 11;
4056
+ _context24.next = 11;
3909
4057
  break;
3910
4058
  }
3911
- return _context21.abrupt("continue", 28);
4059
+ return _context24.abrupt("continue", 28);
3912
4060
  case 11:
3913
4061
  if (!booking) {
3914
- _context21.next = 26;
4062
+ _context24.next = 26;
3915
4063
  break;
3916
4064
  }
3917
4065
  productRecord = product;
3918
4066
  splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3919
4067
  if (!(splitCount > 1)) {
3920
- _context21.next = 26;
4068
+ _context24.next = 26;
3921
4069
  break;
3922
4070
  }
3923
4071
  i = 0;
3924
4072
  case 16:
3925
4073
  if (!(i < splitCount)) {
3926
- _context21.next = 25;
4074
+ _context24.next = 25;
3927
4075
  break;
3928
4076
  }
3929
4077
  singleLine = cloneDeep(productRecord);
3930
4078
  singleLine.num = 1;
3931
4079
  delete singleLine.product_quantity;
3932
- _context21.next = 22;
4080
+ _context24.next = 22;
3933
4081
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3934
4082
  case 22:
3935
4083
  i += 1;
3936
- _context21.next = 16;
4084
+ _context24.next = 16;
3937
4085
  break;
3938
4086
  case 25:
3939
- return _context21.abrupt("continue", 28);
4087
+ return _context24.abrupt("continue", 28);
3940
4088
  case 26:
3941
- _context21.next = 28;
4089
+ _context24.next = 28;
3942
4090
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3943
4091
  case 28:
3944
- _context21.next = 6;
4092
+ _context24.next = 6;
3945
4093
  break;
3946
4094
  case 30:
3947
- _context21.next = 35;
4095
+ _context24.next = 35;
3948
4096
  break;
3949
4097
  case 32:
3950
- _context21.prev = 32;
3951
- _context21.t0 = _context21["catch"](4);
3952
- _iterator20.e(_context21.t0);
4098
+ _context24.prev = 32;
4099
+ _context24.t0 = _context24["catch"](4);
4100
+ _iterator20.e(_context24.t0);
3953
4101
  case 35:
3954
- _context21.prev = 35;
4102
+ _context24.prev = 35;
3955
4103
  _iterator20.f();
3956
- return _context21.finish(35);
4104
+ return _context24.finish(35);
3957
4105
  case 38:
3958
- _context21.next = 40;
4106
+ _context24.next = 40;
3959
4107
  return this.finalizeProductOrderMutation(tempOrder, options);
3960
4108
  case 40:
3961
4109
  this.logInfo('addProductsToOrder success', {
3962
4110
  itemsCount: items.length
3963
4111
  });
3964
- return _context21.abrupt("return", tempOrder.products);
4112
+ return _context24.abrupt("return", tempOrder.products);
3965
4113
  case 42:
3966
4114
  case "end":
3967
- return _context21.stop();
4115
+ return _context24.stop();
3968
4116
  }
3969
- }, _callee19, this, [[4, 32, 35, 38]]);
4117
+ }, _callee22, this, [[4, 32, 35, 38]]);
3970
4118
  }));
3971
- function addProductsToOrder(_x22, _x23) {
4119
+ function addProductsToOrder(_x27, _x28) {
3972
4120
  return _addProductsToOrder.apply(this, arguments);
3973
4121
  }
3974
4122
  return addProductsToOrder;
@@ -4002,17 +4150,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4002
4150
  }, {
4003
4151
  key: "preservePersistedBundlePriceFields",
4004
4152
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4005
- var _this24 = this;
4153
+ var _this27 = this;
4006
4154
  if (!Array.isArray(nextBundles)) return nextBundles;
4007
4155
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4008
4156
  var previousByIdentity = new Map();
4009
4157
  previousBundles.forEach(function (bundle) {
4010
- var identity = _this24.getBundleRuntimeIdentity(bundle);
4158
+ var identity = _this27.getBundleRuntimeIdentity(bundle);
4011
4159
  if (identity) previousByIdentity.set(identity, bundle);
4012
4160
  });
4013
4161
  return nextBundles.map(function (bundle, index) {
4014
4162
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4015
- var previous = previousByIdentity.get(_this24.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4163
+ var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4016
4164
  if (!previous || _typeof(previous) !== 'object') return bundle;
4017
4165
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4018
4166
  cover: previous.cover
@@ -4165,21 +4313,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4165
4313
  }, {
4166
4314
  key: "updateOrderProduct",
4167
4315
  value: function () {
4168
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
4316
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4169
4317
  var tempOrder, updatedProductUid;
4170
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4171
- while (1) switch (_context22.prev = _context22.next) {
4318
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4319
+ while (1) switch (_context25.prev = _context25.next) {
4172
4320
  case 0:
4173
4321
  tempOrder = this.ensureTempOrder();
4174
4322
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4175
- _context22.next = 4;
4323
+ _context25.next = 4;
4176
4324
  return this.applyPromotion();
4177
4325
  case 4:
4178
4326
  this.applyDiscount({
4179
4327
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4180
4328
  });
4181
4329
  this.sanitizeTempOrderProducts(tempOrder);
4182
- _context22.next = 8;
4330
+ _context25.next = 8;
4183
4331
  return this.recalculateSummary({
4184
4332
  createIfMissing: true
4185
4333
  });
@@ -4188,14 +4336,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4188
4336
  this.logInfo('updateOrderProduct success', {
4189
4337
  params: params
4190
4338
  });
4191
- return _context22.abrupt("return", tempOrder.products);
4339
+ return _context25.abrupt("return", tempOrder.products);
4192
4340
  case 11:
4193
4341
  case "end":
4194
- return _context22.stop();
4342
+ return _context25.stop();
4195
4343
  }
4196
- }, _callee20, this);
4344
+ }, _callee23, this);
4197
4345
  }));
4198
- function updateOrderProduct(_x24) {
4346
+ function updateOrderProduct(_x29) {
4199
4347
  return _updateOrderProduct.apply(this, arguments);
4200
4348
  }
4201
4349
  return updateOrderProduct;
@@ -4203,28 +4351,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4203
4351
  }, {
4204
4352
  key: "updateOrderProducts",
4205
4353
  value: function () {
4206
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(paramsList) {
4207
- var _this25 = this;
4354
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4355
+ var _this28 = this;
4208
4356
  var tempOrder, reapplyBookingDiscountProductUids;
4209
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4210
- while (1) switch (_context23.prev = _context23.next) {
4357
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4358
+ while (1) switch (_context26.prev = _context26.next) {
4211
4359
  case 0:
4212
4360
  tempOrder = this.ensureTempOrder();
4213
4361
  if (paramsList.length) {
4214
- _context23.next = 3;
4362
+ _context26.next = 3;
4215
4363
  break;
4216
4364
  }
4217
- return _context23.abrupt("return", tempOrder.products);
4365
+ return _context26.abrupt("return", tempOrder.products);
4218
4366
  case 3:
4219
4367
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4220
- var updatedProductUid = _this25.applyOrderProductUpdateToTempOrder(tempOrder, params);
4368
+ var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4221
4369
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4222
4370
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4223
4371
  acc.push(String(updatedProductUid));
4224
4372
  }
4225
4373
  return acc;
4226
4374
  }, []);
4227
- _context23.next = 6;
4375
+ _context26.next = 6;
4228
4376
  return this.finalizeAfterProductsMutation(tempOrder, {
4229
4377
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4230
4378
  });
@@ -4232,14 +4380,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4232
4380
  this.logInfo('updateOrderProduct success', {
4233
4381
  paramsList: paramsList
4234
4382
  });
4235
- return _context23.abrupt("return", tempOrder.products);
4383
+ return _context26.abrupt("return", tempOrder.products);
4236
4384
  case 8:
4237
4385
  case "end":
4238
- return _context23.stop();
4386
+ return _context26.stop();
4239
4387
  }
4240
- }, _callee21, this);
4388
+ }, _callee24, this);
4241
4389
  }));
4242
- function updateOrderProducts(_x25) {
4390
+ function updateOrderProducts(_x30) {
4243
4391
  return _updateOrderProducts.apply(this, arguments);
4244
4392
  }
4245
4393
  return updateOrderProducts;
@@ -4247,11 +4395,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4247
4395
  }, {
4248
4396
  key: "updateOrderProductQuantity",
4249
4397
  value: function () {
4250
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
4398
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4251
4399
  var _targetProduct$metada10;
4252
4400
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4253
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4254
- while (1) switch (_context24.prev = _context24.next) {
4401
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4402
+ while (1) switch (_context27.prev = _context27.next) {
4255
4403
  case 0:
4256
4404
  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;
4257
4405
  tempOrder = this.ensureTempOrder();
@@ -4280,7 +4428,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4280
4428
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4281
4429
  }
4282
4430
  if (!(productIndex === -1)) {
4283
- _context24.next = 12;
4431
+ _context27.next = 12;
4284
4432
  break;
4285
4433
  }
4286
4434
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -4294,12 +4442,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4294
4442
  }));
4295
4443
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4296
4444
  tempOrder.products[productIndex] = normalizedProduct;
4297
- _context24.next = 18;
4445
+ _context27.next = 18;
4298
4446
  return this.applyPromotion();
4299
4447
  case 18:
4300
4448
  this.applyDiscount();
4301
4449
  this.sanitizeTempOrderProducts(tempOrder);
4302
- _context24.next = 22;
4450
+ _context27.next = 22;
4303
4451
  return this.recalculateSummary({
4304
4452
  createIfMissing: true
4305
4453
  });
@@ -4308,14 +4456,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4308
4456
  this.logInfo('updateOrderProductQuantity success', {
4309
4457
  params: params
4310
4458
  });
4311
- return _context24.abrupt("return", tempOrder.products);
4459
+ return _context27.abrupt("return", tempOrder.products);
4312
4460
  case 25:
4313
4461
  case "end":
4314
- return _context24.stop();
4462
+ return _context27.stop();
4315
4463
  }
4316
- }, _callee22, this);
4464
+ }, _callee25, this);
4317
4465
  }));
4318
- function updateOrderProductQuantity(_x26) {
4466
+ function updateOrderProductQuantity(_x31) {
4319
4467
  return _updateOrderProductQuantity.apply(this, arguments);
4320
4468
  }
4321
4469
  return updateOrderProductQuantity;
@@ -4356,19 +4504,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4356
4504
  }, {
4357
4505
  key: "finalizeAfterProductsMutation",
4358
4506
  value: (function () {
4359
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(tempOrder, options) {
4360
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4361
- while (1) switch (_context25.prev = _context25.next) {
4507
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4508
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4509
+ while (1) switch (_context28.prev = _context28.next) {
4362
4510
  case 0:
4363
4511
  this.syncTempOrderHolderFromBookings(tempOrder);
4364
- _context25.next = 3;
4512
+ _context28.next = 3;
4365
4513
  return this.applyPromotion();
4366
4514
  case 3:
4367
4515
  this.applyDiscount({
4368
4516
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4369
4517
  });
4370
4518
  this.sanitizeTempOrderProducts(tempOrder);
4371
- _context25.next = 7;
4519
+ _context28.next = 7;
4372
4520
  return this.recalculateSummary({
4373
4521
  createIfMissing: true
4374
4522
  });
@@ -4376,11 +4524,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4376
4524
  this.persistTempOrder();
4377
4525
  case 8:
4378
4526
  case "end":
4379
- return _context25.stop();
4527
+ return _context28.stop();
4380
4528
  }
4381
- }, _callee23, this);
4529
+ }, _callee26, this);
4382
4530
  }));
4383
- function finalizeAfterProductsMutation(_x27, _x28) {
4531
+ function finalizeAfterProductsMutation(_x32, _x33) {
4384
4532
  return _finalizeAfterProductsMutation.apply(this, arguments);
4385
4533
  }
4386
4534
  return finalizeAfterProductsMutation;
@@ -4395,18 +4543,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4395
4543
  }, {
4396
4544
  key: "removeProductsFromOrder",
4397
4545
  value: (function () {
4398
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identities) {
4399
- var _this26 = this;
4546
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities) {
4547
+ var _this29 = this;
4400
4548
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4401
- return _regeneratorRuntime().wrap(function _callee24$(_context27) {
4402
- while (1) switch (_context27.prev = _context27.next) {
4549
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4550
+ while (1) switch (_context30.prev = _context30.next) {
4403
4551
  case 0:
4404
4552
  tempOrder = this.ensureTempOrder();
4405
4553
  if (identities.length) {
4406
- _context27.next = 3;
4554
+ _context30.next = 3;
4407
4555
  break;
4408
4556
  }
4409
- return _context27.abrupt("return", tempOrder.products);
4557
+ return _context30.abrupt("return", tempOrder.products);
4410
4558
  case 3:
4411
4559
  productsBeforeRemove = tempOrder.products || [];
4412
4560
  bookingsBeforeRemove = tempOrder.bookings || [];
@@ -4429,29 +4577,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4429
4577
  }
4430
4578
  linkedBookingUidsToRemove = new Set();
4431
4579
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4432
- _context27.prev = 11;
4580
+ _context30.prev = 11;
4433
4581
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4434
4582
  var _metadata8, _metadata9, _metadata10, _metadata11;
4435
4583
  var product, productUid, productBookingUid, isAddTimeProduct;
4436
- return _regeneratorRuntime().wrap(function _loop3$(_context26) {
4437
- while (1) switch (_context26.prev = _context26.next) {
4584
+ return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4585
+ while (1) switch (_context29.prev = _context29.next) {
4438
4586
  case 0:
4439
4587
  product = _step21.value;
4440
4588
  productUid = (product === null || product === void 0 || (_metadata8 = product.metadata) === null || _metadata8 === void 0 ? void 0 : _metadata8.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4441
4589
  productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata9 = product.metadata) === null || _metadata9 === void 0 ? void 0 : _metadata9.booking_uid);
4442
4590
  isAddTimeProduct = (product === null || product === void 0 || (_metadata10 = product.metadata) === null || _metadata10 === void 0 ? void 0 : _metadata10.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.product_add_schedule_time) !== null;
4443
4591
  if (!isAddTimeProduct) {
4444
- _context26.next = 6;
4592
+ _context29.next = 6;
4445
4593
  break;
4446
4594
  }
4447
- return _context26.abrupt("return", 1);
4595
+ return _context29.abrupt("return", 1);
4448
4596
  case 6:
4449
4597
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4450
4598
  linkedBookingUidsToRemove.add(String(productBookingUid));
4451
4599
  }
4452
4600
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4453
4601
  bookingsBeforeRemove.forEach(function (booking) {
4454
- var bookingUid = _this26.getBookingUniqueIdentificationNumber(booking);
4602
+ var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
4455
4603
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4456
4604
  linkedBookingUidsToRemove.add(bookingUid);
4457
4605
  }
@@ -4459,37 +4607,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4459
4607
  }
4460
4608
  case 8:
4461
4609
  case "end":
4462
- return _context26.stop();
4610
+ return _context29.stop();
4463
4611
  }
4464
4612
  }, _loop3);
4465
4613
  });
4466
4614
  _iterator21.s();
4467
4615
  case 14:
4468
4616
  if ((_step21 = _iterator21.n()).done) {
4469
- _context27.next = 20;
4617
+ _context30.next = 20;
4470
4618
  break;
4471
4619
  }
4472
- return _context27.delegateYield(_loop3(), "t0", 16);
4620
+ return _context30.delegateYield(_loop3(), "t0", 16);
4473
4621
  case 16:
4474
- if (!_context27.t0) {
4475
- _context27.next = 18;
4622
+ if (!_context30.t0) {
4623
+ _context30.next = 18;
4476
4624
  break;
4477
4625
  }
4478
- return _context27.abrupt("continue", 18);
4626
+ return _context30.abrupt("continue", 18);
4479
4627
  case 18:
4480
- _context27.next = 14;
4628
+ _context30.next = 14;
4481
4629
  break;
4482
4630
  case 20:
4483
- _context27.next = 25;
4631
+ _context30.next = 25;
4484
4632
  break;
4485
4633
  case 22:
4486
- _context27.prev = 22;
4487
- _context27.t1 = _context27["catch"](11);
4488
- _iterator21.e(_context27.t1);
4634
+ _context30.prev = 22;
4635
+ _context30.t1 = _context30["catch"](11);
4636
+ _iterator21.e(_context30.t1);
4489
4637
  case 25:
4490
- _context27.prev = 25;
4638
+ _context30.prev = 25;
4491
4639
  _iterator21.f();
4492
- return _context27.finish(25);
4640
+ return _context30.finish(25);
4493
4641
  case 28:
4494
4642
  if (linkedBookingUidsToRemove.size > 0) {
4495
4643
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
@@ -4500,20 +4648,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4500
4648
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4501
4649
  });
4502
4650
  }
4503
- _context27.next = 31;
4651
+ _context30.next = 31;
4504
4652
  return this.finalizeAfterProductsMutation(tempOrder);
4505
4653
  case 31:
4506
4654
  this.logInfo('removeProductsFromOrder success', {
4507
4655
  identities: identities
4508
4656
  });
4509
- return _context27.abrupt("return", tempOrder.products);
4657
+ return _context30.abrupt("return", tempOrder.products);
4510
4658
  case 33:
4511
4659
  case "end":
4512
- return _context27.stop();
4660
+ return _context30.stop();
4513
4661
  }
4514
- }, _callee24, this, [[11, 22, 25, 28]]);
4662
+ }, _callee27, this, [[11, 22, 25, 28]]);
4515
4663
  }));
4516
- function removeProductsFromOrder(_x29) {
4664
+ function removeProductsFromOrder(_x34) {
4517
4665
  return _removeProductsFromOrder.apply(this, arguments);
4518
4666
  }
4519
4667
  return removeProductsFromOrder;
@@ -4521,18 +4669,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4521
4669
  }, {
4522
4670
  key: "removeProductFromOrder",
4523
4671
  value: function () {
4524
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identity) {
4525
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4526
- while (1) switch (_context28.prev = _context28.next) {
4672
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
4673
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4674
+ while (1) switch (_context31.prev = _context31.next) {
4527
4675
  case 0:
4528
- return _context28.abrupt("return", this.removeProductsFromOrder([identity]));
4676
+ return _context31.abrupt("return", this.removeProductsFromOrder([identity]));
4529
4677
  case 1:
4530
4678
  case "end":
4531
- return _context28.stop();
4679
+ return _context31.stop();
4532
4680
  }
4533
- }, _callee25, this);
4681
+ }, _callee28, this);
4534
4682
  }));
4535
- function removeProductFromOrder(_x30) {
4683
+ function removeProductFromOrder(_x35) {
4536
4684
  return _removeProductFromOrder.apply(this, arguments);
4537
4685
  }
4538
4686
  return removeProductFromOrder;
@@ -4544,10 +4692,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4544
4692
  }, {
4545
4693
  key: "clearOrderCartLines",
4546
4694
  value: (function () {
4547
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4695
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4548
4696
  var tempOrder;
4549
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4550
- while (1) switch (_context29.prev = _context29.next) {
4697
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4698
+ while (1) switch (_context32.prev = _context32.next) {
4551
4699
  case 0:
4552
4700
  tempOrder = this.ensureTempOrder();
4553
4701
  tempOrder.products = [];
@@ -4558,24 +4706,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4558
4706
  productsByUid: {}
4559
4707
  });
4560
4708
  }
4561
- _context29.next = 7;
4709
+ _context32.next = 7;
4562
4710
  return this.applyPromotion();
4563
4711
  case 7:
4564
4712
  this.applyDiscount();
4565
4713
  this.sanitizeTempOrderProducts(tempOrder);
4566
- _context29.next = 11;
4714
+ _context32.next = 11;
4567
4715
  return this.recalculateSummary({
4568
4716
  createIfMissing: true
4569
4717
  });
4570
4718
  case 11:
4571
4719
  this.persistTempOrder();
4572
4720
  this.logInfo('clearOrderCartLines success', {});
4573
- return _context29.abrupt("return", tempOrder);
4721
+ return _context32.abrupt("return", tempOrder);
4574
4722
  case 14:
4575
4723
  case "end":
4576
- return _context29.stop();
4724
+ return _context32.stop();
4577
4725
  }
4578
- }, _callee26, this);
4726
+ }, _callee29, this);
4579
4727
  }));
4580
4728
  function clearOrderCartLines() {
4581
4729
  return _clearOrderCartLines.apply(this, arguments);
@@ -4613,17 +4761,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4613
4761
  }, {
4614
4762
  key: "applyLocalPrintOrderNumbers",
4615
4763
  value: function () {
4616
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order) {
4764
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
4617
4765
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4618
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4619
- while (1) switch (_context30.prev = _context30.next) {
4766
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4767
+ while (1) switch (_context33.prev = _context33.next) {
4620
4768
  case 0:
4621
4769
  tempOrder = this.ensureTempOrder();
4622
4770
  if (!(!order || _typeof(order) !== 'object')) {
4623
- _context30.next = 3;
4771
+ _context33.next = 3;
4624
4772
  break;
4625
4773
  }
4626
- return _context30.abrupt("return", tempOrder);
4774
+ return _context33.abrupt("return", tempOrder);
4627
4775
  case 3:
4628
4776
  shopOrderNumber = order.shop_order_number;
4629
4777
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4634,21 +4782,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4634
4782
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4635
4783
  }
4636
4784
  this.persistTempOrder();
4637
- _context30.next = 10;
4785
+ _context33.next = 10;
4638
4786
  return this.saveDraft();
4639
4787
  case 10:
4640
- return _context30.abrupt("return", tempOrder);
4788
+ return _context33.abrupt("return", tempOrder);
4641
4789
  case 11:
4642
4790
  case "end":
4643
- return _context30.stop();
4791
+ return _context33.stop();
4644
4792
  }
4645
- }, _callee27, this);
4793
+ }, _callee30, this);
4646
4794
  }));
4647
- function applyLocalPrintOrderNumbers(_x31) {
4795
+ function applyLocalPrintOrderNumbers(_x36) {
4648
4796
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4649
4797
  }
4650
4798
  return applyLocalPrintOrderNumbers;
4651
4799
  }()
4800
+ }, {
4801
+ key: "saveTempOrderAsDraft",
4802
+ value: function () {
4803
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4804
+ var _params$cacheId2, _this$otherParams6, _ref72, _params$businessCode2, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4805
+ var tempOrder, latestSummary, payload;
4806
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4807
+ while (1) switch (_context34.prev = _context34.next) {
4808
+ case 0:
4809
+ tempOrder = this.ensureTempOrder();
4810
+ this.ensureExternalSaleNumber(tempOrder);
4811
+ this.persistTempOrder();
4812
+ _context34.next = 5;
4813
+ return this.recalculateSummary({
4814
+ createIfMissing: true
4815
+ });
4816
+ case 5:
4817
+ _context34.t1 = _context34.sent;
4818
+ if (_context34.t1) {
4819
+ _context34.next = 8;
4820
+ break;
4821
+ }
4822
+ _context34.t1 = this.store.summary;
4823
+ case 8:
4824
+ _context34.t0 = _context34.t1;
4825
+ if (_context34.t0) {
4826
+ _context34.next = 11;
4827
+ break;
4828
+ }
4829
+ _context34.t0 = createEmptySummary();
4830
+ case 11:
4831
+ latestSummary = _context34.t0;
4832
+ payload = buildSubmitPayload({
4833
+ tempOrder: tempOrder,
4834
+ cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
4835
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4836
+ businessCode: (_ref72 = (_params$businessCode2 = params === null || params === void 0 ? void 0 : params.businessCode) !== null && _params$businessCode2 !== void 0 ? _params$businessCode2 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref72 !== void 0 ? _ref72 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4837
+ channel: params === null || params === void 0 ? void 0 : params.channel,
4838
+ 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,
4839
+ summary: latestSummary,
4840
+ enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
4841
+ });
4842
+ if (!payload.created_at) {
4843
+ payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4844
+ }
4845
+ payload.need_sync = 0;
4846
+ payload.is_draft_order = 1;
4847
+ this.logInfo('saveTempOrderAsDraft calling sales draft', {
4848
+ orderId: payload.order_id,
4849
+ externalSaleNumber: payload.external_sale_number,
4850
+ productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
4851
+ });
4852
+ return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
4853
+ osServer: true,
4854
+ customToast: function customToast() {}
4855
+ }));
4856
+ case 18:
4857
+ case "end":
4858
+ return _context34.stop();
4859
+ }
4860
+ }, _callee31, this);
4861
+ }));
4862
+ function saveTempOrderAsDraft(_x37) {
4863
+ return _saveTempOrderAsDraft.apply(this, arguments);
4864
+ }
4865
+ return saveTempOrderAsDraft;
4866
+ }()
4652
4867
  /**
4653
4868
  * 提交当前 Sales tempOrder。
4654
4869
  *
@@ -4658,18 +4873,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4658
4873
  }, {
4659
4874
  key: "submitTempOrder",
4660
4875
  value: (function () {
4661
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
4662
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4663
- while (1) switch (_context31.prev = _context31.next) {
4876
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
4877
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
4878
+ while (1) switch (_context35.prev = _context35.next) {
4664
4879
  case 0:
4665
- return _context31.abrupt("return", this.runSubmitTempOrder(params));
4880
+ return _context35.abrupt("return", this.runSubmitTempOrder(params));
4666
4881
  case 1:
4667
4882
  case "end":
4668
- return _context31.stop();
4883
+ return _context35.stop();
4669
4884
  }
4670
- }, _callee28, this);
4885
+ }, _callee32, this);
4671
4886
  }));
4672
- function submitTempOrder(_x32) {
4887
+ function submitTempOrder(_x38) {
4673
4888
  return _submitTempOrder.apply(this, arguments);
4674
4889
  }
4675
4890
  return submitTempOrder;
@@ -4677,20 +4892,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4677
4892
  }, {
4678
4893
  key: "submitTempOrderAsync",
4679
4894
  value: function () {
4680
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4681
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4682
- while (1) switch (_context32.prev = _context32.next) {
4895
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
4896
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
4897
+ while (1) switch (_context36.prev = _context36.next) {
4683
4898
  case 0:
4684
- return _context32.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4899
+ return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4685
4900
  syncMode: true
4686
4901
  })));
4687
4902
  case 1:
4688
4903
  case "end":
4689
- return _context32.stop();
4904
+ return _context36.stop();
4690
4905
  }
4691
- }, _callee29, this);
4906
+ }, _callee33, this);
4692
4907
  }));
4693
- function submitTempOrderAsync(_x33) {
4908
+ function submitTempOrderAsync(_x39) {
4694
4909
  return _submitTempOrderAsync.apply(this, arguments);
4695
4910
  }
4696
4911
  return submitTempOrderAsync;
@@ -4698,11 +4913,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4698
4913
  }, {
4699
4914
  key: "runSubmitTempOrder",
4700
4915
  value: function () {
4701
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
4702
- var _params$cacheId2, _this$otherParams6, _ref72, _ref73, _submitSnapshot$busin, _this$otherParams7, _this$otherParams8, _submitSnapshot$type;
4916
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
4917
+ var _params$cacheId3, _this$otherParams10, _ref73, _ref74, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4703
4918
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4704
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4705
- while (1) switch (_context33.prev = _context33.next) {
4919
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
4920
+ while (1) switch (_context37.prev = _context37.next) {
4706
4921
  case 0:
4707
4922
  tempOrder = this.ensureTempOrder();
4708
4923
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -4722,27 +4937,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4722
4937
  }
4723
4938
  }
4724
4939
  this.persistTempOrder();
4725
- _context33.next = 8;
4940
+ _context37.next = 8;
4726
4941
  return this.recalculateSummary({
4727
4942
  createIfMissing: true
4728
4943
  });
4729
4944
  case 8:
4730
- _context33.t1 = _context33.sent;
4731
- if (_context33.t1) {
4732
- _context33.next = 11;
4945
+ _context37.t1 = _context37.sent;
4946
+ if (_context37.t1) {
4947
+ _context37.next = 11;
4733
4948
  break;
4734
4949
  }
4735
- _context33.t1 = this.store.summary;
4950
+ _context37.t1 = this.store.summary;
4736
4951
  case 11:
4737
- _context33.t0 = _context33.t1;
4738
- if (_context33.t0) {
4739
- _context33.next = 14;
4952
+ _context37.t0 = _context37.t1;
4953
+ if (_context37.t0) {
4954
+ _context37.next = 14;
4740
4955
  break;
4741
4956
  }
4742
- _context33.t0 = createEmptySummary();
4957
+ _context37.t0 = createEmptySummary();
4743
4958
  case 14:
4744
- latestSummary = _context33.t0;
4745
- effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
4959
+ latestSummary = _context37.t0;
4960
+ effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
4746
4961
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4747
4962
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4748
4963
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
@@ -4760,8 +4975,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4760
4975
  payload = buildSubmitPayload({
4761
4976
  tempOrder: tempOrder,
4762
4977
  cacheId: effectiveCacheId,
4763
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4764
- businessCode: (_ref72 = (_ref73 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref72 !== void 0 ? _ref72 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
4978
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
4979
+ businessCode: (_ref73 = (_ref74 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref73 !== void 0 ? _ref73 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
4765
4980
  channel: params === null || params === void 0 ? void 0 : params.channel,
4766
4981
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4767
4982
  summary: latestSummary,
@@ -4776,10 +4991,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4776
4991
  if (!payload.created_at) {
4777
4992
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4778
4993
  }
4779
- _context33.next = 26;
4994
+ _context37.next = 26;
4780
4995
  return this.saveDraft();
4781
4996
  case 26:
4782
- _context33.prev = 26;
4997
+ _context37.prev = 26;
4783
4998
  this.logInfo('submitTempOrder calling sales checkout', {
4784
4999
  orderId: payload.order_id,
4785
5000
  externalSaleNumber: payload.external_sale_number,
@@ -4789,43 +5004,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4789
5004
  smallTicketDataFlag: payload.small_ticket_data_flag,
4790
5005
  syncMode: payload.sync_mode
4791
5006
  });
4792
- _context33.next = 30;
5007
+ _context37.next = 30;
4793
5008
  return this.submitSalesOrder({
4794
5009
  query: payload
4795
5010
  });
4796
5011
  case 30:
4797
- result = _context33.sent;
4798
- _context33.next = 43;
5012
+ result = _context37.sent;
5013
+ _context37.next = 43;
4799
5014
  break;
4800
5015
  case 33:
4801
- _context33.prev = 33;
4802
- _context33.t2 = _context33["catch"](26);
4803
- backendErrorResponse = this.extractSubmitErrorResponse(_context33.t2);
5016
+ _context37.prev = 33;
5017
+ _context37.t2 = _context37["catch"](26);
5018
+ backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
4804
5019
  if (!backendErrorResponse) {
4805
- _context33.next = 40;
5020
+ _context37.next = 40;
4806
5021
  break;
4807
5022
  }
4808
5023
  this.store.syncState = 'failed';
4809
5024
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4810
- return _context33.abrupt("return", backendErrorResponse);
5025
+ return _context37.abrupt("return", backendErrorResponse);
4811
5026
  case 40:
4812
5027
  this.store.syncState = 'failed';
4813
5028
  this.logError('submitTempOrder failed', {
4814
- error: _context33.t2 instanceof Error ? _context33.t2.message : String(_context33.t2),
5029
+ error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
4815
5030
  orderId: payload.order_id,
4816
5031
  externalSaleNumber: payload.external_sale_number,
4817
5032
  paymentStatus: payload.payment_status,
4818
5033
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4819
5034
  });
4820
- throw _context33.t2;
5035
+ throw _context37.t2;
4821
5036
  case 43:
4822
5037
  if (!this.isSubmitResponseRejected(result)) {
4823
- _context33.next = 47;
5038
+ _context37.next = 47;
4824
5039
  break;
4825
5040
  }
4826
5041
  this.store.syncState = 'failed';
4827
5042
  this.logSubmitBackendRejected(result, payload);
4828
- return _context33.abrupt("return", result);
5043
+ return _context37.abrupt("return", result);
4829
5044
  case 47:
4830
5045
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4831
5046
  this.logInfo('runSubmitTempOrder: 提交成功', {
@@ -4836,15 +5051,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4836
5051
  })
4837
5052
  });
4838
5053
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4839
- _context33.next = 56;
5054
+ _context37.next = 56;
4840
5055
  break;
4841
5056
  }
4842
5057
  tempOrder.order_id = submittedOrderId;
4843
5058
  resultRecord = result;
4844
- _context33.next = 54;
5059
+ _context37.next = 54;
4845
5060
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4846
5061
  case 54:
4847
- _context33.next = 57;
5062
+ _context37.next = 57;
4848
5063
  break;
4849
5064
  case 56:
4850
5065
  if (this.isLocalPendingSubmitResult(result)) {
@@ -4853,14 +5068,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4853
5068
  this.store.syncState = 'submitted';
4854
5069
  }
4855
5070
  case 57:
4856
- return _context33.abrupt("return", result);
5071
+ return _context37.abrupt("return", result);
4857
5072
  case 58:
4858
5073
  case "end":
4859
- return _context33.stop();
5074
+ return _context37.stop();
4860
5075
  }
4861
- }, _callee30, this, [[26, 33]]);
5076
+ }, _callee34, this, [[26, 33]]);
4862
5077
  }));
4863
- function runSubmitTempOrder(_x34) {
5078
+ function runSubmitTempOrder(_x40) {
4864
5079
  return _runSubmitTempOrder.apply(this, arguments);
4865
5080
  }
4866
5081
  return runSubmitTempOrder;
@@ -4868,10 +5083,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4868
5083
  }, {
4869
5084
  key: "markLocalOrderSynced",
4870
5085
  value: function () {
4871
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderId, remoteOrder) {
5086
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
4872
5087
  var tempOrder;
4873
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4874
- while (1) switch (_context34.prev = _context34.next) {
5088
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5089
+ while (1) switch (_context38.prev = _context38.next) {
4875
5090
  case 0:
4876
5091
  tempOrder = this.ensureTempOrder();
4877
5092
  tempOrder.order_id = orderId;
@@ -4879,15 +5094,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4879
5094
  this.store.lastOrderInfo = remoteOrder;
4880
5095
  this.store.syncState = 'submitted';
4881
5096
  this.persistTempOrder();
4882
- _context34.next = 8;
5097
+ _context38.next = 8;
4883
5098
  return this.saveDraft();
4884
5099
  case 8:
4885
5100
  case "end":
4886
- return _context34.stop();
5101
+ return _context38.stop();
4887
5102
  }
4888
- }, _callee31, this);
5103
+ }, _callee35, this);
4889
5104
  }));
4890
- function markLocalOrderSynced(_x35, _x36) {
5105
+ function markLocalOrderSynced(_x41, _x42) {
4891
5106
  return _markLocalOrderSynced.apply(this, arguments);
4892
5107
  }
4893
5108
  return markLocalOrderSynced;
@@ -4930,10 +5145,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4930
5145
  value: function extractSubmitErrorResponse(error) {
4931
5146
  var _error$response,
4932
5147
  _error$response2,
4933
- _this27 = this;
5148
+ _this30 = this;
4934
5149
  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];
4935
5150
  return candidates.find(function (candidate) {
4936
- return _this27.isSubmitErrorResponse(candidate);
5151
+ return _this30.isSubmitErrorResponse(candidate);
4937
5152
  }) || null;
4938
5153
  }
4939
5154
  }, {
@@ -4960,14 +5175,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4960
5175
  }, {
4961
5176
  key: "syncPaymentsToOrder",
4962
5177
  value: function () {
4963
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
4964
- var _params$confirmPendin;
4965
- var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
4966
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
4967
- while (1) switch (_context35.prev = _context35.next) {
5178
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5179
+ var _this31 = this,
5180
+ _params$confirmPendin;
5181
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
5182
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5183
+ while (1) switch (_context39.prev = _context39.next) {
4968
5184
  case 0:
4969
5185
  tempOrder = this.ensureTempOrder();
4970
- mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
5186
+ needsPaymentNumber = (params.payments || []).some(function (payment) {
5187
+ return String(payment.payment_number || '').trim() === '';
5188
+ });
5189
+ if (!needsPaymentNumber) {
5190
+ _context39.next = 8;
5191
+ break;
5192
+ }
5193
+ _context39.next = 5;
5194
+ return this.getPaymentNumberDevicePrefixAsync();
5195
+ case 5:
5196
+ _context39.t0 = _context39.sent;
5197
+ _context39.next = 9;
5198
+ break;
5199
+ case 8:
5200
+ _context39.t0 = 'LOCAL';
5201
+ case 9:
5202
+ devicePrefix = _context39.t0;
5203
+ mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5204
+ return _this31.normalizePaymentSource(payment, {
5205
+ defaultPaid: false,
5206
+ devicePrefix: devicePrefix
5207
+ });
5208
+ }));
4971
5209
  shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
4972
5210
  effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
4973
5211
  completion = this.getPaymentCompletion(effectivePayments);
@@ -4976,24 +5214,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4976
5214
  tempOrder.payments = effectivePayments;
4977
5215
  tempOrder.payment_status = paymentStatus;
4978
5216
  this.persistTempOrder();
4979
- _context35.next = 12;
5217
+ _context39.next = 21;
4980
5218
  return this.saveDraft();
4981
- case 12:
5219
+ case 21:
4982
5220
  if (params.submitWhenPaid) {
4983
- _context35.next = 14;
5221
+ _context39.next = 23;
4984
5222
  break;
4985
5223
  }
4986
- return _context35.abrupt("return", completion);
4987
- case 14:
5224
+ return _context39.abrupt("return", completion);
5225
+ case 23:
4988
5226
  if (!(this.store.syncState === 'submitting')) {
4989
- _context35.next = 16;
5227
+ _context39.next = 25;
4990
5228
  break;
4991
5229
  }
4992
- return _context35.abrupt("return", completion);
4993
- case 16:
5230
+ return _context39.abrupt("return", completion);
5231
+ case 25:
4994
5232
  this.store.syncState = 'submitting';
4995
5233
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
4996
- _context35.next = 20;
5234
+ _context39.next = 29;
4997
5235
  return this.submitTempOrder({
4998
5236
  payments: effectivePayments,
4999
5237
  paymentStatus: paymentStatus,
@@ -5008,18 +5246,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5008
5246
  return nextPayload;
5009
5247
  }
5010
5248
  });
5011
- case 20:
5012
- submitResult = _context35.sent;
5013
- return _context35.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5249
+ case 29:
5250
+ submitResult = _context39.sent;
5251
+ return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5014
5252
  submitResult: submitResult
5015
5253
  }));
5016
- case 22:
5254
+ case 31:
5017
5255
  case "end":
5018
- return _context35.stop();
5256
+ return _context39.stop();
5019
5257
  }
5020
- }, _callee32, this);
5258
+ }, _callee36, this);
5021
5259
  }));
5022
- function syncPaymentsToOrder(_x37) {
5260
+ function syncPaymentsToOrder(_x43) {
5023
5261
  return _syncPaymentsToOrder.apply(this, arguments);
5024
5262
  }
5025
5263
  return syncPaymentsToOrder;
@@ -5108,11 +5346,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5108
5346
  }, {
5109
5347
  key: "submitOrder",
5110
5348
  value: function () {
5111
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
5349
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5112
5350
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5113
5351
  var url, query, fetchUrl, params;
5114
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5115
- while (1) switch (_context36.prev = _context36.next) {
5352
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5353
+ while (1) switch (_context40.prev = _context40.next) {
5116
5354
  case 0:
5117
5355
  this.logInfo('submitOrder called', {
5118
5356
  url: order.url,
@@ -5132,14 +5370,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5132
5370
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5133
5371
  scheduleDate: params.schedule_date
5134
5372
  });
5135
- return _context36.abrupt("return", this.request.post(fetchUrl, params));
5373
+ return _context40.abrupt("return", this.request.post(fetchUrl, params));
5136
5374
  case 6:
5137
5375
  case "end":
5138
- return _context36.stop();
5376
+ return _context40.stop();
5139
5377
  }
5140
- }, _callee33, this);
5378
+ }, _callee37, this);
5141
5379
  }));
5142
- function submitOrder(_x38) {
5380
+ function submitOrder(_x44) {
5143
5381
  return _submitOrder.apply(this, arguments);
5144
5382
  }
5145
5383
  return submitOrder;
@@ -5147,13 +5385,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5147
5385
  }, {
5148
5386
  key: "cancelOrder",
5149
5387
  value: function () {
5150
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5388
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5151
5389
  var payload;
5152
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5153
- while (1) switch (_context37.prev = _context37.next) {
5390
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5391
+ while (1) switch (_context41.prev = _context41.next) {
5154
5392
  case 0:
5155
5393
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5156
- _context37.next = 2;
5394
+ _context41.next = 2;
5157
5395
  break;
5158
5396
  }
5159
5397
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5169,16 +5407,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5169
5407
  method: 'PUT',
5170
5408
  orderIdsCount: params.order_ids.length
5171
5409
  });
5172
- return _context37.abrupt("return", this.request.put('/order/update-status', payload, {
5410
+ return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5173
5411
  isShopApi: true
5174
5412
  }));
5175
5413
  case 5:
5176
5414
  case "end":
5177
- return _context37.stop();
5415
+ return _context41.stop();
5178
5416
  }
5179
- }, _callee34, this);
5417
+ }, _callee38, this);
5180
5418
  }));
5181
- function cancelOrder(_x39) {
5419
+ function cancelOrder(_x45) {
5182
5420
  return _cancelOrder.apply(this, arguments);
5183
5421
  }
5184
5422
  return cancelOrder;
@@ -5186,19 +5424,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5186
5424
  }, {
5187
5425
  key: "changeBookingStatus",
5188
5426
  value: function () {
5189
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5427
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5190
5428
  var url, payload;
5191
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5192
- while (1) switch (_context38.prev = _context38.next) {
5429
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5430
+ while (1) switch (_context42.prev = _context42.next) {
5193
5431
  case 0:
5194
5432
  if (params.booking_id) {
5195
- _context38.next = 2;
5433
+ _context42.next = 2;
5196
5434
  break;
5197
5435
  }
5198
5436
  throw new Error('变更预约状态失败:booking_id 不能为空');
5199
5437
  case 2:
5200
5438
  if (params.appointment_status) {
5201
- _context38.next = 4;
5439
+ _context42.next = 4;
5202
5440
  break;
5203
5441
  }
5204
5442
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5213,16 +5451,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5213
5451
  bookingId: params.booking_id,
5214
5452
  appointmentStatus: params.appointment_status
5215
5453
  });
5216
- return _context38.abrupt("return", this.request.put(url, payload, {
5454
+ return _context42.abrupt("return", this.request.put(url, payload, {
5217
5455
  isShopApi: true
5218
5456
  }));
5219
5457
  case 8:
5220
5458
  case "end":
5221
- return _context38.stop();
5459
+ return _context42.stop();
5222
5460
  }
5223
- }, _callee35, this);
5461
+ }, _callee39, this);
5224
5462
  }));
5225
- function changeBookingStatus(_x40) {
5463
+ function changeBookingStatus(_x46) {
5226
5464
  return _changeBookingStatus.apply(this, arguments);
5227
5465
  }
5228
5466
  return changeBookingStatus;
@@ -5240,11 +5478,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5240
5478
  }, {
5241
5479
  key: "createOrderByCheckout",
5242
5480
  value: (function () {
5243
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5481
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5244
5482
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5245
5483
  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;
5246
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5247
- while (1) switch (_context39.prev = _context39.next) {
5484
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5485
+ while (1) switch (_context43.prev = _context43.next) {
5248
5486
  case 0:
5249
5487
  // 过滤掉由在线店铺下单的 payment 支付数据
5250
5488
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5278,7 +5516,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5278
5516
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5279
5517
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5280
5518
  });
5281
- _context39.prev = 4;
5519
+ _context43.prev = 4;
5282
5520
  // 构建订单数据,设置默认值并允许 params 覆盖
5283
5521
  orderData = _objectSpread({
5284
5522
  sales_channel: 'my_pisel',
@@ -5340,13 +5578,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5340
5578
  hasOrderId: !!orderData.order_id,
5341
5579
  smallTicketDataFlag: orderData.small_ticket_data_flag
5342
5580
  });
5343
- _context39.next = 12;
5581
+ _context43.next = 12;
5344
5582
  return this.request.post('/order/checkout', orderData, {
5345
5583
  osServer: true,
5346
5584
  customToast: function customToast() {}
5347
5585
  });
5348
5586
  case 12:
5349
- response = _context39.sent;
5587
+ response = _context43.sent;
5350
5588
  this.logInfo('Order API called successfully', {
5351
5589
  response: response
5352
5590
  });
@@ -5354,22 +5592,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5354
5592
  success: !!response,
5355
5593
  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)
5356
5594
  });
5357
- return _context39.abrupt("return", response);
5595
+ return _context43.abrupt("return", response);
5358
5596
  case 18:
5359
- _context39.prev = 18;
5360
- _context39.t0 = _context39["catch"](4);
5361
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context39.t0);
5597
+ _context43.prev = 18;
5598
+ _context43.t0 = _context43["catch"](4);
5599
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
5362
5600
  this.logInfo('Order API called failed', {
5363
- error: _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0)
5601
+ error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
5364
5602
  });
5365
- throw _context39.t0;
5603
+ throw _context43.t0;
5366
5604
  case 23:
5367
5605
  case "end":
5368
- return _context39.stop();
5606
+ return _context43.stop();
5369
5607
  }
5370
- }, _callee36, this, [[4, 18]]);
5608
+ }, _callee40, this, [[4, 18]]);
5371
5609
  }));
5372
- function createOrderByCheckout(_x41) {
5610
+ function createOrderByCheckout(_x47) {
5373
5611
  return _createOrderByCheckout.apply(this, arguments);
5374
5612
  }
5375
5613
  return createOrderByCheckout;
@@ -5377,24 +5615,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5377
5615
  }, {
5378
5616
  key: "submitSalesOrder",
5379
5617
  value: function () {
5380
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5618
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5381
5619
  var url, query, fetchUrl;
5382
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5383
- while (1) switch (_context40.prev = _context40.next) {
5620
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5621
+ while (1) switch (_context44.prev = _context44.next) {
5384
5622
  case 0:
5385
5623
  url = params.url, query = params.query;
5386
5624
  fetchUrl = url || '/order/sales/checkout';
5387
- return _context40.abrupt("return", this.request.post(fetchUrl, query, {
5625
+ return _context44.abrupt("return", this.request.post(fetchUrl, query, {
5388
5626
  osServer: true,
5389
5627
  customToast: function customToast() {}
5390
5628
  }));
5391
5629
  case 3:
5392
5630
  case "end":
5393
- return _context40.stop();
5631
+ return _context44.stop();
5394
5632
  }
5395
- }, _callee37, this);
5633
+ }, _callee41, this);
5396
5634
  }));
5397
- function submitSalesOrder(_x42) {
5635
+ function submitSalesOrder(_x48) {
5398
5636
  return _submitSalesOrder.apply(this, arguments);
5399
5637
  }
5400
5638
  return submitSalesOrder;
@@ -5408,37 +5646,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5408
5646
  }, {
5409
5647
  key: "sendCustomerPayLink",
5410
5648
  value: (function () {
5411
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5649
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5412
5650
  var _params$emails;
5413
5651
  var orderIds;
5414
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5415
- while (1) switch (_context41.prev = _context41.next) {
5652
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5653
+ while (1) switch (_context45.prev = _context45.next) {
5416
5654
  case 0:
5417
5655
  orderIds = params.order_ids || params.orderIds || [];
5418
5656
  if (orderIds.length) {
5419
- _context41.next = 3;
5657
+ _context45.next = 3;
5420
5658
  break;
5421
5659
  }
5422
5660
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5423
5661
  case 3:
5424
5662
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5425
- _context41.next = 5;
5663
+ _context45.next = 5;
5426
5664
  break;
5427
5665
  }
5428
5666
  throw new Error('发送支付链接需要至少一个邮箱');
5429
5667
  case 5:
5430
- return _context41.abrupt("return", this.request.post('/order/batch-email', {
5668
+ return _context45.abrupt("return", this.request.post('/order/batch-email', {
5431
5669
  order_ids: orderIds,
5432
5670
  notify_action: params.notify_action || 'order_payment_reminder',
5433
5671
  emails: params.emails
5434
5672
  }));
5435
5673
  case 6:
5436
5674
  case "end":
5437
- return _context41.stop();
5675
+ return _context45.stop();
5438
5676
  }
5439
- }, _callee38, this);
5677
+ }, _callee42, this);
5440
5678
  }));
5441
- function sendCustomerPayLink(_x43) {
5679
+ function sendCustomerPayLink(_x49) {
5442
5680
  return _sendCustomerPayLink.apply(this, arguments);
5443
5681
  }
5444
5682
  return sendCustomerPayLink;
@@ -5446,14 +5684,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5446
5684
  }, {
5447
5685
  key: "getSalesOrderByLookup",
5448
5686
  value: function () {
5449
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5687
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5450
5688
  var lookup, res;
5451
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5452
- while (1) switch (_context42.prev = _context42.next) {
5689
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5690
+ while (1) switch (_context46.prev = _context46.next) {
5453
5691
  case 0:
5454
5692
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5455
5693
  if (lookup) {
5456
- _context42.next = 3;
5694
+ _context46.next = 3;
5457
5695
  break;
5458
5696
  }
5459
5697
  throw new Error('加载销售详情需要 lookup');
@@ -5462,7 +5700,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5462
5700
  if (lookup.startsWith('LOCAL_')) {
5463
5701
  params.forceRemote = false;
5464
5702
  }
5465
- _context42.next = 6;
5703
+ _context46.next = 6;
5466
5704
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5467
5705
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
5468
5706
  }, params.forceRemote ? {
@@ -5471,18 +5709,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5471
5709
  osServer: true
5472
5710
  });
5473
5711
  case 6:
5474
- res = _context42.sent;
5712
+ res = _context46.sent;
5475
5713
  if (res.code === 200) {
5476
5714
  this.store.lastOrderInfo = res.data;
5477
5715
  }
5478
- return _context42.abrupt("return", res);
5716
+ return _context46.abrupt("return", res);
5479
5717
  case 9:
5480
5718
  case "end":
5481
- return _context42.stop();
5719
+ return _context46.stop();
5482
5720
  }
5483
- }, _callee39, this);
5721
+ }, _callee43, this);
5484
5722
  }));
5485
- function getSalesOrderByLookup(_x44) {
5723
+ function getSalesOrderByLookup(_x50) {
5486
5724
  return _getSalesOrderByLookup.apply(this, arguments);
5487
5725
  }
5488
5726
  return getSalesOrderByLookup;
@@ -5496,11 +5734,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5496
5734
  }, {
5497
5735
  key: "hydrateTempOrderFromRecord",
5498
5736
  value: (function () {
5499
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(record, options) {
5737
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5500
5738
  var _this$store$discount19;
5501
- var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount20, _this$store$discount21;
5502
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5503
- while (1) switch (_context43.prev = _context43.next) {
5739
+ 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;
5740
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5741
+ while (1) switch (_context47.prev = _context47.next) {
5504
5742
  case 0:
5505
5743
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5506
5744
  identityReadySource = this.seedAnonymousBookingUidsFromProducts(sourceRaw);
@@ -5525,7 +5763,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5525
5763
  }
5526
5764
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
5527
5765
  makeEditMark: true
5528
- });
5766
+ }); // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
5767
+ sourceLastOrderInfo = raw.lastOrderInfo || raw;
5768
+ isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
5769
+ syntheticIdentityOptions = {
5770
+ isDraftOrder: isDraftOrder,
5771
+ externalSaleNumber: nextTempOrder.external_sale_number
5772
+ };
5529
5773
  rawSummary = raw.summary && _typeof(raw.summary) === 'object' ? raw.summary : {};
5530
5774
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
5531
5775
  return _objectSpread({}, s || {});
@@ -5545,10 +5789,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5545
5789
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
5546
5790
  }
5547
5791
  });
5548
- // lastOrderInfo carries the exact backend snapshot used by deposit/type recovery.
5549
- // Runtime collection repair lives in tempOrder/originalSalesSnapshot and must not
5550
- // rewrite this protocol snapshot as a side effect of hydration.
5551
- this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
5792
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5793
+ hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5794
+ if (hadSyntheticDraftOrderId && this.store.syncState !== 'submitting') {
5795
+ this.store.syncState = 'local';
5796
+ }
5552
5797
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
5553
5798
  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() || [] : [];
5554
5799
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
@@ -5563,34 +5808,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5563
5808
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
5564
5809
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
5565
5810
  if (shouldSkipEmptyDiscountSync) {
5566
- _context43.next = 26;
5811
+ _context47.next = 31;
5567
5812
  break;
5568
5813
  }
5569
5814
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
5570
- _context43.next = 24;
5815
+ _context47.next = 29;
5571
5816
  return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(nextDiscounts);
5572
- case 24:
5573
- _context43.next = 26;
5817
+ case 29:
5818
+ _context47.next = 31;
5574
5819
  return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(nextDiscounts);
5575
- case 26:
5820
+ case 31:
5576
5821
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5577
- _context43.next = 29;
5822
+ _context47.next = 34;
5578
5823
  break;
5579
5824
  }
5580
- _context43.next = 29;
5825
+ _context47.next = 34;
5581
5826
  return this.recalculateSummary({
5582
5827
  createIfMissing: false
5583
5828
  });
5584
- case 29:
5829
+ case 34:
5585
5830
  this.persistTempOrder();
5586
- return _context43.abrupt("return", nextTempOrder);
5587
- case 31:
5831
+ return _context47.abrupt("return", nextTempOrder);
5832
+ case 36:
5588
5833
  case "end":
5589
- return _context43.stop();
5834
+ return _context47.stop();
5590
5835
  }
5591
- }, _callee40, this);
5836
+ }, _callee44, this);
5592
5837
  }));
5593
- function hydrateTempOrderFromRecord(_x45, _x46) {
5838
+ function hydrateTempOrderFromRecord(_x51, _x52) {
5594
5839
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5595
5840
  }
5596
5841
  return hydrateTempOrderFromRecord;
@@ -5704,11 +5949,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5704
5949
  }, {
5705
5950
  key: "normalizeTempOrderForRuntime",
5706
5951
  value: function normalizeTempOrderForRuntime(raw, options) {
5707
- var _this28 = this;
5708
- var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
5952
+ var _this32 = this;
5953
+ var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
5954
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
5709
5955
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5710
- 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) {
5711
- nextTempOrder.order_id = raw.id;
5956
+ 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) {
5957
+ nextTempOrder.order_id = runtimeRaw.id;
5712
5958
  }
5713
5959
  delete nextTempOrder.summary;
5714
5960
  delete nextTempOrder.lastOrderInfo;
@@ -5727,12 +5973,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5727
5973
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5728
5974
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5729
5975
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5730
- return _this28.normalizeHydratedOrderProduct(p, {
5976
+ return _this32.normalizeHydratedOrderProduct(p, {
5731
5977
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
5732
5978
  });
5733
5979
  }) : [];
5734
5980
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5735
- var booking = _this28.normalizeHydratedBookingHolder(b || {});
5981
+ var booking = _this32.normalizeHydratedBookingHolder(b || {});
5736
5982
  return _objectSpread(_objectSpread({}, booking), {}, {
5737
5983
  is_all: normalizeBookingIsAll(booking),
5738
5984
  sub_type: normalizeBookingSubType(booking)
@@ -5762,7 +6008,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5762
6008
  _step24;
5763
6009
  try {
5764
6010
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
5765
- var _product$metadata11, _ref74, _ref75, _existed$origin, _rawProduct$metadata;
6011
+ var _product$metadata11, _ref75, _ref76, _existed$origin, _rawProduct$metadata;
5766
6012
  var _step24$value = _slicedToArray(_step24.value, 2),
5767
6013
  index = _step24$value[0],
5768
6014
  product = _step24$value[1];
@@ -5770,7 +6016,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5770
6016
  if (!uid) continue;
5771
6017
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
5772
6018
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
5773
- var origin = (_ref74 = (_ref75 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref75 !== void 0 ? _ref75 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref74 !== void 0 ? _ref74 : rawProduct;
6019
+ var origin = (_ref75 = (_ref76 = (_existed$origin = existed.origin) !== null && _existed$origin !== void 0 ? _existed$origin : rawProduct._origin) !== null && _ref76 !== void 0 ? _ref76 : (_rawProduct$metadata = rawProduct.metadata) === null || _rawProduct$metadata === void 0 ? void 0 : _rawProduct$metadata.origin) !== null && _ref75 !== void 0 ? _ref75 : rawProduct;
5774
6020
  var originSnapshot = cloneDeep(origin);
5775
6021
  var productOptionString = this.buildHydratedProductOptionString(rawProduct) || this.buildHydratedProductOptionString(product);
5776
6022
  if (productOptionString && originSnapshot && _typeof(originSnapshot) === 'object') {
@@ -5798,6 +6044,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5798
6044
  nextTempOrder.vouchers = raw.vouchers || [];
5799
6045
  return nextTempOrder;
5800
6046
  }
6047
+ }, {
6048
+ key: "isSyntheticDraftOrderIdForRuntime",
6049
+ value: function isSyntheticDraftOrderIdForRuntime(record, options) {
6050
+ var _options$isDraftOrder, _record$external_sale;
6051
+ 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;
6052
+ 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;
6053
+ var orderId = record === null || record === void 0 ? void 0 : record.order_id;
6054
+ return Boolean(isDraftOrder && orderId !== undefined && orderId !== null && orderId !== '' && externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '' && String(orderId) === String(externalSaleNumber));
6055
+ }
6056
+ }, {
6057
+ key: "withoutSyntheticDraftOrderIdForRuntime",
6058
+ value: function withoutSyntheticDraftOrderIdForRuntime(record, options) {
6059
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options)) return record;
6060
+ return _objectSpread(_objectSpread({}, record), {}, {
6061
+ order_id: null
6062
+ });
6063
+ }
5801
6064
  }, {
5802
6065
  key: "hydrateLinkedBookingIdentity",
5803
6066
  value: function hydrateLinkedBookingIdentity(tempOrder) {
@@ -5882,10 +6145,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5882
6145
  }, {
5883
6146
  key: "normalizeHydratedProductOptionItem",
5884
6147
  value: function normalizeHydratedProductOptionItem(optionItem) {
5885
- var _ref76, _optionItem$num, _ref77, _optionItem$add_price;
5886
- var rawNum = (_ref76 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref76 !== void 0 ? _ref76 : 1;
6148
+ var _ref77, _optionItem$num, _ref78, _optionItem$add_price;
6149
+ var rawNum = (_ref77 = (_optionItem$num = optionItem === null || optionItem === void 0 ? void 0 : optionItem.num) !== null && _optionItem$num !== void 0 ? _optionItem$num : optionItem === null || optionItem === void 0 ? void 0 : optionItem.quantity) !== null && _ref77 !== void 0 ? _ref77 : 1;
5887
6150
  var parsedNum = Number(rawNum);
5888
- var rawPrice = (_ref77 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref77 !== void 0 ? _ref77 : 0;
6151
+ var rawPrice = (_ref78 = (_optionItem$add_price = optionItem === null || optionItem === void 0 ? void 0 : optionItem.add_price) !== null && _optionItem$add_price !== void 0 ? _optionItem$add_price : optionItem === null || optionItem === void 0 ? void 0 : optionItem.price) !== null && _ref78 !== void 0 ? _ref78 : 0;
5889
6152
  var parsedPrice = Number(rawPrice);
5890
6153
  var normalized = _objectSpread(_objectSpread({}, optionItem), {}, {
5891
6154
  option_group_item_id: optionItem === null || optionItem === void 0 ? void 0 : optionItem.option_group_item_id,
@@ -5902,7 +6165,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5902
6165
  }, {
5903
6166
  key: "normalizeHydratedOrderProduct",
5904
6167
  value: function normalizeHydratedOrderProduct(product, options) {
5905
- var _this29 = this;
6168
+ var _this33 = this;
5906
6169
  var row = _objectSpread({}, product || {});
5907
6170
  if (row.num === undefined && row.product_quantity !== undefined) {
5908
6171
  row.num = row.product_quantity;
@@ -5910,7 +6173,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5910
6173
  var productSku = ensureProductSku(row);
5911
6174
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5912
6175
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5913
- return _this29.normalizeHydratedProductOptionItem(optionItem || {});
6176
+ return _this33.normalizeHydratedProductOptionItem(optionItem || {});
5914
6177
  }))
5915
6178
  });
5916
6179
  delete row["product_".concat('option', "_item")];
@@ -5947,27 +6210,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5947
6210
  }, {
5948
6211
  key: "getOrderInfo",
5949
6212
  value: function () {
5950
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(order_id) {
6213
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
5951
6214
  var res;
5952
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5953
- while (1) switch (_context44.prev = _context44.next) {
6215
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6216
+ while (1) switch (_context48.prev = _context48.next) {
5954
6217
  case 0:
5955
- _context44.next = 2;
6218
+ _context48.next = 2;
5956
6219
  return this.request.get("/order/sales/".concat(order_id), {
5957
6220
  with: ['products', 'bookings']
5958
6221
  }, {
5959
6222
  osServer: true
5960
6223
  });
5961
6224
  case 2:
5962
- res = _context44.sent;
5963
- return _context44.abrupt("return", res);
6225
+ res = _context48.sent;
6226
+ return _context48.abrupt("return", res);
5964
6227
  case 4:
5965
6228
  case "end":
5966
- return _context44.stop();
6229
+ return _context48.stop();
5967
6230
  }
5968
- }, _callee41, this);
6231
+ }, _callee45, this);
5969
6232
  }));
5970
- function getOrderInfo(_x47) {
6233
+ function getOrderInfo(_x53) {
5971
6234
  return _getOrderInfo.apply(this, arguments);
5972
6235
  }
5973
6236
  return getOrderInfo;
@@ -6026,10 +6289,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6026
6289
  _step29;
6027
6290
  try {
6028
6291
  for (_iterator29.s(); !(_step29 = _iterator29.n()).done;) {
6029
- var _ref78, _bundle$num3;
6292
+ var _ref79, _bundle$num3;
6030
6293
  var bundle = _step29.value;
6031
6294
  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));
6032
- var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref78 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref78 !== void 0 ? _ref78 : 1) || 1).toNumber();
6295
+ var bundleQty = new Decimal(Number(qty) || 1).times(Number((_ref79 = (_bundle$num3 = bundle === null || bundle === void 0 ? void 0 : bundle.num) !== null && _bundle$num3 !== void 0 ? _bundle$num3 : bundle === null || bundle === void 0 ? void 0 : bundle.quantity) !== null && _ref79 !== void 0 ? _ref79 : 1) || 1).toNumber();
6033
6296
  var _iterator30 = _createForOfIteratorHelper((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []),
6034
6297
  _step30;
6035
6298
  try {