@pisell/pisellos 2.2.267 → 2.2.269

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 (121) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +7 -0
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +9 -0
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +12 -10
  14. package/dist/modules/OpenData/index.d.ts +2 -0
  15. package/dist/modules/OpenData/index.js +8 -0
  16. package/dist/modules/Order/index.d.ts +33 -13
  17. package/dist/modules/Order/index.js +883 -524
  18. package/dist/modules/Order/payment-utils.d.ts +26 -0
  19. package/dist/modules/Order/payment-utils.js +225 -0
  20. package/dist/modules/Order/types.d.ts +56 -4
  21. package/dist/modules/Order/types.js +11 -0
  22. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  23. package/dist/modules/Order/utils.js +10 -6
  24. package/dist/modules/Payment/index.d.ts +2 -0
  25. package/dist/modules/Payment/index.js +78 -49
  26. package/dist/modules/Payment/types.d.ts +104 -25
  27. package/dist/modules/Payment/types.js +17 -0
  28. package/dist/modules/Payment/walletpass.d.ts +38 -1
  29. package/dist/modules/Payment/walletpass.js +917 -114
  30. package/dist/modules/Rules/index.d.ts +3 -0
  31. package/dist/modules/Rules/index.js +146 -106
  32. package/dist/modules/SalesSummary/utils.js +7 -1
  33. package/dist/server/index.d.ts +16 -0
  34. package/dist/server/index.js +1940 -1043
  35. package/dist/server/modules/index.d.ts +1 -1
  36. package/dist/server/modules/order/index.d.ts +70 -4
  37. package/dist/server/modules/order/index.js +1816 -728
  38. package/dist/server/modules/order/types.d.ts +25 -3
  39. package/dist/server/modules/order/types.js +7 -1
  40. package/dist/solution/BaseSales/index.d.ts +118 -9
  41. package/dist/solution/BaseSales/index.js +1849 -480
  42. package/dist/solution/BaseSales/types.d.ts +55 -1
  43. package/dist/solution/BaseSales/types.js +2 -1
  44. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  45. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  46. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  47. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  48. package/dist/solution/BookingTicket/index.d.ts +8 -16
  49. package/dist/solution/BookingTicket/index.js +138 -52
  50. package/dist/solution/BookingTicket/types.d.ts +4 -0
  51. package/dist/solution/BookingTicket/utils/cartView.js +44 -32
  52. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  53. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  54. package/dist/solution/Sales/index.d.ts +2 -0
  55. package/dist/solution/Sales/index.js +26 -4
  56. package/dist/solution/ScanOrder/index.js +31 -20
  57. package/dist/solution/VenueBooking/index.d.ts +1 -0
  58. package/dist/solution/VenueBooking/index.js +30 -19
  59. package/dist/types/index.d.ts +1 -0
  60. package/dist/utils/payment-number.d.ts +9 -0
  61. package/dist/utils/payment-number.js +69 -0
  62. package/lib/core/index.d.ts +2 -0
  63. package/lib/core/index.js +4 -0
  64. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  65. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  66. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  67. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  68. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  69. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  70. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  71. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  72. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  73. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -1
  74. package/lib/modules/OpenData/index.d.ts +2 -0
  75. package/lib/modules/OpenData/index.js +5 -0
  76. package/lib/modules/Order/index.d.ts +33 -13
  77. package/lib/modules/Order/index.js +306 -79
  78. package/lib/modules/Order/payment-utils.d.ts +26 -0
  79. package/lib/modules/Order/payment-utils.js +224 -0
  80. package/lib/modules/Order/types.d.ts +56 -4
  81. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  82. package/lib/modules/Order/utils.js +11 -4
  83. package/lib/modules/Payment/index.d.ts +2 -0
  84. package/lib/modules/Payment/index.js +33 -12
  85. package/lib/modules/Payment/types.d.ts +104 -25
  86. package/lib/modules/Payment/types.js +1 -0
  87. package/lib/modules/Payment/walletpass.d.ts +38 -1
  88. package/lib/modules/Payment/walletpass.js +730 -21
  89. package/lib/modules/Rules/index.d.ts +3 -0
  90. package/lib/modules/Rules/index.js +54 -21
  91. package/lib/modules/SalesSummary/utils.js +5 -1
  92. package/lib/server/index.d.ts +16 -0
  93. package/lib/server/index.js +670 -18
  94. package/lib/server/modules/index.d.ts +1 -1
  95. package/lib/server/modules/order/index.d.ts +70 -4
  96. package/lib/server/modules/order/index.js +818 -69
  97. package/lib/server/modules/order/types.d.ts +25 -3
  98. package/lib/server/modules/order/types.js +1 -0
  99. package/lib/solution/BaseSales/index.d.ts +118 -9
  100. package/lib/solution/BaseSales/index.js +902 -38
  101. package/lib/solution/BaseSales/types.d.ts +55 -1
  102. package/lib/solution/BaseSales/types.js +2 -1
  103. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  104. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  105. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  106. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  107. package/lib/solution/BookingTicket/index.d.ts +8 -16
  108. package/lib/solution/BookingTicket/index.js +63 -9
  109. package/lib/solution/BookingTicket/types.d.ts +4 -0
  110. package/lib/solution/BookingTicket/utils/cartView.js +43 -30
  111. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  112. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  113. package/lib/solution/Sales/index.d.ts +2 -0
  114. package/lib/solution/Sales/index.js +20 -6
  115. package/lib/solution/ScanOrder/index.js +8 -0
  116. package/lib/solution/VenueBooking/index.d.ts +1 -0
  117. package/lib/solution/VenueBooking/index.js +8 -0
  118. package/lib/types/index.d.ts +1 -0
  119. package/lib/utils/payment-number.d.ts +9 -0
  120. package/lib/utils/payment-number.js +64 -0
  121. package/package.json +1 -1
@@ -10,8 +10,6 @@ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableTo
10
10
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
11
11
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
12
12
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
13
- function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
14
- function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
15
13
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
16
14
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
17
15
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
@@ -27,6 +25,8 @@ function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) ===
27
25
  function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
28
26
  function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
29
27
  function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
29
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
30
30
  function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
31
31
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
32
32
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
@@ -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";
@@ -68,6 +70,22 @@ function isManualProductDiscountProduct(product) {
68
70
  }
69
71
  var ORDER_PAYMENT_STATUS_PAID = 'paid';
70
72
  var ORDER_PAYMENT_STATUS_PENDING = 'payment_pending';
73
+ var CUSTOMER_PROMOTION_DISCOUNT_TAGS = new Set(['good_pass', 'product_discount_card', 'discount_card']);
74
+ function isCustomerPromotionDiscount(discount) {
75
+ return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(String((discount === null || discount === void 0 ? void 0 : discount.tag) || (discount === null || discount === void 0 ? void 0 : discount.type) || '').toLowerCase());
76
+ }
77
+ function markScannedDiscounts(discountList, scannedDiscountList) {
78
+ var scannedIds = new Set(scannedDiscountList.map(function (discount) {
79
+ return discount === null || discount === void 0 ? void 0 : discount.id;
80
+ }).filter(function (id) {
81
+ return id !== undefined && id !== null;
82
+ }).map(String));
83
+ return discountList.map(function (discount) {
84
+ return scannedIds.has(String(discount === null || discount === void 0 ? void 0 : discount.id)) ? _objectSpread(_objectSpread({}, discount), {}, {
85
+ isScan: true
86
+ }) : discount;
87
+ });
88
+ }
71
89
  function isVoucherPaymentRecord(payment) {
72
90
  return (payment === null || payment === void 0 ? void 0 : payment.voucher_id) !== undefined && Number(payment.voucher_id) !== 0;
73
91
  }
@@ -83,6 +101,10 @@ function isPaidPaymentRecord(payment) {
83
101
  function isCommittedVoucherPaymentRecord(payment) {
84
102
  return isVoucherPaymentRecord(payment) && (payment === null || payment === void 0 ? void 0 : payment.status) !== 'voided' && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
85
103
  }
104
+ function getVoucherPaymentLifecycleKey(payment) {
105
+ if (!isVoucherPaymentRecord(payment)) return null;
106
+ return "".concat(String(payment.voucher_id), "::").concat(String(payment.status || ''));
107
+ }
86
108
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
87
109
  _inherits(OrderModule, _BaseModule);
88
110
  var _super = _createSuper(OrderModule);
@@ -97,6 +119,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
97
119
  _defineProperty(_assertThisInitialized(_this), "logger", void 0);
98
120
  // LoggerManager 实例
99
121
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
122
+ _defineProperty(_assertThisInitialized(_this), "appPlugin", void 0);
100
123
  _defineProperty(_assertThisInitialized(_this), "cacheId", void 0);
101
124
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
102
125
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
@@ -140,6 +163,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
140
163
  var item = _step2.value;
141
164
  var type = (_item$type2 = item === null || item === void 0 ? void 0 : item.type) !== null && _item$type2 !== void 0 ? _item$type2 : item === null || item === void 0 ? void 0 : item.tag;
142
165
  if (!type || type === 'product') continue;
166
+ var isDiscountCard = type === 'discount_card' || type === 'product_discount_card';
143
167
  var resourceId = (_ref = (_ref2 = (_item$discount$resour = item === null || item === void 0 || (_item$discount = item.discount) === null || _item$discount === void 0 ? void 0 : _item$discount.resource_id) !== null && _item$discount$resour !== void 0 ? _item$discount$resour : item === null || item === void 0 ? void 0 : item.resource_id) !== null && _ref2 !== void 0 ? _ref2 : item === null || item === void 0 ? void 0 : item.discount_id) !== null && _ref !== void 0 ? _ref : item === null || item === void 0 ? void 0 : item.order_discount_id;
144
168
  if (resourceId === undefined || resourceId === null || resourceId === '') continue;
145
169
  var id = Number(resourceId);
@@ -162,7 +186,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
162
186
  var _existed$limited_rela;
163
187
  existed.amount = Number(existed.amount || 0) + amount;
164
188
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
165
- existed.balance = String(Number(existed.balance || 0) + amount);
189
+ if (!isDiscountCard) {
190
+ existed.balance = String(Number(existed.balance || 0) + amount);
191
+ }
166
192
  var productIds = Array.isArray((_existed$limited_rela = existed.limited_relation_product_data) === null || _existed$limited_rela === void 0 ? void 0 : _existed$limited_rela.product_ids) ? existed.limited_relation_product_data.product_ids : [];
167
193
  if ((product === null || product === void 0 ? void 0 : product.product_id) !== undefined && (product === null || product === void 0 ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
168
194
  existed.limited_relation_product_data = _objectSpread(_objectSpread({}, existed.limited_relation_product_data || {}), {}, {
@@ -194,7 +220,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
194
220
  filter: 0,
195
221
  exclude_product_ids: []
196
222
  },
197
- balance: String((_item$amount3 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount3 !== void 0 ? _item$amount3 : '0'),
223
+ balance: isDiscountCard ? undefined : String((_item$amount3 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount3 !== void 0 ? _item$amount3 : '0'),
198
224
  format_title: title,
199
225
  product: {
200
226
  id: (_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : 0,
@@ -284,7 +310,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
284
310
  value: function () {
285
311
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
286
312
  var _otherParams$rules, _otherParams$order, _otherParams$hooks;
287
- var appPlugin, app, otherParams;
313
+ var app, otherParams;
288
314
  return _regeneratorRuntime().wrap(function _callee$(_context) {
289
315
  while (1) switch (_context.prev = _context.next) {
290
316
  case 0:
@@ -300,14 +326,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
300
326
  this.store.availableWalletIds = [];
301
327
  }
302
328
  this.request = this.core.getPlugin('request');
303
- appPlugin = this.core.getPlugin('app');
304
- if (appPlugin) {
329
+ this.appPlugin = this.core.getPlugin('app');
330
+ if (this.appPlugin) {
305
331
  _context.next = 9;
306
332
  break;
307
333
  }
308
334
  throw new Error('Order 模块需要 app 插件支持');
309
335
  case 9:
310
- app = appPlugin.getApp();
336
+ app = this.appPlugin.getApp();
311
337
  this.logger = app.logger;
312
338
  this.window = this.core.getPlugin('window');
313
339
  otherParams = options.otherParams || {};
@@ -660,7 +686,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
660
686
  value: function () {
661
687
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
662
688
  var _this$store$discount11, _tempOrder$holder, _this$store$summary;
663
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, unavailableReason, _this$store$discount12;
689
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
664
690
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
665
691
  while (1) switch (_context6.prev = _context6.next) {
666
692
  case 0:
@@ -689,6 +715,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
689
715
  return _context6.abrupt("return", {
690
716
  type: 'clientCalc',
691
717
  isAvailable: false,
718
+ isAccepted: false,
692
719
  discountList: this.getDiscountList(),
693
720
  scannedDiscountList: resultDiscountList,
694
721
  unavailableReason: UnavailableReason.Unknown
@@ -701,6 +728,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
701
728
  return _context6.abrupt("return", {
702
729
  type: 'server',
703
730
  isAvailable: false,
731
+ isAccepted: false,
704
732
  discountList: this.getDiscountList(),
705
733
  scannedDiscountList: resultDiscountList,
706
734
  unavailableReasonKey: unavailableReasonKey
@@ -728,6 +756,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
728
756
  return _context6.abrupt("return", {
729
757
  type: 'clientCalc',
730
758
  isAvailable: true,
759
+ isAccepted: true,
731
760
  discountList: this.getDiscountList(),
732
761
  scannedDiscountList: resultDiscountList
733
762
  });
@@ -746,24 +775,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
746
775
  }) || {
747
776
  isAvailable: false,
748
777
  discountList: this.getDiscountList()
749
- }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, unavailableReason = _ref13.unavailableReason;
750
- if (!(isAvailable && newDiscountList)) {
751
- _context6.next = 26;
778
+ }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, evaluatedDiscountList = _ref13.evaluatedDiscountList, unavailableReason = _ref13.unavailableReason;
779
+ shouldRetainForLater = !isAvailable && unavailableReason === UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
780
+ normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
781
+ retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
782
+ resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
783
+ if (!(isAvailable && normalizedNewDiscountList)) {
784
+ _context6.next = 34;
752
785
  break;
753
786
  }
754
- (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 || _this$store$discount12.setDiscountList(newDiscountList);
787
+ _context6.next = 28;
788
+ return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
789
+ case 28:
755
790
  this.applyDiscount();
756
- _context6.next = 26;
791
+ _context6.next = 31;
757
792
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
758
- case 26:
793
+ case 31:
794
+ resolvedDiscountList = this.getDiscountList();
795
+ _context6.next = 40;
796
+ break;
797
+ case 34:
798
+ if (!(shouldRetainForLater && retainedDiscountList)) {
799
+ _context6.next = 40;
800
+ break;
801
+ }
802
+ _context6.next = 37;
803
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
804
+ case 37:
805
+ _context6.next = 39;
806
+ return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
807
+ case 39:
808
+ resolvedDiscountList = this.getDiscountList();
809
+ case 40:
759
810
  return _context6.abrupt("return", {
760
811
  type: 'clientCalc',
761
812
  isAvailable: isAvailable || false,
762
- discountList: newDiscountList || this.getDiscountList(),
813
+ isAccepted: Boolean(isAvailable || shouldRetainForLater),
814
+ discountList: resolvedDiscountList,
763
815
  scannedDiscountList: resultDiscountList,
764
816
  unavailableReason: unavailableReason
765
817
  });
766
- case 27:
818
+ case 41:
767
819
  case "end":
768
820
  return _context6.stop();
769
821
  }
@@ -777,7 +829,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
777
829
  }, {
778
830
  key: "applyDiscount",
779
831
  value: function applyDiscount(options) {
780
- var _this$store$discount13,
832
+ var _this$store$discount14,
781
833
  _this$store$summary2,
782
834
  _this2 = this;
783
835
  var tempOrder = this.store.tempOrder;
@@ -787,7 +839,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
787
839
  if (!tempOrder) return;
788
840
  this.syncLinkedBookingHoldersToProducts(tempOrder);
789
841
  delete tempOrder.discount_list;
790
- var discountList = ((_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.getDiscountList()) || [];
842
+ var discountList = ((_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.getDiscountList()) || [];
791
843
  var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
792
844
  if (shouldSkipDiscountCalculation) return;
793
845
  var rulesModule = this.store.rules;
@@ -819,9 +871,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
819
871
  }));
820
872
  }
821
873
  if (result !== null && result !== void 0 && result.discountList) {
822
- var _this$store$discount14;
874
+ var _this$store$discount15;
823
875
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
824
- (_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 || _this$store$discount14.setDiscountList(result.discountList);
876
+ (_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 || _this$store$discount15.setDiscountList(result.discountList);
825
877
  }
826
878
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
827
879
  return _this2.productHasCustomerBoundDiscount(product);
@@ -1510,19 +1562,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1510
1562
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1511
1563
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1512
1564
  }
1565
+ }, {
1566
+ key: "getPaymentNumberAppData",
1567
+ value: function getPaymentNumberAppData(key) {
1568
+ var _appPlugin$getData, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
1569
+ var appPlugin = this.appPlugin;
1570
+ if (!appPlugin) return undefined;
1571
+ var getData = (_appPlugin$getData = appPlugin.getData) === null || _appPlugin$getData === void 0 ? void 0 : _appPlugin$getData.call(appPlugin);
1572
+ if (typeof getData === 'function') return getData(key);
1573
+ var app = appPlugin.getApp();
1574
+ 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');
1575
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1576
+ }
1577
+ }, {
1578
+ key: "getPaymentNumberDevicePrefixSync",
1579
+ value: function getPaymentNumberDevicePrefixSync() {
1580
+ var _this7 = this;
1581
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1582
+ return _this7.getPaymentNumberAppData(key);
1583
+ });
1584
+ }
1585
+ }, {
1586
+ key: "getPaymentNumberDevicePrefixAsync",
1587
+ value: function getPaymentNumberDevicePrefixAsync() {
1588
+ var _this8 = this;
1589
+ return resolvePaymentNumberDevicePrefix(function (key) {
1590
+ return _this8.getPaymentNumberAppData(key);
1591
+ });
1592
+ }
1513
1593
  }, {
1514
1594
  key: "normalizePaymentSource",
1515
1595
  value: function normalizePaymentSource(payment, options) {
1516
1596
  var _ref19, _paymentRecord$origin;
1517
1597
  var paymentRecord = payment;
1518
1598
  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), {}, {
1599
+ var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1523
1600
  metadata: metadata,
1524
1601
  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
- });
1602
+ }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1526
1603
  if (paymentRecord.status !== undefined) {
1527
1604
  normalized.status = paymentRecord.status;
1528
1605
  } else if ((options === null || options === void 0 ? void 0 : options.defaultPaid) !== false) {
@@ -1640,16 +1717,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1640
1717
  }, {
1641
1718
  key: "calculatePaidPaymentSummary",
1642
1719
  value: function calculatePaidPaymentSummary(payments) {
1643
- var _this7 = this;
1720
+ var _this9 = this;
1644
1721
  return (payments || []).reduce(function (summary, payment) {
1645
1722
  var paymentRecord = payment;
1646
1723
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
1647
1724
  return {
1648
1725
  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))
1726
+ orderPaidAmount: summary.orderPaidAmount.plus(_this9.calculatePaymentOrderAmount(paymentRecord)),
1727
+ gapPaidAmount: summary.gapPaidAmount.plus(_this9.calculatePaymentGapAmount(paymentRecord)),
1728
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this9.calculatePaymentServiceFee(paymentRecord)),
1729
+ roundingAmount: summary.roundingAmount.plus(_this9.calculatePaymentRoundingAmount(paymentRecord))
1653
1730
  };
1654
1731
  }, {
1655
1732
  customerPaidAmount: new Decimal(0),
@@ -1851,15 +1928,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1851
1928
  }, {
1852
1929
  key: "normalizeFingerprintValue",
1853
1930
  value: function normalizeFingerprintValue(value) {
1854
- var _this8 = this;
1931
+ var _this10 = this;
1855
1932
  if (Array.isArray(value)) {
1856
1933
  return value.map(function (item) {
1857
- return _this8.normalizeFingerprintValue(item);
1934
+ return _this10.normalizeFingerprintValue(item);
1858
1935
  });
1859
1936
  }
1860
1937
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
1861
1938
  return Object.keys(value).sort().reduce(function (result, key) {
1862
- result[key] = _this8.normalizeFingerprintValue(value[key]);
1939
+ result[key] = _this10.normalizeFingerprintValue(value[key]);
1863
1940
  return result;
1864
1941
  }, {});
1865
1942
  }
@@ -1874,7 +1951,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1874
1951
  _sku$barcode,
1875
1952
  _ref20,
1876
1953
  _sku$variant_id,
1877
- _this9 = this;
1954
+ _this11 = this;
1878
1955
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1879
1956
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1880
1957
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1908,7 +1985,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1908
1985
  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
1986
  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
1987
  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)
1988
+ 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
1989
  };
1913
1990
  })
1914
1991
  }),
@@ -1918,8 +1995,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1918
1995
  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
1996
  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
1997
  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),
1998
+ price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1999
+ bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1923
2000
  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
2001
  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
2002
  };
@@ -1929,7 +2006,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1929
2006
  return {
1930
2007
  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
2008
  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)
2009
+ amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1933
2010
  };
1934
2011
  }))
1935
2012
  };
@@ -1937,9 +2014,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1937
2014
  }, {
1938
2015
  key: "buildOrderProductsFingerprint",
1939
2016
  value: function buildOrderProductsFingerprint(products) {
1940
- var _this10 = this;
2017
+ var _this12 = this;
1941
2018
  var items = (products || []).map(function (product) {
1942
- return _this10.buildProductFingerprintItem(product);
2019
+ return _this12.buildProductFingerprintItem(product);
1943
2020
  });
1944
2021
  items.sort(function (left, right) {
1945
2022
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -1961,7 +2038,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1961
2038
  _sku$barcode2,
1962
2039
  _ref30,
1963
2040
  _sku$variant_id2,
1964
- _this11 = this;
2041
+ _this13 = this;
1965
2042
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1966
2043
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1967
2044
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1992,7 +2069,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1992
2069
  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
2070
  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
2071
  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)
2072
+ 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
2073
  };
1997
2074
  })
1998
2075
  }),
@@ -2006,14 +2083,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2006
2083
  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
2084
  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
2085
  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) {
2086
+ option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2010
2087
  var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
2011
2088
  return {
2012
2089
  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
2090
  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
2091
  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
2092
  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)
2093
+ 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
2094
  };
2018
2095
  }))
2019
2096
  };
@@ -2023,7 +2100,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2023
2100
  return {
2024
2101
  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
2102
  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)
2103
+ amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2027
2104
  };
2028
2105
  }))
2029
2106
  };
@@ -2031,9 +2108,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2031
2108
  }, {
2032
2109
  key: "buildOrderProductsStructuralFingerprint",
2033
2110
  value: function buildOrderProductsStructuralFingerprint(products) {
2034
- var _this12 = this;
2111
+ var _this14 = this;
2035
2112
  var items = (products || []).map(function (product) {
2036
- return _this12.buildProductStructuralFingerprintItem(product);
2113
+ return _this14.buildProductStructuralFingerprintItem(product);
2037
2114
  });
2038
2115
  items.sort(function (left, right) {
2039
2116
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2250,7 +2327,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2250
2327
  }, {
2251
2328
  key: "restoreOrder",
2252
2329
  value: function restoreOrder() {
2253
- var _this$store$discount15, _this$store$discount16;
2330
+ var _this$store$discount16, _this$store$discount17;
2254
2331
  this.logInfo('restoreOrder start', {});
2255
2332
  var freshTempOrder = this.createDefaultTempOrderInstance();
2256
2333
  this.ensureExternalSaleNumber(freshTempOrder);
@@ -2258,8 +2335,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2258
2335
  this.store.summary = createEmptySummary();
2259
2336
  this.store.lastOrderInfo = undefined;
2260
2337
  this.store.syncState = undefined;
2261
- void ((_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.setOriginalDiscountList([]));
2262
- void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setDiscountList([]));
2338
+ void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList([]));
2339
+ void ((_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList([]));
2263
2340
  this.persistTempOrder();
2264
2341
  return freshTempOrder;
2265
2342
  }
@@ -2461,9 +2538,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2461
2538
  }, {
2462
2539
  key: "sanitizeTempOrderProducts",
2463
2540
  value: function sanitizeTempOrderProducts(tempOrder) {
2464
- var _this13 = this;
2541
+ var _this15 = this;
2465
2542
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2466
- return _this13.sanitizeOrderProductForTempOrder(product);
2543
+ return _this15.sanitizeOrderProductForTempOrder(product);
2467
2544
  });
2468
2545
  }
2469
2546
  }, {
@@ -2566,7 +2643,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2566
2643
  }, {
2567
2644
  key: "syncLinkedBookingHoldersToProducts",
2568
2645
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2569
- var _this14 = this;
2646
+ var _this16 = this;
2570
2647
  var bookings = tempOrder.bookings || [];
2571
2648
  var products = tempOrder.products || [];
2572
2649
  if (!bookings.length || !products.length) return;
@@ -2591,7 +2668,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2591
2668
  var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2592
2669
  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
2670
  if (linkedBooking) {
2594
- _this14.setProductHolderFromBooking(product, linkedBooking);
2671
+ _this16.setProductHolderFromBooking(product, linkedBooking);
2595
2672
  }
2596
2673
  });
2597
2674
  }
@@ -2719,9 +2796,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2719
2796
  }, {
2720
2797
  key: "findBookingIndexByUniqueIdentificationNumber",
2721
2798
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
2722
- var _this15 = this;
2799
+ var _this17 = this;
2723
2800
  return (tempOrder.bookings || []).findIndex(function (booking) {
2724
- return _this15.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2801
+ return _this17.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2725
2802
  });
2726
2803
  }
2727
2804
  }, {
@@ -2729,12 +2806,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2729
2806
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2730
2807
  var _product$metadata7,
2731
2808
  _product$metadata8,
2732
- _this16 = this;
2809
+ _this18 = this;
2733
2810
  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
2811
  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
2812
  if (!productUid && !bookingUid) return;
2736
2813
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2737
- var currentBookingUid = _this16.getBookingUniqueIdentificationNumber(booking);
2814
+ var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
2738
2815
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2739
2816
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
2740
2817
  return true;
@@ -3067,35 +3144,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3067
3144
  }, {
3068
3145
  key: "productHasCustomerBoundDiscount",
3069
3146
  value: function productHasCustomerBoundDiscount(product) {
3070
- var _this17 = this;
3147
+ var _this19 = this;
3071
3148
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3072
- return _this17.isCustomerBoundDiscount(discount);
3149
+ return _this19.isCustomerBoundDiscount(discount);
3073
3150
  })) {
3074
3151
  return true;
3075
3152
  }
3076
3153
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3077
3154
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3078
- return _this17.isCustomerBoundDiscount(discount);
3155
+ return _this19.isCustomerBoundDiscount(discount);
3079
3156
  });
3080
3157
  });
3081
3158
  }
3082
3159
  }, {
3083
3160
  key: "shouldSkipDiscountCalculation",
3084
3161
  value: function shouldSkipDiscountCalculation(tempOrder) {
3085
- var _this$store$discount17,
3086
- _this$store$discount18,
3087
- _this18 = this;
3162
+ var _this$store$discount18,
3163
+ _this$store$discount19,
3164
+ _this20 = this;
3088
3165
  if (this.hasActiveCustomerBoundDiscount) return false;
3089
- 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)) || [];
3166
+ var discountList = ((_this$store$discount18 = this.store.discount) === null || _this$store$discount18 === void 0 || (_this$store$discount19 = _this$store$discount18.getDiscountList) === null || _this$store$discount19 === void 0 ? void 0 : _this$store$discount19.call(_this$store$discount18)) || [];
3090
3167
  if (discountList.length > 0) return false;
3091
3168
  return !(tempOrder.products || []).some(function (product) {
3092
- return _this18.productHasCustomerBoundDiscount(product);
3169
+ return _this20.productHasCustomerBoundDiscount(product);
3093
3170
  });
3094
3171
  }
3095
3172
  }, {
3096
3173
  key: "clearCustomerBoundDiscounts",
3097
3174
  value: function clearCustomerBoundDiscounts(tempOrder) {
3098
- var _this19 = this,
3175
+ var _this21 = this,
3099
3176
  _discountModule$getDi,
3100
3177
  _discountModule$getOr,
3101
3178
  _discountModule$setDi,
@@ -3104,7 +3181,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3104
3181
  var filterDiscountList = function filterDiscountList(discountList) {
3105
3182
  if (!Array.isArray(discountList)) return [];
3106
3183
  return discountList.filter(function (discount) {
3107
- var shouldRemove = _this19.isCustomerBoundDiscount(discount);
3184
+ var shouldRemove = _this21.isCustomerBoundDiscount(discount);
3108
3185
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3109
3186
  return !shouldRemove;
3110
3187
  });
@@ -3131,12 +3208,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3131
3208
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3132
3209
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3133
3210
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3134
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3135
- return !_this19.isCustomerBoundDiscount(discount);
3211
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3212
+ return !_this21.isCustomerBoundDiscount(discount);
3136
3213
  });
3137
3214
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3138
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3139
- return !_this19.isCustomerBoundDiscount(discount);
3215
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3216
+ return !_this21.isCustomerBoundDiscount(discount);
3140
3217
  });
3141
3218
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3142
3219
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3290,23 +3367,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3290
3367
  * 用一组支付来源覆盖当前订单支付项。
3291
3368
  *
3292
3369
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
3293
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
3370
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
3294
3371
  * isSynced 等运行态字段不会进入 tempOrder.payments。
3295
3372
  */
3296
3373
  }, {
3297
3374
  key: "setOrderPayments",
3298
3375
  value: function setOrderPayments(payments) {
3376
+ var _this22 = this;
3299
3377
  var tempOrder = this.ensureTempOrder();
3300
- tempOrder.payments = mapPaymentItemsToOrderPayments(payments);
3378
+ tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
3379
+ return _this22.normalizePaymentSource(payment, {
3380
+ defaultPaid: false
3381
+ });
3382
+ }));
3301
3383
  this.persistTempOrder();
3302
3384
  return tempOrder.payments;
3303
3385
  }
3304
3386
 
3305
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
3387
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
3306
3388
  }, {
3307
3389
  key: "addOrderPayment",
3308
3390
  value: function addOrderPayment(payment) {
3309
- var _this20 = this;
3391
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3392
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3393
+ }
3394
+
3395
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
3396
+ }, {
3397
+ key: "addOrderPaymentAsync",
3398
+ value: (function () {
3399
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(payment) {
3400
+ var hasPaymentNumber, devicePrefix;
3401
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3402
+ while (1) switch (_context17.prev = _context17.next) {
3403
+ case 0:
3404
+ hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3405
+ if (!hasPaymentNumber) {
3406
+ _context17.next = 5;
3407
+ break;
3408
+ }
3409
+ _context17.t0 = 'LOCAL';
3410
+ _context17.next = 8;
3411
+ break;
3412
+ case 5:
3413
+ _context17.next = 7;
3414
+ return this.getPaymentNumberDevicePrefixAsync();
3415
+ case 7:
3416
+ _context17.t0 = _context17.sent;
3417
+ case 8:
3418
+ devicePrefix = _context17.t0;
3419
+ return _context17.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3420
+ case 10:
3421
+ case "end":
3422
+ return _context17.stop();
3423
+ }
3424
+ }, _callee15, this);
3425
+ }));
3426
+ function addOrderPaymentAsync(_x14) {
3427
+ return _addOrderPaymentAsync.apply(this, arguments);
3428
+ }
3429
+ return addOrderPaymentAsync;
3430
+ }())
3431
+ }, {
3432
+ key: "addOrderPaymentWithDevicePrefix",
3433
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3434
+ var _this23 = this;
3310
3435
  this.logInfo('addOrderPayment', {
3311
3436
  payment: payment
3312
3437
  });
@@ -3316,14 +3441,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3316
3441
  type: orderPaymentType,
3317
3442
  order_payment_type: orderPaymentType
3318
3443
  }), {
3319
- defaultPaid: true
3444
+ defaultPaid: true,
3445
+ devicePrefix: devicePrefix
3320
3446
  })]);
3321
3447
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
3322
3448
  this.persistTempOrder();
3323
3449
  void this.recalculateSummary({
3324
3450
  createIfMissing: true
3325
3451
  }).catch(function (error) {
3326
- _this20.logError('recalculate summary after addOrderPayment failed', {
3452
+ _this23.logError('recalculate summary after addOrderPayment failed', {
3327
3453
  error: error instanceof Error ? error.message : String(error)
3328
3454
  });
3329
3455
  });
@@ -3331,49 +3457,80 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3331
3457
  }
3332
3458
 
3333
3459
  /**
3334
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
3335
- *
3336
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
3337
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
3460
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
3461
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
3338
3462
  */
3339
3463
  }, {
3340
3464
  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
- /** 从当前订单支付项中移除指定支付项。 */
3465
+ value: (function () {
3466
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentIdentity, updates) {
3467
+ var options,
3468
+ tempOrder,
3469
+ identity,
3470
+ matchMode,
3471
+ matchedPayment,
3472
+ updatedPayment,
3473
+ summary,
3474
+ payments,
3475
+ _args18 = arguments;
3476
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3477
+ while (1) switch (_context18.prev = _context18.next) {
3478
+ case 0:
3479
+ options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
3480
+ tempOrder = this.ensureTempOrder();
3481
+ identity = String(paymentIdentity);
3482
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3483
+ matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
3484
+ if (matchedPayment) {
3485
+ _context18.next = 7;
3486
+ break;
3487
+ }
3488
+ throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
3489
+ case 7:
3490
+ updatedPayment = null;
3491
+ tempOrder.payments = (tempOrder.payments || []).map(function (payment, index) {
3492
+ if (index !== matchedPayment.index) return payment;
3493
+ var nextPayment = mergeOrderPaymentRecord(payment, _objectSpread(_objectSpread({}, updates), {}, {
3494
+ updated_at: updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
3495
+ }));
3496
+ updatedPayment = nextPayment;
3497
+ return nextPayment;
3498
+ });
3499
+ this.persistTempOrder();
3500
+ _context18.next = 12;
3501
+ return this.recalculateSummary({
3502
+ createIfMissing: true
3503
+ });
3504
+ case 12:
3505
+ summary = _context18.sent;
3506
+ this.persistTempOrder();
3507
+ payments = tempOrder.payments;
3508
+ return _context18.abrupt("return", {
3509
+ updated: true,
3510
+ payment: payments[matchedPayment.index] || updatedPayment,
3511
+ payments: payments,
3512
+ summary: summary
3513
+ });
3514
+ case 16:
3515
+ case "end":
3516
+ return _context18.stop();
3517
+ }
3518
+ }, _callee16, this);
3519
+ }));
3520
+ function updateOrderPayment(_x15, _x16) {
3521
+ return _updateOrderPayment.apply(this, arguments);
3522
+ }
3523
+ return updateOrderPayment;
3524
+ }() /** 从当前订单支付项中移除指定支付项。 */)
3363
3525
  }, {
3364
3526
  key: "deleteOrderPayment",
3365
3527
  value: function deleteOrderPayment(paymentIdentity) {
3366
3528
  var tempOrder = this.ensureTempOrder();
3367
3529
  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
- });
3530
+ var matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, 'compat');
3531
+ if (!matchedPayment) return tempOrder.payments;
3532
+ tempOrder.payments = (tempOrder.payments || []).filter(function (_, index) {
3533
+ return index !== matchedPayment.index;
3377
3534
  });
3378
3535
  this.persistTempOrder();
3379
3536
  return tempOrder.payments;
@@ -3405,7 +3562,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3405
3562
  }, {
3406
3563
  key: "applyPaymentLifecycleChange",
3407
3564
  value: function applyPaymentLifecycleChange(tempOrder, options) {
3408
- var _this21 = this;
3565
+ var _this24 = this;
3409
3566
  this.updateTempOrderPaymentStatus(tempOrder);
3410
3567
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3411
3568
  this.persistTempOrder();
@@ -3415,7 +3572,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3415
3572
  void this.recalculateSummary({
3416
3573
  createIfMissing: true
3417
3574
  }).catch(function (error) {
3418
- _this21.logError("recalculate summary after ".concat(logContext, " failed"), {
3575
+ _this24.logError("recalculate summary after ".concat(logContext, " failed"), {
3419
3576
  error: error instanceof Error ? error.message : String(error)
3420
3577
  });
3421
3578
  });
@@ -3459,7 +3616,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3459
3616
  }, {
3460
3617
  key: "updateVoucherOrderPayments",
3461
3618
  value: function updateVoucherOrderPayments(payments, options) {
3462
- var _this22 = this;
3619
+ var _this25 = this;
3463
3620
  var tempOrder = this.ensureTempOrder();
3464
3621
  var isOrderPaymentType = function isOrderPaymentType(value) {
3465
3622
  return value === 'normal' || value === 'deposit';
@@ -3494,8 +3651,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3494
3651
  });
3495
3652
  };
3496
3653
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3497
- return _this22.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3498
- defaultPaid: false
3654
+ return _this25.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3655
+ defaultPaid: false,
3656
+ devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
3499
3657
  });
3500
3658
  })).filter(function (payment) {
3501
3659
  return isVoucherPaymentRecord(payment);
@@ -3521,14 +3679,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3521
3679
  }).map(function (payment) {
3522
3680
  return String(payment.order_payment_id);
3523
3681
  }));
3524
- var committedVoucherIds = new Set(committedVoucherPayments.map(function (payment) {
3525
- return String(payment.voucher_id);
3682
+ var committedVoucherLifecycleKeys = new Set(committedVoucherPayments.map(function (payment) {
3683
+ return getVoucherPaymentLifecycleKey(payment);
3684
+ }).filter(function (key) {
3685
+ return key !== null;
3526
3686
  }));
3527
3687
  var replaceableVouchers = mappedVouchers.filter(function (payment) {
3528
3688
  if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
3529
3689
  return false;
3530
3690
  }
3531
- if (payment.voucher_id !== undefined && committedVoucherIds.has(String(payment.voucher_id))) {
3691
+ var lifecycleKey = getVoucherPaymentLifecycleKey(payment);
3692
+ if (lifecycleKey && committedVoucherLifecycleKeys.has(lifecycleKey)) {
3532
3693
  return false;
3533
3694
  }
3534
3695
  return true;
@@ -3543,54 +3704,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3543
3704
  void this.recalculateSummary({
3544
3705
  createIfMissing: true
3545
3706
  }).catch(function (error) {
3546
- _this22.logError('recalculate summary after updateVoucherOrderPayments failed', {
3707
+ _this25.logError('recalculate summary after updateVoucherOrderPayments failed', {
3547
3708
  error: error instanceof Error ? error.message : String(error)
3548
3709
  });
3549
3710
  });
3550
3711
  return tempOrder.payments;
3551
3712
  }
3713
+ }, {
3714
+ key: "updateVoucherOrderPaymentsAsync",
3715
+ value: function () {
3716
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(payments, options) {
3717
+ var needsPaymentNumber, devicePrefix;
3718
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3719
+ while (1) switch (_context19.prev = _context19.next) {
3720
+ case 0:
3721
+ needsPaymentNumber = (payments || []).some(function (payment) {
3722
+ return String(payment.payment_number || '').trim() === '';
3723
+ });
3724
+ if (!needsPaymentNumber) {
3725
+ _context19.next = 7;
3726
+ break;
3727
+ }
3728
+ _context19.next = 4;
3729
+ return this.getPaymentNumberDevicePrefixAsync();
3730
+ case 4:
3731
+ _context19.t0 = _context19.sent;
3732
+ _context19.next = 8;
3733
+ break;
3734
+ case 7:
3735
+ _context19.t0 = 'LOCAL';
3736
+ case 8:
3737
+ devicePrefix = _context19.t0;
3738
+ return _context19.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
3739
+ devicePrefix: devicePrefix
3740
+ })));
3741
+ case 10:
3742
+ case "end":
3743
+ return _context19.stop();
3744
+ }
3745
+ }, _callee17, this);
3746
+ }));
3747
+ function updateVoucherOrderPaymentsAsync(_x17, _x18) {
3748
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3749
+ }
3750
+ return updateVoucherOrderPaymentsAsync;
3751
+ }()
3552
3752
  }, {
3553
3753
  key: "shouldMergeProductToOrder",
3554
3754
  value: function () {
3555
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
3755
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3556
3756
  var _this$orderHooks;
3557
3757
  var onBeforeMergeProductToOrder, result;
3558
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3559
- while (1) switch (_context17.prev = _context17.next) {
3758
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3759
+ while (1) switch (_context20.prev = _context20.next) {
3560
3760
  case 0:
3561
3761
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3562
3762
  if (onBeforeMergeProductToOrder) {
3563
- _context17.next = 3;
3763
+ _context20.next = 3;
3564
3764
  break;
3565
3765
  }
3566
- return _context17.abrupt("return", true);
3766
+ return _context20.abrupt("return", true);
3567
3767
  case 3:
3568
- _context17.next = 5;
3768
+ _context20.next = 5;
3569
3769
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3570
3770
  defaultShouldMerge: true
3571
3771
  }));
3572
3772
  case 5:
3573
- result = _context17.sent;
3773
+ result = _context20.sent;
3574
3774
  if (!(typeof result === 'boolean')) {
3575
- _context17.next = 8;
3775
+ _context20.next = 8;
3576
3776
  break;
3577
3777
  }
3578
- return _context17.abrupt("return", result);
3778
+ return _context20.abrupt("return", result);
3579
3779
  case 8:
3580
3780
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3581
- _context17.next = 10;
3781
+ _context20.next = 10;
3582
3782
  break;
3583
3783
  }
3584
- return _context17.abrupt("return", result.shouldMerge);
3784
+ return _context20.abrupt("return", result.shouldMerge);
3585
3785
  case 10:
3586
- return _context17.abrupt("return", true);
3786
+ return _context20.abrupt("return", true);
3587
3787
  case 11:
3588
3788
  case "end":
3589
- return _context17.stop();
3789
+ return _context20.stop();
3590
3790
  }
3591
- }, _callee15, this);
3791
+ }, _callee18, this);
3592
3792
  }));
3593
- function shouldMergeProductToOrder(_x14) {
3793
+ function shouldMergeProductToOrder(_x19) {
3594
3794
  return _shouldMergeProductToOrder.apply(this, arguments);
3595
3795
  }
3596
3796
  return shouldMergeProductToOrder;
@@ -3626,30 +3826,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3626
3826
  }, {
3627
3827
  key: "finalizeProductOrderMutation",
3628
3828
  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) {
3829
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3830
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3831
+ while (1) switch (_context21.prev = _context21.next) {
3632
3832
  case 0:
3633
3833
  this.syncTempOrderHolderFromBookings(tempOrder);
3634
3834
  if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3635
- _context18.next = 4;
3835
+ _context21.next = 4;
3636
3836
  break;
3637
3837
  }
3638
- _context18.next = 4;
3838
+ _context21.next = 4;
3639
3839
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3640
3840
  case 4:
3641
3841
  if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3642
- _context18.next = 7;
3842
+ _context21.next = 7;
3643
3843
  break;
3644
3844
  }
3645
- _context18.next = 7;
3845
+ _context21.next = 7;
3646
3846
  return this.applyPromotion();
3647
3847
  case 7:
3648
3848
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
3649
3849
  this.applyDiscount();
3650
3850
  }
3651
3851
  this.sanitizeTempOrderProducts(tempOrder);
3652
- _context18.next = 11;
3852
+ _context21.next = 11;
3653
3853
  return this.recalculateSummary({
3654
3854
  createIfMissing: true
3655
3855
  });
@@ -3657,11 +3857,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3657
3857
  this.persistTempOrder();
3658
3858
  case 12:
3659
3859
  case "end":
3660
- return _context18.stop();
3860
+ return _context21.stop();
3661
3861
  }
3662
- }, _callee16, this);
3862
+ }, _callee19, this);
3663
3863
  }));
3664
- function finalizeProductOrderMutation(_x15, _x16) {
3864
+ function finalizeProductOrderMutation(_x20, _x21) {
3665
3865
  return _finalizeProductOrderMutation.apply(this, arguments);
3666
3866
  }
3667
3867
  return finalizeProductOrderMutation;
@@ -3676,15 +3876,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3676
3876
  }, {
3677
3877
  key: "appendProductLineToTempOrder",
3678
3878
  value: (function () {
3679
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(tempOrder, product, booking) {
3879
+ var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking, options) {
3680
3880
  var _normalizedIncoming$p,
3681
3881
  _normalizedIncoming$p2,
3682
3882
  _booking_uid,
3683
3883
  _metadata,
3684
- _this23 = this;
3685
- var linked, productToAdd, incomingFingerprint, normalizedIncoming, isWeighingProduct, netWeight, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3686
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3687
- while (1) switch (_context19.prev = _context19.next) {
3884
+ _this26 = this;
3885
+ var linked, productToAdd, incomingFingerprint, normalizedIncoming, isWeighingProduct, netWeight, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, insertAtIndex, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList, mergedProduct;
3886
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3887
+ while (1) switch (_context22.prev = _context22.next) {
3688
3888
  case 0:
3689
3889
  linked = booking ? this.createLinkedProductAndBooking({
3690
3890
  product: product,
@@ -3696,7 +3896,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3696
3896
  isWeighingProduct = Number(((_normalizedIncoming$p = normalizedIncoming.product_sku) === null || _normalizedIncoming$p === void 0 ? void 0 : _normalizedIncoming$p.open_sold_weight) || 0) === 1;
3697
3897
  netWeight = Number((_normalizedIncoming$p2 = normalizedIncoming.product_sku) === null || _normalizedIncoming$p2 === void 0 ? void 0 : _normalizedIncoming$p2.net_weight);
3698
3898
  if (!(isWeighingProduct && (!Number.isFinite(netWeight) || netWeight <= 0))) {
3699
- _context19.next = 8;
3899
+ _context22.next = 8;
3700
3900
  break;
3701
3901
  }
3702
3902
  throw new Error('[Order] 称重商品净重必须大于 0');
@@ -3715,8 +3915,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3715
3915
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid || isWeighingProduct;
3716
3916
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3717
3917
  var _item$metadata3;
3718
- if (_this23.hasGoodPassDiscount(item)) return false;
3719
- if (_this23.hasOrderProductLineNote(item)) return false;
3918
+ if (_this26.hasGoodPassDiscount(item)) return false;
3919
+ if (_this26.hasOrderProductLineNote(item)) return false;
3720
3920
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3721
3921
  if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
3722
3922
  if (item.product_id !== productToAdd.product_id) return false;
@@ -3727,10 +3927,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3727
3927
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3728
3928
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3729
3929
  if (!matchedProduct) {
3730
- _context19.next = 24;
3930
+ _context22.next = 24;
3731
3931
  break;
3732
3932
  }
3733
- _context19.next = 21;
3933
+ _context22.next = 21;
3734
3934
  return this.shouldMergeProductToOrder({
3735
3935
  incomingProduct: productToAdd,
3736
3936
  normalizedIncoming: normalizedIncoming,
@@ -3742,13 +3942,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3742
3942
  booking: booking
3743
3943
  });
3744
3944
  case 21:
3745
- _context19.t0 = _context19.sent;
3746
- _context19.next = 25;
3945
+ _context22.t0 = _context22.sent;
3946
+ _context22.next = 25;
3747
3947
  break;
3748
3948
  case 24:
3749
- _context19.t0 = false;
3949
+ _context22.t0 = false;
3750
3950
  case 25:
3751
- shouldMerge = _context19.t0;
3951
+ shouldMerge = _context22.t0;
3752
3952
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3753
3953
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
3754
3954
  if (linked) {
@@ -3757,8 +3957,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3757
3957
  booking_uid: linked.bookingUid
3758
3958
  });
3759
3959
  }
3760
- // tempOrder.products.push(normalizedIncoming);
3761
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
3960
+ insertAtIndex = options === null || options === void 0 ? void 0 : options.insertAtIndex;
3961
+ if (Number.isInteger(insertAtIndex) && Number(insertAtIndex) >= 0 && Number(insertAtIndex) < tempOrder.products.length) {
3962
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, insertAtIndex)), [normalizedIncoming], _toConsumableArray(tempOrder.products.slice(insertAtIndex)));
3963
+ } else {
3964
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
3965
+ }
3762
3966
  } else {
3763
3967
  targetProduct = matchedProduct;
3764
3968
  targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
@@ -3796,17 +4000,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3796
4000
  num: nextNum
3797
4001
  });
3798
4002
  this.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4003
+ if (matchedIndex !== tempOrder.products.length - 1) {
4004
+ mergedProduct = tempOrder.products[matchedIndex];
4005
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, matchedIndex)), _toConsumableArray(tempOrder.products.slice(matchedIndex + 1)), [mergedProduct]);
4006
+ }
3799
4007
  }
3800
4008
  if (linked) {
3801
4009
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
3802
4010
  }
3803
4011
  case 28:
3804
4012
  case "end":
3805
- return _context19.stop();
4013
+ return _context22.stop();
3806
4014
  }
3807
- }, _callee17, this);
4015
+ }, _callee20, this);
3808
4016
  }));
3809
- function appendProductLineToTempOrder(_x17, _x18, _x19) {
4017
+ function appendProductLineToTempOrder(_x22, _x23, _x24, _x25) {
3810
4018
  return _appendProductLineToTempOrder.apply(this, arguments);
3811
4019
  }
3812
4020
  return appendProductLineToTempOrder;
@@ -3822,61 +4030,74 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3822
4030
  }, {
3823
4031
  key: "addProductToOrder",
3824
4032
  value: (function () {
3825
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(product, booking) {
3826
- var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3827
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3828
- while (1) switch (_context20.prev = _context20.next) {
4033
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking, options) {
4034
+ var tempOrder, insertAfterProductUid, anchorIndex, insertAtIndex, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
4035
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4036
+ while (1) switch (_context23.prev = _context23.next) {
3829
4037
  case 0:
3830
4038
  tempOrder = this.ensureTempOrder();
4039
+ insertAfterProductUid = options === null || options === void 0 ? void 0 : options.insertAfterProductUid;
4040
+ anchorIndex = booking && insertAfterProductUid ? tempOrder.products.findIndex(function (line) {
4041
+ var _line$metadata;
4042
+ var uid = ((_line$metadata = line.metadata) === null || _line$metadata === void 0 ? void 0 : _line$metadata.unique_identification_number) || line.unique_identification_number;
4043
+ return uid !== undefined && uid !== null && String(uid) === String(insertAfterProductUid);
4044
+ }) : -1;
4045
+ insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
3831
4046
  if (!booking) {
3832
- _context20.next = 18;
4047
+ _context23.next = 22;
3833
4048
  break;
3834
4049
  }
3835
4050
  productRecord = product;
3836
4051
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3837
4052
  if (!(splitCount > 1)) {
3838
- _context20.next = 18;
4053
+ _context23.next = 22;
3839
4054
  break;
3840
4055
  }
3841
4056
  i = 0;
3842
- case 6:
4057
+ case 9:
3843
4058
  if (!(i < splitCount)) {
3844
- _context20.next = 15;
4059
+ _context23.next = 19;
3845
4060
  break;
3846
4061
  }
3847
4062
  singleLine = cloneDeep(productRecord);
3848
4063
  singleLine.num = 1;
3849
4064
  delete singleLine.product_quantity;
3850
- _context20.next = 12;
3851
- return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3852
- case 12:
4065
+ _context23.next = 15;
4066
+ return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking), {
4067
+ insertAtIndex: insertAtIndex
4068
+ });
4069
+ case 15:
4070
+ if (insertAtIndex !== undefined) insertAtIndex += 1;
4071
+ case 16:
3853
4072
  i += 1;
3854
- _context20.next = 6;
4073
+ _context23.next = 9;
3855
4074
  break;
3856
- case 15:
3857
- _context20.next = 17;
3858
- return this.finalizeProductOrderMutation(tempOrder);
3859
- case 17:
3860
- return _context20.abrupt("return", tempOrder.products);
3861
- case 18:
3862
- _context20.next = 20;
3863
- return this.appendProductLineToTempOrder(tempOrder, product, booking);
3864
- case 20:
3865
- _context20.next = 22;
4075
+ case 19:
4076
+ _context23.next = 21;
3866
4077
  return this.finalizeProductOrderMutation(tempOrder);
4078
+ case 21:
4079
+ return _context23.abrupt("return", tempOrder.products);
3867
4080
  case 22:
4081
+ _context23.next = 24;
4082
+ return this.appendProductLineToTempOrder(tempOrder, product, booking, {
4083
+ insertAtIndex: insertAtIndex
4084
+ });
4085
+ case 24:
4086
+ _context23.next = 26;
4087
+ return this.finalizeProductOrderMutation(tempOrder);
4088
+ case 26:
3868
4089
  this.logInfo('addProductToOrder success', {
3869
4090
  product_id: product.product_id,
3870
4091
  with_booking: !!booking
3871
4092
  });
3872
- return _context20.abrupt("return", tempOrder.products);
3873
- case 24:
4093
+ return _context23.abrupt("return", tempOrder.products);
4094
+ case 28:
3874
4095
  case "end":
3875
- return _context20.stop();
4096
+ return _context23.stop();
3876
4097
  }
3877
- }, _callee18, this);
4098
+ }, _callee21, this);
3878
4099
  }));
3879
- function addProductToOrder(_x20, _x21) {
4100
+ function addProductToOrder(_x26, _x27, _x28) {
3880
4101
  return _addProductToOrder.apply(this, arguments);
3881
4102
  }
3882
4103
  return addProductToOrder;
@@ -3894,93 +4115,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3894
4115
  }, {
3895
4116
  key: "addProductsToOrder",
3896
4117
  value: (function () {
3897
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(items, options) {
4118
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
3898
4119
  var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3899
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3900
- while (1) switch (_context21.prev = _context21.next) {
4120
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4121
+ while (1) switch (_context24.prev = _context24.next) {
3901
4122
  case 0:
3902
4123
  tempOrder = this.ensureTempOrder();
3903
4124
  if (!(!Array.isArray(items) || items.length === 0)) {
3904
- _context21.next = 3;
4125
+ _context24.next = 3;
3905
4126
  break;
3906
4127
  }
3907
- return _context21.abrupt("return", tempOrder.products);
4128
+ return _context24.abrupt("return", tempOrder.products);
3908
4129
  case 3:
3909
4130
  _iterator20 = _createForOfIteratorHelper(items || []);
3910
- _context21.prev = 4;
4131
+ _context24.prev = 4;
3911
4132
  _iterator20.s();
3912
4133
  case 6:
3913
4134
  if ((_step20 = _iterator20.n()).done) {
3914
- _context21.next = 30;
4135
+ _context24.next = 30;
3915
4136
  break;
3916
4137
  }
3917
4138
  item = _step20.value;
3918
4139
  product = item.product, booking = item.booking;
3919
4140
  if (product) {
3920
- _context21.next = 11;
4141
+ _context24.next = 11;
3921
4142
  break;
3922
4143
  }
3923
- return _context21.abrupt("continue", 28);
4144
+ return _context24.abrupt("continue", 28);
3924
4145
  case 11:
3925
4146
  if (!booking) {
3926
- _context21.next = 26;
4147
+ _context24.next = 26;
3927
4148
  break;
3928
4149
  }
3929
4150
  productRecord = product;
3930
4151
  splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3931
4152
  if (!(splitCount > 1)) {
3932
- _context21.next = 26;
4153
+ _context24.next = 26;
3933
4154
  break;
3934
4155
  }
3935
4156
  i = 0;
3936
4157
  case 16:
3937
4158
  if (!(i < splitCount)) {
3938
- _context21.next = 25;
4159
+ _context24.next = 25;
3939
4160
  break;
3940
4161
  }
3941
4162
  singleLine = cloneDeep(productRecord);
3942
4163
  singleLine.num = 1;
3943
4164
  delete singleLine.product_quantity;
3944
- _context21.next = 22;
4165
+ _context24.next = 22;
3945
4166
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3946
4167
  case 22:
3947
4168
  i += 1;
3948
- _context21.next = 16;
4169
+ _context24.next = 16;
3949
4170
  break;
3950
4171
  case 25:
3951
- return _context21.abrupt("continue", 28);
4172
+ return _context24.abrupt("continue", 28);
3952
4173
  case 26:
3953
- _context21.next = 28;
4174
+ _context24.next = 28;
3954
4175
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3955
4176
  case 28:
3956
- _context21.next = 6;
4177
+ _context24.next = 6;
3957
4178
  break;
3958
4179
  case 30:
3959
- _context21.next = 35;
4180
+ _context24.next = 35;
3960
4181
  break;
3961
4182
  case 32:
3962
- _context21.prev = 32;
3963
- _context21.t0 = _context21["catch"](4);
3964
- _iterator20.e(_context21.t0);
4183
+ _context24.prev = 32;
4184
+ _context24.t0 = _context24["catch"](4);
4185
+ _iterator20.e(_context24.t0);
3965
4186
  case 35:
3966
- _context21.prev = 35;
4187
+ _context24.prev = 35;
3967
4188
  _iterator20.f();
3968
- return _context21.finish(35);
4189
+ return _context24.finish(35);
3969
4190
  case 38:
3970
- _context21.next = 40;
4191
+ _context24.next = 40;
3971
4192
  return this.finalizeProductOrderMutation(tempOrder, options);
3972
4193
  case 40:
3973
4194
  this.logInfo('addProductsToOrder success', {
3974
4195
  itemsCount: items.length
3975
4196
  });
3976
- return _context21.abrupt("return", tempOrder.products);
4197
+ return _context24.abrupt("return", tempOrder.products);
3977
4198
  case 42:
3978
4199
  case "end":
3979
- return _context21.stop();
4200
+ return _context24.stop();
3980
4201
  }
3981
- }, _callee19, this, [[4, 32, 35, 38]]);
4202
+ }, _callee22, this, [[4, 32, 35, 38]]);
3982
4203
  }));
3983
- function addProductsToOrder(_x22, _x23) {
4204
+ function addProductsToOrder(_x29, _x30) {
3984
4205
  return _addProductsToOrder.apply(this, arguments);
3985
4206
  }
3986
4207
  return addProductsToOrder;
@@ -4014,17 +4235,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4014
4235
  }, {
4015
4236
  key: "preservePersistedBundlePriceFields",
4016
4237
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4017
- var _this24 = this;
4238
+ var _this27 = this;
4018
4239
  if (!Array.isArray(nextBundles)) return nextBundles;
4019
4240
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4020
4241
  var previousByIdentity = new Map();
4021
4242
  previousBundles.forEach(function (bundle) {
4022
- var identity = _this24.getBundleRuntimeIdentity(bundle);
4243
+ var identity = _this27.getBundleRuntimeIdentity(bundle);
4023
4244
  if (identity) previousByIdentity.set(identity, bundle);
4024
4245
  });
4025
4246
  return nextBundles.map(function (bundle, index) {
4026
4247
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4027
- var previous = previousByIdentity.get(_this24.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4248
+ var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4028
4249
  if (!previous || _typeof(previous) !== 'object') return bundle;
4029
4250
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4030
4251
  cover: previous.cover
@@ -4225,21 +4446,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4225
4446
  }, {
4226
4447
  key: "updateOrderProduct",
4227
4448
  value: function () {
4228
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
4449
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4229
4450
  var tempOrder, updatedProductUid;
4230
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4231
- while (1) switch (_context22.prev = _context22.next) {
4451
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4452
+ while (1) switch (_context25.prev = _context25.next) {
4232
4453
  case 0:
4233
4454
  tempOrder = this.ensureTempOrder();
4234
4455
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4235
- _context22.next = 4;
4456
+ _context25.next = 4;
4236
4457
  return this.applyPromotion();
4237
4458
  case 4:
4238
4459
  this.applyDiscount({
4239
4460
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4240
4461
  });
4241
4462
  this.sanitizeTempOrderProducts(tempOrder);
4242
- _context22.next = 8;
4463
+ _context25.next = 8;
4243
4464
  return this.recalculateSummary({
4244
4465
  createIfMissing: true
4245
4466
  });
@@ -4248,14 +4469,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4248
4469
  this.logInfo('updateOrderProduct success', {
4249
4470
  params: params
4250
4471
  });
4251
- return _context22.abrupt("return", tempOrder.products);
4472
+ return _context25.abrupt("return", tempOrder.products);
4252
4473
  case 11:
4253
4474
  case "end":
4254
- return _context22.stop();
4475
+ return _context25.stop();
4255
4476
  }
4256
- }, _callee20, this);
4477
+ }, _callee23, this);
4257
4478
  }));
4258
- function updateOrderProduct(_x24) {
4479
+ function updateOrderProduct(_x31) {
4259
4480
  return _updateOrderProduct.apply(this, arguments);
4260
4481
  }
4261
4482
  return updateOrderProduct;
@@ -4263,28 +4484,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4263
4484
  }, {
4264
4485
  key: "updateOrderProducts",
4265
4486
  value: function () {
4266
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(paramsList) {
4267
- var _this25 = this;
4487
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4488
+ var _this28 = this;
4268
4489
  var tempOrder, reapplyBookingDiscountProductUids;
4269
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4270
- while (1) switch (_context23.prev = _context23.next) {
4490
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4491
+ while (1) switch (_context26.prev = _context26.next) {
4271
4492
  case 0:
4272
4493
  tempOrder = this.ensureTempOrder();
4273
4494
  if (paramsList.length) {
4274
- _context23.next = 3;
4495
+ _context26.next = 3;
4275
4496
  break;
4276
4497
  }
4277
- return _context23.abrupt("return", tempOrder.products);
4498
+ return _context26.abrupt("return", tempOrder.products);
4278
4499
  case 3:
4279
4500
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4280
- var updatedProductUid = _this25.applyOrderProductUpdateToTempOrder(tempOrder, params);
4501
+ var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4281
4502
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4282
4503
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4283
4504
  acc.push(String(updatedProductUid));
4284
4505
  }
4285
4506
  return acc;
4286
4507
  }, []);
4287
- _context23.next = 6;
4508
+ _context26.next = 6;
4288
4509
  return this.finalizeAfterProductsMutation(tempOrder, {
4289
4510
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4290
4511
  });
@@ -4292,14 +4513,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4292
4513
  this.logInfo('updateOrderProduct success', {
4293
4514
  paramsList: paramsList
4294
4515
  });
4295
- return _context23.abrupt("return", tempOrder.products);
4516
+ return _context26.abrupt("return", tempOrder.products);
4296
4517
  case 8:
4297
4518
  case "end":
4298
- return _context23.stop();
4519
+ return _context26.stop();
4299
4520
  }
4300
- }, _callee21, this);
4521
+ }, _callee24, this);
4301
4522
  }));
4302
- function updateOrderProducts(_x25) {
4523
+ function updateOrderProducts(_x32) {
4303
4524
  return _updateOrderProducts.apply(this, arguments);
4304
4525
  }
4305
4526
  return updateOrderProducts;
@@ -4307,11 +4528,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4307
4528
  }, {
4308
4529
  key: "updateOrderProductQuantity",
4309
4530
  value: function () {
4310
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
4531
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4311
4532
  var _targetProduct$metada17;
4312
4533
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4313
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4314
- while (1) switch (_context24.prev = _context24.next) {
4534
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4535
+ while (1) switch (_context27.prev = _context27.next) {
4315
4536
  case 0:
4316
4537
  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;
4317
4538
  tempOrder = this.ensureTempOrder();
@@ -4340,7 +4561,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4340
4561
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4341
4562
  }
4342
4563
  if (!(productIndex === -1)) {
4343
- _context24.next = 12;
4564
+ _context27.next = 12;
4344
4565
  break;
4345
4566
  }
4346
4567
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -4354,12 +4575,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4354
4575
  }));
4355
4576
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4356
4577
  tempOrder.products[productIndex] = normalizedProduct;
4357
- _context24.next = 18;
4578
+ _context27.next = 18;
4358
4579
  return this.applyPromotion();
4359
4580
  case 18:
4360
4581
  this.applyDiscount();
4361
4582
  this.sanitizeTempOrderProducts(tempOrder);
4362
- _context24.next = 22;
4583
+ _context27.next = 22;
4363
4584
  return this.recalculateSummary({
4364
4585
  createIfMissing: true
4365
4586
  });
@@ -4368,14 +4589,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4368
4589
  this.logInfo('updateOrderProductQuantity success', {
4369
4590
  params: params
4370
4591
  });
4371
- return _context24.abrupt("return", tempOrder.products);
4592
+ return _context27.abrupt("return", tempOrder.products);
4372
4593
  case 25:
4373
4594
  case "end":
4374
- return _context24.stop();
4595
+ return _context27.stop();
4375
4596
  }
4376
- }, _callee22, this);
4597
+ }, _callee25, this);
4377
4598
  }));
4378
- function updateOrderProductQuantity(_x26) {
4599
+ function updateOrderProductQuantity(_x33) {
4379
4600
  return _updateOrderProductQuantity.apply(this, arguments);
4380
4601
  }
4381
4602
  return updateOrderProductQuantity;
@@ -4416,19 +4637,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4416
4637
  }, {
4417
4638
  key: "finalizeAfterProductsMutation",
4418
4639
  value: (function () {
4419
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(tempOrder, options) {
4420
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4421
- while (1) switch (_context25.prev = _context25.next) {
4640
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4641
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4642
+ while (1) switch (_context28.prev = _context28.next) {
4422
4643
  case 0:
4423
4644
  this.syncTempOrderHolderFromBookings(tempOrder);
4424
- _context25.next = 3;
4645
+ _context28.next = 3;
4425
4646
  return this.applyPromotion();
4426
4647
  case 3:
4427
4648
  this.applyDiscount({
4428
4649
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4429
4650
  });
4430
4651
  this.sanitizeTempOrderProducts(tempOrder);
4431
- _context25.next = 7;
4652
+ _context28.next = 7;
4432
4653
  return this.recalculateSummary({
4433
4654
  createIfMissing: true
4434
4655
  });
@@ -4436,11 +4657,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4436
4657
  this.persistTempOrder();
4437
4658
  case 8:
4438
4659
  case "end":
4439
- return _context25.stop();
4660
+ return _context28.stop();
4440
4661
  }
4441
- }, _callee23, this);
4662
+ }, _callee26, this);
4442
4663
  }));
4443
- function finalizeAfterProductsMutation(_x27, _x28) {
4664
+ function finalizeAfterProductsMutation(_x34, _x35) {
4444
4665
  return _finalizeAfterProductsMutation.apply(this, arguments);
4445
4666
  }
4446
4667
  return finalizeAfterProductsMutation;
@@ -4455,21 +4676,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4455
4676
  }, {
4456
4677
  key: "removeProductsFromOrder",
4457
4678
  value: (function () {
4458
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identities) {
4459
- var _this26 = this;
4460
- var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4461
- return _regeneratorRuntime().wrap(function _callee24$(_context27) {
4462
- while (1) switch (_context27.prev = _context27.next) {
4679
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities, options) {
4680
+ var _this29 = this;
4681
+ var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
4682
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4683
+ while (1) switch (_context30.prev = _context30.next) {
4463
4684
  case 0:
4464
4685
  tempOrder = this.ensureTempOrder();
4465
4686
  if (identities.length) {
4466
- _context27.next = 3;
4687
+ _context30.next = 3;
4467
4688
  break;
4468
4689
  }
4469
- return _context27.abrupt("return", tempOrder.products);
4690
+ return _context30.abrupt("return", tempOrder.products);
4470
4691
  case 3:
4471
4692
  productsBeforeRemove = tempOrder.products || [];
4472
4693
  bookingsBeforeRemove = tempOrder.bookings || [];
4694
+ preserveDisplayPosition = options === null || options === void 0 ? void 0 : options.preserveDisplayPosition;
4695
+ anchorIndex = preserveDisplayPosition ? productsBeforeRemove.findIndex(function (item) {
4696
+ var _item$metadata6;
4697
+ var uid = ((_item$metadata6 = item.metadata) === null || _item$metadata6 === void 0 ? void 0 : _item$metadata6.unique_identification_number) || item.unique_identification_number;
4698
+ return uid !== undefined && uid !== null && String(uid) === String(preserveDisplayPosition.anchorProductUid);
4699
+ }) : -1;
4700
+ productsAfterAnchor = anchorIndex >= 0 ? productsBeforeRemove.slice(anchorIndex + 1) : [];
4473
4701
  matchedProducts = productsBeforeRemove.filter(function (item) {
4474
4702
  return identities.some(function (identity) {
4475
4703
  return isIdentityMatch(item, identity);
@@ -4489,29 +4717,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4489
4717
  }
4490
4718
  linkedBookingUidsToRemove = new Set();
4491
4719
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4492
- _context27.prev = 11;
4720
+ _context30.prev = 14;
4493
4721
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4494
4722
  var _metadata11, _metadata12, _metadata13, _metadata14;
4495
4723
  var product, productUid, productBookingUid, isAddTimeProduct;
4496
- return _regeneratorRuntime().wrap(function _loop3$(_context26) {
4497
- while (1) switch (_context26.prev = _context26.next) {
4724
+ return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4725
+ while (1) switch (_context29.prev = _context29.next) {
4498
4726
  case 0:
4499
4727
  product = _step21.value;
4500
4728
  productUid = (product === null || product === void 0 || (_metadata11 = product.metadata) === null || _metadata11 === void 0 ? void 0 : _metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
4501
4729
  productBookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_metadata12 = product.metadata) === null || _metadata12 === void 0 ? void 0 : _metadata12.booking_uid);
4502
4730
  isAddTimeProduct = (product === null || product === void 0 || (_metadata13 = product.metadata) === null || _metadata13 === void 0 ? void 0 : _metadata13.product_add_schedule_time) !== undefined && (product === null || product === void 0 || (_metadata14 = product.metadata) === null || _metadata14 === void 0 ? void 0 : _metadata14.product_add_schedule_time) !== null;
4503
4731
  if (!isAddTimeProduct) {
4504
- _context26.next = 6;
4732
+ _context29.next = 6;
4505
4733
  break;
4506
4734
  }
4507
- return _context26.abrupt("return", 1);
4735
+ return _context29.abrupt("return", 1);
4508
4736
  case 6:
4509
4737
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4510
4738
  linkedBookingUidsToRemove.add(String(productBookingUid));
4511
4739
  }
4512
4740
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4513
4741
  bookingsBeforeRemove.forEach(function (booking) {
4514
- var bookingUid = _this26.getBookingUniqueIdentificationNumber(booking);
4742
+ var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
4515
4743
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4516
4744
  linkedBookingUidsToRemove.add(bookingUid);
4517
4745
  }
@@ -4519,61 +4747,77 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4519
4747
  }
4520
4748
  case 8:
4521
4749
  case "end":
4522
- return _context26.stop();
4750
+ return _context29.stop();
4523
4751
  }
4524
4752
  }, _loop3);
4525
4753
  });
4526
4754
  _iterator21.s();
4527
- case 14:
4755
+ case 17:
4528
4756
  if ((_step21 = _iterator21.n()).done) {
4529
- _context27.next = 20;
4757
+ _context30.next = 23;
4530
4758
  break;
4531
4759
  }
4532
- return _context27.delegateYield(_loop3(), "t0", 16);
4533
- case 16:
4534
- if (!_context27.t0) {
4535
- _context27.next = 18;
4760
+ return _context30.delegateYield(_loop3(), "t0", 19);
4761
+ case 19:
4762
+ if (!_context30.t0) {
4763
+ _context30.next = 21;
4536
4764
  break;
4537
4765
  }
4538
- return _context27.abrupt("continue", 18);
4539
- case 18:
4540
- _context27.next = 14;
4766
+ return _context30.abrupt("continue", 21);
4767
+ case 21:
4768
+ _context30.next = 17;
4541
4769
  break;
4542
- case 20:
4543
- _context27.next = 25;
4770
+ case 23:
4771
+ _context30.next = 28;
4544
4772
  break;
4545
- case 22:
4546
- _context27.prev = 22;
4547
- _context27.t1 = _context27["catch"](11);
4548
- _iterator21.e(_context27.t1);
4549
4773
  case 25:
4550
- _context27.prev = 25;
4551
- _iterator21.f();
4552
- return _context27.finish(25);
4774
+ _context30.prev = 25;
4775
+ _context30.t1 = _context30["catch"](14);
4776
+ _iterator21.e(_context30.t1);
4553
4777
  case 28:
4778
+ _context30.prev = 28;
4779
+ _iterator21.f();
4780
+ return _context30.finish(28);
4781
+ case 31:
4554
4782
  if (linkedBookingUidsToRemove.size > 0) {
4555
4783
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
4556
4784
  tempOrder.products = (tempOrder.products || []).filter(function (line) {
4557
- var _line$metadata, _line$metadata2, _line$metadata3;
4558
- var lineBookingUid = (line === null || line === void 0 || (_line$metadata = line.metadata) === null || _line$metadata === void 0 ? void 0 : _line$metadata.booking_uid) || (line === null || line === void 0 ? void 0 : line.booking_uid);
4559
- var isAddTimeProduct = (line === null || line === void 0 || (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2.product_add_schedule_time) !== undefined && (line === null || line === void 0 || (_line$metadata3 = line.metadata) === null || _line$metadata3 === void 0 ? void 0 : _line$metadata3.product_add_schedule_time) !== null;
4785
+ var _line$metadata2, _line$metadata3, _line$metadata4;
4786
+ var lineBookingUid = (line === null || line === void 0 || (_line$metadata2 = line.metadata) === null || _line$metadata2 === void 0 ? void 0 : _line$metadata2.booking_uid) || (line === null || line === void 0 ? void 0 : line.booking_uid);
4787
+ var isAddTimeProduct = (line === null || line === void 0 || (_line$metadata3 = line.metadata) === null || _line$metadata3 === void 0 ? void 0 : _line$metadata3.product_add_schedule_time) !== undefined && (line === null || line === void 0 || (_line$metadata4 = line.metadata) === null || _line$metadata4 === void 0 ? void 0 : _line$metadata4.product_add_schedule_time) !== null;
4560
4788
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4561
4789
  });
4562
4790
  }
4563
- _context27.next = 31;
4791
+ if (preserveDisplayPosition && anchorIndex >= 0) {
4792
+ remainingProductIndex = tempOrder.products.findIndex(function (item) {
4793
+ var _item$metadata7;
4794
+ var uid = ((_item$metadata7 = item.metadata) === null || _item$metadata7 === void 0 ? void 0 : _item$metadata7.unique_identification_number) || item.unique_identification_number;
4795
+ return uid !== undefined && uid !== null && String(uid) === String(preserveDisplayPosition.remainingProductUid);
4796
+ });
4797
+ if (remainingProductIndex >= 0) {
4798
+ remainingProduct = tempOrder.products[remainingProductIndex];
4799
+ nextProduct = productsAfterAnchor.find(function (item) {
4800
+ return tempOrder.products.includes(item);
4801
+ });
4802
+ productsWithoutRemaining = [].concat(_toConsumableArray(tempOrder.products.slice(0, remainingProductIndex)), _toConsumableArray(tempOrder.products.slice(remainingProductIndex + 1)));
4803
+ nextProductIndex = nextProduct ? productsWithoutRemaining.indexOf(nextProduct) : -1;
4804
+ tempOrder.products = nextProductIndex >= 0 ? [].concat(_toConsumableArray(productsWithoutRemaining.slice(0, nextProductIndex)), [remainingProduct], _toConsumableArray(productsWithoutRemaining.slice(nextProductIndex))) : [].concat(_toConsumableArray(productsWithoutRemaining), [remainingProduct]);
4805
+ }
4806
+ }
4807
+ _context30.next = 35;
4564
4808
  return this.finalizeAfterProductsMutation(tempOrder);
4565
- case 31:
4809
+ case 35:
4566
4810
  this.logInfo('removeProductsFromOrder success', {
4567
4811
  identities: identities
4568
4812
  });
4569
- return _context27.abrupt("return", tempOrder.products);
4570
- case 33:
4813
+ return _context30.abrupt("return", tempOrder.products);
4814
+ case 37:
4571
4815
  case "end":
4572
- return _context27.stop();
4816
+ return _context30.stop();
4573
4817
  }
4574
- }, _callee24, this, [[11, 22, 25, 28]]);
4818
+ }, _callee27, this, [[14, 25, 28, 31]]);
4575
4819
  }));
4576
- function removeProductsFromOrder(_x29) {
4820
+ function removeProductsFromOrder(_x36, _x37) {
4577
4821
  return _removeProductsFromOrder.apply(this, arguments);
4578
4822
  }
4579
4823
  return removeProductsFromOrder;
@@ -4581,18 +4825,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4581
4825
  }, {
4582
4826
  key: "removeProductFromOrder",
4583
4827
  value: function () {
4584
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identity) {
4585
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4586
- while (1) switch (_context28.prev = _context28.next) {
4828
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity, options) {
4829
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4830
+ while (1) switch (_context31.prev = _context31.next) {
4587
4831
  case 0:
4588
- return _context28.abrupt("return", this.removeProductsFromOrder([identity]));
4832
+ return _context31.abrupt("return", this.removeProductsFromOrder([identity], options));
4589
4833
  case 1:
4590
4834
  case "end":
4591
- return _context28.stop();
4835
+ return _context31.stop();
4592
4836
  }
4593
- }, _callee25, this);
4837
+ }, _callee28, this);
4594
4838
  }));
4595
- function removeProductFromOrder(_x30) {
4839
+ function removeProductFromOrder(_x38, _x39) {
4596
4840
  return _removeProductFromOrder.apply(this, arguments);
4597
4841
  }
4598
4842
  return removeProductFromOrder;
@@ -4604,10 +4848,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4604
4848
  }, {
4605
4849
  key: "clearOrderCartLines",
4606
4850
  value: (function () {
4607
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4851
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4608
4852
  var tempOrder;
4609
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4610
- while (1) switch (_context29.prev = _context29.next) {
4853
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4854
+ while (1) switch (_context32.prev = _context32.next) {
4611
4855
  case 0:
4612
4856
  tempOrder = this.ensureTempOrder();
4613
4857
  tempOrder.products = [];
@@ -4618,24 +4862,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4618
4862
  productsByUid: {}
4619
4863
  });
4620
4864
  }
4621
- _context29.next = 7;
4865
+ _context32.next = 7;
4622
4866
  return this.applyPromotion();
4623
4867
  case 7:
4624
4868
  this.applyDiscount();
4625
4869
  this.sanitizeTempOrderProducts(tempOrder);
4626
- _context29.next = 11;
4870
+ _context32.next = 11;
4627
4871
  return this.recalculateSummary({
4628
4872
  createIfMissing: true
4629
4873
  });
4630
4874
  case 11:
4631
4875
  this.persistTempOrder();
4632
4876
  this.logInfo('clearOrderCartLines success', {});
4633
- return _context29.abrupt("return", tempOrder);
4877
+ return _context32.abrupt("return", tempOrder);
4634
4878
  case 14:
4635
4879
  case "end":
4636
- return _context29.stop();
4880
+ return _context32.stop();
4637
4881
  }
4638
- }, _callee26, this);
4882
+ }, _callee29, this);
4639
4883
  }));
4640
4884
  function clearOrderCartLines() {
4641
4885
  return _clearOrderCartLines.apply(this, arguments);
@@ -4673,17 +4917,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4673
4917
  }, {
4674
4918
  key: "applyLocalPrintOrderNumbers",
4675
4919
  value: function () {
4676
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order) {
4920
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
4677
4921
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4678
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4679
- while (1) switch (_context30.prev = _context30.next) {
4922
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4923
+ while (1) switch (_context33.prev = _context33.next) {
4680
4924
  case 0:
4681
4925
  tempOrder = this.ensureTempOrder();
4682
4926
  if (!(!order || _typeof(order) !== 'object')) {
4683
- _context30.next = 3;
4927
+ _context33.next = 3;
4684
4928
  break;
4685
4929
  }
4686
- return _context30.abrupt("return", tempOrder);
4930
+ return _context33.abrupt("return", tempOrder);
4687
4931
  case 3:
4688
4932
  shopOrderNumber = order.shop_order_number;
4689
4933
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4694,21 +4938,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4694
4938
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4695
4939
  }
4696
4940
  this.persistTempOrder();
4697
- _context30.next = 10;
4941
+ _context33.next = 10;
4698
4942
  return this.saveDraft();
4699
4943
  case 10:
4700
- return _context30.abrupt("return", tempOrder);
4944
+ return _context33.abrupt("return", tempOrder);
4701
4945
  case 11:
4702
4946
  case "end":
4703
- return _context30.stop();
4947
+ return _context33.stop();
4704
4948
  }
4705
- }, _callee27, this);
4949
+ }, _callee30, this);
4706
4950
  }));
4707
- function applyLocalPrintOrderNumbers(_x31) {
4951
+ function applyLocalPrintOrderNumbers(_x40) {
4708
4952
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4709
4953
  }
4710
4954
  return applyLocalPrintOrderNumbers;
4711
4955
  }()
4956
+ }, {
4957
+ key: "saveTempOrderAsDraft",
4958
+ value: function () {
4959
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4960
+ var _params$cacheId2, _this$otherParams6, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4961
+ var tempOrder, latestSummary, payload;
4962
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4963
+ while (1) switch (_context34.prev = _context34.next) {
4964
+ case 0:
4965
+ tempOrder = this.ensureTempOrder();
4966
+ this.ensureExternalSaleNumber(tempOrder);
4967
+ this.persistTempOrder();
4968
+ _context34.next = 5;
4969
+ return this.recalculateSummary({
4970
+ createIfMissing: true
4971
+ });
4972
+ case 5:
4973
+ _context34.t1 = _context34.sent;
4974
+ if (_context34.t1) {
4975
+ _context34.next = 8;
4976
+ break;
4977
+ }
4978
+ _context34.t1 = this.store.summary;
4979
+ case 8:
4980
+ _context34.t0 = _context34.t1;
4981
+ if (_context34.t0) {
4982
+ _context34.next = 11;
4983
+ break;
4984
+ }
4985
+ _context34.t0 = createEmptySummary();
4986
+ case 11:
4987
+ latestSummary = _context34.t0;
4988
+ payload = buildSubmitPayload({
4989
+ tempOrder: tempOrder,
4990
+ cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
4991
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4992
+ businessCode: (params === null || params === void 0 ? void 0 : params.businessCode) || ((_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) || ((_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code) || tempOrder.business_code,
4993
+ channel: params === null || params === void 0 ? void 0 : params.channel,
4994
+ 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,
4995
+ summary: latestSummary,
4996
+ enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
4997
+ });
4998
+ if (!payload.created_at) {
4999
+ payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
5000
+ }
5001
+ payload.need_sync = 0;
5002
+ payload.is_draft_order = 1;
5003
+ this.logInfo('saveTempOrderAsDraft calling sales draft', {
5004
+ orderId: payload.order_id,
5005
+ externalSaleNumber: payload.external_sale_number,
5006
+ productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
5007
+ });
5008
+ return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
5009
+ osServer: true,
5010
+ customToast: function customToast() {}
5011
+ }));
5012
+ case 18:
5013
+ case "end":
5014
+ return _context34.stop();
5015
+ }
5016
+ }, _callee31, this);
5017
+ }));
5018
+ function saveTempOrderAsDraft(_x41) {
5019
+ return _saveTempOrderAsDraft.apply(this, arguments);
5020
+ }
5021
+ return saveTempOrderAsDraft;
5022
+ }()
4712
5023
  /**
4713
5024
  * 提交当前 Sales tempOrder。
4714
5025
  *
@@ -4718,18 +5029,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4718
5029
  }, {
4719
5030
  key: "submitTempOrder",
4720
5031
  value: (function () {
4721
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
4722
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4723
- while (1) switch (_context31.prev = _context31.next) {
5032
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5033
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5034
+ while (1) switch (_context35.prev = _context35.next) {
4724
5035
  case 0:
4725
- return _context31.abrupt("return", this.runSubmitTempOrder(params));
5036
+ return _context35.abrupt("return", this.runSubmitTempOrder(params));
4726
5037
  case 1:
4727
5038
  case "end":
4728
- return _context31.stop();
5039
+ return _context35.stop();
4729
5040
  }
4730
- }, _callee28, this);
5041
+ }, _callee32, this);
4731
5042
  }));
4732
- function submitTempOrder(_x32) {
5043
+ function submitTempOrder(_x42) {
4733
5044
  return _submitTempOrder.apply(this, arguments);
4734
5045
  }
4735
5046
  return submitTempOrder;
@@ -4737,20 +5048,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4737
5048
  }, {
4738
5049
  key: "submitTempOrderAsync",
4739
5050
  value: function () {
4740
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4741
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4742
- while (1) switch (_context32.prev = _context32.next) {
5051
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5052
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5053
+ while (1) switch (_context36.prev = _context36.next) {
4743
5054
  case 0:
4744
- return _context32.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5055
+ return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4745
5056
  syncMode: true
4746
5057
  })));
4747
5058
  case 1:
4748
5059
  case "end":
4749
- return _context32.stop();
5060
+ return _context36.stop();
4750
5061
  }
4751
- }, _callee29, this);
5062
+ }, _callee33, this);
4752
5063
  }));
4753
- function submitTempOrderAsync(_x33) {
5064
+ function submitTempOrderAsync(_x43) {
4754
5065
  return _submitTempOrderAsync.apply(this, arguments);
4755
5066
  }
4756
5067
  return submitTempOrderAsync;
@@ -4758,11 +5069,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4758
5069
  }, {
4759
5070
  key: "runSubmitTempOrder",
4760
5071
  value: function () {
4761
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
4762
- var _params$cacheId2, _this$otherParams6, _ref74, _ref75, _submitSnapshot$busin, _this$otherParams7, _this$otherParams8, _submitSnapshot$type;
5072
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5073
+ var _params$cacheId3, _this$otherParams10, _ref74, _ref75, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4763
5074
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4764
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4765
- while (1) switch (_context33.prev = _context33.next) {
5075
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5076
+ while (1) switch (_context37.prev = _context37.next) {
4766
5077
  case 0:
4767
5078
  tempOrder = this.ensureTempOrder();
4768
5079
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -4782,27 +5093,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4782
5093
  }
4783
5094
  }
4784
5095
  this.persistTempOrder();
4785
- _context33.next = 8;
5096
+ _context37.next = 8;
4786
5097
  return this.recalculateSummary({
4787
5098
  createIfMissing: true
4788
5099
  });
4789
5100
  case 8:
4790
- _context33.t1 = _context33.sent;
4791
- if (_context33.t1) {
4792
- _context33.next = 11;
5101
+ _context37.t1 = _context37.sent;
5102
+ if (_context37.t1) {
5103
+ _context37.next = 11;
4793
5104
  break;
4794
5105
  }
4795
- _context33.t1 = this.store.summary;
5106
+ _context37.t1 = this.store.summary;
4796
5107
  case 11:
4797
- _context33.t0 = _context33.t1;
4798
- if (_context33.t0) {
4799
- _context33.next = 14;
5108
+ _context37.t0 = _context37.t1;
5109
+ if (_context37.t0) {
5110
+ _context37.next = 14;
4800
5111
  break;
4801
5112
  }
4802
- _context33.t0 = createEmptySummary();
5113
+ _context37.t0 = createEmptySummary();
4803
5114
  case 14:
4804
- latestSummary = _context33.t0;
4805
- effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
5115
+ latestSummary = _context37.t0;
5116
+ effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
4806
5117
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4807
5118
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4808
5119
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
@@ -4820,8 +5131,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4820
5131
  payload = buildSubmitPayload({
4821
5132
  tempOrder: tempOrder,
4822
5133
  cacheId: effectiveCacheId,
4823
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4824
- businessCode: (_ref74 = (_ref75 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams7 = this.otherParams) === null || _this$otherParams7 === void 0 ? void 0 : _this$otherParams7.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams8 = this.otherParams) === null || _this$otherParams8 === void 0 ? void 0 : _this$otherParams8.business_code,
5134
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
5135
+ businessCode: (_ref74 = (_ref75 = (_submitSnapshot$busin = submitSnapshot.businessCode) !== null && _submitSnapshot$busin !== void 0 ? _submitSnapshot$busin : params === null || params === void 0 ? void 0 : params.businessCode) !== null && _ref75 !== void 0 ? _ref75 : (_this$otherParams11 = this.otherParams) === null || _this$otherParams11 === void 0 ? void 0 : _this$otherParams11.businessCode) !== null && _ref74 !== void 0 ? _ref74 : (_this$otherParams12 = this.otherParams) === null || _this$otherParams12 === void 0 ? void 0 : _this$otherParams12.business_code,
4825
5136
  channel: params === null || params === void 0 ? void 0 : params.channel,
4826
5137
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4827
5138
  summary: latestSummary,
@@ -4836,10 +5147,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4836
5147
  if (!payload.created_at) {
4837
5148
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4838
5149
  }
4839
- _context33.next = 26;
5150
+ _context37.next = 26;
4840
5151
  return this.saveDraft();
4841
5152
  case 26:
4842
- _context33.prev = 26;
5153
+ _context37.prev = 26;
4843
5154
  this.logInfo('submitTempOrder calling sales checkout', {
4844
5155
  orderId: payload.order_id,
4845
5156
  externalSaleNumber: payload.external_sale_number,
@@ -4849,43 +5160,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4849
5160
  smallTicketDataFlag: payload.small_ticket_data_flag,
4850
5161
  syncMode: payload.sync_mode
4851
5162
  });
4852
- _context33.next = 30;
5163
+ _context37.next = 30;
4853
5164
  return this.submitSalesOrder({
4854
5165
  query: payload
4855
5166
  });
4856
5167
  case 30:
4857
- result = _context33.sent;
4858
- _context33.next = 43;
5168
+ result = _context37.sent;
5169
+ _context37.next = 43;
4859
5170
  break;
4860
5171
  case 33:
4861
- _context33.prev = 33;
4862
- _context33.t2 = _context33["catch"](26);
4863
- backendErrorResponse = this.extractSubmitErrorResponse(_context33.t2);
5172
+ _context37.prev = 33;
5173
+ _context37.t2 = _context37["catch"](26);
5174
+ backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
4864
5175
  if (!backendErrorResponse) {
4865
- _context33.next = 40;
5176
+ _context37.next = 40;
4866
5177
  break;
4867
5178
  }
4868
5179
  this.store.syncState = 'failed';
4869
5180
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4870
- return _context33.abrupt("return", backendErrorResponse);
5181
+ return _context37.abrupt("return", backendErrorResponse);
4871
5182
  case 40:
4872
5183
  this.store.syncState = 'failed';
4873
5184
  this.logError('submitTempOrder failed', {
4874
- error: _context33.t2 instanceof Error ? _context33.t2.message : String(_context33.t2),
5185
+ error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
4875
5186
  orderId: payload.order_id,
4876
5187
  externalSaleNumber: payload.external_sale_number,
4877
5188
  paymentStatus: payload.payment_status,
4878
5189
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4879
5190
  });
4880
- throw _context33.t2;
5191
+ throw _context37.t2;
4881
5192
  case 43:
4882
5193
  if (!this.isSubmitResponseRejected(result)) {
4883
- _context33.next = 47;
5194
+ _context37.next = 47;
4884
5195
  break;
4885
5196
  }
4886
5197
  this.store.syncState = 'failed';
4887
5198
  this.logSubmitBackendRejected(result, payload);
4888
- return _context33.abrupt("return", result);
5199
+ return _context37.abrupt("return", result);
4889
5200
  case 47:
4890
5201
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4891
5202
  this.logInfo('runSubmitTempOrder: 提交成功', {
@@ -4896,15 +5207,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4896
5207
  })
4897
5208
  });
4898
5209
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4899
- _context33.next = 56;
5210
+ _context37.next = 56;
4900
5211
  break;
4901
5212
  }
4902
5213
  tempOrder.order_id = submittedOrderId;
4903
5214
  resultRecord = result;
4904
- _context33.next = 54;
5215
+ _context37.next = 54;
4905
5216
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4906
5217
  case 54:
4907
- _context33.next = 57;
5218
+ _context37.next = 57;
4908
5219
  break;
4909
5220
  case 56:
4910
5221
  if (this.isLocalPendingSubmitResult(result)) {
@@ -4913,14 +5224,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4913
5224
  this.store.syncState = 'submitted';
4914
5225
  }
4915
5226
  case 57:
4916
- return _context33.abrupt("return", result);
5227
+ return _context37.abrupt("return", result);
4917
5228
  case 58:
4918
5229
  case "end":
4919
- return _context33.stop();
5230
+ return _context37.stop();
4920
5231
  }
4921
- }, _callee30, this, [[26, 33]]);
5232
+ }, _callee34, this, [[26, 33]]);
4922
5233
  }));
4923
- function runSubmitTempOrder(_x34) {
5234
+ function runSubmitTempOrder(_x44) {
4924
5235
  return _runSubmitTempOrder.apply(this, arguments);
4925
5236
  }
4926
5237
  return runSubmitTempOrder;
@@ -4928,10 +5239,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4928
5239
  }, {
4929
5240
  key: "markLocalOrderSynced",
4930
5241
  value: function () {
4931
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderId, remoteOrder) {
5242
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
4932
5243
  var tempOrder;
4933
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4934
- while (1) switch (_context34.prev = _context34.next) {
5244
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5245
+ while (1) switch (_context38.prev = _context38.next) {
4935
5246
  case 0:
4936
5247
  tempOrder = this.ensureTempOrder();
4937
5248
  tempOrder.order_id = orderId;
@@ -4939,15 +5250,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4939
5250
  this.store.lastOrderInfo = remoteOrder;
4940
5251
  this.store.syncState = 'submitted';
4941
5252
  this.persistTempOrder();
4942
- _context34.next = 8;
5253
+ _context38.next = 8;
4943
5254
  return this.saveDraft();
4944
5255
  case 8:
4945
5256
  case "end":
4946
- return _context34.stop();
5257
+ return _context38.stop();
4947
5258
  }
4948
- }, _callee31, this);
5259
+ }, _callee35, this);
4949
5260
  }));
4950
- function markLocalOrderSynced(_x35, _x36) {
5261
+ function markLocalOrderSynced(_x45, _x46) {
4951
5262
  return _markLocalOrderSynced.apply(this, arguments);
4952
5263
  }
4953
5264
  return markLocalOrderSynced;
@@ -4990,10 +5301,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4990
5301
  value: function extractSubmitErrorResponse(error) {
4991
5302
  var _error$response,
4992
5303
  _error$response2,
4993
- _this27 = this;
5304
+ _this30 = this;
4994
5305
  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];
4995
5306
  return candidates.find(function (candidate) {
4996
- return _this27.isSubmitErrorResponse(candidate);
5307
+ return _this30.isSubmitErrorResponse(candidate);
4997
5308
  }) || null;
4998
5309
  }
4999
5310
  }, {
@@ -5020,14 +5331,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5020
5331
  }, {
5021
5332
  key: "syncPaymentsToOrder",
5022
5333
  value: function () {
5023
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5024
- var _params$confirmPendin;
5025
- var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
5026
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5027
- while (1) switch (_context35.prev = _context35.next) {
5334
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5335
+ var _this31 = this,
5336
+ _params$confirmPendin;
5337
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
5338
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5339
+ while (1) switch (_context39.prev = _context39.next) {
5028
5340
  case 0:
5029
5341
  tempOrder = this.ensureTempOrder();
5030
- mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
5342
+ needsPaymentNumber = (params.payments || []).some(function (payment) {
5343
+ return String(payment.payment_number || '').trim() === '';
5344
+ });
5345
+ if (!needsPaymentNumber) {
5346
+ _context39.next = 8;
5347
+ break;
5348
+ }
5349
+ _context39.next = 5;
5350
+ return this.getPaymentNumberDevicePrefixAsync();
5351
+ case 5:
5352
+ _context39.t0 = _context39.sent;
5353
+ _context39.next = 9;
5354
+ break;
5355
+ case 8:
5356
+ _context39.t0 = 'LOCAL';
5357
+ case 9:
5358
+ devicePrefix = _context39.t0;
5359
+ mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5360
+ return _this31.normalizePaymentSource(payment, {
5361
+ defaultPaid: false,
5362
+ devicePrefix: devicePrefix
5363
+ });
5364
+ }));
5031
5365
  shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
5032
5366
  effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
5033
5367
  completion = this.getPaymentCompletion(effectivePayments);
@@ -5036,24 +5370,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5036
5370
  tempOrder.payments = effectivePayments;
5037
5371
  tempOrder.payment_status = paymentStatus;
5038
5372
  this.persistTempOrder();
5039
- _context35.next = 12;
5373
+ _context39.next = 21;
5040
5374
  return this.saveDraft();
5041
- case 12:
5375
+ case 21:
5042
5376
  if (params.submitWhenPaid) {
5043
- _context35.next = 14;
5377
+ _context39.next = 23;
5044
5378
  break;
5045
5379
  }
5046
- return _context35.abrupt("return", completion);
5047
- case 14:
5380
+ return _context39.abrupt("return", completion);
5381
+ case 23:
5048
5382
  if (!(this.store.syncState === 'submitting')) {
5049
- _context35.next = 16;
5383
+ _context39.next = 25;
5050
5384
  break;
5051
5385
  }
5052
- return _context35.abrupt("return", completion);
5053
- case 16:
5386
+ return _context39.abrupt("return", completion);
5387
+ case 25:
5054
5388
  this.store.syncState = 'submitting';
5055
5389
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
5056
- _context35.next = 20;
5390
+ _context39.next = 29;
5057
5391
  return this.submitTempOrder({
5058
5392
  payments: effectivePayments,
5059
5393
  paymentStatus: paymentStatus,
@@ -5068,18 +5402,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5068
5402
  return nextPayload;
5069
5403
  }
5070
5404
  });
5071
- case 20:
5072
- submitResult = _context35.sent;
5073
- return _context35.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5405
+ case 29:
5406
+ submitResult = _context39.sent;
5407
+ return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5074
5408
  submitResult: submitResult
5075
5409
  }));
5076
- case 22:
5410
+ case 31:
5077
5411
  case "end":
5078
- return _context35.stop();
5412
+ return _context39.stop();
5079
5413
  }
5080
- }, _callee32, this);
5414
+ }, _callee36, this);
5081
5415
  }));
5082
- function syncPaymentsToOrder(_x37) {
5416
+ function syncPaymentsToOrder(_x47) {
5083
5417
  return _syncPaymentsToOrder.apply(this, arguments);
5084
5418
  }
5085
5419
  return syncPaymentsToOrder;
@@ -5168,11 +5502,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5168
5502
  }, {
5169
5503
  key: "submitOrder",
5170
5504
  value: function () {
5171
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
5505
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5172
5506
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5173
5507
  var url, query, fetchUrl, params;
5174
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5175
- while (1) switch (_context36.prev = _context36.next) {
5508
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5509
+ while (1) switch (_context40.prev = _context40.next) {
5176
5510
  case 0:
5177
5511
  this.logInfo('submitOrder called', {
5178
5512
  url: order.url,
@@ -5192,14 +5526,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5192
5526
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5193
5527
  scheduleDate: params.schedule_date
5194
5528
  });
5195
- return _context36.abrupt("return", this.request.post(fetchUrl, params));
5529
+ return _context40.abrupt("return", this.request.post(fetchUrl, params));
5196
5530
  case 6:
5197
5531
  case "end":
5198
- return _context36.stop();
5532
+ return _context40.stop();
5199
5533
  }
5200
- }, _callee33, this);
5534
+ }, _callee37, this);
5201
5535
  }));
5202
- function submitOrder(_x38) {
5536
+ function submitOrder(_x48) {
5203
5537
  return _submitOrder.apply(this, arguments);
5204
5538
  }
5205
5539
  return submitOrder;
@@ -5207,13 +5541,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5207
5541
  }, {
5208
5542
  key: "cancelOrder",
5209
5543
  value: function () {
5210
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5544
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5211
5545
  var payload;
5212
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5213
- while (1) switch (_context37.prev = _context37.next) {
5546
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5547
+ while (1) switch (_context41.prev = _context41.next) {
5214
5548
  case 0:
5215
5549
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5216
- _context37.next = 2;
5550
+ _context41.next = 2;
5217
5551
  break;
5218
5552
  }
5219
5553
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5229,16 +5563,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5229
5563
  method: 'PUT',
5230
5564
  orderIdsCount: params.order_ids.length
5231
5565
  });
5232
- return _context37.abrupt("return", this.request.put('/order/update-status', payload, {
5566
+ return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5233
5567
  isShopApi: true
5234
5568
  }));
5235
5569
  case 5:
5236
5570
  case "end":
5237
- return _context37.stop();
5571
+ return _context41.stop();
5238
5572
  }
5239
- }, _callee34, this);
5573
+ }, _callee38, this);
5240
5574
  }));
5241
- function cancelOrder(_x39) {
5575
+ function cancelOrder(_x49) {
5242
5576
  return _cancelOrder.apply(this, arguments);
5243
5577
  }
5244
5578
  return cancelOrder;
@@ -5246,19 +5580,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5246
5580
  }, {
5247
5581
  key: "changeBookingStatus",
5248
5582
  value: function () {
5249
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5583
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5250
5584
  var url, payload;
5251
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5252
- while (1) switch (_context38.prev = _context38.next) {
5585
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5586
+ while (1) switch (_context42.prev = _context42.next) {
5253
5587
  case 0:
5254
5588
  if (params.booking_id) {
5255
- _context38.next = 2;
5589
+ _context42.next = 2;
5256
5590
  break;
5257
5591
  }
5258
5592
  throw new Error('变更预约状态失败:booking_id 不能为空');
5259
5593
  case 2:
5260
5594
  if (params.appointment_status) {
5261
- _context38.next = 4;
5595
+ _context42.next = 4;
5262
5596
  break;
5263
5597
  }
5264
5598
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5273,16 +5607,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5273
5607
  bookingId: params.booking_id,
5274
5608
  appointmentStatus: params.appointment_status
5275
5609
  });
5276
- return _context38.abrupt("return", this.request.put(url, payload, {
5610
+ return _context42.abrupt("return", this.request.put(url, payload, {
5277
5611
  isShopApi: true
5278
5612
  }));
5279
5613
  case 8:
5280
5614
  case "end":
5281
- return _context38.stop();
5615
+ return _context42.stop();
5282
5616
  }
5283
- }, _callee35, this);
5617
+ }, _callee39, this);
5284
5618
  }));
5285
- function changeBookingStatus(_x40) {
5619
+ function changeBookingStatus(_x50) {
5286
5620
  return _changeBookingStatus.apply(this, arguments);
5287
5621
  }
5288
5622
  return changeBookingStatus;
@@ -5300,11 +5634,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5300
5634
  }, {
5301
5635
  key: "createOrderByCheckout",
5302
5636
  value: (function () {
5303
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5637
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5304
5638
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5305
5639
  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;
5306
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5307
- while (1) switch (_context39.prev = _context39.next) {
5640
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5641
+ while (1) switch (_context43.prev = _context43.next) {
5308
5642
  case 0:
5309
5643
  // 过滤掉由在线店铺下单的 payment 支付数据
5310
5644
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5338,7 +5672,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5338
5672
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5339
5673
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5340
5674
  });
5341
- _context39.prev = 4;
5675
+ _context43.prev = 4;
5342
5676
  // 构建订单数据,设置默认值并允许 params 覆盖
5343
5677
  orderData = _objectSpread({
5344
5678
  sales_channel: 'my_pisel',
@@ -5400,13 +5734,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5400
5734
  hasOrderId: !!orderData.order_id,
5401
5735
  smallTicketDataFlag: orderData.small_ticket_data_flag
5402
5736
  });
5403
- _context39.next = 12;
5737
+ _context43.next = 12;
5404
5738
  return this.request.post('/order/checkout', orderData, {
5405
5739
  osServer: true,
5406
5740
  customToast: function customToast() {}
5407
5741
  });
5408
5742
  case 12:
5409
- response = _context39.sent;
5743
+ response = _context43.sent;
5410
5744
  this.logInfo('Order API called successfully', {
5411
5745
  response: response
5412
5746
  });
@@ -5414,22 +5748,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5414
5748
  success: !!response,
5415
5749
  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)
5416
5750
  });
5417
- return _context39.abrupt("return", response);
5751
+ return _context43.abrupt("return", response);
5418
5752
  case 18:
5419
- _context39.prev = 18;
5420
- _context39.t0 = _context39["catch"](4);
5421
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context39.t0);
5753
+ _context43.prev = 18;
5754
+ _context43.t0 = _context43["catch"](4);
5755
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
5422
5756
  this.logInfo('Order API called failed', {
5423
- error: _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0)
5757
+ error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
5424
5758
  });
5425
- throw _context39.t0;
5759
+ throw _context43.t0;
5426
5760
  case 23:
5427
5761
  case "end":
5428
- return _context39.stop();
5762
+ return _context43.stop();
5429
5763
  }
5430
- }, _callee36, this, [[4, 18]]);
5764
+ }, _callee40, this, [[4, 18]]);
5431
5765
  }));
5432
- function createOrderByCheckout(_x41) {
5766
+ function createOrderByCheckout(_x51) {
5433
5767
  return _createOrderByCheckout.apply(this, arguments);
5434
5768
  }
5435
5769
  return createOrderByCheckout;
@@ -5437,24 +5771,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5437
5771
  }, {
5438
5772
  key: "submitSalesOrder",
5439
5773
  value: function () {
5440
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5774
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5441
5775
  var url, query, fetchUrl;
5442
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5443
- while (1) switch (_context40.prev = _context40.next) {
5776
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5777
+ while (1) switch (_context44.prev = _context44.next) {
5444
5778
  case 0:
5445
5779
  url = params.url, query = params.query;
5446
5780
  fetchUrl = url || '/order/sales/checkout';
5447
- return _context40.abrupt("return", this.request.post(fetchUrl, query, {
5781
+ return _context44.abrupt("return", this.request.post(fetchUrl, query, {
5448
5782
  osServer: true,
5449
5783
  customToast: function customToast() {}
5450
5784
  }));
5451
5785
  case 3:
5452
5786
  case "end":
5453
- return _context40.stop();
5787
+ return _context44.stop();
5454
5788
  }
5455
- }, _callee37, this);
5789
+ }, _callee41, this);
5456
5790
  }));
5457
- function submitSalesOrder(_x42) {
5791
+ function submitSalesOrder(_x52) {
5458
5792
  return _submitSalesOrder.apply(this, arguments);
5459
5793
  }
5460
5794
  return submitSalesOrder;
@@ -5468,37 +5802,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5468
5802
  }, {
5469
5803
  key: "sendCustomerPayLink",
5470
5804
  value: (function () {
5471
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5805
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5472
5806
  var _params$emails;
5473
5807
  var orderIds;
5474
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5475
- while (1) switch (_context41.prev = _context41.next) {
5808
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5809
+ while (1) switch (_context45.prev = _context45.next) {
5476
5810
  case 0:
5477
5811
  orderIds = params.order_ids || params.orderIds || [];
5478
5812
  if (orderIds.length) {
5479
- _context41.next = 3;
5813
+ _context45.next = 3;
5480
5814
  break;
5481
5815
  }
5482
5816
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5483
5817
  case 3:
5484
5818
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5485
- _context41.next = 5;
5819
+ _context45.next = 5;
5486
5820
  break;
5487
5821
  }
5488
5822
  throw new Error('发送支付链接需要至少一个邮箱');
5489
5823
  case 5:
5490
- return _context41.abrupt("return", this.request.post('/order/batch-email', {
5824
+ return _context45.abrupt("return", this.request.post('/order/batch-email', {
5491
5825
  order_ids: orderIds,
5492
5826
  notify_action: params.notify_action || 'order_payment_reminder',
5493
5827
  emails: params.emails
5494
5828
  }));
5495
5829
  case 6:
5496
5830
  case "end":
5497
- return _context41.stop();
5831
+ return _context45.stop();
5498
5832
  }
5499
- }, _callee38, this);
5833
+ }, _callee42, this);
5500
5834
  }));
5501
- function sendCustomerPayLink(_x43) {
5835
+ function sendCustomerPayLink(_x53) {
5502
5836
  return _sendCustomerPayLink.apply(this, arguments);
5503
5837
  }
5504
5838
  return sendCustomerPayLink;
@@ -5506,14 +5840,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5506
5840
  }, {
5507
5841
  key: "getSalesOrderByLookup",
5508
5842
  value: function () {
5509
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5843
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5510
5844
  var lookup, res;
5511
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5512
- while (1) switch (_context42.prev = _context42.next) {
5845
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5846
+ while (1) switch (_context46.prev = _context46.next) {
5513
5847
  case 0:
5514
5848
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5515
5849
  if (lookup) {
5516
- _context42.next = 3;
5850
+ _context46.next = 3;
5517
5851
  break;
5518
5852
  }
5519
5853
  throw new Error('加载销售详情需要 lookup');
@@ -5522,27 +5856,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5522
5856
  if (lookup.startsWith('LOCAL_')) {
5523
5857
  params.forceRemote = false;
5524
5858
  }
5525
- _context42.next = 6;
5859
+ _context46.next = 6;
5526
5860
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5527
- with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
5861
+ with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds']
5528
5862
  }, params.forceRemote ? {
5529
5863
  forceRemote: true
5530
5864
  } : {}), {
5531
5865
  osServer: true
5532
5866
  });
5533
5867
  case 6:
5534
- res = _context42.sent;
5868
+ res = _context46.sent;
5535
5869
  if (res.code === 200) {
5536
5870
  this.store.lastOrderInfo = res.data;
5537
5871
  }
5538
- return _context42.abrupt("return", res);
5872
+ return _context46.abrupt("return", res);
5539
5873
  case 9:
5540
5874
  case "end":
5541
- return _context42.stop();
5875
+ return _context46.stop();
5542
5876
  }
5543
- }, _callee39, this);
5877
+ }, _callee43, this);
5544
5878
  }));
5545
- function getSalesOrderByLookup(_x44) {
5879
+ function getSalesOrderByLookup(_x54) {
5546
5880
  return _getSalesOrderByLookup.apply(this, arguments);
5547
5881
  }
5548
5882
  return getSalesOrderByLookup;
@@ -5556,11 +5890,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5556
5890
  }, {
5557
5891
  key: "hydrateTempOrderFromRecord",
5558
5892
  value: (function () {
5559
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(record, options) {
5560
- var _this$store$discount19;
5561
- var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount20, _this$store$discount21;
5562
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5563
- while (1) switch (_context43.prev = _context43.next) {
5893
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5894
+ var _this$store$discount20;
5895
+ var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount21, _this$store$discount22;
5896
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5897
+ while (1) switch (_context47.prev = _context47.next) {
5564
5898
  case 0:
5565
5899
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5566
5900
  identityReadySource = this.seedAnonymousBookingUidsFromProducts(sourceRaw);
@@ -5585,7 +5919,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5585
5919
  }
5586
5920
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
5587
5921
  makeEditMark: true
5588
- });
5922
+ }); // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
5923
+ sourceLastOrderInfo = raw.lastOrderInfo || raw;
5924
+ isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
5925
+ syntheticIdentityOptions = {
5926
+ isDraftOrder: isDraftOrder,
5927
+ externalSaleNumber: nextTempOrder.external_sale_number
5928
+ };
5589
5929
  rawSummary = raw.summary && _typeof(raw.summary) === 'object' ? raw.summary : {};
5590
5930
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
5591
5931
  return _objectSpread({}, s || {});
@@ -5605,12 +5945,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5605
5945
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
5606
5946
  }
5607
5947
  });
5608
- // lastOrderInfo carries the exact backend snapshot used by deposit/type recovery.
5609
- // Runtime collection repair lives in tempOrder/originalSalesSnapshot and must not
5610
- // rewrite this protocol snapshot as a side effect of hydration.
5611
- this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
5948
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5949
+ hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
5950
+ if (hadSyntheticDraftOrderId && this.store.syncState !== 'submitting') {
5951
+ this.store.syncState = 'local';
5952
+ }
5612
5953
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
5613
- 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() || [] : [];
5954
+ currentDiscounts = typeof ((_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5614
5955
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
5615
5956
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
5616
5957
  });
@@ -5623,34 +5964,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5623
5964
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
5624
5965
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
5625
5966
  if (shouldSkipEmptyDiscountSync) {
5626
- _context43.next = 26;
5967
+ _context47.next = 31;
5627
5968
  break;
5628
5969
  }
5629
5970
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
5630
- _context43.next = 24;
5631
- return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(nextDiscounts);
5632
- case 24:
5633
- _context43.next = 26;
5634
- return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(nextDiscounts);
5635
- case 26:
5971
+ _context47.next = 29;
5972
+ return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setOriginalDiscountList(nextDiscounts);
5973
+ case 29:
5974
+ _context47.next = 31;
5975
+ return (_this$store$discount22 = this.store.discount) === null || _this$store$discount22 === void 0 ? void 0 : _this$store$discount22.setDiscountList(nextDiscounts);
5976
+ case 31:
5636
5977
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5637
- _context43.next = 29;
5978
+ _context47.next = 34;
5638
5979
  break;
5639
5980
  }
5640
- _context43.next = 29;
5981
+ _context47.next = 34;
5641
5982
  return this.recalculateSummary({
5642
5983
  createIfMissing: false
5643
5984
  });
5644
- case 29:
5985
+ case 34:
5645
5986
  this.persistTempOrder();
5646
- return _context43.abrupt("return", nextTempOrder);
5647
- case 31:
5987
+ return _context47.abrupt("return", nextTempOrder);
5988
+ case 36:
5648
5989
  case "end":
5649
- return _context43.stop();
5990
+ return _context47.stop();
5650
5991
  }
5651
- }, _callee40, this);
5992
+ }, _callee44, this);
5652
5993
  }));
5653
- function hydrateTempOrderFromRecord(_x45, _x46) {
5994
+ function hydrateTempOrderFromRecord(_x55, _x56) {
5654
5995
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5655
5996
  }
5656
5997
  return hydrateTempOrderFromRecord;
@@ -5764,11 +6105,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5764
6105
  }, {
5765
6106
  key: "normalizeTempOrderForRuntime",
5766
6107
  value: function normalizeTempOrderForRuntime(raw, options) {
5767
- var _this28 = this;
5768
- var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
6108
+ var _this32 = this;
6109
+ var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6110
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
5769
6111
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5770
- 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) {
5771
- nextTempOrder.order_id = raw.id;
6112
+ 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) {
6113
+ nextTempOrder.order_id = runtimeRaw.id;
5772
6114
  }
5773
6115
  delete nextTempOrder.summary;
5774
6116
  delete nextTempOrder.lastOrderInfo;
@@ -5787,12 +6129,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5787
6129
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5788
6130
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5789
6131
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5790
- return _this28.normalizeHydratedOrderProduct(p, {
6132
+ return _this32.normalizeHydratedOrderProduct(p, {
5791
6133
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
5792
6134
  });
5793
6135
  }) : [];
5794
6136
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5795
- var booking = _this28.normalizeHydratedBookingHolder(b || {});
6137
+ var booking = _this32.normalizeHydratedBookingHolder(b || {});
5796
6138
  return _objectSpread(_objectSpread({}, booking), {}, {
5797
6139
  is_all: normalizeBookingIsAll(booking),
5798
6140
  sub_type: normalizeBookingSubType(booking)
@@ -5858,6 +6200,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5858
6200
  nextTempOrder.vouchers = raw.vouchers || [];
5859
6201
  return nextTempOrder;
5860
6202
  }
6203
+ }, {
6204
+ key: "isSyntheticDraftOrderIdForRuntime",
6205
+ value: function isSyntheticDraftOrderIdForRuntime(record, options) {
6206
+ var _options$isDraftOrder, _record$external_sale;
6207
+ 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;
6208
+ 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;
6209
+ var orderId = record === null || record === void 0 ? void 0 : record.order_id;
6210
+ return Boolean(isDraftOrder && orderId !== undefined && orderId !== null && orderId !== '' && externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '' && String(orderId) === String(externalSaleNumber));
6211
+ }
6212
+ }, {
6213
+ key: "withoutSyntheticDraftOrderIdForRuntime",
6214
+ value: function withoutSyntheticDraftOrderIdForRuntime(record, options) {
6215
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options)) return record;
6216
+ return _objectSpread(_objectSpread({}, record), {}, {
6217
+ order_id: null
6218
+ });
6219
+ }
5861
6220
  }, {
5862
6221
  key: "hydrateLinkedBookingIdentity",
5863
6222
  value: function hydrateLinkedBookingIdentity(tempOrder) {
@@ -5962,7 +6321,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5962
6321
  }, {
5963
6322
  key: "normalizeHydratedOrderProduct",
5964
6323
  value: function normalizeHydratedOrderProduct(product, options) {
5965
- var _this29 = this;
6324
+ var _this33 = this;
5966
6325
  var row = _objectSpread({}, product || {});
5967
6326
  if (row.num === undefined && row.product_quantity !== undefined) {
5968
6327
  row.num = row.product_quantity;
@@ -5970,7 +6329,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5970
6329
  var productSku = ensureProductSku(row);
5971
6330
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5972
6331
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5973
- return _this29.normalizeHydratedProductOptionItem(optionItem || {});
6332
+ return _this33.normalizeHydratedProductOptionItem(optionItem || {});
5974
6333
  }))
5975
6334
  });
5976
6335
  delete row["product_".concat('option', "_item")];
@@ -6007,27 +6366,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6007
6366
  }, {
6008
6367
  key: "getOrderInfo",
6009
6368
  value: function () {
6010
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(order_id) {
6369
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
6011
6370
  var res;
6012
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6013
- while (1) switch (_context44.prev = _context44.next) {
6371
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6372
+ while (1) switch (_context48.prev = _context48.next) {
6014
6373
  case 0:
6015
- _context44.next = 2;
6374
+ _context48.next = 2;
6016
6375
  return this.request.get("/order/sales/".concat(order_id), {
6017
6376
  with: ['products', 'bookings']
6018
6377
  }, {
6019
6378
  osServer: true
6020
6379
  });
6021
6380
  case 2:
6022
- res = _context44.sent;
6023
- return _context44.abrupt("return", res);
6381
+ res = _context48.sent;
6382
+ return _context48.abrupt("return", res);
6024
6383
  case 4:
6025
6384
  case "end":
6026
- return _context44.stop();
6385
+ return _context48.stop();
6027
6386
  }
6028
- }, _callee41, this);
6387
+ }, _callee45, this);
6029
6388
  }));
6030
- function getOrderInfo(_x47) {
6389
+ function getOrderInfo(_x57) {
6031
6390
  return _getOrderInfo.apply(this, arguments);
6032
6391
  }
6033
6392
  return getOrderInfo;