@pisell/pisellos 0.10.2 → 0.10.4

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 (139) 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 +0 -9
  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/BaseModule.d.ts +1 -0
  14. package/dist/modules/BaseModule.js +24 -28
  15. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  16. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  17. package/dist/modules/OpenData/index.d.ts +2 -0
  18. package/dist/modules/OpenData/index.js +8 -0
  19. package/dist/modules/Order/index.d.ts +41 -10
  20. package/dist/modules/Order/index.js +943 -546
  21. package/dist/modules/Order/payment-utils.d.ts +26 -0
  22. package/dist/modules/Order/payment-utils.js +225 -0
  23. package/dist/modules/Order/types.d.ts +43 -2
  24. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  25. package/dist/modules/Order/utils.js +10 -6
  26. package/dist/modules/Payment/index.d.ts +2 -0
  27. package/dist/modules/Payment/index.js +79 -50
  28. package/dist/modules/Payment/types.d.ts +107 -28
  29. package/dist/modules/Payment/types.js +20 -3
  30. package/dist/modules/Payment/walletpass.d.ts +38 -1
  31. package/dist/modules/Payment/walletpass.js +917 -114
  32. package/dist/modules/ProductList/index.js +1 -1
  33. package/dist/modules/Rules/index.d.ts +3 -0
  34. package/dist/modules/Rules/index.js +130 -99
  35. package/dist/server/index.d.ts +16 -0
  36. package/dist/server/index.js +2084 -1188
  37. package/dist/server/modules/index.d.ts +1 -1
  38. package/dist/server/modules/order/index.d.ts +70 -4
  39. package/dist/server/modules/order/index.js +1816 -728
  40. package/dist/server/modules/order/types.d.ts +25 -3
  41. package/dist/server/modules/order/types.js +7 -1
  42. package/dist/solution/BaseSales/index.d.ts +114 -14
  43. package/dist/solution/BaseSales/index.js +1848 -478
  44. package/dist/solution/BaseSales/types.d.ts +55 -1
  45. package/dist/solution/BaseSales/types.js +2 -1
  46. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  47. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  48. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  49. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  50. package/dist/solution/BookingByStep/index.d.ts +1 -1
  51. package/dist/solution/BookingTicket/index.d.ts +8 -16
  52. package/dist/solution/BookingTicket/index.js +138 -52
  53. package/dist/solution/BookingTicket/types.d.ts +1 -0
  54. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  55. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  56. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  57. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  58. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  59. package/dist/solution/Sales/index.d.ts +1 -0
  60. package/dist/solution/Sales/index.js +10 -2
  61. package/dist/solution/ScanOrder/index.js +31 -20
  62. package/dist/solution/UnifiedBookingSales/index.d.ts +3 -0
  63. package/dist/solution/UnifiedBookingSales/index.js +392 -304
  64. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -0
  65. package/dist/solution/VenueBooking/index.d.ts +1 -0
  66. package/dist/solution/VenueBooking/index.js +34 -24
  67. package/dist/types/index.d.ts +1 -0
  68. package/dist/utils/payment-number.d.ts +9 -0
  69. package/dist/utils/payment-number.js +69 -0
  70. package/lib/core/index.d.ts +2 -0
  71. package/lib/core/index.js +4 -0
  72. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  73. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  74. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  75. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  76. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  77. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  78. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  79. package/lib/model/strategy/adapter/promotion/index.js +2 -0
  80. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  81. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  82. package/lib/modules/BaseModule.d.ts +1 -0
  83. package/lib/modules/BaseModule.js +24 -37
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  86. package/lib/modules/OpenData/index.d.ts +2 -0
  87. package/lib/modules/OpenData/index.js +5 -0
  88. package/lib/modules/Order/index.d.ts +41 -10
  89. package/lib/modules/Order/index.js +322 -86
  90. package/lib/modules/Order/payment-utils.d.ts +26 -0
  91. package/lib/modules/Order/payment-utils.js +224 -0
  92. package/lib/modules/Order/types.d.ts +43 -2
  93. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  94. package/lib/modules/Order/utils.js +11 -4
  95. package/lib/modules/Payment/index.d.ts +2 -0
  96. package/lib/modules/Payment/index.js +34 -13
  97. package/lib/modules/Payment/types.d.ts +107 -28
  98. package/lib/modules/Payment/types.js +4 -3
  99. package/lib/modules/Payment/walletpass.d.ts +38 -1
  100. package/lib/modules/Payment/walletpass.js +730 -21
  101. package/lib/modules/ProductList/index.js +9 -1
  102. package/lib/modules/Rules/index.d.ts +3 -0
  103. package/lib/modules/Rules/index.js +39 -10
  104. package/lib/server/index.d.ts +16 -0
  105. package/lib/server/index.js +677 -28
  106. package/lib/server/modules/index.d.ts +1 -1
  107. package/lib/server/modules/order/index.d.ts +70 -4
  108. package/lib/server/modules/order/index.js +818 -69
  109. package/lib/server/modules/order/types.d.ts +25 -3
  110. package/lib/server/modules/order/types.js +1 -0
  111. package/lib/solution/BaseSales/index.d.ts +114 -14
  112. package/lib/solution/BaseSales/index.js +907 -58
  113. package/lib/solution/BaseSales/types.d.ts +55 -1
  114. package/lib/solution/BaseSales/types.js +2 -1
  115. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  116. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  117. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  118. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  119. package/lib/solution/BookingByStep/index.d.ts +1 -1
  120. package/lib/solution/BookingTicket/index.d.ts +8 -16
  121. package/lib/solution/BookingTicket/index.js +63 -9
  122. package/lib/solution/BookingTicket/types.d.ts +1 -0
  123. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  124. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  125. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  126. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  127. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  128. package/lib/solution/Sales/index.d.ts +1 -0
  129. package/lib/solution/Sales/index.js +5 -3
  130. package/lib/solution/ScanOrder/index.js +8 -0
  131. package/lib/solution/UnifiedBookingSales/index.d.ts +3 -0
  132. package/lib/solution/UnifiedBookingSales/index.js +48 -2
  133. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -0
  134. package/lib/solution/VenueBooking/index.d.ts +1 -0
  135. package/lib/solution/VenueBooking/index.js +13 -6
  136. package/lib/types/index.d.ts +1 -0
  137. package/lib/utils/payment-number.d.ts +9 -0
  138. package/lib/utils/payment-number.js +64 -0
  139. 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, ensureCartItemOriginHolder, 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,7 +119,12 @@ 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);
124
+ _defineProperty(_assertThisInitialized(_this), "fatherModule", void 0);
125
+ _defineProperty(_assertThisInitialized(_this), "openCache", false);
126
+ _defineProperty(_assertThisInitialized(_this), "sessionStoragePersistEnabled", false);
127
+ _defineProperty(_assertThisInitialized(_this), "sessionStorageRestoreRecord", null);
101
128
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
102
129
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
103
130
  _defineProperty(_assertThisInitialized(_this), "moduleHooksOverride", void 0);
@@ -140,6 +167,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
140
167
  var item = _step2.value;
141
168
  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
169
  if (!type || type === 'product') continue;
170
+ var isDiscountCard = type === 'discount_card' || type === 'product_discount_card';
143
171
  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
172
  if (resourceId === undefined || resourceId === null || resourceId === '') continue;
145
173
  var id = Number(resourceId);
@@ -162,7 +190,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
162
190
  var _existed$limited_rela;
163
191
  existed.amount = Number(existed.amount || 0) + amount;
164
192
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
165
- existed.balance = String(Number(existed.balance || 0) + amount);
193
+ if (!isDiscountCard) {
194
+ existed.balance = String(Number(existed.balance || 0) + amount);
195
+ }
166
196
  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
197
  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
198
  existed.limited_relation_product_data = _objectSpread(_objectSpread({}, existed.limited_relation_product_data || {}), {}, {
@@ -194,7 +224,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
194
224
  filter: 0,
195
225
  exclude_product_ids: []
196
226
  },
197
- balance: String((_item$amount3 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount3 !== void 0 ? _item$amount3 : '0'),
227
+ balance: isDiscountCard ? undefined : String((_item$amount3 = item === null || item === void 0 ? void 0 : item.amount) !== null && _item$amount3 !== void 0 ? _item$amount3 : '0'),
198
228
  format_title: title,
199
229
  product: {
200
230
  id: (_product$product_id = product === null || product === void 0 ? void 0 : product.product_id) !== null && _product$product_id !== void 0 ? _product$product_id : 0,
@@ -279,18 +309,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
279
309
  return product;
280
310
  });
281
311
  }
312
+ }, {
313
+ key: "syncSessionStorageOptions",
314
+ value: function syncSessionStorageOptions(otherParams) {
315
+ this.cacheId = otherParams.cacheId;
316
+ this.fatherModule = otherParams.fatherModule;
317
+ this.openCache = Boolean(this.cacheId && otherParams.openCache !== false);
318
+ this.sessionStoragePersistEnabled = Boolean(this.openCache && otherParams.enableSessionStoragePersist === true);
319
+ }
282
320
  }, {
283
321
  key: "initialize",
284
322
  value: function () {
285
323
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
286
324
  var _appPlugin$getApp, _otherParams$rules, _otherParams$order, _otherParams$hooks;
287
- var appPlugin, app, otherParams;
325
+ var otherParams, cachedTempOrder, appPlugin, app;
288
326
  return _regeneratorRuntime().wrap(function _callee$(_context) {
289
327
  while (1) switch (_context.prev = _context.next) {
290
328
  case 0:
291
329
  this.core = core;
292
330
  this.store = options.store;
293
- if (!this.store.tempOrder) {
331
+ otherParams = options.otherParams || {};
332
+ this.syncSessionStorageOptions(otherParams);
333
+ if (this.sessionStoragePersistEnabled) {
334
+ cachedTempOrder = this.store.tempOrder;
335
+ this.sessionStorageRestoreRecord = isTempOrder(cachedTempOrder) ? cloneDeep(cachedTempOrder) : null;
336
+ // 统一由 loadSalesDetail hydrate,初始化阶段不直接把缓存态暴露给业务。
337
+ this.store.tempOrder = null;
338
+ this.store.summary = createEmptySummary();
339
+ this.store.availableWalletIds = [];
340
+ this.store.lastOrderInfo = undefined;
341
+ this.store.syncState = undefined;
342
+ this.store.discountList = [];
343
+ } else if (!this.store.tempOrder) {
294
344
  this.store.tempOrder = null;
295
345
  }
296
346
  if (!this.store.summary) {
@@ -307,8 +357,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
307
357
  app = appPlugin === null || appPlugin === void 0 || (_appPlugin$getApp = appPlugin.getApp) === null || _appPlugin$getApp === void 0 ? void 0 : _appPlugin$getApp.call(appPlugin);
308
358
  this.logger = app === null || app === void 0 ? void 0 : app.logger;
309
359
  this.window = this.core.getPlugin('window');
310
- otherParams = options.otherParams || {};
311
- this.cacheId = otherParams.cacheId;
312
360
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
313
361
  this.rulesHooksOverride = (_otherParams$rules = otherParams.rules) === null || _otherParams$rules === void 0 ? void 0 : _otherParams$rules.hooks;
314
362
  this.moduleHooksOverride = options.hooks;
@@ -336,49 +384,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
336
384
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
337
385
  while (1) switch (_context2.prev = _context2.next) {
338
386
  case 0:
387
+ this.sessionStorageRestoreRecord = null;
339
388
  childModules = [(_this$store = this.store) === null || _this$store === void 0 ? void 0 : _this$store.discount, (_this$store2 = this.store) === null || _this$store2 === void 0 ? void 0 : _this$store2.rules];
340
389
  _i = 0, _childModules = childModules;
341
- case 2:
390
+ case 3:
342
391
  if (!(_i < _childModules.length)) {
343
- _context2.next = 18;
392
+ _context2.next = 19;
344
393
  break;
345
394
  }
346
395
  childModule = _childModules[_i];
347
396
  if (!(!childModule || typeof childModule.destroy !== 'function')) {
348
- _context2.next = 6;
397
+ _context2.next = 7;
349
398
  break;
350
399
  }
351
- return _context2.abrupt("continue", 15);
352
- case 6:
353
- _context2.prev = 6;
354
- _context2.next = 9;
400
+ return _context2.abrupt("continue", 16);
401
+ case 7:
402
+ _context2.prev = 7;
403
+ _context2.next = 10;
355
404
  return childModule.destroy();
356
- case 9:
357
- _context2.next = 15;
405
+ case 10:
406
+ _context2.next = 16;
358
407
  break;
359
- case 11:
360
- _context2.prev = 11;
361
- _context2.t0 = _context2["catch"](6);
408
+ case 12:
409
+ _context2.prev = 12;
410
+ _context2.t0 = _context2["catch"](7);
362
411
  errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0);
363
412
  this.logWarning('Destroy child module failed', {
364
413
  module: childModule.name,
365
414
  error: errorMessage
366
415
  });
367
- case 15:
416
+ case 16:
368
417
  _i++;
369
- _context2.next = 2;
418
+ _context2.next = 3;
370
419
  break;
371
- case 18:
420
+ case 19:
372
421
  if (this.store) {
373
422
  this.store.discount = null;
374
423
  this.store.rules = null;
375
424
  }
376
425
  _get(_getPrototypeOf(OrderModule.prototype), "destroy", this).call(this);
377
- case 20:
426
+ case 21:
378
427
  case "end":
379
428
  return _context2.stop();
380
429
  }
381
- }, _callee2, this, [[6, 11]]);
430
+ }, _callee2, this, [[7, 12]]);
382
431
  }));
383
432
  function destroy() {
384
433
  return _destroy.apply(this, arguments);
@@ -396,7 +445,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
396
445
  value: function updateOtherParams(params) {
397
446
  var _otherParams$rules2, _otherParams$order2, _otherParams$hooks2;
398
447
  var otherParams = params || {};
399
- this.cacheId = otherParams.cacheId;
448
+ this.syncSessionStorageOptions(otherParams);
400
449
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
401
450
  this.rulesHooksOverride = (_otherParams$rules2 = otherParams.rules) === null || _otherParams$rules2 === void 0 ? void 0 : _otherParams$rules2.hooks;
402
451
  this.orderHooks = this.moduleHooksOverride || ((_otherParams$order2 = otherParams.order) === null || _otherParams$order2 === void 0 ? void 0 : _otherParams$order2.hooks) || ((_otherParams$hooks2 = otherParams.hooks) === null || _otherParams$hooks2 === void 0 ? void 0 : _otherParams$hooks2.order);
@@ -454,15 +503,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
454
503
  value: function registerDiscountModules(options) {
455
504
  var _targetCacheData;
456
505
  var targetCacheData = {};
457
- if (this.cacheId && this.window) {
458
- var sessionData = this.window.sessionStorage.getItem(this.name);
459
- if (sessionData) {
460
- try {
506
+ if (!this.sessionStoragePersistEnabled && this.openCache && this.cacheId && this.window) {
507
+ try {
508
+ var sessionData = this.window.sessionStorage.getItem(this.name);
509
+ if (sessionData) {
461
510
  var data = JSON.parse(sessionData);
462
511
  targetCacheData = (data === null || data === void 0 ? void 0 : data[this.cacheId]) || {};
463
- } catch (_unused) {
464
- // sessionStorage 损坏则忽略,按空 initialState 走
465
512
  }
513
+ } catch (_unused) {
514
+ // sessionStorage 损坏或不可用时忽略,按空 initialState 走
466
515
  }
467
516
  }
468
517
  var discount = new DiscountModule("".concat(this.name, "_discount"));
@@ -470,7 +519,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
470
519
  initialState: (_targetCacheData = targetCacheData) === null || _targetCacheData === void 0 ? void 0 : _targetCacheData[discount.name],
471
520
  otherParams: {
472
521
  fatherModule: this.name,
473
- openCache: !!this.cacheId,
522
+ // Unified 的单快照由 Order 管理;其他 Solution 保持原有 Discount 缓存语义。
523
+ openCache: this.openCache && !this.sessionStoragePersistEnabled,
474
524
  cacheId: this.cacheId
475
525
  }
476
526
  });
@@ -657,7 +707,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
657
707
  value: function () {
658
708
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee6(code, customerId) {
659
709
  var _this$store$discount11, _tempOrder$holder, _this$store$summary;
660
- var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, unavailableReason, _this$store$discount12;
710
+ var resultDiscountWithReason, resultDiscountList, unavailableReasonKey, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref13, isAvailable, newDiscountList, evaluatedDiscountList, unavailableReason, shouldRetainForLater, normalizedNewDiscountList, retainedDiscountList, resolvedDiscountList, _this$store$discount12, _this$store$discount13;
661
711
  return _regeneratorRuntime().wrap(function _callee6$(_context6) {
662
712
  while (1) switch (_context6.prev = _context6.next) {
663
713
  case 0:
@@ -686,6 +736,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
686
736
  return _context6.abrupt("return", {
687
737
  type: 'clientCalc',
688
738
  isAvailable: false,
739
+ isAccepted: false,
689
740
  discountList: this.getDiscountList(),
690
741
  scannedDiscountList: resultDiscountList,
691
742
  unavailableReason: UnavailableReason.Unknown
@@ -698,6 +749,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
698
749
  return _context6.abrupt("return", {
699
750
  type: 'server',
700
751
  isAvailable: false,
752
+ isAccepted: false,
701
753
  discountList: this.getDiscountList(),
702
754
  scannedDiscountList: resultDiscountList,
703
755
  unavailableReasonKey: unavailableReasonKey
@@ -725,6 +777,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
725
777
  return _context6.abrupt("return", {
726
778
  type: 'clientCalc',
727
779
  isAvailable: true,
780
+ isAccepted: true,
728
781
  discountList: this.getDiscountList(),
729
782
  scannedDiscountList: resultDiscountList
730
783
  });
@@ -743,24 +796,47 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
743
796
  }) || {
744
797
  isAvailable: false,
745
798
  discountList: this.getDiscountList()
746
- }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, unavailableReason = _ref13.unavailableReason;
747
- if (!(isAvailable && newDiscountList)) {
748
- _context6.next = 26;
799
+ }, isAvailable = _ref13.isAvailable, newDiscountList = _ref13.discountList, evaluatedDiscountList = _ref13.evaluatedDiscountList, unavailableReason = _ref13.unavailableReason;
800
+ shouldRetainForLater = !isAvailable && unavailableReason === UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
801
+ normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : undefined;
802
+ retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
803
+ resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
804
+ if (!(isAvailable && normalizedNewDiscountList)) {
805
+ _context6.next = 34;
749
806
  break;
750
807
  }
751
- (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 || _this$store$discount12.setDiscountList(newDiscountList);
808
+ _context6.next = 28;
809
+ return (_this$store$discount12 = this.store.discount) === null || _this$store$discount12 === void 0 ? void 0 : _this$store$discount12.setDiscountList(normalizedNewDiscountList);
810
+ case 28:
752
811
  this.applyDiscount();
753
- _context6.next = 26;
812
+ _context6.next = 31;
754
813
  return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
755
- case 26:
814
+ case 31:
815
+ resolvedDiscountList = this.getDiscountList();
816
+ _context6.next = 40;
817
+ break;
818
+ case 34:
819
+ if (!(shouldRetainForLater && retainedDiscountList)) {
820
+ _context6.next = 40;
821
+ break;
822
+ }
823
+ _context6.next = 37;
824
+ return (_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.setDiscountList(retainedDiscountList);
825
+ case 37:
826
+ _context6.next = 39;
827
+ return this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
828
+ case 39:
829
+ resolvedDiscountList = this.getDiscountList();
830
+ case 40:
756
831
  return _context6.abrupt("return", {
757
832
  type: 'clientCalc',
758
833
  isAvailable: isAvailable || false,
759
- discountList: newDiscountList || this.getDiscountList(),
834
+ isAccepted: Boolean(isAvailable || shouldRetainForLater),
835
+ discountList: resolvedDiscountList,
760
836
  scannedDiscountList: resultDiscountList,
761
837
  unavailableReason: unavailableReason
762
838
  });
763
- case 27:
839
+ case 41:
764
840
  case "end":
765
841
  return _context6.stop();
766
842
  }
@@ -774,7 +850,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
774
850
  }, {
775
851
  key: "applyDiscount",
776
852
  value: function applyDiscount(options) {
777
- var _this$store$discount13,
853
+ var _this$store$discount14,
778
854
  _this$store$summary2,
779
855
  _this2 = this;
780
856
  var tempOrder = this.store.tempOrder;
@@ -784,7 +860,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
784
860
  if (!tempOrder) return;
785
861
  this.syncLinkedBookingHoldersToProducts(tempOrder);
786
862
  delete tempOrder.discount_list;
787
- var discountList = ((_this$store$discount13 = this.store.discount) === null || _this$store$discount13 === void 0 ? void 0 : _this$store$discount13.getDiscountList()) || [];
863
+ var discountList = ((_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 ? void 0 : _this$store$discount14.getDiscountList()) || [];
788
864
  var shouldSkipDiscountCalculation = this.shouldSkipDiscountCalculation(tempOrder);
789
865
  if (shouldSkipDiscountCalculation) return;
790
866
  var rulesModule = this.store.rules;
@@ -816,9 +892,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
816
892
  }));
817
893
  }
818
894
  if (result !== null && result !== void 0 && result.discountList) {
819
- var _this$store$discount14;
895
+ var _this$store$discount15;
820
896
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
821
- (_this$store$discount14 = this.store.discount) === null || _this$store$discount14 === void 0 || _this$store$discount14.setDiscountList(result.discountList);
897
+ (_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 || _this$store$discount15.setDiscountList(result.discountList);
822
898
  }
823
899
  this.hasActiveCustomerBoundDiscount = (tempOrder.products || []).some(function (product) {
824
900
  return _this2.productHasCustomerBoundDiscount(product);
@@ -1197,7 +1273,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1197
1273
 
1198
1274
  /**
1199
1275
  * 控制 IndexedDB 草稿(saveDraft)是否写入。
1200
- * localStorage tempOrder 持久化已废弃,此方法仅影响 saveDraft。
1276
+ * 此开关仅影响 saveDraft;可选 sessionStorage 会话恢复由
1277
+ * enableSessionStoragePersist 独立控制。
1201
1278
  *
1202
1279
  * @example
1203
1280
  * order.setEnableTempOrderPersist(false); // BigSale 弹窗:跳过 ~1s 的 dbUpdate
@@ -1215,11 +1292,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1215
1292
  return this.draftPersistEnabled;
1216
1293
  }
1217
1294
 
1218
- /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
1295
+ /**
1296
+ * 在 UnifiedBookingSales 显式开启会话恢复时,将完整 tempOrder 写入
1297
+ * sessionStorage 的 cacheId 分桶。写入失败由 BaseModule 静默降级。
1298
+ */
1219
1299
  }, {
1220
1300
  key: "persistTempOrder",
1221
1301
  value: function persistTempOrder() {
1222
- // no-op: OrderModule 的刷新恢复不再依赖 localStorage。
1302
+ if (!this.sessionStoragePersistEnabled || !this.store.tempOrder) return;
1303
+ this.checkSaveCache({
1304
+ cacheId: this.cacheId,
1305
+ fatherModule: this.fatherModule,
1306
+ store: {
1307
+ tempOrder: this.store.tempOrder
1308
+ },
1309
+ cacheKey: ['tempOrder']
1310
+ });
1311
+ }
1312
+ }, {
1313
+ key: "consumeSessionStorageRestore",
1314
+ value: function consumeSessionStorageRestore() {
1315
+ var record = this.sessionStorageRestoreRecord;
1316
+ this.sessionStorageRestoreRecord = null;
1317
+ return record ? cloneDeep(record) : null;
1223
1318
  }
1224
1319
  }, {
1225
1320
  key: "notifyTempOrderChanged",
@@ -1517,19 +1612,44 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1517
1612
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1518
1613
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1519
1614
  }
1615
+ }, {
1616
+ key: "getPaymentNumberAppData",
1617
+ value: function getPaymentNumberAppData(key) {
1618
+ var _appPlugin$getData, _app$models, _app$models$getStore, _app$models$getStore$, _app$models$getStore$2;
1619
+ var appPlugin = this.appPlugin;
1620
+ if (!appPlugin) return undefined;
1621
+ var getData = (_appPlugin$getData = appPlugin.getData) === null || _appPlugin$getData === void 0 ? void 0 : _appPlugin$getData.call(appPlugin);
1622
+ if (typeof getData === 'function') return getData(key);
1623
+ var app = appPlugin.getApp();
1624
+ 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');
1625
+ return coreData === null || coreData === void 0 ? void 0 : coreData[key];
1626
+ }
1627
+ }, {
1628
+ key: "getPaymentNumberDevicePrefixSync",
1629
+ value: function getPaymentNumberDevicePrefixSync() {
1630
+ var _this7 = this;
1631
+ return resolvePaymentNumberDevicePrefixFromDeviceId(function (key) {
1632
+ return _this7.getPaymentNumberAppData(key);
1633
+ });
1634
+ }
1635
+ }, {
1636
+ key: "getPaymentNumberDevicePrefixAsync",
1637
+ value: function getPaymentNumberDevicePrefixAsync() {
1638
+ var _this8 = this;
1639
+ return resolvePaymentNumberDevicePrefix(function (key) {
1640
+ return _this8.getPaymentNumberAppData(key);
1641
+ });
1642
+ }
1520
1643
  }, {
1521
1644
  key: "normalizePaymentSource",
1522
1645
  value: function normalizePaymentSource(payment, options) {
1523
1646
  var _ref19, _paymentRecord$origin;
1524
1647
  var paymentRecord = payment;
1525
1648
  var metadata = paymentRecord.metadata && _typeof(paymentRecord.metadata) === 'object' ? _objectSpread({}, paymentRecord.metadata) : {};
1526
- if (!metadata.unique_payment_number) {
1527
- metadata.unique_payment_number = createUuidV4();
1528
- }
1529
- var normalized = _objectSpread(_objectSpread({}, paymentRecord), {}, {
1649
+ var normalized = ensureOrderPaymentNumber(_objectSpread(_objectSpread({}, paymentRecord), {}, {
1530
1650
  metadata: metadata,
1531
1651
  origin_amount: (_ref19 = (_paymentRecord$origin = paymentRecord.origin_amount) !== null && _paymentRecord$origin !== void 0 ? _paymentRecord$origin : paymentRecord.amount) !== null && _ref19 !== void 0 ? _ref19 : '0.00'
1532
- });
1652
+ }), (options === null || options === void 0 ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(), createUuidV4);
1533
1653
  if (paymentRecord.status !== undefined) {
1534
1654
  normalized.status = paymentRecord.status;
1535
1655
  } else if ((options === null || options === void 0 ? void 0 : options.defaultPaid) !== false) {
@@ -1647,16 +1767,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1647
1767
  }, {
1648
1768
  key: "calculatePaidPaymentSummary",
1649
1769
  value: function calculatePaidPaymentSummary(payments) {
1650
- var _this7 = this;
1770
+ var _this9 = this;
1651
1771
  return (payments || []).reduce(function (summary, payment) {
1652
1772
  var paymentRecord = payment;
1653
1773
  if (!isPaidPaymentRecord(paymentRecord)) return summary;
1654
1774
  return {
1655
1775
  customerPaidAmount: summary.customerPaidAmount.plus(paymentRecord.amount || 0),
1656
- orderPaidAmount: summary.orderPaidAmount.plus(_this7.calculatePaymentOrderAmount(paymentRecord)),
1657
- gapPaidAmount: summary.gapPaidAmount.plus(_this7.calculatePaymentGapAmount(paymentRecord)),
1658
- payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this7.calculatePaymentServiceFee(paymentRecord)),
1659
- roundingAmount: summary.roundingAmount.plus(_this7.calculatePaymentRoundingAmount(paymentRecord))
1776
+ orderPaidAmount: summary.orderPaidAmount.plus(_this9.calculatePaymentOrderAmount(paymentRecord)),
1777
+ gapPaidAmount: summary.gapPaidAmount.plus(_this9.calculatePaymentGapAmount(paymentRecord)),
1778
+ payServiceChargeAmount: summary.payServiceChargeAmount.plus(_this9.calculatePaymentServiceFee(paymentRecord)),
1779
+ roundingAmount: summary.roundingAmount.plus(_this9.calculatePaymentRoundingAmount(paymentRecord))
1660
1780
  };
1661
1781
  }, {
1662
1782
  customerPaidAmount: new Decimal(0),
@@ -1858,15 +1978,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1858
1978
  }, {
1859
1979
  key: "normalizeFingerprintValue",
1860
1980
  value: function normalizeFingerprintValue(value) {
1861
- var _this8 = this;
1981
+ var _this10 = this;
1862
1982
  if (Array.isArray(value)) {
1863
1983
  return value.map(function (item) {
1864
- return _this8.normalizeFingerprintValue(item);
1984
+ return _this10.normalizeFingerprintValue(item);
1865
1985
  });
1866
1986
  }
1867
1987
  if (!value || _typeof(value) !== 'object') return value !== null && value !== void 0 ? value : '';
1868
1988
  return Object.keys(value).sort().reduce(function (result, key) {
1869
- result[key] = _this8.normalizeFingerprintValue(value[key]);
1989
+ result[key] = _this10.normalizeFingerprintValue(value[key]);
1870
1990
  return result;
1871
1991
  }, {});
1872
1992
  }
@@ -1881,7 +2001,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1881
2001
  _sku$barcode,
1882
2002
  _ref20,
1883
2003
  _sku$variant_id,
1884
- _this9 = this;
2004
+ _this11 = this;
1885
2005
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1886
2006
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1887
2007
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1915,7 +2035,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1915
2035
  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,
1916
2036
  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,
1917
2037
  num: Number((_option$num = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num !== void 0 ? _option$num : 1) || 1,
1918
- 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)
2038
+ 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)
1919
2039
  };
1920
2040
  })
1921
2041
  }),
@@ -1925,8 +2045,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1925
2045
  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,
1926
2046
  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,
1927
2047
  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),
1928
- price: _this9.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
1929
- bundle_selling_price: _this9.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
2048
+ price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.price),
2049
+ bundle_selling_price: _this11.normalizeFingerprintMoney(bundle === null || bundle === void 0 ? void 0 : bundle.bundle_selling_price),
1930
2050
  price_type: (_bundle$price_type = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type !== void 0 ? _bundle$price_type : '',
1931
2051
  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 : ''
1932
2052
  };
@@ -1936,7 +2056,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1936
2056
  return {
1937
2057
  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 : '',
1938
2058
  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,
1939
- amount: _this9.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2059
+ amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
1940
2060
  };
1941
2061
  }))
1942
2062
  };
@@ -1944,9 +2064,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1944
2064
  }, {
1945
2065
  key: "buildOrderProductsFingerprint",
1946
2066
  value: function buildOrderProductsFingerprint(products) {
1947
- var _this10 = this;
2067
+ var _this12 = this;
1948
2068
  var items = (products || []).map(function (product) {
1949
- return _this10.buildProductFingerprintItem(product);
2069
+ return _this12.buildProductFingerprintItem(product);
1950
2070
  });
1951
2071
  items.sort(function (left, right) {
1952
2072
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -1968,7 +2088,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1968
2088
  _sku$barcode2,
1969
2089
  _ref30,
1970
2090
  _sku$variant_id2,
1971
- _this11 = this;
2091
+ _this13 = this;
1972
2092
  var sku = (product === null || product === void 0 ? void 0 : product.product_sku) || {};
1973
2093
  var metadata = (product === null || product === void 0 ? void 0 : product.metadata) || {};
1974
2094
  var discountTypes = ((product === null || product === void 0 ? void 0 : product.discount_list) || []).map(function (discount) {
@@ -1999,7 +2119,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1999
2119
  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,
2000
2120
  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,
2001
2121
  num: Number((_option$num2 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num2 !== void 0 ? _option$num2 : 1) || 1,
2002
- 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)
2122
+ 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)
2003
2123
  };
2004
2124
  })
2005
2125
  }),
@@ -2013,14 +2133,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2013
2133
  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),
2014
2134
  price_type: (_bundle$price_type2 = bundle === null || bundle === void 0 ? void 0 : bundle.price_type) !== null && _bundle$price_type2 !== void 0 ? _bundle$price_type2 : '',
2015
2135
  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 : '',
2016
- option: _this11.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2136
+ option: _this13.normalizeFingerprintValue(((bundle === null || bundle === void 0 ? void 0 : bundle.option) || []).map(function (option) {
2017
2137
  var _ref38, _option$id3, _option$option_group_5, _ref39, _option$option_group_6, _option$num3, _option$add_price3;
2018
2138
  return {
2019
2139
  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,
2020
2140
  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,
2021
2141
  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,
2022
2142
  num: Number((_option$num3 = option === null || option === void 0 ? void 0 : option.num) !== null && _option$num3 !== void 0 ? _option$num3 : 1) || 1,
2023
- 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)
2143
+ 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)
2024
2144
  };
2025
2145
  }))
2026
2146
  };
@@ -2030,7 +2150,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2030
2150
  return {
2031
2151
  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 : '',
2032
2152
  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,
2033
- amount: _this11.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2153
+ amount: _this13.normalizeFingerprintMoney(discount === null || discount === void 0 ? void 0 : discount.amount)
2034
2154
  };
2035
2155
  }))
2036
2156
  };
@@ -2038,9 +2158,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2038
2158
  }, {
2039
2159
  key: "buildOrderProductsStructuralFingerprint",
2040
2160
  value: function buildOrderProductsStructuralFingerprint(products) {
2041
- var _this12 = this;
2161
+ var _this14 = this;
2042
2162
  var items = (products || []).map(function (product) {
2043
- return _this12.buildProductStructuralFingerprintItem(product);
2163
+ return _this14.buildProductStructuralFingerprintItem(product);
2044
2164
  });
2045
2165
  items.sort(function (left, right) {
2046
2166
  return JSON.stringify(left).localeCompare(JSON.stringify(right));
@@ -2257,16 +2377,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2257
2377
  }, {
2258
2378
  key: "restoreOrder",
2259
2379
  value: function restoreOrder() {
2260
- var _this$store$discount15, _this$store$discount16;
2380
+ var _this$store$discount16, _this$store$discount17;
2261
2381
  this.logInfo('restoreOrder start', {});
2382
+ this.sessionStorageRestoreRecord = null;
2262
2383
  var freshTempOrder = this.createDefaultTempOrderInstance();
2263
2384
  this.ensureExternalSaleNumber(freshTempOrder);
2264
2385
  this.store.tempOrder = freshTempOrder;
2265
2386
  this.store.summary = createEmptySummary();
2266
2387
  this.store.lastOrderInfo = undefined;
2267
2388
  this.store.syncState = undefined;
2268
- void ((_this$store$discount15 = this.store.discount) === null || _this$store$discount15 === void 0 ? void 0 : _this$store$discount15.setOriginalDiscountList([]));
2269
- void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setDiscountList([]));
2389
+ void ((_this$store$discount16 = this.store.discount) === null || _this$store$discount16 === void 0 ? void 0 : _this$store$discount16.setOriginalDiscountList([]));
2390
+ void ((_this$store$discount17 = this.store.discount) === null || _this$store$discount17 === void 0 ? void 0 : _this$store$discount17.setDiscountList([]));
2270
2391
  this.persistTempOrder();
2271
2392
  return freshTempOrder;
2272
2393
  }
@@ -2289,36 +2410,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2289
2410
  }
2290
2411
  throw new Error('无效的 tempOrder 数据');
2291
2412
  case 2:
2413
+ this.sessionStorageRestoreRecord = null;
2292
2414
  nextTempOrder = this.normalizeTempOrderForRuntime(cloneDeep(tempOrder), {
2293
2415
  ensureIdentity: false
2294
2416
  });
2295
2417
  this.store.tempOrder = nextTempOrder;
2296
2418
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
2297
- _context12.next = 9;
2419
+ _context12.next = 10;
2298
2420
  break;
2299
2421
  }
2300
- _context12.next = 7;
2422
+ _context12.next = 8;
2301
2423
  return this.recalculateSummary({
2302
2424
  createIfMissing: false
2303
2425
  });
2304
- case 7:
2305
- _context12.next = 10;
2426
+ case 8:
2427
+ _context12.next = 11;
2306
2428
  break;
2307
- case 9:
2308
- this.store.summary = createEmptySummary();
2309
2429
  case 10:
2430
+ this.store.summary = createEmptySummary();
2431
+ case 11:
2310
2432
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
2311
2433
  this.persistTempOrder();
2312
2434
  }
2313
2435
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
2314
- _context12.next = 14;
2436
+ _context12.next = 15;
2315
2437
  break;
2316
2438
  }
2317
- _context12.next = 14;
2439
+ _context12.next = 15;
2318
2440
  return this.saveDraft();
2319
- case 14:
2320
- return _context12.abrupt("return", nextTempOrder);
2321
2441
  case 15:
2442
+ return _context12.abrupt("return", nextTempOrder);
2443
+ case 16:
2322
2444
  case "end":
2323
2445
  return _context12.stop();
2324
2446
  }
@@ -2468,9 +2590,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2468
2590
  }, {
2469
2591
  key: "sanitizeTempOrderProducts",
2470
2592
  value: function sanitizeTempOrderProducts(tempOrder) {
2471
- var _this13 = this;
2593
+ var _this15 = this;
2472
2594
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2473
- return _this13.sanitizeOrderProductForTempOrder(product);
2595
+ return _this15.sanitizeOrderProductForTempOrder(product);
2474
2596
  });
2475
2597
  }
2476
2598
  }, {
@@ -2573,7 +2695,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2573
2695
  }, {
2574
2696
  key: "syncLinkedBookingHoldersToProducts",
2575
2697
  value: function syncLinkedBookingHoldersToProducts(tempOrder) {
2576
- var _this14 = this;
2698
+ var _this16 = this;
2577
2699
  var bookings = tempOrder.bookings || [];
2578
2700
  var products = tempOrder.products || [];
2579
2701
  if (!bookings.length || !products.length) return;
@@ -2598,7 +2720,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2598
2720
  var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2599
2721
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2600
2722
  if (linkedBooking) {
2601
- _this14.setProductHolderFromBooking(product, linkedBooking);
2723
+ _this16.setProductHolderFromBooking(product, linkedBooking);
2602
2724
  }
2603
2725
  });
2604
2726
  }
@@ -2726,9 +2848,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2726
2848
  }, {
2727
2849
  key: "findBookingIndexByUniqueIdentificationNumber",
2728
2850
  value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
2729
- var _this15 = this;
2851
+ var _this17 = this;
2730
2852
  return (tempOrder.bookings || []).findIndex(function (booking) {
2731
- return _this15.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2853
+ return _this17.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
2732
2854
  });
2733
2855
  }
2734
2856
  }, {
@@ -2736,12 +2858,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2736
2858
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2737
2859
  var _product$metadata7,
2738
2860
  _product$metadata8,
2739
- _this16 = this;
2861
+ _this18 = this;
2740
2862
  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);
2741
2863
  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);
2742
2864
  if (!productUid && !bookingUid) return;
2743
2865
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2744
- var currentBookingUid = _this16.getBookingUniqueIdentificationNumber(booking);
2866
+ var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
2745
2867
  if (bookingUid && currentBookingUid === String(bookingUid)) return false;
2746
2868
  if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
2747
2869
  return true;
@@ -3074,35 +3196,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3074
3196
  }, {
3075
3197
  key: "productHasCustomerBoundDiscount",
3076
3198
  value: function productHasCustomerBoundDiscount(product) {
3077
- var _this17 = this;
3199
+ var _this19 = this;
3078
3200
  if (((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (discount) {
3079
- return _this17.isCustomerBoundDiscount(discount);
3201
+ return _this19.isCustomerBoundDiscount(discount);
3080
3202
  })) {
3081
3203
  return true;
3082
3204
  }
3083
3205
  return ((product === null || product === void 0 ? void 0 : product.product_bundle) || []).some(function (bundle) {
3084
3206
  return ((bundle === null || bundle === void 0 ? void 0 : bundle.discount_list) || []).some(function (discount) {
3085
- return _this17.isCustomerBoundDiscount(discount);
3207
+ return _this19.isCustomerBoundDiscount(discount);
3086
3208
  });
3087
3209
  });
3088
3210
  }
3089
3211
  }, {
3090
3212
  key: "shouldSkipDiscountCalculation",
3091
3213
  value: function shouldSkipDiscountCalculation(tempOrder) {
3092
- var _this$store$discount17,
3093
- _this$store$discount18,
3094
- _this18 = this;
3214
+ var _this$store$discount18,
3215
+ _this$store$discount19,
3216
+ _this20 = this;
3095
3217
  if (this.hasActiveCustomerBoundDiscount) return false;
3096
- 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)) || [];
3218
+ 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)) || [];
3097
3219
  if (discountList.length > 0) return false;
3098
3220
  return !(tempOrder.products || []).some(function (product) {
3099
- return _this18.productHasCustomerBoundDiscount(product);
3221
+ return _this20.productHasCustomerBoundDiscount(product);
3100
3222
  });
3101
3223
  }
3102
3224
  }, {
3103
3225
  key: "clearCustomerBoundDiscounts",
3104
3226
  value: function clearCustomerBoundDiscounts(tempOrder) {
3105
- var _this19 = this,
3227
+ var _this21 = this,
3106
3228
  _discountModule$getDi,
3107
3229
  _discountModule$getOr,
3108
3230
  _discountModule$setDi,
@@ -3111,7 +3233,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3111
3233
  var filterDiscountList = function filterDiscountList(discountList) {
3112
3234
  if (!Array.isArray(discountList)) return [];
3113
3235
  return discountList.filter(function (discount) {
3114
- var shouldRemove = _this19.isCustomerBoundDiscount(discount);
3236
+ var shouldRemove = _this21.isCustomerBoundDiscount(discount);
3115
3237
  if (shouldRemove) didRemoveCustomerBoundDiscount = true;
3116
3238
  return !shouldRemove;
3117
3239
  });
@@ -3138,12 +3260,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3138
3260
  var currentDiscounts = ((_discountModule$getDi = discountModule.getDiscountList) === null || _discountModule$getDi === void 0 ? void 0 : _discountModule$getDi.call(discountModule)) || [];
3139
3261
  var currentOriginalDiscounts = ((_discountModule$getOr = discountModule.getOriginalDiscountList) === null || _discountModule$getOr === void 0 ? void 0 : _discountModule$getOr.call(discountModule)) || [];
3140
3262
  var nextDiscounts = currentDiscounts.filter(function (discount) {
3141
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3142
- return !_this19.isCustomerBoundDiscount(discount);
3263
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3264
+ return !_this21.isCustomerBoundDiscount(discount);
3143
3265
  });
3144
3266
  var nextOriginalDiscounts = currentOriginalDiscounts.filter(function (discount) {
3145
- if (_this19.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3146
- return !_this19.isCustomerBoundDiscount(discount);
3267
+ if (_this21.shouldKeepCustomerBoundDiscountAfterCustomerChange(discount)) return true;
3268
+ return !_this21.isCustomerBoundDiscount(discount);
3147
3269
  });
3148
3270
  void ((_discountModule$setDi = discountModule.setDiscountList) === null || _discountModule$setDi === void 0 ? void 0 : _discountModule$setDi.call(discountModule, nextDiscounts));
3149
3271
  void ((_discountModule$setOr = discountModule.setOriginalDiscountList) === null || _discountModule$setOr === void 0 ? void 0 : _discountModule$setOr.call(discountModule, nextOriginalDiscounts));
@@ -3297,23 +3419,71 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3297
3419
  * 用一组支付来源覆盖当前订单支付项。
3298
3420
  *
3299
3421
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
3300
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
3422
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
3301
3423
  * isSynced 等运行态字段不会进入 tempOrder.payments。
3302
3424
  */
3303
3425
  }, {
3304
3426
  key: "setOrderPayments",
3305
3427
  value: function setOrderPayments(payments) {
3428
+ var _this22 = this;
3306
3429
  var tempOrder = this.ensureTempOrder();
3307
- tempOrder.payments = mapPaymentItemsToOrderPayments(payments);
3430
+ tempOrder.payments = mapPaymentItemsToOrderPayments((payments || []).map(function (payment) {
3431
+ return _this22.normalizePaymentSource(payment, {
3432
+ defaultPaid: false
3433
+ });
3434
+ }));
3308
3435
  this.persistTempOrder();
3309
3436
  return tempOrder.payments;
3310
3437
  }
3311
3438
 
3312
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
3439
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
3313
3440
  }, {
3314
3441
  key: "addOrderPayment",
3315
3442
  value: function addOrderPayment(payment) {
3316
- var _this20 = this;
3443
+ var hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3444
+ return this.addOrderPaymentWithDevicePrefix(payment, hasPaymentNumber ? 'LOCAL' : this.getPaymentNumberDevicePrefixSync());
3445
+ }
3446
+
3447
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
3448
+ }, {
3449
+ key: "addOrderPaymentAsync",
3450
+ value: (function () {
3451
+ var _addOrderPaymentAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(payment) {
3452
+ var hasPaymentNumber, devicePrefix;
3453
+ return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3454
+ while (1) switch (_context17.prev = _context17.next) {
3455
+ case 0:
3456
+ hasPaymentNumber = String(payment.payment_number || '').trim() !== '';
3457
+ if (!hasPaymentNumber) {
3458
+ _context17.next = 5;
3459
+ break;
3460
+ }
3461
+ _context17.t0 = 'LOCAL';
3462
+ _context17.next = 8;
3463
+ break;
3464
+ case 5:
3465
+ _context17.next = 7;
3466
+ return this.getPaymentNumberDevicePrefixAsync();
3467
+ case 7:
3468
+ _context17.t0 = _context17.sent;
3469
+ case 8:
3470
+ devicePrefix = _context17.t0;
3471
+ return _context17.abrupt("return", this.addOrderPaymentWithDevicePrefix(payment, devicePrefix));
3472
+ case 10:
3473
+ case "end":
3474
+ return _context17.stop();
3475
+ }
3476
+ }, _callee15, this);
3477
+ }));
3478
+ function addOrderPaymentAsync(_x14) {
3479
+ return _addOrderPaymentAsync.apply(this, arguments);
3480
+ }
3481
+ return addOrderPaymentAsync;
3482
+ }())
3483
+ }, {
3484
+ key: "addOrderPaymentWithDevicePrefix",
3485
+ value: function addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
3486
+ var _this23 = this;
3317
3487
  this.logInfo('addOrderPayment', {
3318
3488
  payment: payment
3319
3489
  });
@@ -3323,14 +3493,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3323
3493
  type: orderPaymentType,
3324
3494
  order_payment_type: orderPaymentType
3325
3495
  }), {
3326
- defaultPaid: true
3496
+ defaultPaid: true,
3497
+ devicePrefix: devicePrefix
3327
3498
  })]);
3328
3499
  tempOrder.payments = [].concat(_toConsumableArray(tempOrder.payments || []), _toConsumableArray(mapped));
3329
3500
  this.persistTempOrder();
3330
3501
  void this.recalculateSummary({
3331
3502
  createIfMissing: true
3332
3503
  }).catch(function (error) {
3333
- _this20.logError('recalculate summary after addOrderPayment failed', {
3504
+ _this23.logError('recalculate summary after addOrderPayment failed', {
3334
3505
  error: error instanceof Error ? error.message : String(error)
3335
3506
  });
3336
3507
  });
@@ -3338,49 +3509,80 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3338
3509
  }
3339
3510
 
3340
3511
  /**
3341
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
3342
- *
3343
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
3344
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
3512
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
3513
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
3345
3514
  */
3346
3515
  }, {
3347
3516
  key: "updateOrderPayment",
3348
- value: function updateOrderPayment(paymentIdentity, updates) {
3349
- var tempOrder = this.ensureTempOrder();
3350
- var identity = String(paymentIdentity);
3351
- tempOrder.payments = (tempOrder.payments || []).map(function (payment) {
3352
- var _payment$metadata;
3353
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata = payment.metadata) === null || _payment$metadata === void 0 ? void 0 : _payment$metadata.unique_payment_number;
3354
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3355
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3356
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3357
- var matched = [uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3358
- return value !== undefined && String(value) === identity;
3359
- });
3360
- if (!matched) return payment;
3361
- return _objectSpread(_objectSpread(_objectSpread({}, payment), updates), {}, {
3362
- metadata: _objectSpread(_objectSpread({}, payment.metadata || {}), updates.metadata || {})
3363
- });
3364
- });
3365
- this.persistTempOrder();
3366
- return tempOrder.payments;
3367
- }
3368
-
3369
- /** 从当前订单支付项中移除指定支付项。 */
3517
+ value: (function () {
3518
+ var _updateOrderPayment = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(paymentIdentity, updates) {
3519
+ var options,
3520
+ tempOrder,
3521
+ identity,
3522
+ matchMode,
3523
+ matchedPayment,
3524
+ updatedPayment,
3525
+ summary,
3526
+ payments,
3527
+ _args18 = arguments;
3528
+ return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3529
+ while (1) switch (_context18.prev = _context18.next) {
3530
+ case 0:
3531
+ options = _args18.length > 2 && _args18[2] !== undefined ? _args18[2] : {};
3532
+ tempOrder = this.ensureTempOrder();
3533
+ identity = String(paymentIdentity);
3534
+ matchMode = options.matchBy === 'compat' || options.matchBy === 'legacy' ? 'compat' : 'payment_number';
3535
+ matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, matchMode);
3536
+ if (matchedPayment) {
3537
+ _context18.next = 7;
3538
+ break;
3539
+ }
3540
+ throw new Error("\u672A\u627E\u5230\u652F\u4ED8\u9879: ".concat(identity));
3541
+ case 7:
3542
+ updatedPayment = null;
3543
+ tempOrder.payments = (tempOrder.payments || []).map(function (payment, index) {
3544
+ if (index !== matchedPayment.index) return payment;
3545
+ var nextPayment = mergeOrderPaymentRecord(payment, _objectSpread(_objectSpread({}, updates), {}, {
3546
+ updated_at: updates.updated_at || dayjs().format('YYYY-MM-DD HH:mm:ss')
3547
+ }));
3548
+ updatedPayment = nextPayment;
3549
+ return nextPayment;
3550
+ });
3551
+ this.persistTempOrder();
3552
+ _context18.next = 12;
3553
+ return this.recalculateSummary({
3554
+ createIfMissing: true
3555
+ });
3556
+ case 12:
3557
+ summary = _context18.sent;
3558
+ this.persistTempOrder();
3559
+ payments = tempOrder.payments;
3560
+ return _context18.abrupt("return", {
3561
+ updated: true,
3562
+ payment: payments[matchedPayment.index] || updatedPayment,
3563
+ payments: payments,
3564
+ summary: summary
3565
+ });
3566
+ case 16:
3567
+ case "end":
3568
+ return _context18.stop();
3569
+ }
3570
+ }, _callee16, this);
3571
+ }));
3572
+ function updateOrderPayment(_x15, _x16) {
3573
+ return _updateOrderPayment.apply(this, arguments);
3574
+ }
3575
+ return updateOrderPayment;
3576
+ }() /** 从当前订单支付项中移除指定支付项。 */)
3370
3577
  }, {
3371
3578
  key: "deleteOrderPayment",
3372
3579
  value: function deleteOrderPayment(paymentIdentity) {
3373
3580
  var tempOrder = this.ensureTempOrder();
3374
3581
  var identity = String(paymentIdentity);
3375
- tempOrder.payments = (tempOrder.payments || []).filter(function (payment) {
3376
- var _payment$metadata2;
3377
- var uniquePaymentNumber = payment === null || payment === void 0 || (_payment$metadata2 = payment.metadata) === null || _payment$metadata2 === void 0 ? void 0 : _payment$metadata2.unique_payment_number;
3378
- var orderPaymentId = payment === null || payment === void 0 ? void 0 : payment.order_payment_id;
3379
- var customPaymentId = payment === null || payment === void 0 ? void 0 : payment.custom_payment_id;
3380
- var uuid = payment === null || payment === void 0 ? void 0 : payment.uuid;
3381
- return ![uniquePaymentNumber, orderPaymentId, customPaymentId, uuid].some(function (value) {
3382
- return value !== undefined && String(value) === identity;
3383
- });
3582
+ var matchedPayment = resolveOrderPaymentIdentity(tempOrder.payments || [], identity, 'compat');
3583
+ if (!matchedPayment) return tempOrder.payments;
3584
+ tempOrder.payments = (tempOrder.payments || []).filter(function (_, index) {
3585
+ return index !== matchedPayment.index;
3384
3586
  });
3385
3587
  this.persistTempOrder();
3386
3588
  return tempOrder.payments;
@@ -3412,7 +3614,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3412
3614
  }, {
3413
3615
  key: "applyPaymentLifecycleChange",
3414
3616
  value: function applyPaymentLifecycleChange(tempOrder, options) {
3415
- var _this21 = this;
3617
+ var _this24 = this;
3416
3618
  this.updateTempOrderPaymentStatus(tempOrder);
3417
3619
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
3418
3620
  this.persistTempOrder();
@@ -3422,7 +3624,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3422
3624
  void this.recalculateSummary({
3423
3625
  createIfMissing: true
3424
3626
  }).catch(function (error) {
3425
- _this21.logError("recalculate summary after ".concat(logContext, " failed"), {
3627
+ _this24.logError("recalculate summary after ".concat(logContext, " failed"), {
3426
3628
  error: error instanceof Error ? error.message : String(error)
3427
3629
  });
3428
3630
  });
@@ -3466,7 +3668,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3466
3668
  }, {
3467
3669
  key: "updateVoucherOrderPayments",
3468
3670
  value: function updateVoucherOrderPayments(payments, options) {
3469
- var _this22 = this;
3671
+ var _this25 = this;
3470
3672
  var tempOrder = this.ensureTempOrder();
3471
3673
  var isOrderPaymentType = function isOrderPaymentType(value) {
3472
3674
  return value === 'normal' || value === 'deposit';
@@ -3501,8 +3703,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3501
3703
  });
3502
3704
  };
3503
3705
  var mappedVouchers = mapPaymentItemsToOrderPayments(payments.map(function (payment) {
3504
- return _this22.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3505
- defaultPaid: false
3706
+ return _this25.normalizePaymentSource(normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)), {
3707
+ defaultPaid: false,
3708
+ devicePrefix: options === null || options === void 0 ? void 0 : options.devicePrefix
3506
3709
  });
3507
3710
  })).filter(function (payment) {
3508
3711
  return isVoucherPaymentRecord(payment);
@@ -3528,14 +3731,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3528
3731
  }).map(function (payment) {
3529
3732
  return String(payment.order_payment_id);
3530
3733
  }));
3531
- var committedVoucherIds = new Set(committedVoucherPayments.map(function (payment) {
3532
- return String(payment.voucher_id);
3734
+ var committedVoucherLifecycleKeys = new Set(committedVoucherPayments.map(function (payment) {
3735
+ return getVoucherPaymentLifecycleKey(payment);
3736
+ }).filter(function (key) {
3737
+ return key !== null;
3533
3738
  }));
3534
3739
  var replaceableVouchers = mappedVouchers.filter(function (payment) {
3535
3740
  if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
3536
3741
  return false;
3537
3742
  }
3538
- if (payment.voucher_id !== undefined && committedVoucherIds.has(String(payment.voucher_id))) {
3743
+ var lifecycleKey = getVoucherPaymentLifecycleKey(payment);
3744
+ if (lifecycleKey && committedVoucherLifecycleKeys.has(lifecycleKey)) {
3539
3745
  return false;
3540
3746
  }
3541
3747
  return true;
@@ -3550,54 +3756,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3550
3756
  void this.recalculateSummary({
3551
3757
  createIfMissing: true
3552
3758
  }).catch(function (error) {
3553
- _this22.logError('recalculate summary after updateVoucherOrderPayments failed', {
3759
+ _this25.logError('recalculate summary after updateVoucherOrderPayments failed', {
3554
3760
  error: error instanceof Error ? error.message : String(error)
3555
3761
  });
3556
3762
  });
3557
3763
  return tempOrder.payments;
3558
3764
  }
3765
+ }, {
3766
+ key: "updateVoucherOrderPaymentsAsync",
3767
+ value: function () {
3768
+ var _updateVoucherOrderPaymentsAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(payments, options) {
3769
+ var needsPaymentNumber, devicePrefix;
3770
+ return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3771
+ while (1) switch (_context19.prev = _context19.next) {
3772
+ case 0:
3773
+ needsPaymentNumber = (payments || []).some(function (payment) {
3774
+ return String(payment.payment_number || '').trim() === '';
3775
+ });
3776
+ if (!needsPaymentNumber) {
3777
+ _context19.next = 7;
3778
+ break;
3779
+ }
3780
+ _context19.next = 4;
3781
+ return this.getPaymentNumberDevicePrefixAsync();
3782
+ case 4:
3783
+ _context19.t0 = _context19.sent;
3784
+ _context19.next = 8;
3785
+ break;
3786
+ case 7:
3787
+ _context19.t0 = 'LOCAL';
3788
+ case 8:
3789
+ devicePrefix = _context19.t0;
3790
+ return _context19.abrupt("return", this.updateVoucherOrderPayments(payments, _objectSpread(_objectSpread({}, options), {}, {
3791
+ devicePrefix: devicePrefix
3792
+ })));
3793
+ case 10:
3794
+ case "end":
3795
+ return _context19.stop();
3796
+ }
3797
+ }, _callee17, this);
3798
+ }));
3799
+ function updateVoucherOrderPaymentsAsync(_x17, _x18) {
3800
+ return _updateVoucherOrderPaymentsAsync.apply(this, arguments);
3801
+ }
3802
+ return updateVoucherOrderPaymentsAsync;
3803
+ }()
3559
3804
  }, {
3560
3805
  key: "shouldMergeProductToOrder",
3561
3806
  value: function () {
3562
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(params) {
3807
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3563
3808
  var _this$orderHooks;
3564
3809
  var onBeforeMergeProductToOrder, result;
3565
- return _regeneratorRuntime().wrap(function _callee15$(_context17) {
3566
- while (1) switch (_context17.prev = _context17.next) {
3810
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3811
+ while (1) switch (_context20.prev = _context20.next) {
3567
3812
  case 0:
3568
3813
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3569
3814
  if (onBeforeMergeProductToOrder) {
3570
- _context17.next = 3;
3815
+ _context20.next = 3;
3571
3816
  break;
3572
3817
  }
3573
- return _context17.abrupt("return", true);
3818
+ return _context20.abrupt("return", true);
3574
3819
  case 3:
3575
- _context17.next = 5;
3820
+ _context20.next = 5;
3576
3821
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3577
3822
  defaultShouldMerge: true
3578
3823
  }));
3579
3824
  case 5:
3580
- result = _context17.sent;
3825
+ result = _context20.sent;
3581
3826
  if (!(typeof result === 'boolean')) {
3582
- _context17.next = 8;
3827
+ _context20.next = 8;
3583
3828
  break;
3584
3829
  }
3585
- return _context17.abrupt("return", result);
3830
+ return _context20.abrupt("return", result);
3586
3831
  case 8:
3587
3832
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3588
- _context17.next = 10;
3833
+ _context20.next = 10;
3589
3834
  break;
3590
3835
  }
3591
- return _context17.abrupt("return", result.shouldMerge);
3836
+ return _context20.abrupt("return", result.shouldMerge);
3592
3837
  case 10:
3593
- return _context17.abrupt("return", true);
3838
+ return _context20.abrupt("return", true);
3594
3839
  case 11:
3595
3840
  case "end":
3596
- return _context17.stop();
3841
+ return _context20.stop();
3597
3842
  }
3598
- }, _callee15, this);
3843
+ }, _callee18, this);
3599
3844
  }));
3600
- function shouldMergeProductToOrder(_x14) {
3845
+ function shouldMergeProductToOrder(_x19) {
3601
3846
  return _shouldMergeProductToOrder.apply(this, arguments);
3602
3847
  }
3603
3848
  return shouldMergeProductToOrder;
@@ -3633,30 +3878,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3633
3878
  }, {
3634
3879
  key: "finalizeProductOrderMutation",
3635
3880
  value: function () {
3636
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(tempOrder, options) {
3637
- return _regeneratorRuntime().wrap(function _callee16$(_context18) {
3638
- while (1) switch (_context18.prev = _context18.next) {
3881
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3882
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3883
+ while (1) switch (_context21.prev = _context21.next) {
3639
3884
  case 0:
3640
3885
  this.syncTempOrderHolderFromBookings(tempOrder);
3641
3886
  if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3642
- _context18.next = 4;
3887
+ _context21.next = 4;
3643
3888
  break;
3644
3889
  }
3645
- _context18.next = 4;
3890
+ _context21.next = 4;
3646
3891
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3647
3892
  case 4:
3648
3893
  if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3649
- _context18.next = 7;
3894
+ _context21.next = 7;
3650
3895
  break;
3651
3896
  }
3652
- _context18.next = 7;
3897
+ _context21.next = 7;
3653
3898
  return this.applyPromotion();
3654
3899
  case 7:
3655
3900
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
3656
3901
  this.applyDiscount();
3657
3902
  }
3658
3903
  this.sanitizeTempOrderProducts(tempOrder);
3659
- _context18.next = 11;
3904
+ _context21.next = 11;
3660
3905
  return this.recalculateSummary({
3661
3906
  createIfMissing: true
3662
3907
  });
@@ -3664,11 +3909,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3664
3909
  this.persistTempOrder();
3665
3910
  case 12:
3666
3911
  case "end":
3667
- return _context18.stop();
3912
+ return _context21.stop();
3668
3913
  }
3669
- }, _callee16, this);
3914
+ }, _callee19, this);
3670
3915
  }));
3671
- function finalizeProductOrderMutation(_x15, _x16) {
3916
+ function finalizeProductOrderMutation(_x20, _x21) {
3672
3917
  return _finalizeProductOrderMutation.apply(this, arguments);
3673
3918
  }
3674
3919
  return finalizeProductOrderMutation;
@@ -3683,13 +3928,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3683
3928
  }, {
3684
3929
  key: "appendProductLineToTempOrder",
3685
3930
  value: (function () {
3686
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(tempOrder, product, booking) {
3931
+ var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking) {
3687
3932
  var _booking_uid,
3688
3933
  _metadata,
3689
- _this23 = this;
3934
+ _this26 = this;
3690
3935
  var linked, productToAdd, incomingFingerprint, normalizedIncoming, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList;
3691
- return _regeneratorRuntime().wrap(function _callee17$(_context19) {
3692
- while (1) switch (_context19.prev = _context19.next) {
3936
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3937
+ while (1) switch (_context22.prev = _context22.next) {
3693
3938
  case 0:
3694
3939
  linked = booking ? this.createLinkedProductAndBooking({
3695
3940
  product: product,
@@ -3712,8 +3957,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3712
3957
  shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid;
3713
3958
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3714
3959
  var _item$metadata3;
3715
- if (_this23.hasGoodPassDiscount(item)) return false;
3716
- if (_this23.hasOrderProductLineNote(item)) return false;
3960
+ if (_this26.hasGoodPassDiscount(item)) return false;
3961
+ if (_this26.hasOrderProductLineNote(item)) return false;
3717
3962
  if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3718
3963
  if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
3719
3964
  if (item.product_id !== productToAdd.product_id) return false;
@@ -3724,10 +3969,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3724
3969
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3725
3970
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3726
3971
  if (!matchedProduct) {
3727
- _context19.next = 20;
3972
+ _context22.next = 20;
3728
3973
  break;
3729
3974
  }
3730
- _context19.next = 17;
3975
+ _context22.next = 17;
3731
3976
  return this.shouldMergeProductToOrder({
3732
3977
  incomingProduct: productToAdd,
3733
3978
  normalizedIncoming: normalizedIncoming,
@@ -3739,13 +3984,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3739
3984
  booking: booking
3740
3985
  });
3741
3986
  case 17:
3742
- _context19.t0 = _context19.sent;
3743
- _context19.next = 21;
3987
+ _context22.t0 = _context22.sent;
3988
+ _context22.next = 21;
3744
3989
  break;
3745
3990
  case 20:
3746
- _context19.t0 = false;
3991
+ _context22.t0 = false;
3747
3992
  case 21:
3748
- shouldMerge = _context19.t0;
3993
+ shouldMerge = _context22.t0;
3749
3994
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3750
3995
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
3751
3996
  if (linked) {
@@ -3799,11 +4044,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3799
4044
  }
3800
4045
  case 24:
3801
4046
  case "end":
3802
- return _context19.stop();
4047
+ return _context22.stop();
3803
4048
  }
3804
- }, _callee17, this);
4049
+ }, _callee20, this);
3805
4050
  }));
3806
- function appendProductLineToTempOrder(_x17, _x18, _x19) {
4051
+ function appendProductLineToTempOrder(_x22, _x23, _x24) {
3807
4052
  return _appendProductLineToTempOrder.apply(this, arguments);
3808
4053
  }
3809
4054
  return appendProductLineToTempOrder;
@@ -3819,61 +4064,61 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3819
4064
  }, {
3820
4065
  key: "addProductToOrder",
3821
4066
  value: (function () {
3822
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(product, booking) {
4067
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking) {
3823
4068
  var tempOrder, _ref61, _productRecord$num, productRecord, splitCount, i, singleLine;
3824
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3825
- while (1) switch (_context20.prev = _context20.next) {
4069
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4070
+ while (1) switch (_context23.prev = _context23.next) {
3826
4071
  case 0:
3827
4072
  tempOrder = this.ensureTempOrder();
3828
4073
  if (!booking) {
3829
- _context20.next = 18;
4074
+ _context23.next = 18;
3830
4075
  break;
3831
4076
  }
3832
4077
  productRecord = product;
3833
4078
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
3834
4079
  if (!(splitCount > 1)) {
3835
- _context20.next = 18;
4080
+ _context23.next = 18;
3836
4081
  break;
3837
4082
  }
3838
4083
  i = 0;
3839
4084
  case 6:
3840
4085
  if (!(i < splitCount)) {
3841
- _context20.next = 15;
4086
+ _context23.next = 15;
3842
4087
  break;
3843
4088
  }
3844
4089
  singleLine = cloneDeep(productRecord);
3845
4090
  singleLine.num = 1;
3846
4091
  delete singleLine.product_quantity;
3847
- _context20.next = 12;
4092
+ _context23.next = 12;
3848
4093
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3849
4094
  case 12:
3850
4095
  i += 1;
3851
- _context20.next = 6;
4096
+ _context23.next = 6;
3852
4097
  break;
3853
4098
  case 15:
3854
- _context20.next = 17;
4099
+ _context23.next = 17;
3855
4100
  return this.finalizeProductOrderMutation(tempOrder);
3856
4101
  case 17:
3857
- return _context20.abrupt("return", tempOrder.products);
4102
+ return _context23.abrupt("return", tempOrder.products);
3858
4103
  case 18:
3859
- _context20.next = 20;
4104
+ _context23.next = 20;
3860
4105
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3861
4106
  case 20:
3862
- _context20.next = 22;
4107
+ _context23.next = 22;
3863
4108
  return this.finalizeProductOrderMutation(tempOrder);
3864
4109
  case 22:
3865
4110
  this.logInfo('addProductToOrder success', {
3866
4111
  product_id: product.product_id,
3867
4112
  with_booking: !!booking
3868
4113
  });
3869
- return _context20.abrupt("return", tempOrder.products);
4114
+ return _context23.abrupt("return", tempOrder.products);
3870
4115
  case 24:
3871
4116
  case "end":
3872
- return _context20.stop();
4117
+ return _context23.stop();
3873
4118
  }
3874
- }, _callee18, this);
4119
+ }, _callee21, this);
3875
4120
  }));
3876
- function addProductToOrder(_x20, _x21) {
4121
+ function addProductToOrder(_x25, _x26) {
3877
4122
  return _addProductToOrder.apply(this, arguments);
3878
4123
  }
3879
4124
  return addProductToOrder;
@@ -3891,93 +4136,93 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3891
4136
  }, {
3892
4137
  key: "addProductsToOrder",
3893
4138
  value: (function () {
3894
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(items, options) {
4139
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
3895
4140
  var tempOrder, _iterator20, _step20, item, product, booking, _ref62, _productRecord$num2, productRecord, splitCount, i, singleLine;
3896
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3897
- while (1) switch (_context21.prev = _context21.next) {
4141
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4142
+ while (1) switch (_context24.prev = _context24.next) {
3898
4143
  case 0:
3899
4144
  tempOrder = this.ensureTempOrder();
3900
4145
  if (!(!Array.isArray(items) || items.length === 0)) {
3901
- _context21.next = 3;
4146
+ _context24.next = 3;
3902
4147
  break;
3903
4148
  }
3904
- return _context21.abrupt("return", tempOrder.products);
4149
+ return _context24.abrupt("return", tempOrder.products);
3905
4150
  case 3:
3906
4151
  _iterator20 = _createForOfIteratorHelper(items || []);
3907
- _context21.prev = 4;
4152
+ _context24.prev = 4;
3908
4153
  _iterator20.s();
3909
4154
  case 6:
3910
4155
  if ((_step20 = _iterator20.n()).done) {
3911
- _context21.next = 30;
4156
+ _context24.next = 30;
3912
4157
  break;
3913
4158
  }
3914
4159
  item = _step20.value;
3915
4160
  product = item.product, booking = item.booking;
3916
4161
  if (product) {
3917
- _context21.next = 11;
4162
+ _context24.next = 11;
3918
4163
  break;
3919
4164
  }
3920
- return _context21.abrupt("continue", 28);
4165
+ return _context24.abrupt("continue", 28);
3921
4166
  case 11:
3922
4167
  if (!booking) {
3923
- _context21.next = 26;
4168
+ _context24.next = 26;
3924
4169
  break;
3925
4170
  }
3926
4171
  productRecord = product;
3927
4172
  splitCount = getSafeProductNum((_ref62 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref62 !== void 0 ? _ref62 : 1);
3928
4173
  if (!(splitCount > 1)) {
3929
- _context21.next = 26;
4174
+ _context24.next = 26;
3930
4175
  break;
3931
4176
  }
3932
4177
  i = 0;
3933
4178
  case 16:
3934
4179
  if (!(i < splitCount)) {
3935
- _context21.next = 25;
4180
+ _context24.next = 25;
3936
4181
  break;
3937
4182
  }
3938
4183
  singleLine = cloneDeep(productRecord);
3939
4184
  singleLine.num = 1;
3940
4185
  delete singleLine.product_quantity;
3941
- _context21.next = 22;
4186
+ _context24.next = 22;
3942
4187
  return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
3943
4188
  case 22:
3944
4189
  i += 1;
3945
- _context21.next = 16;
4190
+ _context24.next = 16;
3946
4191
  break;
3947
4192
  case 25:
3948
- return _context21.abrupt("continue", 28);
4193
+ return _context24.abrupt("continue", 28);
3949
4194
  case 26:
3950
- _context21.next = 28;
4195
+ _context24.next = 28;
3951
4196
  return this.appendProductLineToTempOrder(tempOrder, product, booking);
3952
4197
  case 28:
3953
- _context21.next = 6;
4198
+ _context24.next = 6;
3954
4199
  break;
3955
4200
  case 30:
3956
- _context21.next = 35;
4201
+ _context24.next = 35;
3957
4202
  break;
3958
4203
  case 32:
3959
- _context21.prev = 32;
3960
- _context21.t0 = _context21["catch"](4);
3961
- _iterator20.e(_context21.t0);
4204
+ _context24.prev = 32;
4205
+ _context24.t0 = _context24["catch"](4);
4206
+ _iterator20.e(_context24.t0);
3962
4207
  case 35:
3963
- _context21.prev = 35;
4208
+ _context24.prev = 35;
3964
4209
  _iterator20.f();
3965
- return _context21.finish(35);
4210
+ return _context24.finish(35);
3966
4211
  case 38:
3967
- _context21.next = 40;
4212
+ _context24.next = 40;
3968
4213
  return this.finalizeProductOrderMutation(tempOrder, options);
3969
4214
  case 40:
3970
4215
  this.logInfo('addProductsToOrder success', {
3971
4216
  itemsCount: items.length
3972
4217
  });
3973
- return _context21.abrupt("return", tempOrder.products);
4218
+ return _context24.abrupt("return", tempOrder.products);
3974
4219
  case 42:
3975
4220
  case "end":
3976
- return _context21.stop();
4221
+ return _context24.stop();
3977
4222
  }
3978
- }, _callee19, this, [[4, 32, 35, 38]]);
4223
+ }, _callee22, this, [[4, 32, 35, 38]]);
3979
4224
  }));
3980
- function addProductsToOrder(_x22, _x23) {
4225
+ function addProductsToOrder(_x27, _x28) {
3981
4226
  return _addProductsToOrder.apply(this, arguments);
3982
4227
  }
3983
4228
  return addProductsToOrder;
@@ -4011,17 +4256,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4011
4256
  }, {
4012
4257
  key: "preservePersistedBundlePriceFields",
4013
4258
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4014
- var _this24 = this;
4259
+ var _this27 = this;
4015
4260
  if (!Array.isArray(nextBundles)) return nextBundles;
4016
4261
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4017
4262
  var previousByIdentity = new Map();
4018
4263
  previousBundles.forEach(function (bundle) {
4019
- var identity = _this24.getBundleRuntimeIdentity(bundle);
4264
+ var identity = _this27.getBundleRuntimeIdentity(bundle);
4020
4265
  if (identity) previousByIdentity.set(identity, bundle);
4021
4266
  });
4022
4267
  return nextBundles.map(function (bundle, index) {
4023
4268
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4024
- var previous = previousByIdentity.get(_this24.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4269
+ var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4025
4270
  if (!previous || _typeof(previous) !== 'object') return bundle;
4026
4271
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4027
4272
  cover: previous.cover
@@ -4222,21 +4467,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4222
4467
  }, {
4223
4468
  key: "updateOrderProduct",
4224
4469
  value: function () {
4225
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
4470
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4226
4471
  var tempOrder, updatedProductUid;
4227
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4228
- while (1) switch (_context22.prev = _context22.next) {
4472
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4473
+ while (1) switch (_context25.prev = _context25.next) {
4229
4474
  case 0:
4230
4475
  tempOrder = this.ensureTempOrder();
4231
4476
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4232
- _context22.next = 4;
4477
+ _context25.next = 4;
4233
4478
  return this.applyPromotion();
4234
4479
  case 4:
4235
4480
  this.applyDiscount({
4236
4481
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4237
4482
  });
4238
4483
  this.sanitizeTempOrderProducts(tempOrder);
4239
- _context22.next = 8;
4484
+ _context25.next = 8;
4240
4485
  return this.recalculateSummary({
4241
4486
  createIfMissing: true
4242
4487
  });
@@ -4245,14 +4490,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4245
4490
  this.logInfo('updateOrderProduct success', {
4246
4491
  params: params
4247
4492
  });
4248
- return _context22.abrupt("return", tempOrder.products);
4493
+ return _context25.abrupt("return", tempOrder.products);
4249
4494
  case 11:
4250
4495
  case "end":
4251
- return _context22.stop();
4496
+ return _context25.stop();
4252
4497
  }
4253
- }, _callee20, this);
4498
+ }, _callee23, this);
4254
4499
  }));
4255
- function updateOrderProduct(_x24) {
4500
+ function updateOrderProduct(_x29) {
4256
4501
  return _updateOrderProduct.apply(this, arguments);
4257
4502
  }
4258
4503
  return updateOrderProduct;
@@ -4260,28 +4505,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4260
4505
  }, {
4261
4506
  key: "updateOrderProducts",
4262
4507
  value: function () {
4263
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(paramsList) {
4264
- var _this25 = this;
4508
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4509
+ var _this28 = this;
4265
4510
  var tempOrder, reapplyBookingDiscountProductUids;
4266
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4267
- while (1) switch (_context23.prev = _context23.next) {
4511
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4512
+ while (1) switch (_context26.prev = _context26.next) {
4268
4513
  case 0:
4269
4514
  tempOrder = this.ensureTempOrder();
4270
4515
  if (paramsList.length) {
4271
- _context23.next = 3;
4516
+ _context26.next = 3;
4272
4517
  break;
4273
4518
  }
4274
- return _context23.abrupt("return", tempOrder.products);
4519
+ return _context26.abrupt("return", tempOrder.products);
4275
4520
  case 3:
4276
4521
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4277
- var updatedProductUid = _this25.applyOrderProductUpdateToTempOrder(tempOrder, params);
4522
+ var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4278
4523
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4279
4524
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4280
4525
  acc.push(String(updatedProductUid));
4281
4526
  }
4282
4527
  return acc;
4283
4528
  }, []);
4284
- _context23.next = 6;
4529
+ _context26.next = 6;
4285
4530
  return this.finalizeAfterProductsMutation(tempOrder, {
4286
4531
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4287
4532
  });
@@ -4289,14 +4534,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4289
4534
  this.logInfo('updateOrderProduct success', {
4290
4535
  paramsList: paramsList
4291
4536
  });
4292
- return _context23.abrupt("return", tempOrder.products);
4537
+ return _context26.abrupt("return", tempOrder.products);
4293
4538
  case 8:
4294
4539
  case "end":
4295
- return _context23.stop();
4540
+ return _context26.stop();
4296
4541
  }
4297
- }, _callee21, this);
4542
+ }, _callee24, this);
4298
4543
  }));
4299
- function updateOrderProducts(_x25) {
4544
+ function updateOrderProducts(_x30) {
4300
4545
  return _updateOrderProducts.apply(this, arguments);
4301
4546
  }
4302
4547
  return updateOrderProducts;
@@ -4304,11 +4549,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4304
4549
  }, {
4305
4550
  key: "updateOrderProductQuantity",
4306
4551
  value: function () {
4307
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
4552
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4308
4553
  var _targetProduct$metada17;
4309
4554
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4310
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4311
- while (1) switch (_context24.prev = _context24.next) {
4555
+ return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4556
+ while (1) switch (_context27.prev = _context27.next) {
4312
4557
  case 0:
4313
4558
  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;
4314
4559
  tempOrder = this.ensureTempOrder();
@@ -4337,7 +4582,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4337
4582
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4338
4583
  }
4339
4584
  if (!(productIndex === -1)) {
4340
- _context24.next = 12;
4585
+ _context27.next = 12;
4341
4586
  break;
4342
4587
  }
4343
4588
  throw new Error('[Order] 目标商品不存在,无法更新数量');
@@ -4351,12 +4596,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4351
4596
  }));
4352
4597
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4353
4598
  tempOrder.products[productIndex] = normalizedProduct;
4354
- _context24.next = 18;
4599
+ _context27.next = 18;
4355
4600
  return this.applyPromotion();
4356
4601
  case 18:
4357
4602
  this.applyDiscount();
4358
4603
  this.sanitizeTempOrderProducts(tempOrder);
4359
- _context24.next = 22;
4604
+ _context27.next = 22;
4360
4605
  return this.recalculateSummary({
4361
4606
  createIfMissing: true
4362
4607
  });
@@ -4365,14 +4610,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4365
4610
  this.logInfo('updateOrderProductQuantity success', {
4366
4611
  params: params
4367
4612
  });
4368
- return _context24.abrupt("return", tempOrder.products);
4613
+ return _context27.abrupt("return", tempOrder.products);
4369
4614
  case 25:
4370
4615
  case "end":
4371
- return _context24.stop();
4616
+ return _context27.stop();
4372
4617
  }
4373
- }, _callee22, this);
4618
+ }, _callee25, this);
4374
4619
  }));
4375
- function updateOrderProductQuantity(_x26) {
4620
+ function updateOrderProductQuantity(_x31) {
4376
4621
  return _updateOrderProductQuantity.apply(this, arguments);
4377
4622
  }
4378
4623
  return updateOrderProductQuantity;
@@ -4413,19 +4658,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4413
4658
  }, {
4414
4659
  key: "finalizeAfterProductsMutation",
4415
4660
  value: (function () {
4416
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(tempOrder, options) {
4417
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4418
- while (1) switch (_context25.prev = _context25.next) {
4661
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4662
+ return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4663
+ while (1) switch (_context28.prev = _context28.next) {
4419
4664
  case 0:
4420
4665
  this.syncTempOrderHolderFromBookings(tempOrder);
4421
- _context25.next = 3;
4666
+ _context28.next = 3;
4422
4667
  return this.applyPromotion();
4423
4668
  case 3:
4424
4669
  this.applyDiscount({
4425
4670
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4426
4671
  });
4427
4672
  this.sanitizeTempOrderProducts(tempOrder);
4428
- _context25.next = 7;
4673
+ _context28.next = 7;
4429
4674
  return this.recalculateSummary({
4430
4675
  createIfMissing: true
4431
4676
  });
@@ -4433,11 +4678,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4433
4678
  this.persistTempOrder();
4434
4679
  case 8:
4435
4680
  case "end":
4436
- return _context25.stop();
4681
+ return _context28.stop();
4437
4682
  }
4438
- }, _callee23, this);
4683
+ }, _callee26, this);
4439
4684
  }));
4440
- function finalizeAfterProductsMutation(_x27, _x28) {
4685
+ function finalizeAfterProductsMutation(_x32, _x33) {
4441
4686
  return _finalizeAfterProductsMutation.apply(this, arguments);
4442
4687
  }
4443
4688
  return finalizeAfterProductsMutation;
@@ -4452,18 +4697,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4452
4697
  }, {
4453
4698
  key: "removeProductsFromOrder",
4454
4699
  value: (function () {
4455
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(identities) {
4456
- var _this26 = this;
4700
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities) {
4701
+ var _this29 = this;
4457
4702
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3;
4458
- return _regeneratorRuntime().wrap(function _callee24$(_context27) {
4459
- while (1) switch (_context27.prev = _context27.next) {
4703
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4704
+ while (1) switch (_context30.prev = _context30.next) {
4460
4705
  case 0:
4461
4706
  tempOrder = this.ensureTempOrder();
4462
4707
  if (identities.length) {
4463
- _context27.next = 3;
4708
+ _context30.next = 3;
4464
4709
  break;
4465
4710
  }
4466
- return _context27.abrupt("return", tempOrder.products);
4711
+ return _context30.abrupt("return", tempOrder.products);
4467
4712
  case 3:
4468
4713
  productsBeforeRemove = tempOrder.products || [];
4469
4714
  bookingsBeforeRemove = tempOrder.bookings || [];
@@ -4486,29 +4731,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4486
4731
  }
4487
4732
  linkedBookingUidsToRemove = new Set();
4488
4733
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4489
- _context27.prev = 11;
4734
+ _context30.prev = 11;
4490
4735
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4491
4736
  var _metadata11, _metadata12, _metadata13, _metadata14;
4492
4737
  var product, productUid, productBookingUid, isAddTimeProduct;
4493
- return _regeneratorRuntime().wrap(function _loop3$(_context26) {
4494
- while (1) switch (_context26.prev = _context26.next) {
4738
+ return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4739
+ while (1) switch (_context29.prev = _context29.next) {
4495
4740
  case 0:
4496
4741
  product = _step21.value;
4497
4742
  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);
4498
4743
  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);
4499
4744
  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;
4500
4745
  if (!isAddTimeProduct) {
4501
- _context26.next = 6;
4746
+ _context29.next = 6;
4502
4747
  break;
4503
4748
  }
4504
- return _context26.abrupt("return", 1);
4749
+ return _context29.abrupt("return", 1);
4505
4750
  case 6:
4506
4751
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4507
4752
  linkedBookingUidsToRemove.add(String(productBookingUid));
4508
4753
  }
4509
4754
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4510
4755
  bookingsBeforeRemove.forEach(function (booking) {
4511
- var bookingUid = _this26.getBookingUniqueIdentificationNumber(booking);
4756
+ var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
4512
4757
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4513
4758
  linkedBookingUidsToRemove.add(bookingUid);
4514
4759
  }
@@ -4516,37 +4761,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4516
4761
  }
4517
4762
  case 8:
4518
4763
  case "end":
4519
- return _context26.stop();
4764
+ return _context29.stop();
4520
4765
  }
4521
4766
  }, _loop3);
4522
4767
  });
4523
4768
  _iterator21.s();
4524
4769
  case 14:
4525
4770
  if ((_step21 = _iterator21.n()).done) {
4526
- _context27.next = 20;
4771
+ _context30.next = 20;
4527
4772
  break;
4528
4773
  }
4529
- return _context27.delegateYield(_loop3(), "t0", 16);
4774
+ return _context30.delegateYield(_loop3(), "t0", 16);
4530
4775
  case 16:
4531
- if (!_context27.t0) {
4532
- _context27.next = 18;
4776
+ if (!_context30.t0) {
4777
+ _context30.next = 18;
4533
4778
  break;
4534
4779
  }
4535
- return _context27.abrupt("continue", 18);
4780
+ return _context30.abrupt("continue", 18);
4536
4781
  case 18:
4537
- _context27.next = 14;
4782
+ _context30.next = 14;
4538
4783
  break;
4539
4784
  case 20:
4540
- _context27.next = 25;
4785
+ _context30.next = 25;
4541
4786
  break;
4542
4787
  case 22:
4543
- _context27.prev = 22;
4544
- _context27.t1 = _context27["catch"](11);
4545
- _iterator21.e(_context27.t1);
4788
+ _context30.prev = 22;
4789
+ _context30.t1 = _context30["catch"](11);
4790
+ _iterator21.e(_context30.t1);
4546
4791
  case 25:
4547
- _context27.prev = 25;
4792
+ _context30.prev = 25;
4548
4793
  _iterator21.f();
4549
- return _context27.finish(25);
4794
+ return _context30.finish(25);
4550
4795
  case 28:
4551
4796
  if (linkedBookingUidsToRemove.size > 0) {
4552
4797
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
@@ -4557,20 +4802,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4557
4802
  return !(isAddTimeProduct && lineBookingUid !== undefined && lineBookingUid !== null && linkedBookingUidsToRemove.has(String(lineBookingUid)));
4558
4803
  });
4559
4804
  }
4560
- _context27.next = 31;
4805
+ _context30.next = 31;
4561
4806
  return this.finalizeAfterProductsMutation(tempOrder);
4562
4807
  case 31:
4563
4808
  this.logInfo('removeProductsFromOrder success', {
4564
4809
  identities: identities
4565
4810
  });
4566
- return _context27.abrupt("return", tempOrder.products);
4811
+ return _context30.abrupt("return", tempOrder.products);
4567
4812
  case 33:
4568
4813
  case "end":
4569
- return _context27.stop();
4814
+ return _context30.stop();
4570
4815
  }
4571
- }, _callee24, this, [[11, 22, 25, 28]]);
4816
+ }, _callee27, this, [[11, 22, 25, 28]]);
4572
4817
  }));
4573
- function removeProductsFromOrder(_x29) {
4818
+ function removeProductsFromOrder(_x34) {
4574
4819
  return _removeProductsFromOrder.apply(this, arguments);
4575
4820
  }
4576
4821
  return removeProductsFromOrder;
@@ -4578,18 +4823,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4578
4823
  }, {
4579
4824
  key: "removeProductFromOrder",
4580
4825
  value: function () {
4581
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identity) {
4582
- return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4583
- while (1) switch (_context28.prev = _context28.next) {
4826
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity) {
4827
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4828
+ while (1) switch (_context31.prev = _context31.next) {
4584
4829
  case 0:
4585
- return _context28.abrupt("return", this.removeProductsFromOrder([identity]));
4830
+ return _context31.abrupt("return", this.removeProductsFromOrder([identity]));
4586
4831
  case 1:
4587
4832
  case "end":
4588
- return _context28.stop();
4833
+ return _context31.stop();
4589
4834
  }
4590
- }, _callee25, this);
4835
+ }, _callee28, this);
4591
4836
  }));
4592
- function removeProductFromOrder(_x30) {
4837
+ function removeProductFromOrder(_x35) {
4593
4838
  return _removeProductFromOrder.apply(this, arguments);
4594
4839
  }
4595
4840
  return removeProductFromOrder;
@@ -4601,10 +4846,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4601
4846
  }, {
4602
4847
  key: "clearOrderCartLines",
4603
4848
  value: (function () {
4604
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26() {
4849
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4605
4850
  var tempOrder;
4606
- return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4607
- while (1) switch (_context29.prev = _context29.next) {
4851
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4852
+ while (1) switch (_context32.prev = _context32.next) {
4608
4853
  case 0:
4609
4854
  tempOrder = this.ensureTempOrder();
4610
4855
  tempOrder.products = [];
@@ -4615,24 +4860,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4615
4860
  productsByUid: {}
4616
4861
  });
4617
4862
  }
4618
- _context29.next = 7;
4863
+ _context32.next = 7;
4619
4864
  return this.applyPromotion();
4620
4865
  case 7:
4621
4866
  this.applyDiscount();
4622
4867
  this.sanitizeTempOrderProducts(tempOrder);
4623
- _context29.next = 11;
4868
+ _context32.next = 11;
4624
4869
  return this.recalculateSummary({
4625
4870
  createIfMissing: true
4626
4871
  });
4627
4872
  case 11:
4628
4873
  this.persistTempOrder();
4629
4874
  this.logInfo('clearOrderCartLines success', {});
4630
- return _context29.abrupt("return", tempOrder);
4875
+ return _context32.abrupt("return", tempOrder);
4631
4876
  case 14:
4632
4877
  case "end":
4633
- return _context29.stop();
4878
+ return _context32.stop();
4634
4879
  }
4635
- }, _callee26, this);
4880
+ }, _callee29, this);
4636
4881
  }));
4637
4882
  function clearOrderCartLines() {
4638
4883
  return _clearOrderCartLines.apply(this, arguments);
@@ -4670,17 +4915,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4670
4915
  }, {
4671
4916
  key: "applyLocalPrintOrderNumbers",
4672
4917
  value: function () {
4673
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order) {
4918
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
4674
4919
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4675
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4676
- while (1) switch (_context30.prev = _context30.next) {
4920
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4921
+ while (1) switch (_context33.prev = _context33.next) {
4677
4922
  case 0:
4678
4923
  tempOrder = this.ensureTempOrder();
4679
4924
  if (!(!order || _typeof(order) !== 'object')) {
4680
- _context30.next = 3;
4925
+ _context33.next = 3;
4681
4926
  break;
4682
4927
  }
4683
- return _context30.abrupt("return", tempOrder);
4928
+ return _context33.abrupt("return", tempOrder);
4684
4929
  case 3:
4685
4930
  shopOrderNumber = order.shop_order_number;
4686
4931
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4691,21 +4936,88 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4691
4936
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4692
4937
  }
4693
4938
  this.persistTempOrder();
4694
- _context30.next = 10;
4939
+ _context33.next = 10;
4695
4940
  return this.saveDraft();
4696
4941
  case 10:
4697
- return _context30.abrupt("return", tempOrder);
4942
+ return _context33.abrupt("return", tempOrder);
4698
4943
  case 11:
4699
4944
  case "end":
4700
- return _context30.stop();
4945
+ return _context33.stop();
4701
4946
  }
4702
- }, _callee27, this);
4947
+ }, _callee30, this);
4703
4948
  }));
4704
- function applyLocalPrintOrderNumbers(_x31) {
4949
+ function applyLocalPrintOrderNumbers(_x36) {
4705
4950
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4706
4951
  }
4707
4952
  return applyLocalPrintOrderNumbers;
4708
4953
  }()
4954
+ }, {
4955
+ key: "saveTempOrderAsDraft",
4956
+ value: function () {
4957
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
4958
+ var _params$cacheId2, _this$otherParams6, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4959
+ var tempOrder, latestSummary, payload;
4960
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4961
+ while (1) switch (_context34.prev = _context34.next) {
4962
+ case 0:
4963
+ tempOrder = this.ensureTempOrder();
4964
+ this.ensureExternalSaleNumber(tempOrder);
4965
+ this.persistTempOrder();
4966
+ _context34.next = 5;
4967
+ return this.recalculateSummary({
4968
+ createIfMissing: true
4969
+ });
4970
+ case 5:
4971
+ _context34.t1 = _context34.sent;
4972
+ if (_context34.t1) {
4973
+ _context34.next = 8;
4974
+ break;
4975
+ }
4976
+ _context34.t1 = this.store.summary;
4977
+ case 8:
4978
+ _context34.t0 = _context34.t1;
4979
+ if (_context34.t0) {
4980
+ _context34.next = 11;
4981
+ break;
4982
+ }
4983
+ _context34.t0 = createEmptySummary();
4984
+ case 11:
4985
+ latestSummary = _context34.t0;
4986
+ payload = buildSubmitPayload({
4987
+ tempOrder: tempOrder,
4988
+ cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
4989
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4990
+ 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,
4991
+ channel: params === null || params === void 0 ? void 0 : params.channel,
4992
+ 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,
4993
+ summary: latestSummary,
4994
+ enhance: params === null || params === void 0 ? void 0 : params.enhancePayload
4995
+ });
4996
+ if (!payload.created_at) {
4997
+ payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4998
+ }
4999
+ payload.need_sync = 0;
5000
+ payload.is_draft_order = 1;
5001
+ this.logInfo('saveTempOrderAsDraft calling sales draft', {
5002
+ orderId: payload.order_id,
5003
+ externalSaleNumber: payload.external_sale_number,
5004
+ productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
5005
+ });
5006
+ return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
5007
+ osServer: true,
5008
+ customToast: function customToast() {}
5009
+ }));
5010
+ case 18:
5011
+ case "end":
5012
+ return _context34.stop();
5013
+ }
5014
+ }, _callee31, this);
5015
+ }));
5016
+ function saveTempOrderAsDraft(_x37) {
5017
+ return _saveTempOrderAsDraft.apply(this, arguments);
5018
+ }
5019
+ return saveTempOrderAsDraft;
5020
+ }()
4709
5021
  /**
4710
5022
  * 提交当前 Sales tempOrder。
4711
5023
  *
@@ -4715,18 +5027,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4715
5027
  }, {
4716
5028
  key: "submitTempOrder",
4717
5029
  value: (function () {
4718
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(params) {
4719
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4720
- while (1) switch (_context31.prev = _context31.next) {
5030
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5031
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5032
+ while (1) switch (_context35.prev = _context35.next) {
4721
5033
  case 0:
4722
- return _context31.abrupt("return", this.runSubmitTempOrder(params));
5034
+ return _context35.abrupt("return", this.runSubmitTempOrder(params));
4723
5035
  case 1:
4724
5036
  case "end":
4725
- return _context31.stop();
5037
+ return _context35.stop();
4726
5038
  }
4727
- }, _callee28, this);
5039
+ }, _callee32, this);
4728
5040
  }));
4729
- function submitTempOrder(_x32) {
5041
+ function submitTempOrder(_x38) {
4730
5042
  return _submitTempOrder.apply(this, arguments);
4731
5043
  }
4732
5044
  return submitTempOrder;
@@ -4734,20 +5046,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4734
5046
  }, {
4735
5047
  key: "submitTempOrderAsync",
4736
5048
  value: function () {
4737
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4738
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4739
- while (1) switch (_context32.prev = _context32.next) {
5049
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5050
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5051
+ while (1) switch (_context36.prev = _context36.next) {
4740
5052
  case 0:
4741
- return _context32.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5053
+ return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
4742
5054
  syncMode: true
4743
5055
  })));
4744
5056
  case 1:
4745
5057
  case "end":
4746
- return _context32.stop();
5058
+ return _context36.stop();
4747
5059
  }
4748
- }, _callee29, this);
5060
+ }, _callee33, this);
4749
5061
  }));
4750
- function submitTempOrderAsync(_x33) {
5062
+ function submitTempOrderAsync(_x39) {
4751
5063
  return _submitTempOrderAsync.apply(this, arguments);
4752
5064
  }
4753
5065
  return submitTempOrderAsync;
@@ -4755,11 +5067,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4755
5067
  }, {
4756
5068
  key: "runSubmitTempOrder",
4757
5069
  value: function () {
4758
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
4759
- var _params$cacheId2, _this$otherParams6, _ref74, _ref75, _submitSnapshot$busin, _this$otherParams7, _this$otherParams8, _submitSnapshot$type;
5070
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5071
+ var _params$cacheId3, _this$otherParams10, _ref74, _ref75, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
4760
5072
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
4761
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4762
- while (1) switch (_context33.prev = _context33.next) {
5073
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5074
+ while (1) switch (_context37.prev = _context37.next) {
4763
5075
  case 0:
4764
5076
  tempOrder = this.ensureTempOrder();
4765
5077
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -4779,27 +5091,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4779
5091
  }
4780
5092
  }
4781
5093
  this.persistTempOrder();
4782
- _context33.next = 8;
5094
+ _context37.next = 8;
4783
5095
  return this.recalculateSummary({
4784
5096
  createIfMissing: true
4785
5097
  });
4786
5098
  case 8:
4787
- _context33.t1 = _context33.sent;
4788
- if (_context33.t1) {
4789
- _context33.next = 11;
5099
+ _context37.t1 = _context37.sent;
5100
+ if (_context37.t1) {
5101
+ _context37.next = 11;
4790
5102
  break;
4791
5103
  }
4792
- _context33.t1 = this.store.summary;
5104
+ _context37.t1 = this.store.summary;
4793
5105
  case 11:
4794
- _context33.t0 = _context33.t1;
4795
- if (_context33.t0) {
4796
- _context33.next = 14;
5106
+ _context37.t0 = _context37.t1;
5107
+ if (_context37.t0) {
5108
+ _context37.next = 14;
4797
5109
  break;
4798
5110
  }
4799
- _context33.t0 = createEmptySummary();
5111
+ _context37.t0 = createEmptySummary();
4800
5112
  case 14:
4801
- latestSummary = _context33.t0;
4802
- effectiveCacheId = (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId;
5113
+ latestSummary = _context37.t0;
5114
+ effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
4803
5115
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
4804
5116
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
4805
5117
  enhancePayload = hasPaymentOverride || hasPaymentStatusOverride || hasSmallTicketDataFlagOverride || params !== null && params !== void 0 && params.enhancePayload ? function (payload, ctx) {
@@ -4817,8 +5129,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4817
5129
  payload = buildSubmitPayload({
4818
5130
  tempOrder: tempOrder,
4819
5131
  cacheId: effectiveCacheId,
4820
- platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams6 = this.otherParams) === null || _this$otherParams6 === void 0 ? void 0 : _this$otherParams6.platform),
4821
- 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,
5132
+ platform: (params === null || params === void 0 ? void 0 : params.platform) || ((_this$otherParams10 = this.otherParams) === null || _this$otherParams10 === void 0 ? void 0 : _this$otherParams10.platform),
5133
+ 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,
4822
5134
  channel: params === null || params === void 0 ? void 0 : params.channel,
4823
5135
  type: (_submitSnapshot$type = submitSnapshot.type) !== null && _submitSnapshot$type !== void 0 ? _submitSnapshot$type : params === null || params === void 0 ? void 0 : params.type,
4824
5136
  summary: latestSummary,
@@ -4833,10 +5145,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4833
5145
  if (!payload.created_at) {
4834
5146
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
4835
5147
  }
4836
- _context33.next = 26;
5148
+ _context37.next = 26;
4837
5149
  return this.saveDraft();
4838
5150
  case 26:
4839
- _context33.prev = 26;
5151
+ _context37.prev = 26;
4840
5152
  this.logInfo('submitTempOrder calling sales checkout', {
4841
5153
  orderId: payload.order_id,
4842
5154
  externalSaleNumber: payload.external_sale_number,
@@ -4846,43 +5158,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4846
5158
  smallTicketDataFlag: payload.small_ticket_data_flag,
4847
5159
  syncMode: payload.sync_mode
4848
5160
  });
4849
- _context33.next = 30;
5161
+ _context37.next = 30;
4850
5162
  return this.submitSalesOrder({
4851
5163
  query: payload
4852
5164
  });
4853
5165
  case 30:
4854
- result = _context33.sent;
4855
- _context33.next = 43;
5166
+ result = _context37.sent;
5167
+ _context37.next = 43;
4856
5168
  break;
4857
5169
  case 33:
4858
- _context33.prev = 33;
4859
- _context33.t2 = _context33["catch"](26);
4860
- backendErrorResponse = this.extractSubmitErrorResponse(_context33.t2);
5170
+ _context37.prev = 33;
5171
+ _context37.t2 = _context37["catch"](26);
5172
+ backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
4861
5173
  if (!backendErrorResponse) {
4862
- _context33.next = 40;
5174
+ _context37.next = 40;
4863
5175
  break;
4864
5176
  }
4865
5177
  this.store.syncState = 'failed';
4866
5178
  this.logSubmitBackendRejected(backendErrorResponse, payload);
4867
- return _context33.abrupt("return", backendErrorResponse);
5179
+ return _context37.abrupt("return", backendErrorResponse);
4868
5180
  case 40:
4869
5181
  this.store.syncState = 'failed';
4870
5182
  this.logError('submitTempOrder failed', {
4871
- error: _context33.t2 instanceof Error ? _context33.t2.message : String(_context33.t2),
5183
+ error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
4872
5184
  orderId: payload.order_id,
4873
5185
  externalSaleNumber: payload.external_sale_number,
4874
5186
  paymentStatus: payload.payment_status,
4875
5187
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
4876
5188
  });
4877
- throw _context33.t2;
5189
+ throw _context37.t2;
4878
5190
  case 43:
4879
5191
  if (!this.isSubmitResponseRejected(result)) {
4880
- _context33.next = 47;
5192
+ _context37.next = 47;
4881
5193
  break;
4882
5194
  }
4883
5195
  this.store.syncState = 'failed';
4884
5196
  this.logSubmitBackendRejected(result, payload);
4885
- return _context33.abrupt("return", result);
5197
+ return _context37.abrupt("return", result);
4886
5198
  case 47:
4887
5199
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
4888
5200
  this.logInfo('runSubmitTempOrder: 提交成功', {
@@ -4893,15 +5205,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4893
5205
  })
4894
5206
  });
4895
5207
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
4896
- _context33.next = 56;
5208
+ _context37.next = 56;
4897
5209
  break;
4898
5210
  }
4899
5211
  tempOrder.order_id = submittedOrderId;
4900
5212
  resultRecord = result;
4901
- _context33.next = 54;
5213
+ _context37.next = 54;
4902
5214
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
4903
5215
  case 54:
4904
- _context33.next = 57;
5216
+ _context37.next = 57;
4905
5217
  break;
4906
5218
  case 56:
4907
5219
  if (this.isLocalPendingSubmitResult(result)) {
@@ -4910,14 +5222,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4910
5222
  this.store.syncState = 'submitted';
4911
5223
  }
4912
5224
  case 57:
4913
- return _context33.abrupt("return", result);
5225
+ return _context37.abrupt("return", result);
4914
5226
  case 58:
4915
5227
  case "end":
4916
- return _context33.stop();
5228
+ return _context37.stop();
4917
5229
  }
4918
- }, _callee30, this, [[26, 33]]);
5230
+ }, _callee34, this, [[26, 33]]);
4919
5231
  }));
4920
- function runSubmitTempOrder(_x34) {
5232
+ function runSubmitTempOrder(_x40) {
4921
5233
  return _runSubmitTempOrder.apply(this, arguments);
4922
5234
  }
4923
5235
  return runSubmitTempOrder;
@@ -4925,10 +5237,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4925
5237
  }, {
4926
5238
  key: "markLocalOrderSynced",
4927
5239
  value: function () {
4928
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(orderId, remoteOrder) {
5240
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
4929
5241
  var tempOrder;
4930
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4931
- while (1) switch (_context34.prev = _context34.next) {
5242
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5243
+ while (1) switch (_context38.prev = _context38.next) {
4932
5244
  case 0:
4933
5245
  tempOrder = this.ensureTempOrder();
4934
5246
  tempOrder.order_id = orderId;
@@ -4936,15 +5248,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4936
5248
  this.store.lastOrderInfo = remoteOrder;
4937
5249
  this.store.syncState = 'submitted';
4938
5250
  this.persistTempOrder();
4939
- _context34.next = 8;
5251
+ _context38.next = 8;
4940
5252
  return this.saveDraft();
4941
5253
  case 8:
4942
5254
  case "end":
4943
- return _context34.stop();
5255
+ return _context38.stop();
4944
5256
  }
4945
- }, _callee31, this);
5257
+ }, _callee35, this);
4946
5258
  }));
4947
- function markLocalOrderSynced(_x35, _x36) {
5259
+ function markLocalOrderSynced(_x41, _x42) {
4948
5260
  return _markLocalOrderSynced.apply(this, arguments);
4949
5261
  }
4950
5262
  return markLocalOrderSynced;
@@ -4987,10 +5299,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4987
5299
  value: function extractSubmitErrorResponse(error) {
4988
5300
  var _error$response,
4989
5301
  _error$response2,
4990
- _this27 = this;
5302
+ _this30 = this;
4991
5303
  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];
4992
5304
  return candidates.find(function (candidate) {
4993
- return _this27.isSubmitErrorResponse(candidate);
5305
+ return _this30.isSubmitErrorResponse(candidate);
4994
5306
  }) || null;
4995
5307
  }
4996
5308
  }, {
@@ -5017,14 +5329,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5017
5329
  }, {
5018
5330
  key: "syncPaymentsToOrder",
5019
5331
  value: function () {
5020
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5021
- var _params$confirmPendin;
5022
- var tempOrder, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitParams, submitResult;
5023
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5024
- while (1) switch (_context35.prev = _context35.next) {
5332
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5333
+ var _this31 = this,
5334
+ _params$confirmPendin;
5335
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitParams, submitResult;
5336
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5337
+ while (1) switch (_context39.prev = _context39.next) {
5025
5338
  case 0:
5026
5339
  tempOrder = this.ensureTempOrder();
5027
- mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
5340
+ needsPaymentNumber = (params.payments || []).some(function (payment) {
5341
+ return String(payment.payment_number || '').trim() === '';
5342
+ });
5343
+ if (!needsPaymentNumber) {
5344
+ _context39.next = 8;
5345
+ break;
5346
+ }
5347
+ _context39.next = 5;
5348
+ return this.getPaymentNumberDevicePrefixAsync();
5349
+ case 5:
5350
+ _context39.t0 = _context39.sent;
5351
+ _context39.next = 9;
5352
+ break;
5353
+ case 8:
5354
+ _context39.t0 = 'LOCAL';
5355
+ case 9:
5356
+ devicePrefix = _context39.t0;
5357
+ mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5358
+ return _this31.normalizePaymentSource(payment, {
5359
+ defaultPaid: false,
5360
+ devicePrefix: devicePrefix
5361
+ });
5362
+ }));
5028
5363
  shouldConfirmPendingVoucherPayments = (_params$confirmPendin = params.confirmPendingVoucherPayments) !== null && _params$confirmPendin !== void 0 ? _params$confirmPendin : params.submitWhenPaid === true;
5029
5364
  effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
5030
5365
  completion = this.getPaymentCompletion(effectivePayments);
@@ -5033,21 +5368,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5033
5368
  tempOrder.payments = effectivePayments;
5034
5369
  tempOrder.payment_status = paymentStatus;
5035
5370
  this.persistTempOrder();
5036
- _context35.next = 12;
5371
+ _context39.next = 21;
5037
5372
  return this.saveDraft();
5038
- case 12:
5373
+ case 21:
5039
5374
  if (params.submitWhenPaid) {
5040
- _context35.next = 14;
5375
+ _context39.next = 23;
5041
5376
  break;
5042
5377
  }
5043
- return _context35.abrupt("return", completion);
5044
- case 14:
5378
+ return _context39.abrupt("return", completion);
5379
+ case 23:
5045
5380
  if (!(this.store.syncState === 'submitting')) {
5046
- _context35.next = 16;
5381
+ _context39.next = 25;
5047
5382
  break;
5048
5383
  }
5049
- return _context35.abrupt("return", completion);
5050
- case 16:
5384
+ return _context39.abrupt("return", completion);
5385
+ case 25:
5051
5386
  this.store.syncState = 'submitting';
5052
5387
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
5053
5388
  submitParams = {
@@ -5065,32 +5400,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5065
5400
  }
5066
5401
  };
5067
5402
  if (!(params.checkoutSyncTaskEnabled === false)) {
5068
- _context35.next = 25;
5403
+ _context39.next = 34;
5069
5404
  break;
5070
5405
  }
5071
- _context35.next = 22;
5406
+ _context39.next = 31;
5072
5407
  return this.submitTempOrderAsync(submitParams);
5073
- case 22:
5074
- _context35.t0 = _context35.sent;
5075
- _context35.next = 28;
5408
+ case 31:
5409
+ _context39.t1 = _context39.sent;
5410
+ _context39.next = 37;
5076
5411
  break;
5077
- case 25:
5078
- _context35.next = 27;
5412
+ case 34:
5413
+ _context39.next = 36;
5079
5414
  return this.submitTempOrder(submitParams);
5080
- case 27:
5081
- _context35.t0 = _context35.sent;
5082
- case 28:
5083
- submitResult = _context35.t0;
5084
- return _context35.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5415
+ case 36:
5416
+ _context39.t1 = _context39.sent;
5417
+ case 37:
5418
+ submitResult = _context39.t1;
5419
+ return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5085
5420
  submitResult: submitResult
5086
5421
  }));
5087
- case 30:
5422
+ case 39:
5088
5423
  case "end":
5089
- return _context35.stop();
5424
+ return _context39.stop();
5090
5425
  }
5091
- }, _callee32, this);
5426
+ }, _callee36, this);
5092
5427
  }));
5093
- function syncPaymentsToOrder(_x37) {
5428
+ function syncPaymentsToOrder(_x43) {
5094
5429
  return _syncPaymentsToOrder.apply(this, arguments);
5095
5430
  }
5096
5431
  return syncPaymentsToOrder;
@@ -5098,7 +5433,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5098
5433
  }, {
5099
5434
  key: "createOrder",
5100
5435
  value: function createOrder(params) {
5101
- var _this28 = this;
5436
+ var _this32 = this;
5102
5437
  var order = _objectSpread({
5103
5438
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
5104
5439
  // 要从外面拿,virtual
@@ -5130,7 +5465,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5130
5465
 
5131
5466
  // 为预约补齐 holder 信息
5132
5467
  if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
5133
- ensureCartItemOriginHolder(item, _this28.window);
5468
+ ensureCartItemOriginHolder(item, _this32.window);
5134
5469
  }
5135
5470
 
5136
5471
  // 购物车是否为普通商品
@@ -5187,11 +5522,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5187
5522
  }, {
5188
5523
  key: "submitOrder",
5189
5524
  value: function () {
5190
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(order) {
5525
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5191
5526
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5192
5527
  var url, query, fetchUrl, params;
5193
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5194
- while (1) switch (_context36.prev = _context36.next) {
5528
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5529
+ while (1) switch (_context40.prev = _context40.next) {
5195
5530
  case 0:
5196
5531
  this.logInfo('submitOrder called', {
5197
5532
  url: order.url,
@@ -5211,14 +5546,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5211
5546
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5212
5547
  scheduleDate: params.schedule_date
5213
5548
  });
5214
- return _context36.abrupt("return", this.request.post(fetchUrl, params));
5549
+ return _context40.abrupt("return", this.request.post(fetchUrl, params));
5215
5550
  case 6:
5216
5551
  case "end":
5217
- return _context36.stop();
5552
+ return _context40.stop();
5218
5553
  }
5219
- }, _callee33, this);
5554
+ }, _callee37, this);
5220
5555
  }));
5221
- function submitOrder(_x38) {
5556
+ function submitOrder(_x44) {
5222
5557
  return _submitOrder.apply(this, arguments);
5223
5558
  }
5224
5559
  return submitOrder;
@@ -5226,13 +5561,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5226
5561
  }, {
5227
5562
  key: "cancelOrder",
5228
5563
  value: function () {
5229
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5564
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5230
5565
  var payload;
5231
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5232
- while (1) switch (_context37.prev = _context37.next) {
5566
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5567
+ while (1) switch (_context41.prev = _context41.next) {
5233
5568
  case 0:
5234
5569
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5235
- _context37.next = 2;
5570
+ _context41.next = 2;
5236
5571
  break;
5237
5572
  }
5238
5573
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5248,16 +5583,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5248
5583
  method: 'PUT',
5249
5584
  orderIdsCount: params.order_ids.length
5250
5585
  });
5251
- return _context37.abrupt("return", this.request.put('/order/update-status', payload, {
5586
+ return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5252
5587
  isShopApi: true
5253
5588
  }));
5254
5589
  case 5:
5255
5590
  case "end":
5256
- return _context37.stop();
5591
+ return _context41.stop();
5257
5592
  }
5258
- }, _callee34, this);
5593
+ }, _callee38, this);
5259
5594
  }));
5260
- function cancelOrder(_x39) {
5595
+ function cancelOrder(_x45) {
5261
5596
  return _cancelOrder.apply(this, arguments);
5262
5597
  }
5263
5598
  return cancelOrder;
@@ -5265,19 +5600,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5265
5600
  }, {
5266
5601
  key: "changeBookingStatus",
5267
5602
  value: function () {
5268
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(params) {
5603
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5269
5604
  var url, payload;
5270
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5271
- while (1) switch (_context38.prev = _context38.next) {
5605
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5606
+ while (1) switch (_context42.prev = _context42.next) {
5272
5607
  case 0:
5273
5608
  if (params.booking_id) {
5274
- _context38.next = 2;
5609
+ _context42.next = 2;
5275
5610
  break;
5276
5611
  }
5277
5612
  throw new Error('变更预约状态失败:booking_id 不能为空');
5278
5613
  case 2:
5279
5614
  if (params.appointment_status) {
5280
- _context38.next = 4;
5615
+ _context42.next = 4;
5281
5616
  break;
5282
5617
  }
5283
5618
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5292,16 +5627,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5292
5627
  bookingId: params.booking_id,
5293
5628
  appointmentStatus: params.appointment_status
5294
5629
  });
5295
- return _context38.abrupt("return", this.request.put(url, payload, {
5630
+ return _context42.abrupt("return", this.request.put(url, payload, {
5296
5631
  isShopApi: true
5297
5632
  }));
5298
5633
  case 8:
5299
5634
  case "end":
5300
- return _context38.stop();
5635
+ return _context42.stop();
5301
5636
  }
5302
- }, _callee35, this);
5637
+ }, _callee39, this);
5303
5638
  }));
5304
- function changeBookingStatus(_x40) {
5639
+ function changeBookingStatus(_x46) {
5305
5640
  return _changeBookingStatus.apply(this, arguments);
5306
5641
  }
5307
5642
  return changeBookingStatus;
@@ -5319,11 +5654,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5319
5654
  }, {
5320
5655
  key: "createOrderByCheckout",
5321
5656
  value: (function () {
5322
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5657
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5323
5658
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5324
5659
  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;
5325
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5326
- while (1) switch (_context39.prev = _context39.next) {
5660
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5661
+ while (1) switch (_context43.prev = _context43.next) {
5327
5662
  case 0:
5328
5663
  // 过滤掉由在线店铺下单的 payment 支付数据
5329
5664
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5357,7 +5692,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5357
5692
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5358
5693
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5359
5694
  });
5360
- _context39.prev = 4;
5695
+ _context43.prev = 4;
5361
5696
  // 构建订单数据,设置默认值并允许 params 覆盖
5362
5697
  orderData = _objectSpread({
5363
5698
  sales_channel: 'my_pisel',
@@ -5419,13 +5754,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5419
5754
  hasOrderId: !!orderData.order_id,
5420
5755
  smallTicketDataFlag: orderData.small_ticket_data_flag
5421
5756
  });
5422
- _context39.next = 12;
5757
+ _context43.next = 12;
5423
5758
  return this.request.post('/order/checkout', orderData, {
5424
5759
  osServer: true,
5425
5760
  customToast: function customToast() {}
5426
5761
  });
5427
5762
  case 12:
5428
- response = _context39.sent;
5763
+ response = _context43.sent;
5429
5764
  this.logInfo('Order API called successfully', {
5430
5765
  response: response
5431
5766
  });
@@ -5433,22 +5768,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5433
5768
  success: !!response,
5434
5769
  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)
5435
5770
  });
5436
- return _context39.abrupt("return", response);
5771
+ return _context43.abrupt("return", response);
5437
5772
  case 18:
5438
- _context39.prev = 18;
5439
- _context39.t0 = _context39["catch"](4);
5440
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context39.t0);
5773
+ _context43.prev = 18;
5774
+ _context43.t0 = _context43["catch"](4);
5775
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
5441
5776
  this.logInfo('Order API called failed', {
5442
- error: _context39.t0 instanceof Error ? _context39.t0.message : String(_context39.t0)
5777
+ error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
5443
5778
  });
5444
- throw _context39.t0;
5779
+ throw _context43.t0;
5445
5780
  case 23:
5446
5781
  case "end":
5447
- return _context39.stop();
5782
+ return _context43.stop();
5448
5783
  }
5449
- }, _callee36, this, [[4, 18]]);
5784
+ }, _callee40, this, [[4, 18]]);
5450
5785
  }));
5451
- function createOrderByCheckout(_x41) {
5786
+ function createOrderByCheckout(_x47) {
5452
5787
  return _createOrderByCheckout.apply(this, arguments);
5453
5788
  }
5454
5789
  return createOrderByCheckout;
@@ -5456,24 +5791,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5456
5791
  }, {
5457
5792
  key: "submitSalesOrder",
5458
5793
  value: function () {
5459
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5794
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5460
5795
  var url, query, fetchUrl;
5461
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5462
- while (1) switch (_context40.prev = _context40.next) {
5796
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5797
+ while (1) switch (_context44.prev = _context44.next) {
5463
5798
  case 0:
5464
5799
  url = params.url, query = params.query;
5465
5800
  fetchUrl = url || '/order/sales/checkout';
5466
- return _context40.abrupt("return", this.request.post(fetchUrl, query, {
5801
+ return _context44.abrupt("return", this.request.post(fetchUrl, query, {
5467
5802
  osServer: true,
5468
5803
  customToast: function customToast() {}
5469
5804
  }));
5470
5805
  case 3:
5471
5806
  case "end":
5472
- return _context40.stop();
5807
+ return _context44.stop();
5473
5808
  }
5474
- }, _callee37, this);
5809
+ }, _callee41, this);
5475
5810
  }));
5476
- function submitSalesOrder(_x42) {
5811
+ function submitSalesOrder(_x48) {
5477
5812
  return _submitSalesOrder.apply(this, arguments);
5478
5813
  }
5479
5814
  return submitSalesOrder;
@@ -5487,37 +5822,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5487
5822
  }, {
5488
5823
  key: "sendCustomerPayLink",
5489
5824
  value: (function () {
5490
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5825
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5491
5826
  var _params$emails;
5492
5827
  var orderIds;
5493
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5494
- while (1) switch (_context41.prev = _context41.next) {
5828
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5829
+ while (1) switch (_context45.prev = _context45.next) {
5495
5830
  case 0:
5496
5831
  orderIds = params.order_ids || params.orderIds || [];
5497
5832
  if (orderIds.length) {
5498
- _context41.next = 3;
5833
+ _context45.next = 3;
5499
5834
  break;
5500
5835
  }
5501
5836
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5502
5837
  case 3:
5503
5838
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5504
- _context41.next = 5;
5839
+ _context45.next = 5;
5505
5840
  break;
5506
5841
  }
5507
5842
  throw new Error('发送支付链接需要至少一个邮箱');
5508
5843
  case 5:
5509
- return _context41.abrupt("return", this.request.post('/order/batch-email', {
5844
+ return _context45.abrupt("return", this.request.post('/order/batch-email', {
5510
5845
  order_ids: orderIds,
5511
5846
  notify_action: params.notify_action || 'order_payment_reminder',
5512
5847
  emails: params.emails
5513
5848
  }));
5514
5849
  case 6:
5515
5850
  case "end":
5516
- return _context41.stop();
5851
+ return _context45.stop();
5517
5852
  }
5518
- }, _callee38, this);
5853
+ }, _callee42, this);
5519
5854
  }));
5520
- function sendCustomerPayLink(_x43) {
5855
+ function sendCustomerPayLink(_x49) {
5521
5856
  return _sendCustomerPayLink.apply(this, arguments);
5522
5857
  }
5523
5858
  return sendCustomerPayLink;
@@ -5525,14 +5860,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5525
5860
  }, {
5526
5861
  key: "getSalesOrderByLookup",
5527
5862
  value: function () {
5528
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5863
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5529
5864
  var lookup, res;
5530
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5531
- while (1) switch (_context42.prev = _context42.next) {
5865
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5866
+ while (1) switch (_context46.prev = _context46.next) {
5532
5867
  case 0:
5533
5868
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5534
5869
  if (lookup) {
5535
- _context42.next = 3;
5870
+ _context46.next = 3;
5536
5871
  break;
5537
5872
  }
5538
5873
  throw new Error('加载销售详情需要 lookup');
@@ -5541,27 +5876,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5541
5876
  if (lookup.startsWith('LOCAL_')) {
5542
5877
  params.forceRemote = false;
5543
5878
  }
5544
- _context42.next = 6;
5879
+ _context46.next = 6;
5545
5880
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5546
- with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
5881
+ with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds']
5547
5882
  }, params.forceRemote ? {
5548
5883
  forceRemote: true
5549
5884
  } : {}), {
5550
5885
  osServer: true
5551
5886
  });
5552
5887
  case 6:
5553
- res = _context42.sent;
5888
+ res = _context46.sent;
5554
5889
  if (res.code === 200) {
5555
5890
  this.store.lastOrderInfo = res.data;
5556
5891
  }
5557
- return _context42.abrupt("return", res);
5892
+ return _context46.abrupt("return", res);
5558
5893
  case 9:
5559
5894
  case "end":
5560
- return _context42.stop();
5895
+ return _context46.stop();
5561
5896
  }
5562
- }, _callee39, this);
5897
+ }, _callee43, this);
5563
5898
  }));
5564
- function getSalesOrderByLookup(_x44) {
5899
+ function getSalesOrderByLookup(_x50) {
5565
5900
  return _getSalesOrderByLookup.apply(this, arguments);
5566
5901
  }
5567
5902
  return getSalesOrderByLookup;
@@ -5575,11 +5910,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5575
5910
  }, {
5576
5911
  key: "hydrateTempOrderFromRecord",
5577
5912
  value: (function () {
5578
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(record, options) {
5579
- var _this$store$discount19;
5580
- var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, rawSummary, summarySurcharges, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount20, _this$store$discount21;
5581
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5582
- while (1) switch (_context43.prev = _context43.next) {
5913
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5914
+ var _this$store$discount22;
5915
+ var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, isSessionStorageHydrate, nextTempOrder, _this$store$discount20, _this$store$discount21, restoredSessionDiscounts, nextExtend, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount23, _this$store$discount24;
5916
+ return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5917
+ while (1) switch (_context47.prev = _context47.next) {
5583
5918
  case 0:
5584
5919
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5585
5920
  identityReadySource = this.seedAnonymousBookingUidsFromProducts(sourceRaw);
@@ -5602,14 +5937,57 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5602
5937
  this.logInfo('Normalized hydrated order collection identities', identityLogMetadata);
5603
5938
  }
5604
5939
  }
5940
+ isSessionStorageHydrate = (options === null || options === void 0 ? void 0 : options.source) === 'sessionStorage';
5605
5941
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
5606
- makeEditMark: true
5942
+ makeEditMark: !isSessionStorageHydrate
5943
+ });
5944
+ this.store.tempOrder = nextTempOrder;
5945
+ if (!isSessionStorageHydrate) {
5946
+ _context47.next = 27;
5947
+ break;
5948
+ }
5949
+ // 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
5950
+ restoredSessionDiscounts = Array.isArray(raw.discount_list) ? cloneDeep(raw.discount_list) : [];
5951
+ nextExtend = _objectSpread({}, nextTempOrder._extend || {});
5952
+ delete nextExtend.originalSalesSnapshot;
5953
+ nextTempOrder._extend = nextExtend;
5954
+ nextTempOrder.products.forEach(function (product) {
5955
+ if (product.metadata) {
5956
+ delete product.metadata.is_edit_for_runtime;
5957
+ }
5958
+ });
5959
+ nextTempOrder.discount_list = restoredSessionDiscounts;
5960
+ this.store.summary = createEmptySummary();
5961
+ this.store.lastOrderInfo = undefined;
5962
+ _context47.next = 20;
5963
+ return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(cloneDeep(restoredSessionDiscounts));
5964
+ case 20:
5965
+ _context47.next = 22;
5966
+ return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(cloneDeep(restoredSessionDiscounts));
5967
+ case 22:
5968
+ if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5969
+ _context47.next = 25;
5970
+ break;
5971
+ }
5972
+ _context47.next = 25;
5973
+ return this.recalculateSummary({
5974
+ createIfMissing: false
5607
5975
  });
5976
+ case 25:
5977
+ this.persistTempOrder();
5978
+ return _context47.abrupt("return", nextTempOrder);
5979
+ case 27:
5980
+ // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
5981
+ sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
5982
+ isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
5983
+ syntheticIdentityOptions = {
5984
+ isDraftOrder: isDraftOrder,
5985
+ externalSaleNumber: nextTempOrder.external_sale_number
5986
+ };
5608
5987
  rawSummary = raw.summary && _typeof(raw.summary) === 'object' ? raw.summary : {};
5609
5988
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
5610
5989
  return _objectSpread({}, s || {});
5611
5990
  }) : cloneDeep(nextTempOrder.surcharges || []);
5612
- this.store.tempOrder = nextTempOrder;
5613
5991
  this.store.summary = _objectSpread(_objectSpread(_objectSpread({}, createEmptySummary()), rawSummary), {}, {
5614
5992
  surcharges: summarySurcharges
5615
5993
  });
@@ -5624,12 +6002,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5624
6002
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
5625
6003
  }
5626
6004
  });
5627
- // lastOrderInfo carries the exact backend snapshot used by deposit/type recovery.
5628
- // Runtime collection repair lives in tempOrder/originalSalesSnapshot and must not
5629
- // rewrite this protocol snapshot as a side effect of hydration.
5630
- this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
6005
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
6006
+ hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
6007
+ if (hadSyntheticDraftOrderId && this.store.syncState !== 'submitting') {
6008
+ this.store.syncState = 'local';
6009
+ }
5631
6010
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
5632
- 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() || [] : [];
6011
+ currentDiscounts = typeof ((_this$store$discount22 = this.store.discount) === null || _this$store$discount22 === void 0 ? void 0 : _this$store$discount22.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
5633
6012
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
5634
6013
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
5635
6014
  });
@@ -5642,34 +6021,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5642
6021
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
5643
6022
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
5644
6023
  if (shouldSkipEmptyDiscountSync) {
5645
- _context43.next = 26;
6024
+ _context47.next = 50;
5646
6025
  break;
5647
6026
  }
5648
6027
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
5649
- _context43.next = 24;
5650
- return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(nextDiscounts);
5651
- case 24:
5652
- _context43.next = 26;
5653
- return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(nextDiscounts);
5654
- case 26:
6028
+ _context47.next = 48;
6029
+ return (_this$store$discount23 = this.store.discount) === null || _this$store$discount23 === void 0 ? void 0 : _this$store$discount23.setOriginalDiscountList(nextDiscounts);
6030
+ case 48:
6031
+ _context47.next = 50;
6032
+ return (_this$store$discount24 = this.store.discount) === null || _this$store$discount24 === void 0 ? void 0 : _this$store$discount24.setDiscountList(nextDiscounts);
6033
+ case 50:
5655
6034
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5656
- _context43.next = 29;
6035
+ _context47.next = 53;
5657
6036
  break;
5658
6037
  }
5659
- _context43.next = 29;
6038
+ _context47.next = 53;
5660
6039
  return this.recalculateSummary({
5661
6040
  createIfMissing: false
5662
6041
  });
5663
- case 29:
6042
+ case 53:
5664
6043
  this.persistTempOrder();
5665
- return _context43.abrupt("return", nextTempOrder);
5666
- case 31:
6044
+ return _context47.abrupt("return", nextTempOrder);
6045
+ case 55:
5667
6046
  case "end":
5668
- return _context43.stop();
6047
+ return _context47.stop();
5669
6048
  }
5670
- }, _callee40, this);
6049
+ }, _callee44, this);
5671
6050
  }));
5672
- function hydrateTempOrderFromRecord(_x45, _x46) {
6051
+ function hydrateTempOrderFromRecord(_x51, _x52) {
5673
6052
  return _hydrateTempOrderFromRecord.apply(this, arguments);
5674
6053
  }
5675
6054
  return hydrateTempOrderFromRecord;
@@ -5783,11 +6162,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5783
6162
  }, {
5784
6163
  key: "normalizeTempOrderForRuntime",
5785
6164
  value: function normalizeTempOrderForRuntime(raw, options) {
5786
- var _this29 = this;
5787
- var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
6165
+ var _this33 = this;
6166
+ var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6167
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
5788
6168
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
5789
- 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) {
5790
- nextTempOrder.order_id = raw.id;
6169
+ 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) {
6170
+ nextTempOrder.order_id = runtimeRaw.id;
5791
6171
  }
5792
6172
  delete nextTempOrder.summary;
5793
6173
  delete nextTempOrder.lastOrderInfo;
@@ -5806,12 +6186,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5806
6186
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
5807
6187
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
5808
6188
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
5809
- return _this29.normalizeHydratedOrderProduct(p, {
6189
+ return _this33.normalizeHydratedOrderProduct(p, {
5810
6190
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
5811
6191
  });
5812
6192
  }) : [];
5813
6193
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
5814
- var booking = _this29.normalizeHydratedBookingHolder(b || {});
6194
+ var booking = _this33.normalizeHydratedBookingHolder(b || {});
5815
6195
  return _objectSpread(_objectSpread({}, booking), {}, {
5816
6196
  is_all: normalizeBookingIsAll(booking),
5817
6197
  sub_type: normalizeBookingSubType(booking)
@@ -5877,6 +6257,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5877
6257
  nextTempOrder.vouchers = raw.vouchers || [];
5878
6258
  return nextTempOrder;
5879
6259
  }
6260
+ }, {
6261
+ key: "isSyntheticDraftOrderIdForRuntime",
6262
+ value: function isSyntheticDraftOrderIdForRuntime(record, options) {
6263
+ var _options$isDraftOrder, _record$external_sale;
6264
+ 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;
6265
+ 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;
6266
+ var orderId = record === null || record === void 0 ? void 0 : record.order_id;
6267
+ return Boolean(isDraftOrder && orderId !== undefined && orderId !== null && orderId !== '' && externalSaleNumber !== undefined && externalSaleNumber !== null && externalSaleNumber !== '' && String(orderId) === String(externalSaleNumber));
6268
+ }
6269
+ }, {
6270
+ key: "withoutSyntheticDraftOrderIdForRuntime",
6271
+ value: function withoutSyntheticDraftOrderIdForRuntime(record, options) {
6272
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options)) return record;
6273
+ return _objectSpread(_objectSpread({}, record), {}, {
6274
+ order_id: null
6275
+ });
6276
+ }
5880
6277
  }, {
5881
6278
  key: "hydrateLinkedBookingIdentity",
5882
6279
  value: function hydrateLinkedBookingIdentity(tempOrder) {
@@ -5981,7 +6378,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5981
6378
  }, {
5982
6379
  key: "normalizeHydratedOrderProduct",
5983
6380
  value: function normalizeHydratedOrderProduct(product, options) {
5984
- var _this30 = this;
6381
+ var _this34 = this;
5985
6382
  var row = _objectSpread({}, product || {});
5986
6383
  if (row.num === undefined && row.product_quantity !== undefined) {
5987
6384
  row.num = row.product_quantity;
@@ -5989,7 +6386,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5989
6386
  var productSku = ensureProductSku(row);
5990
6387
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
5991
6388
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
5992
- return _this30.normalizeHydratedProductOptionItem(optionItem || {});
6389
+ return _this34.normalizeHydratedProductOptionItem(optionItem || {});
5993
6390
  }))
5994
6391
  });
5995
6392
  delete row["product_".concat('option', "_item")];
@@ -6026,27 +6423,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6026
6423
  }, {
6027
6424
  key: "getOrderInfo",
6028
6425
  value: function () {
6029
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(order_id) {
6426
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
6030
6427
  var res;
6031
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
6032
- while (1) switch (_context44.prev = _context44.next) {
6428
+ return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6429
+ while (1) switch (_context48.prev = _context48.next) {
6033
6430
  case 0:
6034
- _context44.next = 2;
6431
+ _context48.next = 2;
6035
6432
  return this.request.get("/order/sales/".concat(order_id), {
6036
6433
  with: ['products', 'bookings']
6037
6434
  }, {
6038
6435
  osServer: true
6039
6436
  });
6040
6437
  case 2:
6041
- res = _context44.sent;
6042
- return _context44.abrupt("return", res);
6438
+ res = _context48.sent;
6439
+ return _context48.abrupt("return", res);
6043
6440
  case 4:
6044
6441
  case "end":
6045
- return _context44.stop();
6442
+ return _context48.stop();
6046
6443
  }
6047
- }, _callee41, this);
6444
+ }, _callee45, this);
6048
6445
  }));
6049
- function getOrderInfo(_x47) {
6446
+ function getOrderInfo(_x53) {
6050
6447
  return _getOrderInfo.apply(this, arguments);
6051
6448
  }
6052
6449
  return getOrderInfo;