@pisell/pisellos 2.2.278 → 2.2.280

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 (188) hide show
  1. package/dist/modules/BaseModule.d.ts +1 -0
  2. package/dist/modules/BaseModule.js +24 -28
  3. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +7 -3
  4. package/dist/modules/BookingContext/utils/productExtend.js +5 -9
  5. package/dist/modules/BookingContext/utils/timeSlices.js +24 -3
  6. package/dist/modules/Customer/index.d.ts +4 -0
  7. package/dist/modules/Customer/index.js +91 -59
  8. package/dist/modules/Customer/types.d.ts +2 -0
  9. package/dist/modules/Discount/index.d.ts +1 -0
  10. package/dist/modules/Discount/index.js +40 -11
  11. package/dist/modules/Discount/types.d.ts +1 -0
  12. package/dist/modules/Holder/index.d.ts +48 -0
  13. package/dist/modules/Holder/index.js +640 -0
  14. package/dist/modules/Holder/types.d.ts +123 -0
  15. package/dist/modules/Holder/types.js +1 -0
  16. package/dist/modules/Holder/utils.d.ts +13 -0
  17. package/dist/modules/Holder/utils.js +34 -0
  18. package/dist/modules/OpenData/index.js +2 -2
  19. package/dist/modules/Order/index.d.ts +32 -4
  20. package/dist/modules/Order/index.js +868 -675
  21. package/dist/modules/Order/types.d.ts +22 -1
  22. package/dist/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  23. package/dist/modules/Order/utils/discountProductLineIdentity.js +227 -0
  24. package/dist/modules/Order/utils/orderCollectionIdentity.d.ts +15 -0
  25. package/dist/modules/Order/utils/orderCollectionIdentity.js +75 -0
  26. package/dist/modules/Order/utils.d.ts +10 -0
  27. package/dist/modules/Order/utils.js +71 -34
  28. package/dist/modules/Payment/index.d.ts +4 -0
  29. package/dist/modules/Payment/index.js +14 -4
  30. package/dist/modules/Payment/walletpass.js +21 -7
  31. package/dist/modules/Product/types.d.ts +1 -0
  32. package/dist/modules/ProductList/index.js +33 -13
  33. package/dist/modules/Quotation/index.d.ts +1 -1
  34. package/dist/modules/Quotation/index.js +2 -2
  35. package/dist/modules/ResourcePlanner/index.d.ts +24 -0
  36. package/dist/modules/ResourcePlanner/index.js +181 -0
  37. package/dist/modules/ResourcePlanner/planner.d.ts +14 -0
  38. package/dist/modules/ResourcePlanner/planner.js +1069 -0
  39. package/dist/modules/ResourcePlanner/types.d.ts +227 -0
  40. package/dist/modules/ResourcePlanner/types.js +1 -0
  41. package/dist/modules/Rules/index.js +153 -56
  42. package/dist/modules/SalesSummary/index.js +12 -13
  43. package/dist/modules/ScanOrderLogger/index.d.ts +2 -0
  44. package/dist/modules/ScanOrderLogger/index.js +15 -2
  45. package/dist/modules/ScanOrderLogger/providers/feishu.js +45 -27
  46. package/dist/modules/ScanOrderLogger/types.d.ts +1 -0
  47. package/dist/modules/Schedule/index.d.ts +3 -1
  48. package/dist/modules/Schedule/index.js +21 -16
  49. package/dist/modules/Summary/utils.js +38 -13
  50. package/dist/modules/index.d.ts +2 -0
  51. package/dist/modules/index.js +3 -1
  52. package/dist/plugins/window.d.ts +1 -0
  53. package/dist/server/index.d.ts +20 -0
  54. package/dist/server/index.js +1101 -909
  55. package/dist/server/modules/order/index.d.ts +2 -0
  56. package/dist/server/modules/order/index.js +261 -96
  57. package/dist/server/modules/order/types.d.ts +1 -1
  58. package/dist/solution/BaseSales/index.d.ts +20 -1
  59. package/dist/solution/BaseSales/index.js +989 -881
  60. package/dist/solution/BaseSales/utils/cartPromotion.js +19 -1
  61. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  62. package/dist/solution/BaseSales/utils.js +31 -20
  63. package/dist/solution/BookingByStep/index.d.ts +17 -2
  64. package/dist/solution/BookingByStep/index.js +294 -215
  65. package/dist/solution/BookingByStep/types.d.ts +2 -1
  66. package/dist/solution/BookingByStep/types.js +3 -1
  67. package/dist/solution/BookingByStep/utils/capacity.js +17 -1
  68. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  69. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  70. package/dist/solution/BookingTicket/index.d.ts +21 -3
  71. package/dist/solution/BookingTicket/index.js +312 -226
  72. package/dist/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  73. package/dist/solution/BookingTicket/utils/scan/handleScan.js +10 -2
  74. package/dist/solution/ScanOrder/index.d.ts +26 -14
  75. package/dist/solution/ScanOrder/index.js +1142 -739
  76. package/dist/solution/ScanOrder/types.d.ts +21 -1
  77. package/dist/solution/ScanOrder/utils.d.ts +8 -0
  78. package/dist/solution/ScanOrder/utils.js +97 -45
  79. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  80. package/dist/solution/ShopDiscount/index.js +125 -87
  81. package/dist/solution/UnifiedBookingSales/index.d.ts +204 -0
  82. package/dist/solution/UnifiedBookingSales/index.js +2211 -0
  83. package/dist/solution/UnifiedBookingSales/types.d.ts +150 -0
  84. package/dist/solution/UnifiedBookingSales/types.js +11 -0
  85. package/dist/solution/VenueBooking/index.d.ts +39 -11
  86. package/dist/solution/VenueBooking/index.js +1167 -841
  87. package/dist/solution/VenueBooking/types.d.ts +3 -0
  88. package/dist/solution/VenueBooking/utils/resource.js +1 -0
  89. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  90. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -5
  91. package/dist/solution/index.d.ts +1 -0
  92. package/dist/solution/index.js +2 -1
  93. package/dist/types/index.d.ts +1 -0
  94. package/lib/model/strategy/adapter/promotion/index.js +0 -51
  95. package/lib/modules/BaseModule.d.ts +1 -0
  96. package/lib/modules/BaseModule.js +24 -37
  97. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +3 -0
  98. package/lib/modules/BookingContext/utils/productExtend.js +4 -3
  99. package/lib/modules/BookingContext/utils/timeSlices.js +18 -3
  100. package/lib/modules/Customer/index.d.ts +4 -0
  101. package/lib/modules/Customer/index.js +11 -0
  102. package/lib/modules/Customer/types.d.ts +2 -0
  103. package/lib/modules/Discount/index.d.ts +1 -0
  104. package/lib/modules/Discount/index.js +9 -0
  105. package/lib/modules/Discount/types.d.ts +1 -0
  106. package/lib/modules/Holder/index.d.ts +48 -0
  107. package/lib/modules/Holder/index.js +402 -0
  108. package/lib/modules/Holder/types.d.ts +123 -0
  109. package/lib/modules/Holder/types.js +17 -0
  110. package/lib/modules/Holder/utils.d.ts +13 -0
  111. package/lib/modules/Holder/utils.js +71 -0
  112. package/lib/modules/OpenData/index.js +1 -1
  113. package/lib/modules/Order/index.d.ts +32 -4
  114. package/lib/modules/Order/index.js +372 -156
  115. package/lib/modules/Order/types.d.ts +22 -1
  116. package/lib/modules/Order/utils/discountProductLineIdentity.d.ts +45 -0
  117. package/lib/modules/Order/utils/discountProductLineIdentity.js +170 -0
  118. package/lib/modules/Order/utils/orderCollectionIdentity.d.ts +15 -0
  119. package/lib/modules/Order/utils/orderCollectionIdentity.js +70 -0
  120. package/lib/modules/Order/utils.d.ts +10 -0
  121. package/lib/modules/Order/utils.js +39 -6
  122. package/lib/modules/Payment/index.d.ts +4 -0
  123. package/lib/modules/Payment/index.js +7 -0
  124. package/lib/modules/Payment/walletpass.js +12 -0
  125. package/lib/modules/Product/types.d.ts +1 -0
  126. package/lib/modules/ProductList/index.js +49 -31
  127. package/lib/modules/Quotation/index.d.ts +1 -1
  128. package/lib/modules/Quotation/index.js +2 -2
  129. package/lib/modules/ResourcePlanner/index.d.ts +24 -0
  130. package/lib/modules/ResourcePlanner/index.js +148 -0
  131. package/lib/modules/ResourcePlanner/planner.d.ts +14 -0
  132. package/lib/modules/ResourcePlanner/planner.js +933 -0
  133. package/lib/modules/ResourcePlanner/types.d.ts +227 -0
  134. package/lib/modules/ResourcePlanner/types.js +17 -0
  135. package/lib/modules/Rules/index.js +117 -25
  136. package/lib/modules/SalesSummary/index.js +6 -7
  137. package/lib/modules/ScanOrderLogger/index.d.ts +2 -0
  138. package/lib/modules/ScanOrderLogger/index.js +13 -1
  139. package/lib/modules/ScanOrderLogger/providers/feishu.js +15 -6
  140. package/lib/modules/ScanOrderLogger/types.d.ts +1 -0
  141. package/lib/modules/Schedule/index.d.ts +3 -1
  142. package/lib/modules/Schedule/index.js +10 -8
  143. package/lib/modules/Summary/utils.js +21 -1
  144. package/lib/modules/index.d.ts +2 -0
  145. package/lib/modules/index.js +5 -1
  146. package/lib/plugins/window.d.ts +1 -0
  147. package/lib/server/index.d.ts +20 -0
  148. package/lib/server/index.js +124 -19
  149. package/lib/server/modules/order/index.d.ts +2 -0
  150. package/lib/server/modules/order/index.js +75 -5
  151. package/lib/server/modules/order/types.d.ts +1 -1
  152. package/lib/solution/BaseSales/index.d.ts +20 -1
  153. package/lib/solution/BaseSales/index.js +105 -31
  154. package/lib/solution/BaseSales/utils/cartPromotion.js +18 -0
  155. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +1 -0
  156. package/lib/solution/BaseSales/utils.js +29 -18
  157. package/lib/solution/BookingByStep/index.d.ts +17 -2
  158. package/lib/solution/BookingByStep/index.js +60 -18
  159. package/lib/solution/BookingByStep/types.d.ts +2 -1
  160. package/lib/solution/BookingByStep/types.js +5 -0
  161. package/lib/solution/BookingByStep/utils/capacity.js +20 -1
  162. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  163. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  164. package/lib/solution/BookingTicket/index.d.ts +21 -3
  165. package/lib/solution/BookingTicket/index.js +75 -16
  166. package/lib/solution/BookingTicket/utils/scan/handleScan.d.ts +3 -1
  167. package/lib/solution/BookingTicket/utils/scan/handleScan.js +2 -2
  168. package/lib/solution/ScanOrder/index.d.ts +26 -14
  169. package/lib/solution/ScanOrder/index.js +449 -182
  170. package/lib/solution/ScanOrder/types.d.ts +21 -1
  171. package/lib/solution/ScanOrder/utils.d.ts +8 -0
  172. package/lib/solution/ScanOrder/utils.js +60 -18
  173. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  174. package/lib/solution/ShopDiscount/index.js +14 -0
  175. package/lib/solution/UnifiedBookingSales/index.d.ts +204 -0
  176. package/lib/solution/UnifiedBookingSales/index.js +1273 -0
  177. package/lib/solution/UnifiedBookingSales/types.d.ts +150 -0
  178. package/lib/solution/UnifiedBookingSales/types.js +33 -0
  179. package/lib/solution/VenueBooking/index.d.ts +39 -11
  180. package/lib/solution/VenueBooking/index.js +322 -110
  181. package/lib/solution/VenueBooking/types.d.ts +3 -0
  182. package/lib/solution/VenueBooking/utils/resource.js +1 -0
  183. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -4
  184. package/lib/solution/VenueBooking/utils/slotMerge.js +6 -4
  185. package/lib/solution/index.d.ts +1 -0
  186. package/lib/solution/index.js +3 -1
  187. package/lib/types/index.d.ts +1 -0
  188. package/package.json +1 -1
@@ -32,16 +32,17 @@ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol"
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); }
33
33
  import { BaseModule } from "../BaseModule";
34
34
  import { OrderHooks } from "./types";
35
- import { composeLinePrice, generateDuration, getAllDiscountList, mergeRelationForms, buildSubmitPayload, createDefaultTempOrder, createDefaultOrderRulesHooks, createEmptySummary, createUuidV4, formatDateTime, isTempOrder, normalizeBookingIsAll, normalizeBookingSubType, mapPaymentItemsToOrderPayments, normalizeOrderProductDiscountList, resolveEffectivePerUnitDiscount, ensureProductSku, getProductSkuOptions, normalizeProductSkuOptions, sumOptionUnitPrice, clearTempOrderHolderAssignments, getOrderProductLineUid, indexOrderProductsByUid, calculateOrderProductsDeposit, mergeOrderProductDisplayFields, resolveIsFormSubject } from "./utils";
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
38
  import { ensureOrderPaymentNumber, mergeOrderPaymentRecord, resolveOrderPaymentIdentity } from "./payment-utils";
39
39
  import { resolvePaymentNumberDevicePrefix, resolvePaymentNumberDevicePrefixFromDeviceId } from "../../utils/payment-number";
40
40
  import { processCartPromotion, appendPromotionTags as _appendPromotionTags, getOrderProductUid as getPromotionUid } from "../../solution/BaseSales/utils/cartPromotion";
41
41
  import { buildProductLineFingerprint, getProductIdentityIndex, getSafeProductNum, isIdentityMatch, normalizeOrderProduct } from "../../solution/ScanOrder/utils";
42
- import { syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
42
+ import { hasManualProductDiscountFlag, syncManualProductDiscountProductNum } from "./utils/manualProductDiscount";
43
43
  import { expandHydratedProductsForDiscountCollection, restoreHydratedBundleDiscounts } from "./utils/bundleDiscountHydration";
44
- import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
44
+ import { getOrderCollectionPersistentId, getOrderCollectionUid, normalizeOrderCollections, repairDuplicateProductLineIdentities as repairDuplicateOrderProductLineIdentities, setOrderCollectionUid } from "./utils/orderCollectionIdentity";
45
+ import { consolidateDiscountFreeProductLines, ensureUniqueProductLineUids } from "./utils/discountProductLineIdentity";
45
46
  import { DiscountModule } from "../Discount";
46
47
  import { RulesModule } from "../Rules";
47
48
  import { UnavailableReason } from "../Rules/types";
@@ -63,8 +64,7 @@ function isSameDiscountList(left, right) {
63
64
  return JSON.stringify(normalizeDiscountListSignature(left)) === JSON.stringify(normalizeDiscountListSignature(right));
64
65
  }
65
66
  function isManualProductDiscountProduct(product) {
66
- var _product$metadata, _product$metadata2;
67
- return (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.is_manual_discount) === true || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.is_manual_discount) === 1 || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
67
+ return hasManualProductDiscountFlag(product === null || product === void 0 ? void 0 : product.metadata) || ((product === null || product === void 0 ? void 0 : product.discount_list) || []).some(function (item) {
68
68
  return (item === null || item === void 0 ? void 0 : item.type) === 'product';
69
69
  });
70
70
  }
@@ -121,6 +121,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
121
121
  _defineProperty(_assertThisInitialized(_this), "window", void 0);
122
122
  _defineProperty(_assertThisInitialized(_this), "appPlugin", void 0);
123
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);
124
128
  _defineProperty(_assertThisInitialized(_this), "salesSummaryModuleName", void 0);
125
129
  _defineProperty(_assertThisInitialized(_this), "rulesHooksOverride", void 0);
126
130
  _defineProperty(_assertThisInitialized(_this), "moduleHooksOverride", void 0);
@@ -269,7 +273,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
269
273
  key: "applyProductDiscountPrices",
270
274
  value: function applyProductDiscountPrices(products) {
271
275
  return (products || []).map(function (product) {
272
- var _product$metadata$sou, _product$metadata3, _product$metadata4, _product$original_pri2;
276
+ var _product$metadata$sou, _product$metadata, _product$metadata2, _product$original_pri2;
273
277
  if (isManualProductDiscountProduct(product)) return product;
274
278
  var discountItems = Array.isArray(product.discount_list) ? product.discount_list : [];
275
279
  var hasOnlyPersistedDiscountSnapshots = product.order_detail_id !== undefined && product.order_detail_id !== null && discountItems.length > 0 && discountItems.every(function (discount) {
@@ -280,7 +284,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
280
284
  }
281
285
  var totalPerUnitDiscount = resolveEffectivePerUnitDiscount(product);
282
286
  var optionSum = sumOptionUnitPrice(getProductSkuOptions(product));
283
- var sourcePrice = (_product$metadata$sou = (_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
287
+ var sourcePrice = (_product$metadata$sou = (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.source_product_price) !== null && _product$metadata$sou !== void 0 ? _product$metadata$sou : ((_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.main_product_original_price) != null ? new Decimal(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : (_product$original_pri2 = product.original_price) !== null && _product$original_pri2 !== void 0 ? _product$original_pri2 : '0';
284
288
  var newSourceSellingPrice = new Decimal(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
285
289
  var newMainSellingPrice = new Decimal(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
286
290
  if (product.metadata) {
@@ -307,18 +311,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
307
311
  return product;
308
312
  });
309
313
  }
314
+ }, {
315
+ key: "syncSessionStorageOptions",
316
+ value: function syncSessionStorageOptions(otherParams) {
317
+ this.cacheId = otherParams.cacheId;
318
+ this.fatherModule = otherParams.fatherModule;
319
+ this.openCache = Boolean(this.cacheId && otherParams.openCache !== false);
320
+ this.sessionStoragePersistEnabled = Boolean(this.openCache && otherParams.enableSessionStoragePersist === true);
321
+ }
310
322
  }, {
311
323
  key: "initialize",
312
324
  value: function () {
313
325
  var _initialize = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee(core, options) {
314
- var _otherParams$rules, _otherParams$order, _otherParams$hooks;
315
- var app, otherParams;
326
+ var _appPlugin$getApp, _otherParams$rules, _otherParams$order, _otherParams$hooks;
327
+ var otherParams, cachedTempOrder, appPlugin, app;
316
328
  return _regeneratorRuntime().wrap(function _callee$(_context) {
317
329
  while (1) switch (_context.prev = _context.next) {
318
330
  case 0:
319
331
  this.core = core;
320
332
  this.store = options.store;
321
- if (!this.store.tempOrder) {
333
+ otherParams = options.otherParams || {};
334
+ this.syncSessionStorageOptions(otherParams);
335
+ if (this.sessionStoragePersistEnabled) {
336
+ cachedTempOrder = this.store.tempOrder;
337
+ this.sessionStorageRestoreRecord = isTempOrder(cachedTempOrder) ? cloneDeep(cachedTempOrder) : null;
338
+ // 统一由 loadSalesDetail hydrate,初始化阶段不直接把缓存态暴露给业务。
339
+ this.store.tempOrder = null;
340
+ this.store.summary = createEmptySummary();
341
+ this.store.availableWalletIds = [];
342
+ this.store.lastOrderInfo = undefined;
343
+ this.store.syncState = undefined;
344
+ this.store.discountList = [];
345
+ } else if (!this.store.tempOrder) {
322
346
  this.store.tempOrder = null;
323
347
  }
324
348
  if (!this.store.summary) {
@@ -328,18 +352,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
328
352
  this.store.availableWalletIds = [];
329
353
  }
330
354
  this.request = this.core.getPlugin('request');
331
- this.appPlugin = this.core.getPlugin('app');
332
- if (this.appPlugin) {
333
- _context.next = 9;
334
- break;
355
+ appPlugin = this.core.getPlugin('app');
356
+ if (!appPlugin) {
357
+ console.error('Order 模块需要 app 插件支持');
335
358
  }
336
- throw new Error('Order 模块需要 app 插件支持');
337
- case 9:
338
- app = this.appPlugin.getApp();
339
- this.logger = app.logger;
359
+ app = appPlugin === null || appPlugin === void 0 || (_appPlugin$getApp = appPlugin.getApp) === null || _appPlugin$getApp === void 0 ? void 0 : _appPlugin$getApp.call(appPlugin);
360
+ this.logger = app === null || app === void 0 ? void 0 : app.logger;
340
361
  this.window = this.core.getPlugin('window');
341
- otherParams = options.otherParams || {};
342
- this.cacheId = otherParams.cacheId;
343
362
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
344
363
  this.rulesHooksOverride = (_otherParams$rules = otherParams.rules) === null || _otherParams$rules === void 0 ? void 0 : _otherParams$rules.hooks;
345
364
  this.moduleHooksOverride = options.hooks;
@@ -347,7 +366,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
347
366
  this.otherParams = otherParams;
348
367
  this.registerDiscountModules(options);
349
368
  this.logInfo('OrderModule initialized successfully');
350
- case 21:
369
+ case 20:
351
370
  case "end":
352
371
  return _context.stop();
353
372
  }
@@ -367,49 +386,50 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
367
386
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
368
387
  while (1) switch (_context2.prev = _context2.next) {
369
388
  case 0:
389
+ this.sessionStorageRestoreRecord = null;
370
390
  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];
371
391
  _i = 0, _childModules = childModules;
372
- case 2:
392
+ case 3:
373
393
  if (!(_i < _childModules.length)) {
374
- _context2.next = 18;
394
+ _context2.next = 19;
375
395
  break;
376
396
  }
377
397
  childModule = _childModules[_i];
378
398
  if (!(!childModule || typeof childModule.destroy !== 'function')) {
379
- _context2.next = 6;
399
+ _context2.next = 7;
380
400
  break;
381
401
  }
382
- return _context2.abrupt("continue", 15);
383
- case 6:
384
- _context2.prev = 6;
385
- _context2.next = 9;
402
+ return _context2.abrupt("continue", 16);
403
+ case 7:
404
+ _context2.prev = 7;
405
+ _context2.next = 10;
386
406
  return childModule.destroy();
387
- case 9:
388
- _context2.next = 15;
407
+ case 10:
408
+ _context2.next = 16;
389
409
  break;
390
- case 11:
391
- _context2.prev = 11;
392
- _context2.t0 = _context2["catch"](6);
410
+ case 12:
411
+ _context2.prev = 12;
412
+ _context2.t0 = _context2["catch"](7);
393
413
  errorMessage = _context2.t0 instanceof Error ? _context2.t0.message : String(_context2.t0);
394
414
  this.logWarning('Destroy child module failed', {
395
415
  module: childModule.name,
396
416
  error: errorMessage
397
417
  });
398
- case 15:
418
+ case 16:
399
419
  _i++;
400
- _context2.next = 2;
420
+ _context2.next = 3;
401
421
  break;
402
- case 18:
422
+ case 19:
403
423
  if (this.store) {
404
424
  this.store.discount = null;
405
425
  this.store.rules = null;
406
426
  }
407
427
  _get(_getPrototypeOf(OrderModule.prototype), "destroy", this).call(this);
408
- case 20:
428
+ case 21:
409
429
  case "end":
410
430
  return _context2.stop();
411
431
  }
412
- }, _callee2, this, [[6, 11]]);
432
+ }, _callee2, this, [[7, 12]]);
413
433
  }));
414
434
  function destroy() {
415
435
  return _destroy.apply(this, arguments);
@@ -427,7 +447,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
427
447
  value: function updateOtherParams(params) {
428
448
  var _otherParams$rules2, _otherParams$order2, _otherParams$hooks2;
429
449
  var otherParams = params || {};
430
- this.cacheId = otherParams.cacheId;
450
+ this.syncSessionStorageOptions(otherParams);
431
451
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
432
452
  this.rulesHooksOverride = (_otherParams$rules2 = otherParams.rules) === null || _otherParams$rules2 === void 0 ? void 0 : _otherParams$rules2.hooks;
433
453
  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);
@@ -485,15 +505,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
485
505
  value: function registerDiscountModules(options) {
486
506
  var _targetCacheData;
487
507
  var targetCacheData = {};
488
- if (this.cacheId && this.window) {
489
- var sessionData = this.window.sessionStorage.getItem(this.name);
490
- if (sessionData) {
491
- try {
508
+ if (!this.sessionStoragePersistEnabled && this.openCache && this.cacheId && this.window) {
509
+ try {
510
+ var sessionData = this.window.sessionStorage.getItem(this.name);
511
+ if (sessionData) {
492
512
  var data = JSON.parse(sessionData);
493
513
  targetCacheData = (data === null || data === void 0 ? void 0 : data[this.cacheId]) || {};
494
- } catch (_unused) {
495
- // sessionStorage 损坏则忽略,按空 initialState 走
496
514
  }
515
+ } catch (_unused) {
516
+ // sessionStorage 损坏或不可用时忽略,按空 initialState 走
497
517
  }
498
518
  }
499
519
  var discount = new DiscountModule("".concat(this.name, "_discount"));
@@ -501,7 +521,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
501
521
  initialState: (_targetCacheData = targetCacheData) === null || _targetCacheData === void 0 ? void 0 : _targetCacheData[discount.name],
502
522
  otherParams: {
503
523
  fatherModule: this.name,
504
- openCache: !!this.cacheId,
524
+ // Unified 的单快照由 Order 管理;其他 Solution 保持原有 Discount 缓存语义。
525
+ openCache: this.openCache && !this.sessionStoragePersistEnabled,
505
526
  cacheId: this.cacheId
506
527
  }
507
528
  });
@@ -871,6 +892,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
871
892
  discount_list: normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(mergedProduct.discount_list, mergedProduct.num))
872
893
  });
873
894
  }));
895
+ ensureUniqueProductLineUids(tempOrder);
896
+ consolidateDiscountFreeProductLines(tempOrder);
874
897
  }
875
898
  if (result !== null && result !== void 0 && result.discountList) {
876
899
  var _this$store$discount15;
@@ -1254,7 +1277,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1254
1277
 
1255
1278
  /**
1256
1279
  * 控制 IndexedDB 草稿(saveDraft)是否写入。
1257
- * localStorage tempOrder 持久化已废弃,此方法仅影响 saveDraft。
1280
+ * 此开关仅影响 saveDraft;可选 sessionStorage 会话恢复由
1281
+ * enableSessionStoragePersist 独立控制。
1258
1282
  *
1259
1283
  * @example
1260
1284
  * order.setEnableTempOrderPersist(false); // BigSale 弹窗:跳过 ~1s 的 dbUpdate
@@ -1272,11 +1296,86 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1272
1296
  return this.draftPersistEnabled;
1273
1297
  }
1274
1298
 
1275
- /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
1299
+ /**
1300
+ * 在 UnifiedBookingSales 显式开启会话恢复时,将完整 tempOrder 写入
1301
+ * sessionStorage 的 cacheId 分桶。写入失败由 BaseModule 静默降级。
1302
+ */
1276
1303
  }, {
1277
1304
  key: "persistTempOrder",
1278
1305
  value: function persistTempOrder() {
1279
- // no-op: OrderModule 的刷新恢复不再依赖 localStorage。
1306
+ if (!this.sessionStoragePersistEnabled || !this.store.tempOrder) return;
1307
+ this.checkSaveCache({
1308
+ cacheId: this.cacheId,
1309
+ fatherModule: this.fatherModule,
1310
+ store: {
1311
+ tempOrder: this.store.tempOrder
1312
+ },
1313
+ cacheKey: ['tempOrder']
1314
+ });
1315
+ }
1316
+
1317
+ /**
1318
+ * 终止当前模块实例的 sessionStorage 订单恢复会话。
1319
+ *
1320
+ * 支付跳转等终态场景需要同时删除当前 cacheId 的 tempOrder 快照,并关闭
1321
+ * 本实例后续异步任务的再次写入;新模块实例初始化时会按 otherParams 重新启用。
1322
+ */
1323
+ }, {
1324
+ key: "clearSessionStoragePersistedTempOrder",
1325
+ value: function clearSessionStoragePersistedTempOrder() {
1326
+ var _this$window;
1327
+ this.sessionStorageRestoreRecord = null;
1328
+ if (!this.sessionStoragePersistEnabled) return;
1329
+ this.sessionStoragePersistEnabled = false;
1330
+ if (!this.cacheId || !this.fatherModule || !((_this$window = this.window) !== null && _this$window !== void 0 && _this$window.sessionStorage)) {
1331
+ return;
1332
+ }
1333
+ var sessionStorage = this.window.sessionStorage;
1334
+ var rawCacheData = sessionStorage.getItem(this.fatherModule);
1335
+ if (!rawCacheData) return;
1336
+ var parsedCacheData;
1337
+ try {
1338
+ parsedCacheData = JSON.parse(rawCacheData);
1339
+ } catch (_unused2) {
1340
+ return;
1341
+ }
1342
+ if (!parsedCacheData || _typeof(parsedCacheData) !== 'object' || Array.isArray(parsedCacheData)) {
1343
+ return;
1344
+ }
1345
+ var cacheRoot = parsedCacheData;
1346
+ var cacheBucket = cacheRoot[this.cacheId];
1347
+ if (!cacheBucket || _typeof(cacheBucket) !== 'object' || Array.isArray(cacheBucket)) {
1348
+ return;
1349
+ }
1350
+ var moduleBucket = cacheBucket[this.name];
1351
+ if (!moduleBucket || _typeof(moduleBucket) !== 'object' || Array.isArray(moduleBucket)) {
1352
+ return;
1353
+ }
1354
+ delete moduleBucket.tempOrder;
1355
+ if (Object.keys(moduleBucket).length === 0) {
1356
+ delete cacheBucket[this.name];
1357
+ }
1358
+ if (Object.keys(cacheBucket).length === 0) {
1359
+ delete cacheRoot[this.cacheId];
1360
+ }
1361
+ sessionStorage.setItem(this.fatherModule, JSON.stringify(cacheRoot));
1362
+ }
1363
+ }, {
1364
+ key: "consumeSessionStorageRestore",
1365
+ value: function consumeSessionStorageRestore() {
1366
+ var record = this.sessionStorageRestoreRecord;
1367
+ this.sessionStorageRestoreRecord = null;
1368
+ return record ? cloneDeep(record) : null;
1369
+ }
1370
+ }, {
1371
+ key: "notifyTempOrderChanged",
1372
+ value: function notifyTempOrderChanged() {
1373
+ if (!this.store.tempOrder) return;
1374
+ this.store.tempOrder = _objectSpread(_objectSpread({}, this.store.tempOrder), {}, {
1375
+ products: _toConsumableArray(this.store.tempOrder.products),
1376
+ bookings: this.store.tempOrder.bookings ? _toConsumableArray(this.store.tempOrder.bookings) : []
1377
+ });
1378
+ this.persistTempOrder();
1280
1379
  }
1281
1380
 
1282
1381
  // ─── TempOrder: 创建 & 获取 ───
@@ -1533,7 +1632,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1533
1632
  paidAmount: netPaidAmount
1534
1633
  });
1535
1634
  var isOrderFullyPaid = orderExpectedAmount.lte(0) ? true : netPaidAmount.gte(orderExpectedAmount);
1536
- var paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid ? 'deposit' : 'normal';
1635
+ var paymentStage = this.isDepositOrder(tempOrder, depositAmount) && !isDepositFullyPaid && !this.hasPaidNormalPayment(paymentList) ? 'deposit' : 'normal';
1537
1636
  return {
1538
1637
  isFullyPaid: isOrderFullyPaid,
1539
1638
  isOrderFullyPaid: isOrderFullyPaid,
@@ -1555,12 +1654,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1555
1654
  return sum.plus(_this6.calculatePaymentGapAmount(paymentRecord));
1556
1655
  }, new Decimal(0));
1557
1656
  }
1657
+ }, {
1658
+ key: "hasPaidNormalPayment",
1659
+ value: function hasPaidNormalPayment(payments) {
1660
+ return (payments || []).some(function (payment) {
1661
+ var paymentRecord = payment;
1662
+ if (!isPaidPaymentRecord(paymentRecord)) return false;
1663
+ return paymentRecord.order_payment_type !== 'deposit' && paymentRecord.type !== 'deposit';
1664
+ });
1665
+ }
1558
1666
  }, {
1559
1667
  key: "resolveNextOrderPaymentType",
1560
1668
  value: function resolveNextOrderPaymentType(tempOrder) {
1561
1669
  var depositAmount = new Decimal(tempOrder.deposit_amount || '0.00');
1562
1670
  if (!this.isDepositOrder(tempOrder, depositAmount)) return 'normal';
1563
1671
  if (depositAmount.lte(0)) return 'normal';
1672
+ if (this.hasPaidNormalPayment(tempOrder.payments || [])) return 'normal';
1564
1673
  var depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1565
1674
  return depositPaidAmount.lt(depositAmount) ? 'deposit' : 'normal';
1566
1675
  }
@@ -1888,10 +1997,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1888
1997
  value: function calculateSummaryAmountGap(params) {
1889
1998
  var tempOrder = params.tempOrder,
1890
1999
  summary = params.summary,
1891
- orderPaidAmount = params.orderPaidAmount;
2000
+ orderPaidAmount = params.orderPaidAmount,
2001
+ payments = params.payments;
1892
2002
  var refundAmount = this.getSummaryRefundAmount(summary);
1893
2003
  var netOrderPaidAmount = Decimal.max(orderPaidAmount.minus(refundAmount), 0);
1894
- var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary, netOrderPaidAmount);
2004
+ var targetAmount = this.calculatePaymentTargetAmount(tempOrder, summary, netOrderPaidAmount, payments);
1895
2005
  return targetAmount.minus(netOrderPaidAmount).toFixed(2);
1896
2006
  }
1897
2007
  }, {
@@ -1903,10 +2013,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1903
2013
  key: "calculatePaymentTargetAmount",
1904
2014
  value: function calculatePaymentTargetAmount(tempOrder, summary) {
1905
2015
  var paidAmount = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : new Decimal(0);
2016
+ var payments = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : tempOrder.payments || [];
1906
2017
  var depositAmount = this.getDepositAmount(tempOrder, summary);
1907
2018
  if (!this.isDepositOrder(tempOrder, depositAmount)) {
1908
2019
  return this.getOrderExpectedAmount(summary);
1909
2020
  }
2021
+ if (this.hasPaidNormalPayment(payments)) {
2022
+ return this.getOrderExpectedAmount(summary);
2023
+ }
1910
2024
  if (this.isDepositCovered({
1911
2025
  tempOrder: tempOrder,
1912
2026
  summary: summary,
@@ -1923,7 +2037,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1923
2037
  try {
1924
2038
  var parsed = new Decimal(String(value || 0));
1925
2039
  return parsed.toFixed(4);
1926
- } catch (_unused2) {
2040
+ } catch (_unused3) {
1927
2041
  return String(value);
1928
2042
  }
1929
2043
  }
@@ -2159,17 +2273,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2159
2273
  }, {
2160
2274
  key: "isSnapshotPayableAmountUnchanged",
2161
2275
  value: function isSnapshotPayableAmountUnchanged(tempOrder, snapshot, snapshotSummary) {
2162
- var currentPaidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
2276
+ var currentPayments = tempOrder.payments || [];
2277
+ var currentPaidPaymentSummary = this.calculatePaidPaymentSummary(currentPayments);
2163
2278
  var currentAmountGap = this.calculateSummaryAmountGap({
2164
2279
  tempOrder: tempOrder,
2165
2280
  summary: snapshotSummary,
2166
- orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount
2281
+ orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount,
2282
+ payments: currentPayments
2167
2283
  });
2168
- var snapshotPaidPaymentSummary = this.calculatePaidPaymentSummary(Array.isArray(snapshot.payments) ? snapshot.payments : []);
2284
+ var snapshotPayments = Array.isArray(snapshot.payments) ? snapshot.payments : [];
2285
+ var snapshotPaidPaymentSummary = this.calculatePaidPaymentSummary(snapshotPayments);
2169
2286
  var snapshotAmountGap = this.calculateSummaryAmountGap({
2170
2287
  tempOrder: tempOrder,
2171
2288
  summary: snapshotSummary,
2172
- orderPaidAmount: snapshotPaidPaymentSummary.gapPaidAmount
2289
+ orderPaidAmount: snapshotPaidPaymentSummary.gapPaidAmount,
2290
+ payments: snapshotPayments
2173
2291
  });
2174
2292
  return currentAmountGap === snapshotAmountGap;
2175
2293
  }
@@ -2203,6 +2321,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2203
2321
  }
2204
2322
  var isPayableAmountUnchanged = this.isSnapshotPayableAmountUnchanged(tempOrder, snapshot, summary);
2205
2323
  if (!isPayableAmountUnchanged) return null;
2324
+ var currentPaidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
2325
+ summary.amount_gap = this.calculateSummaryAmountGap({
2326
+ tempOrder: tempOrder,
2327
+ summary: summary,
2328
+ orderPaidAmount: currentPaidPaymentSummary.gapPaidAmount
2329
+ });
2206
2330
  if (Array.isArray(snapshot.products)) {
2207
2331
  tempOrder.products = cloneDeep(snapshot.products);
2208
2332
  }
@@ -2331,6 +2455,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2331
2455
  value: function restoreOrder() {
2332
2456
  var _this$store$discount16, _this$store$discount17;
2333
2457
  this.logInfo('restoreOrder start', {});
2458
+ this.sessionStorageRestoreRecord = null;
2334
2459
  var freshTempOrder = this.createDefaultTempOrderInstance();
2335
2460
  this.ensureExternalSaleNumber(freshTempOrder);
2336
2461
  this.store.tempOrder = freshTempOrder;
@@ -2361,36 +2486,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2361
2486
  }
2362
2487
  throw new Error('无效的 tempOrder 数据');
2363
2488
  case 2:
2489
+ this.sessionStorageRestoreRecord = null;
2364
2490
  nextTempOrder = this.normalizeTempOrderForRuntime(cloneDeep(tempOrder), {
2365
2491
  ensureIdentity: false
2366
2492
  });
2367
2493
  this.store.tempOrder = nextTempOrder;
2368
2494
  if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
2369
- _context12.next = 9;
2495
+ _context12.next = 10;
2370
2496
  break;
2371
2497
  }
2372
- _context12.next = 7;
2498
+ _context12.next = 8;
2373
2499
  return this.recalculateSummary({
2374
2500
  createIfMissing: false
2375
2501
  });
2376
- case 7:
2377
- _context12.next = 10;
2502
+ case 8:
2503
+ _context12.next = 11;
2378
2504
  break;
2379
- case 9:
2380
- this.store.summary = createEmptySummary();
2381
2505
  case 10:
2506
+ this.store.summary = createEmptySummary();
2507
+ case 11:
2382
2508
  if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
2383
2509
  this.persistTempOrder();
2384
2510
  }
2385
2511
  if (!(options !== null && options !== void 0 && options.saveDraft)) {
2386
- _context12.next = 14;
2512
+ _context12.next = 15;
2387
2513
  break;
2388
2514
  }
2389
- _context12.next = 14;
2515
+ _context12.next = 15;
2390
2516
  return this.saveDraft();
2391
- case 14:
2392
- return _context12.abrupt("return", nextTempOrder);
2393
2517
  case 15:
2518
+ return _context12.abrupt("return", nextTempOrder);
2519
+ case 16:
2394
2520
  case "end":
2395
2521
  return _context12.stop();
2396
2522
  }
@@ -2544,6 +2670,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2544
2670
  tempOrder.products = (tempOrder.products || []).map(function (product) {
2545
2671
  return _this15.sanitizeOrderProductForTempOrder(product);
2546
2672
  });
2673
+ ensureUniqueProductLineUids(tempOrder);
2547
2674
  }
2548
2675
  }, {
2549
2676
  key: "ensureExtend",
@@ -2558,6 +2685,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2558
2685
  }
2559
2686
  return tempOrder._extend;
2560
2687
  }
2688
+ }, {
2689
+ key: "repairDuplicateProductLineIdentities",
2690
+ value: function repairDuplicateProductLineIdentities(tempOrder) {
2691
+ var _tempOrder$_extend7;
2692
+ var result = repairDuplicateOrderProductLineIdentities(tempOrder.products, (_tempOrder$_extend7 = tempOrder._extend) === null || _tempOrder$_extend7 === void 0 ? void 0 : _tempOrder$_extend7.productsByUid);
2693
+ if (!result.repairs.length) return;
2694
+ tempOrder.products = result.products;
2695
+ if (result.productsByUid) {
2696
+ this.ensureExtend(tempOrder).productsByUid = result.productsByUid;
2697
+ }
2698
+ this.logWarning('Repaired duplicate product line identities', {
2699
+ repairCount: result.repairs.length,
2700
+ repairs: result.repairs
2701
+ });
2702
+ }
2561
2703
  }, {
2562
2704
  key: "captureProductRuntime",
2563
2705
  value: function captureProductRuntime(tempOrder, rawProduct, normalizedProduct, existedUid) {
@@ -2664,10 +2806,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2664
2806
  }
2665
2807
  });
2666
2808
  products.forEach(function (product) {
2667
- var _product$metadata5, _product$metadata6;
2809
+ var _product$metadata3, _product$metadata4;
2668
2810
  if (!product || _typeof(product) !== 'object') return;
2669
- var productUid = ((_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || product.unique_identification_number;
2670
- var bookingUid = product.booking_uid || ((_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2811
+ var productUid = ((_product$metadata3 = product.metadata) === null || _product$metadata3 === void 0 ? void 0 : _product$metadata3.unique_identification_number) || product.unique_identification_number;
2812
+ var bookingUid = product.booking_uid || ((_product$metadata4 = product.metadata) === null || _product$metadata4 === void 0 ? void 0 : _product$metadata4.booking_uid);
2671
2813
  var linkedBooking = (productUid !== undefined && productUid !== null && String(productUid) !== '' ? bookingByProductUid.get(String(productUid)) : undefined) || (bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '' ? bookingByBookingUid.get(String(bookingUid)) : undefined);
2672
2814
  if (linkedBooking) {
2673
2815
  _this16.setProductHolderFromBooking(product, linkedBooking);
@@ -2806,11 +2948,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2806
2948
  }, {
2807
2949
  key: "removeLinkedBookingsForProduct",
2808
2950
  value: function removeLinkedBookingsForProduct(tempOrder, product) {
2809
- var _product$metadata7,
2810
- _product$metadata8,
2951
+ var _product$metadata5,
2952
+ _product$metadata6,
2811
2953
  _this18 = this;
2812
- 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);
2813
- 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);
2954
+ var productUid = (product === null || product === void 0 || (_product$metadata5 = product.metadata) === null || _product$metadata5 === void 0 ? void 0 : _product$metadata5.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
2955
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata6 = product.metadata) === null || _product$metadata6 === void 0 ? void 0 : _product$metadata6.booking_uid);
2814
2956
  if (!productUid && !bookingUid) return;
2815
2957
  tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
2816
2958
  var currentBookingUid = _this18.getBookingUniqueIdentificationNumber(booking);
@@ -2830,9 +2972,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2830
2972
  }, {
2831
2973
  key: "applyOrderProductsDepositSummary",
2832
2974
  value: function applyOrderProductsDepositSummary(tempOrder, summary) {
2833
- var _tempOrder$_extend7;
2975
+ var _tempOrder$_extend8;
2834
2976
  var depositSummary = calculateOrderProductsDeposit(tempOrder.products || [], {
2835
- productsByUid: (_tempOrder$_extend7 = tempOrder._extend) === null || _tempOrder$_extend7 === void 0 ? void 0 : _tempOrder$_extend7.productsByUid
2977
+ productsByUid: (_tempOrder$_extend8 = tempOrder._extend) === null || _tempOrder$_extend8 === void 0 ? void 0 : _tempOrder$_extend8.productsByUid
2836
2978
  });
2837
2979
  var manualDepositOverride = this.getManualDepositOverride(tempOrder);
2838
2980
  var currentStructuralFingerprint = manualDepositOverride ? this.buildOrderProductsStructuralFingerprint(tempOrder.products) : '';
@@ -3333,6 +3475,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3333
3475
  if (tempOrder._extend) delete tempOrder._extend.customerSnapshot;
3334
3476
  this.store.availableWalletIds = [];
3335
3477
  this.clearCustomerBoundDiscounts(tempOrder);
3478
+ this.applyDiscount();
3336
3479
  this.persistTempOrder();
3337
3480
  this.saveDraftInBackground();
3338
3481
  this.core.effects.emit(OrderHooks.OnOrderCustomerChange, null);
@@ -3751,52 +3894,32 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3751
3894
  }
3752
3895
  return updateVoucherOrderPaymentsAsync;
3753
3896
  }()
3897
+ }, {
3898
+ key: "normalizeShouldMergeProductResult",
3899
+ value: function normalizeShouldMergeProductResult(result) {
3900
+ if (typeof result === 'boolean') return result;
3901
+ if (result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean') {
3902
+ return result.shouldMerge;
3903
+ }
3904
+ return true;
3905
+ }
3754
3906
  }, {
3755
3907
  key: "shouldMergeProductToOrder",
3756
- value: function () {
3757
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
3758
- var _this$orderHooks;
3759
- var onBeforeMergeProductToOrder, result;
3760
- return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3761
- while (1) switch (_context20.prev = _context20.next) {
3762
- case 0:
3763
- onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3764
- if (onBeforeMergeProductToOrder) {
3765
- _context20.next = 3;
3766
- break;
3767
- }
3768
- return _context20.abrupt("return", true);
3769
- case 3:
3770
- _context20.next = 5;
3771
- return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3772
- defaultShouldMerge: true
3773
- }));
3774
- case 5:
3775
- result = _context20.sent;
3776
- if (!(typeof result === 'boolean')) {
3777
- _context20.next = 8;
3778
- break;
3779
- }
3780
- return _context20.abrupt("return", result);
3781
- case 8:
3782
- if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
3783
- _context20.next = 10;
3784
- break;
3785
- }
3786
- return _context20.abrupt("return", result.shouldMerge);
3787
- case 10:
3788
- return _context20.abrupt("return", true);
3789
- case 11:
3790
- case "end":
3791
- return _context20.stop();
3792
- }
3793
- }, _callee18, this);
3908
+ value: function shouldMergeProductToOrder(params) {
3909
+ var _this$orderHooks,
3910
+ _this26 = this;
3911
+ var onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
3912
+ if (!onBeforeMergeProductToOrder) return true;
3913
+ var result = onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
3914
+ defaultShouldMerge: true
3794
3915
  }));
3795
- function shouldMergeProductToOrder(_x19) {
3796
- return _shouldMergeProductToOrder.apply(this, arguments);
3916
+ if (result && _typeof(result) === 'object' && typeof result.then === 'function') {
3917
+ return Promise.resolve(result).then(function (resolved) {
3918
+ return _this26.normalizeShouldMergeProductResult(resolved);
3919
+ });
3797
3920
  }
3798
- return shouldMergeProductToOrder;
3799
- }()
3921
+ return this.normalizeShouldMergeProductResult(result);
3922
+ }
3800
3923
  }, {
3801
3924
  key: "hasOrderProductLineNote",
3802
3925
  value: function hasOrderProductLineNote(product) {
@@ -3812,8 +3935,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3812
3935
  }, {
3813
3936
  key: "hasLinkedBookingUid",
3814
3937
  value: function hasLinkedBookingUid(product) {
3815
- var _product$booking_uid, _product$metadata9;
3816
- var bookingUid = (_product$booking_uid = product === null || product === void 0 ? void 0 : product.booking_uid) !== null && _product$booking_uid !== void 0 ? _product$booking_uid : product === null || product === void 0 || (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.booking_uid;
3938
+ var _product$booking_uid, _product$metadata7;
3939
+ var bookingUid = (_product$booking_uid = product === null || product === void 0 ? void 0 : product.booking_uid) !== null && _product$booking_uid !== void 0 ? _product$booking_uid : product === null || product === void 0 || (_product$metadata7 = product.metadata) === null || _product$metadata7 === void 0 ? void 0 : _product$metadata7.booking_uid;
3817
3940
  return bookingUid !== undefined && bookingUid !== null && String(bookingUid) !== '';
3818
3941
  }
3819
3942
 
@@ -3828,30 +3951,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3828
3951
  }, {
3829
3952
  key: "finalizeProductOrderMutation",
3830
3953
  value: function () {
3831
- var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(tempOrder, options) {
3832
- return _regeneratorRuntime().wrap(function _callee19$(_context21) {
3833
- while (1) switch (_context21.prev = _context21.next) {
3954
+ var _finalizeProductOrderMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(tempOrder, options) {
3955
+ return _regeneratorRuntime().wrap(function _callee18$(_context20) {
3956
+ while (1) switch (_context20.prev = _context20.next) {
3834
3957
  case 0:
3835
3958
  this.syncTempOrderHolderFromBookings(tempOrder);
3836
3959
  if (options !== null && options !== void 0 && options.skipEditDiscountConfigRefresh) {
3837
- _context21.next = 4;
3960
+ _context20.next = 4;
3838
3961
  break;
3839
3962
  }
3840
- _context21.next = 4;
3963
+ _context20.next = 4;
3841
3964
  return this.ensureEditDiscountConfigForProductChange(tempOrder);
3842
3965
  case 4:
3843
3966
  if (options !== null && options !== void 0 && options.skipDiscountRecalculation) {
3844
- _context21.next = 7;
3967
+ _context20.next = 7;
3845
3968
  break;
3846
3969
  }
3847
- _context21.next = 7;
3970
+ _context20.next = 7;
3848
3971
  return this.applyPromotion();
3849
3972
  case 7:
3850
3973
  if (!(options !== null && options !== void 0 && options.skipDiscountRecalculation)) {
3851
3974
  this.applyDiscount();
3852
3975
  }
3853
3976
  this.sanitizeTempOrderProducts(tempOrder);
3854
- _context21.next = 11;
3977
+ _context20.next = 11;
3855
3978
  return this.recalculateSummary({
3856
3979
  createIfMissing: true
3857
3980
  });
@@ -3859,11 +3982,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3859
3982
  this.persistTempOrder();
3860
3983
  case 12:
3861
3984
  case "end":
3862
- return _context21.stop();
3985
+ return _context20.stop();
3863
3986
  }
3864
- }, _callee19, this);
3987
+ }, _callee18, this);
3865
3988
  }));
3866
- function finalizeProductOrderMutation(_x20, _x21) {
3989
+ function finalizeProductOrderMutation(_x19, _x20) {
3867
3990
  return _finalizeProductOrderMutation.apply(this, arguments);
3868
3991
  }
3869
3992
  return finalizeProductOrderMutation;
@@ -3873,157 +3996,135 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
3873
3996
  * 带 booking 且 num>1 时由 `addProductToOrder` 拆成多次本方法调用(每次 num=1)。
3874
3997
  *
3875
3998
  * @example
3876
- * await this.appendProductLineToTempOrder(tempOrder, { product_id: 1, num: 1 }, booking);
3999
+ * const pending = this.appendProductLineToTempOrder(
4000
+ * tempOrder,
4001
+ * { product_id: 1, num: 1 },
4002
+ * booking,
4003
+ * );
4004
+ * if (pending) await pending;
3877
4005
  */
3878
4006
  }, {
3879
4007
  key: "appendProductLineToTempOrder",
3880
- value: (function () {
3881
- var _appendProductLineToTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(tempOrder, product, booking, options) {
3882
- var _normalizedIncoming$p,
3883
- _normalizedIncoming$p2,
3884
- _booking_uid,
3885
- _metadata,
3886
- _productToAdd$metadat,
3887
- _origin,
3888
- _this26 = this;
3889
- var linked, productToAdd, incomingFingerprint, normalizedIncoming, isWeighingProduct, netWeight, incomingBookingUid, hasIncomingGoodPass, hasIncomingProductNote, hasIncomingBookingUid, isIncomingCustomItem, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, insertAtIndex, _targetProduct$metada, targetProduct, targetUid, normalizedProduct, nextNum, targetIsManualProductDiscount, nextDiscountList, mergedProduct;
3890
- return _regeneratorRuntime().wrap(function _callee20$(_context22) {
3891
- while (1) switch (_context22.prev = _context22.next) {
3892
- case 0:
3893
- linked = booking ? this.createLinkedProductAndBooking({
3894
- product: product,
3895
- booking: booking
3896
- }) : null;
3897
- productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
3898
- incomingFingerprint = buildProductLineFingerprint(getProductSkuOptions(productToAdd), productToAdd.product_bundle);
3899
- normalizedIncoming = mergeOrderProductDisplayFields(productToAdd, normalizeOrderProduct(productToAdd));
3900
- isWeighingProduct = Number(((_normalizedIncoming$p = normalizedIncoming.product_sku) === null || _normalizedIncoming$p === void 0 ? void 0 : _normalizedIncoming$p.open_sold_weight) || 0) === 1;
3901
- netWeight = Number((_normalizedIncoming$p2 = normalizedIncoming.product_sku) === null || _normalizedIncoming$p2 === void 0 ? void 0 : _normalizedIncoming$p2.net_weight);
3902
- if (!(isWeighingProduct && (!Number.isFinite(netWeight) || netWeight <= 0))) {
3903
- _context22.next = 8;
3904
- break;
3905
- }
3906
- throw new Error('[Order] 称重商品净重必须大于 0');
3907
- case 8:
3908
- incomingBookingUid = (_booking_uid = productToAdd.booking_uid) !== null && _booking_uid !== void 0 ? _booking_uid : (_metadata = productToAdd.metadata) === null || _metadata === void 0 ? void 0 : _metadata.booking_uid;
3909
- if (incomingBookingUid !== undefined && incomingBookingUid !== null && String(incomingBookingUid) !== '') {
3910
- normalizedIncoming.booking_uid = String(incomingBookingUid);
3911
- normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
3912
- booking_uid: String(incomingBookingUid)
3913
- });
3914
- }
3915
- normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
3916
- hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
3917
- hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
3918
- hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
3919
- isIncomingCustomItem = ((_productToAdd$metadat = productToAdd.metadata) === null || _productToAdd$metadat === void 0 || (_productToAdd$metadat = _productToAdd$metadat.origin) === null || _productToAdd$metadat === void 0 ? void 0 : _productToAdd$metadat.isCustomItem) === true || ((_origin = productToAdd._origin) === null || _origin === void 0 ? void 0 : _origin.isCustomItem) === true;
3920
- shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
3921
- matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
3922
- var _item$metadata3;
3923
- if (_this26.hasGoodPassDiscount(item)) return false;
3924
- if (_this26.hasOrderProductLineNote(item)) return false;
3925
- if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
3926
- if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
3927
- if (item.product_id !== productToAdd.product_id) return false;
3928
- if (item.product_variant_id !== productToAdd.product_variant_id) return false;
3929
- var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
3930
- return existedFingerprint === incomingFingerprint;
3931
- });
3932
- matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
3933
- existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
3934
- if (!matchedProduct) {
3935
- _context22.next = 25;
3936
- break;
3937
- }
3938
- _context22.next = 22;
3939
- return this.shouldMergeProductToOrder({
3940
- incomingProduct: productToAdd,
3941
- normalizedIncoming: normalizedIncoming,
3942
- matchedProduct: matchedProduct,
3943
- matchedIndex: matchedIndex,
3944
- incomingFingerprint: incomingFingerprint,
3945
- existedFingerprint: existedFingerprint,
3946
- tempOrder: tempOrder,
3947
- booking: booking
3948
- });
3949
- case 22:
3950
- _context22.t0 = _context22.sent;
3951
- _context22.next = 26;
3952
- break;
3953
- case 25:
3954
- _context22.t0 = false;
3955
- case 26:
3956
- shouldMerge = _context22.t0;
3957
- if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
3958
- this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
3959
- if (linked) {
3960
- normalizedIncoming.booking_uid = linked.bookingUid;
3961
- normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
3962
- booking_uid: linked.bookingUid
3963
- });
3964
- }
3965
- insertAtIndex = options === null || options === void 0 ? void 0 : options.insertAtIndex;
3966
- if (Number.isInteger(insertAtIndex) && Number(insertAtIndex) >= 0 && Number(insertAtIndex) < tempOrder.products.length) {
3967
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, insertAtIndex)), [normalizedIncoming], _toConsumableArray(tempOrder.products.slice(insertAtIndex)));
3968
- } else {
3969
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
3970
- }
3971
- } else {
3972
- targetProduct = matchedProduct;
3973
- targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
3974
- normalizedProduct = mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
3975
- metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
3976
- unique_identification_number: targetUid
3977
- })
3978
- })));
3979
- normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
3980
- nextNum = getSafeProductNum(targetProduct.num + normalizedProduct.num);
3981
- targetIsManualProductDiscount = isManualProductDiscountProduct(targetProduct);
3982
- nextDiscountList = targetIsManualProductDiscount ? normalizeOrderProductDiscountList(syncManualProductDiscountProductNum(targetProduct.discount_list, nextNum)) : normalizedProduct.discount_list;
3983
- tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
3984
- discount_list: nextDiscountList,
3985
- metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
3986
- unique_identification_number: targetUid
3987
- }),
3988
- product_sku: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.product_sku || {
3989
- option: []
3990
- }), normalizedProduct.product_sku || {
3991
- option: []
3992
- }), {}, {
3993
- option: getProductSkuOptions(normalizedProduct)
3994
- })
3995
- }, targetIsManualProductDiscount ? {
3996
- selling_price: targetProduct.selling_price,
3997
- original_price: targetProduct.original_price,
3998
- payment_price: targetProduct.payment_price,
3999
- metadata: _objectSpread(_objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), targetProduct.metadata || {}), {}, {
4000
- unique_identification_number: targetUid
4001
- })
4002
- } : {}), {}, {
4003
- note: targetProduct.note,
4004
- order_detail_id: targetProduct.order_detail_id,
4005
- num: nextNum
4006
- });
4007
- this.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4008
- if (matchedIndex !== tempOrder.products.length - 1) {
4009
- mergedProduct = tempOrder.products[matchedIndex];
4010
- tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, matchedIndex)), _toConsumableArray(tempOrder.products.slice(matchedIndex + 1)), [mergedProduct]);
4011
- }
4012
- }
4013
- if (linked) {
4014
- tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
4015
- }
4016
- case 29:
4017
- case "end":
4018
- return _context22.stop();
4008
+ value: function appendProductLineToTempOrder(tempOrder, product, booking, options) {
4009
+ var _normalizedIncoming$p,
4010
+ _normalizedIncoming$p2,
4011
+ _booking_uid,
4012
+ _metadata,
4013
+ _productToAdd$metadat,
4014
+ _origin,
4015
+ _this27 = this;
4016
+ var linked = booking ? this.createLinkedProductAndBooking({
4017
+ product: product,
4018
+ booking: booking
4019
+ }) : null;
4020
+ var productToAdd = (linked === null || linked === void 0 ? void 0 : linked.product) || product;
4021
+ var incomingFingerprint = buildProductLineFingerprint(getProductSkuOptions(productToAdd), productToAdd.product_bundle);
4022
+ var normalizedIncoming = mergeOrderProductDisplayFields(productToAdd, normalizeOrderProduct(productToAdd));
4023
+ var isWeighingProduct = Number(((_normalizedIncoming$p = normalizedIncoming.product_sku) === null || _normalizedIncoming$p === void 0 ? void 0 : _normalizedIncoming$p.open_sold_weight) || 0) === 1;
4024
+ var netWeight = Number((_normalizedIncoming$p2 = normalizedIncoming.product_sku) === null || _normalizedIncoming$p2 === void 0 ? void 0 : _normalizedIncoming$p2.net_weight);
4025
+ if (isWeighingProduct && (!Number.isFinite(netWeight) || netWeight <= 0)) {
4026
+ throw new Error('[Order] 称重商品净重必须大于 0');
4027
+ }
4028
+ var incomingBookingUid = (_booking_uid = productToAdd.booking_uid) !== null && _booking_uid !== void 0 ? _booking_uid : (_metadata = productToAdd.metadata) === null || _metadata === void 0 ? void 0 : _metadata.booking_uid;
4029
+ if (incomingBookingUid !== undefined && incomingBookingUid !== null && String(incomingBookingUid) !== '') {
4030
+ normalizedIncoming.booking_uid = String(incomingBookingUid);
4031
+ normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
4032
+ booking_uid: String(incomingBookingUid)
4033
+ });
4034
+ }
4035
+ normalizedIncoming.discount_list = normalizeOrderProductDiscountList(normalizedIncoming.discount_list);
4036
+ var hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
4037
+ var hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
4038
+ var hasIncomingManualProductDiscount = isManualProductDiscountProduct(normalizedIncoming);
4039
+ var hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
4040
+ var isIncomingCustomItem = ((_productToAdd$metadat = productToAdd.metadata) === null || _productToAdd$metadat === void 0 || (_productToAdd$metadat = _productToAdd$metadat.origin) === null || _productToAdd$metadat === void 0 ? void 0 : _productToAdd$metadat.isCustomItem) === true || ((_origin = productToAdd._origin) === null || _origin === void 0 ? void 0 : _origin.isCustomItem) === true;
4041
+ var shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingManualProductDiscount || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
4042
+ var matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
4043
+ var _item$metadata3;
4044
+ if (_this27.hasGoodPassDiscount(item)) return false;
4045
+ if (_this27.hasOrderProductLineNote(item)) return false;
4046
+ if (isManualProductDiscountProduct(item)) return false;
4047
+ if (item.order_detail_id !== undefined && item.order_detail_id !== null) return false;
4048
+ if ((_item$metadata3 = item.metadata) !== null && _item$metadata3 !== void 0 && _item$metadata3.is_edit_for_runtime) return false;
4049
+ if (item.product_id !== productToAdd.product_id) return false;
4050
+ if (item.product_variant_id !== productToAdd.product_variant_id) return false;
4051
+ var existedFingerprint = buildProductLineFingerprint(getProductSkuOptions(item), item.product_bundle);
4052
+ return existedFingerprint === incomingFingerprint;
4053
+ });
4054
+ var matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
4055
+ var existedFingerprint = matchedProduct ? buildProductLineFingerprint(getProductSkuOptions(matchedProduct), matchedProduct.product_bundle) : '';
4056
+ var commitProductLine = function commitProductLine(shouldMerge) {
4057
+ if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
4058
+ _this27.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
4059
+ if (linked) {
4060
+ normalizedIncoming.booking_uid = linked.bookingUid;
4061
+ normalizedIncoming.metadata = _objectSpread(_objectSpread({}, normalizedIncoming.metadata || {}), {}, {
4062
+ booking_uid: linked.bookingUid
4063
+ });
4019
4064
  }
4020
- }, _callee20, this);
4021
- }));
4022
- function appendProductLineToTempOrder(_x22, _x23, _x24, _x25) {
4023
- return _appendProductLineToTempOrder.apply(this, arguments);
4065
+ var insertAtIndex = options === null || options === void 0 ? void 0 : options.insertAtIndex;
4066
+ if (Number.isInteger(insertAtIndex) && Number(insertAtIndex) >= 0 && Number(insertAtIndex) < tempOrder.products.length) {
4067
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, insertAtIndex)), [normalizedIncoming], _toConsumableArray(tempOrder.products.slice(insertAtIndex)));
4068
+ } else {
4069
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products), [normalizedIncoming]);
4070
+ }
4071
+ } else {
4072
+ var _targetProduct$metada;
4073
+ var targetProduct = matchedProduct;
4074
+ var targetUid = (_targetProduct$metada = targetProduct.metadata) === null || _targetProduct$metada === void 0 ? void 0 : _targetProduct$metada.unique_identification_number;
4075
+ var normalizedProduct = mergeOrderProductDisplayFields(targetProduct, normalizeOrderProduct(_objectSpread(_objectSpread({}, productToAdd), {}, {
4076
+ metadata: _objectSpread(_objectSpread({}, productToAdd.metadata || {}), {}, {
4077
+ unique_identification_number: targetUid
4078
+ })
4079
+ })));
4080
+ normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4081
+ var nextNum = getSafeProductNum(targetProduct.num + normalizedProduct.num);
4082
+ tempOrder.products[matchedIndex] = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), normalizedProduct), {}, {
4083
+ discount_list: normalizedProduct.discount_list,
4084
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.metadata || {}), normalizedProduct.metadata || {}), {}, {
4085
+ unique_identification_number: targetUid
4086
+ }),
4087
+ product_sku: _objectSpread(_objectSpread(_objectSpread({}, targetProduct.product_sku || {
4088
+ option: []
4089
+ }), normalizedProduct.product_sku || {
4090
+ option: []
4091
+ }), {}, {
4092
+ option: getProductSkuOptions(normalizedProduct)
4093
+ }),
4094
+ note: targetProduct.note,
4095
+ order_detail_id: targetProduct.order_detail_id,
4096
+ num: nextNum
4097
+ });
4098
+ _this27.captureProductRuntime(tempOrder, productToAdd, tempOrder.products[matchedIndex], targetUid);
4099
+ if (matchedIndex !== tempOrder.products.length - 1) {
4100
+ var mergedProduct = tempOrder.products[matchedIndex];
4101
+ tempOrder.products = [].concat(_toConsumableArray(tempOrder.products.slice(0, matchedIndex)), _toConsumableArray(tempOrder.products.slice(matchedIndex + 1)), [mergedProduct]);
4102
+ }
4103
+ }
4104
+ if (linked) {
4105
+ tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
4106
+ }
4107
+ };
4108
+ if (!matchedProduct) {
4109
+ commitProductLine(false);
4110
+ return;
4024
4111
  }
4025
- return appendProductLineToTempOrder;
4026
- }()
4112
+ var shouldMerge = this.shouldMergeProductToOrder({
4113
+ incomingProduct: productToAdd,
4114
+ normalizedIncoming: normalizedIncoming,
4115
+ matchedProduct: matchedProduct,
4116
+ matchedIndex: matchedIndex,
4117
+ incomingFingerprint: incomingFingerprint,
4118
+ existedFingerprint: existedFingerprint,
4119
+ tempOrder: tempOrder,
4120
+ booking: booking
4121
+ });
4122
+ if (shouldMerge && _typeof(shouldMerge) === 'object' && typeof shouldMerge.then === 'function') {
4123
+ return Promise.resolve(shouldMerge).then(commitProductLine);
4124
+ }
4125
+ commitProductLine(shouldMerge);
4126
+ }
4127
+
4027
4128
  /**
4028
4129
  * 添加商品行。带 booking 时强制独立行;num>1 时拆成多条 num=1 的 product+booking(对齐 BookingByStep / ticketBooking addService)。
4029
4130
  *
@@ -4031,14 +4132,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4031
4132
  * await order.addProductToOrder({ product_id: 1, num: 3 }, { start_time: '10:00' });
4032
4133
  * // → tempOrder.products 新增 3 行,每行 num=1,bookings 3 条
4033
4134
  */
4034
- )
4035
4135
  }, {
4036
4136
  key: "addProductToOrder",
4037
4137
  value: (function () {
4038
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(product, booking, options) {
4039
- var tempOrder, insertAfterProductUid, anchorIndex, insertAtIndex, _ref60, _productRecord$num, productRecord, splitCount, i, singleLine;
4040
- return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4041
- while (1) switch (_context23.prev = _context23.next) {
4138
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(product, booking, options) {
4139
+ var tempOrder, insertAfterProductUid, anchorIndex, insertAtIndex, _ref60, _productRecord$num, productRecord, splitCount, i, singleLine, _appendResult, appendResult;
4140
+ return _regeneratorRuntime().wrap(function _callee19$(_context21) {
4141
+ while (1) switch (_context21.prev = _context21.next) {
4042
4142
  case 0:
4043
4143
  tempOrder = this.ensureTempOrder();
4044
4144
  insertAfterProductUid = options === null || options === void 0 ? void 0 : options.insertAfterProductUid;
@@ -4049,60 +4149,70 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4049
4149
  }) : -1;
4050
4150
  insertAtIndex = anchorIndex >= 0 ? anchorIndex + 1 : undefined;
4051
4151
  if (!booking) {
4052
- _context23.next = 22;
4152
+ _context21.next = 24;
4053
4153
  break;
4054
4154
  }
4055
4155
  productRecord = product;
4056
4156
  splitCount = getSafeProductNum((_ref60 = (_productRecord$num = productRecord.num) !== null && _productRecord$num !== void 0 ? _productRecord$num : productRecord.product_quantity) !== null && _ref60 !== void 0 ? _ref60 : 1);
4057
4157
  if (!(splitCount > 1)) {
4058
- _context23.next = 22;
4158
+ _context21.next = 24;
4059
4159
  break;
4060
4160
  }
4061
4161
  i = 0;
4062
4162
  case 9:
4063
4163
  if (!(i < splitCount)) {
4064
- _context23.next = 19;
4164
+ _context21.next = 21;
4065
4165
  break;
4066
4166
  }
4067
4167
  singleLine = cloneDeep(productRecord);
4068
4168
  singleLine.num = 1;
4069
4169
  delete singleLine.product_quantity;
4070
- _context23.next = 15;
4071
- return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking), {
4170
+ _appendResult = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking), {
4072
4171
  insertAtIndex: insertAtIndex
4073
4172
  });
4074
- case 15:
4173
+ if (!_appendResult) {
4174
+ _context21.next = 17;
4175
+ break;
4176
+ }
4177
+ _context21.next = 17;
4178
+ return _appendResult;
4179
+ case 17:
4075
4180
  if (insertAtIndex !== undefined) insertAtIndex += 1;
4076
- case 16:
4181
+ case 18:
4077
4182
  i += 1;
4078
- _context23.next = 9;
4183
+ _context21.next = 9;
4079
4184
  break;
4080
- case 19:
4081
- _context23.next = 21;
4082
- return this.finalizeProductOrderMutation(tempOrder);
4083
4185
  case 21:
4084
- return _context23.abrupt("return", tempOrder.products);
4085
- case 22:
4086
- _context23.next = 24;
4087
- return this.appendProductLineToTempOrder(tempOrder, product, booking, {
4186
+ _context21.next = 23;
4187
+ return this.finalizeProductOrderMutation(tempOrder);
4188
+ case 23:
4189
+ return _context21.abrupt("return", tempOrder.products);
4190
+ case 24:
4191
+ appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking, {
4088
4192
  insertAtIndex: insertAtIndex
4089
4193
  });
4090
- case 24:
4091
- _context23.next = 26;
4194
+ if (!appendResult) {
4195
+ _context21.next = 28;
4196
+ break;
4197
+ }
4198
+ _context21.next = 28;
4199
+ return appendResult;
4200
+ case 28:
4201
+ _context21.next = 30;
4092
4202
  return this.finalizeProductOrderMutation(tempOrder);
4093
- case 26:
4203
+ case 30:
4094
4204
  this.logInfo('addProductToOrder success', {
4095
4205
  product_id: product.product_id,
4096
4206
  with_booking: !!booking
4097
4207
  });
4098
- return _context23.abrupt("return", tempOrder.products);
4099
- case 28:
4208
+ return _context21.abrupt("return", tempOrder.products);
4209
+ case 32:
4100
4210
  case "end":
4101
- return _context23.stop();
4211
+ return _context21.stop();
4102
4212
  }
4103
- }, _callee21, this);
4213
+ }, _callee19, this);
4104
4214
  }));
4105
- function addProductToOrder(_x26, _x27, _x28) {
4215
+ function addProductToOrder(_x21, _x22, _x23) {
4106
4216
  return _addProductToOrder.apply(this, arguments);
4107
4217
  }
4108
4218
  return addProductToOrder;
@@ -4120,93 +4230,103 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4120
4230
  }, {
4121
4231
  key: "addProductsToOrder",
4122
4232
  value: (function () {
4123
- var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(items, options) {
4124
- var tempOrder, _iterator20, _step20, item, product, booking, _ref61, _productRecord$num2, productRecord, splitCount, i, singleLine;
4125
- return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4126
- while (1) switch (_context24.prev = _context24.next) {
4233
+ var _addProductsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(items, options) {
4234
+ var tempOrder, _iterator20, _step20, item, product, booking, _ref61, _productRecord$num2, productRecord, splitCount, i, singleLine, _appendResult2, appendResult;
4235
+ return _regeneratorRuntime().wrap(function _callee20$(_context22) {
4236
+ while (1) switch (_context22.prev = _context22.next) {
4127
4237
  case 0:
4128
4238
  tempOrder = this.ensureTempOrder();
4129
4239
  if (!(!Array.isArray(items) || items.length === 0)) {
4130
- _context24.next = 3;
4240
+ _context22.next = 3;
4131
4241
  break;
4132
4242
  }
4133
- return _context24.abrupt("return", tempOrder.products);
4243
+ return _context22.abrupt("return", tempOrder.products);
4134
4244
  case 3:
4135
4245
  _iterator20 = _createForOfIteratorHelper(items || []);
4136
- _context24.prev = 4;
4246
+ _context22.prev = 4;
4137
4247
  _iterator20.s();
4138
4248
  case 6:
4139
4249
  if ((_step20 = _iterator20.n()).done) {
4140
- _context24.next = 30;
4250
+ _context22.next = 34;
4141
4251
  break;
4142
4252
  }
4143
4253
  item = _step20.value;
4144
4254
  product = item.product, booking = item.booking;
4145
4255
  if (product) {
4146
- _context24.next = 11;
4256
+ _context22.next = 11;
4147
4257
  break;
4148
4258
  }
4149
- return _context24.abrupt("continue", 28);
4259
+ return _context22.abrupt("continue", 32);
4150
4260
  case 11:
4151
4261
  if (!booking) {
4152
- _context24.next = 26;
4262
+ _context22.next = 28;
4153
4263
  break;
4154
4264
  }
4155
4265
  productRecord = product;
4156
4266
  splitCount = getSafeProductNum((_ref61 = (_productRecord$num2 = productRecord.num) !== null && _productRecord$num2 !== void 0 ? _productRecord$num2 : productRecord.product_quantity) !== null && _ref61 !== void 0 ? _ref61 : 1);
4157
4267
  if (!(splitCount > 1)) {
4158
- _context24.next = 26;
4268
+ _context22.next = 28;
4159
4269
  break;
4160
4270
  }
4161
4271
  i = 0;
4162
4272
  case 16:
4163
4273
  if (!(i < splitCount)) {
4164
- _context24.next = 25;
4274
+ _context22.next = 27;
4165
4275
  break;
4166
4276
  }
4167
4277
  singleLine = cloneDeep(productRecord);
4168
4278
  singleLine.num = 1;
4169
4279
  delete singleLine.product_quantity;
4170
- _context24.next = 22;
4171
- return this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4172
- case 22:
4280
+ _appendResult2 = this.appendProductLineToTempOrder(tempOrder, singleLine, cloneDeep(booking));
4281
+ if (!_appendResult2) {
4282
+ _context22.next = 24;
4283
+ break;
4284
+ }
4285
+ _context22.next = 24;
4286
+ return _appendResult2;
4287
+ case 24:
4173
4288
  i += 1;
4174
- _context24.next = 16;
4289
+ _context22.next = 16;
4175
4290
  break;
4176
- case 25:
4177
- return _context24.abrupt("continue", 28);
4178
- case 26:
4179
- _context24.next = 28;
4180
- return this.appendProductLineToTempOrder(tempOrder, product, booking);
4291
+ case 27:
4292
+ return _context22.abrupt("continue", 32);
4181
4293
  case 28:
4182
- _context24.next = 6;
4294
+ appendResult = this.appendProductLineToTempOrder(tempOrder, product, booking);
4295
+ if (!appendResult) {
4296
+ _context22.next = 32;
4297
+ break;
4298
+ }
4299
+ _context22.next = 32;
4300
+ return appendResult;
4301
+ case 32:
4302
+ _context22.next = 6;
4183
4303
  break;
4184
- case 30:
4185
- _context24.next = 35;
4304
+ case 34:
4305
+ _context22.next = 39;
4186
4306
  break;
4187
- case 32:
4188
- _context24.prev = 32;
4189
- _context24.t0 = _context24["catch"](4);
4190
- _iterator20.e(_context24.t0);
4191
- case 35:
4192
- _context24.prev = 35;
4307
+ case 36:
4308
+ _context22.prev = 36;
4309
+ _context22.t0 = _context22["catch"](4);
4310
+ _iterator20.e(_context22.t0);
4311
+ case 39:
4312
+ _context22.prev = 39;
4193
4313
  _iterator20.f();
4194
- return _context24.finish(35);
4195
- case 38:
4196
- _context24.next = 40;
4314
+ return _context22.finish(39);
4315
+ case 42:
4316
+ _context22.next = 44;
4197
4317
  return this.finalizeProductOrderMutation(tempOrder, options);
4198
- case 40:
4318
+ case 44:
4199
4319
  this.logInfo('addProductsToOrder success', {
4200
4320
  itemsCount: items.length
4201
4321
  });
4202
- return _context24.abrupt("return", tempOrder.products);
4203
- case 42:
4322
+ return _context22.abrupt("return", tempOrder.products);
4323
+ case 46:
4204
4324
  case "end":
4205
- return _context24.stop();
4325
+ return _context22.stop();
4206
4326
  }
4207
- }, _callee22, this, [[4, 32, 35, 38]]);
4327
+ }, _callee20, this, [[4, 36, 39, 42]]);
4208
4328
  }));
4209
- function addProductsToOrder(_x29, _x30) {
4329
+ function addProductsToOrder(_x24, _x25) {
4210
4330
  return _addProductsToOrder.apply(this, arguments);
4211
4331
  }
4212
4332
  return addProductsToOrder;
@@ -4240,17 +4360,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4240
4360
  }, {
4241
4361
  key: "preservePersistedBundlePriceFields",
4242
4362
  value: function preservePersistedBundlePriceFields(previousBundles, nextBundles) {
4243
- var _this27 = this;
4363
+ var _this28 = this;
4244
4364
  if (!Array.isArray(nextBundles)) return nextBundles;
4245
4365
  if (!Array.isArray(previousBundles) || previousBundles.length === 0) return nextBundles;
4246
4366
  var previousByIdentity = new Map();
4247
4367
  previousBundles.forEach(function (bundle) {
4248
- var identity = _this27.getBundleRuntimeIdentity(bundle);
4368
+ var identity = _this28.getBundleRuntimeIdentity(bundle);
4249
4369
  if (identity) previousByIdentity.set(identity, bundle);
4250
4370
  });
4251
4371
  return nextBundles.map(function (bundle, index) {
4252
4372
  if (!bundle || _typeof(bundle) !== 'object') return bundle;
4253
- var previous = previousByIdentity.get(_this27.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4373
+ var previous = previousByIdentity.get(_this28.getBundleRuntimeIdentity(bundle)) || previousBundles[index];
4254
4374
  if (!previous || _typeof(previous) !== 'object') return bundle;
4255
4375
  return _objectSpread(_objectSpread(_objectSpread({}, bundle), (bundle.cover === undefined || bundle.cover === null || bundle.cover === '') && previous.cover !== undefined && previous.cover !== null && previous.cover !== '' ? {
4256
4376
  cover: previous.cover
@@ -4451,21 +4571,21 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4451
4571
  }, {
4452
4572
  key: "updateOrderProduct",
4453
4573
  value: function () {
4454
- var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4574
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
4455
4575
  var tempOrder, updatedProductUid;
4456
- return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4457
- while (1) switch (_context25.prev = _context25.next) {
4576
+ return _regeneratorRuntime().wrap(function _callee21$(_context23) {
4577
+ while (1) switch (_context23.prev = _context23.next) {
4458
4578
  case 0:
4459
4579
  tempOrder = this.ensureTempOrder();
4460
4580
  updatedProductUid = this.applyOrderProductUpdateToTempOrder(tempOrder, params);
4461
- _context25.next = 4;
4581
+ _context23.next = 4;
4462
4582
  return this.applyPromotion();
4463
4583
  case 4:
4464
4584
  this.applyDiscount({
4465
4585
  reapplyBookingDiscountProductUids: params.allow_booking_discount_reapply && updatedProductUid ? [String(updatedProductUid)] : undefined
4466
4586
  });
4467
4587
  this.sanitizeTempOrderProducts(tempOrder);
4468
- _context25.next = 8;
4588
+ _context23.next = 8;
4469
4589
  return this.recalculateSummary({
4470
4590
  createIfMissing: true
4471
4591
  });
@@ -4474,14 +4594,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4474
4594
  this.logInfo('updateOrderProduct success', {
4475
4595
  params: params
4476
4596
  });
4477
- return _context25.abrupt("return", tempOrder.products);
4597
+ return _context23.abrupt("return", tempOrder.products);
4478
4598
  case 11:
4479
4599
  case "end":
4480
- return _context25.stop();
4600
+ return _context23.stop();
4481
4601
  }
4482
- }, _callee23, this);
4602
+ }, _callee21, this);
4483
4603
  }));
4484
- function updateOrderProduct(_x31) {
4604
+ function updateOrderProduct(_x26) {
4485
4605
  return _updateOrderProduct.apply(this, arguments);
4486
4606
  }
4487
4607
  return updateOrderProduct;
@@ -4489,28 +4609,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4489
4609
  }, {
4490
4610
  key: "updateOrderProducts",
4491
4611
  value: function () {
4492
- var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(paramsList) {
4493
- var _this28 = this;
4612
+ var _updateOrderProducts = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(paramsList) {
4613
+ var _this29 = this;
4494
4614
  var tempOrder, reapplyBookingDiscountProductUids;
4495
- return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4496
- while (1) switch (_context26.prev = _context26.next) {
4615
+ return _regeneratorRuntime().wrap(function _callee22$(_context24) {
4616
+ while (1) switch (_context24.prev = _context24.next) {
4497
4617
  case 0:
4498
4618
  tempOrder = this.ensureTempOrder();
4499
4619
  if (paramsList.length) {
4500
- _context26.next = 3;
4620
+ _context24.next = 3;
4501
4621
  break;
4502
4622
  }
4503
- return _context26.abrupt("return", tempOrder.products);
4623
+ return _context24.abrupt("return", tempOrder.products);
4504
4624
  case 3:
4505
4625
  reapplyBookingDiscountProductUids = paramsList.reduce(function (acc, params) {
4506
- var updatedProductUid = _this28.applyOrderProductUpdateToTempOrder(tempOrder, params);
4626
+ var updatedProductUid = _this29.applyOrderProductUpdateToTempOrder(tempOrder, params);
4507
4627
  // 批量改预约时间时,延迟到最后一次折扣计算里统一恢复已选预约折扣卡。
4508
4628
  if (params.allow_booking_discount_reapply && updatedProductUid) {
4509
4629
  acc.push(String(updatedProductUid));
4510
4630
  }
4511
4631
  return acc;
4512
4632
  }, []);
4513
- _context26.next = 6;
4633
+ _context24.next = 6;
4514
4634
  return this.finalizeAfterProductsMutation(tempOrder, {
4515
4635
  reapplyBookingDiscountProductUids: reapplyBookingDiscountProductUids.length ? reapplyBookingDiscountProductUids : undefined
4516
4636
  });
@@ -4518,14 +4638,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4518
4638
  this.logInfo('updateOrderProduct success', {
4519
4639
  paramsList: paramsList
4520
4640
  });
4521
- return _context26.abrupt("return", tempOrder.products);
4641
+ return _context24.abrupt("return", tempOrder.products);
4522
4642
  case 8:
4523
4643
  case "end":
4524
- return _context26.stop();
4644
+ return _context24.stop();
4525
4645
  }
4526
- }, _callee24, this);
4646
+ }, _callee22, this);
4527
4647
  }));
4528
- function updateOrderProducts(_x32) {
4648
+ function updateOrderProducts(_x27) {
4529
4649
  return _updateOrderProducts.apply(this, arguments);
4530
4650
  }
4531
4651
  return updateOrderProducts;
@@ -4533,14 +4653,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4533
4653
  }, {
4534
4654
  key: "updateOrderProductQuantity",
4535
4655
  value: function () {
4536
- var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
4656
+ var _updateOrderProductQuantity = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
4537
4657
  var _targetProduct$metada17;
4538
4658
  var product_id, product_variant_id, num, unique_identification_number, identity_key, product_sku, product_bundle, tempOrder, identityLookup, productIndex, targetUid, targetProduct, normalizedProduct;
4539
- return _regeneratorRuntime().wrap(function _callee25$(_context27) {
4540
- while (1) switch (_context27.prev = _context27.next) {
4659
+ return _regeneratorRuntime().wrap(function _callee23$(_context25) {
4660
+ while (1) switch (_context25.prev = _context25.next) {
4541
4661
  case 0:
4542
4662
  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;
4543
4663
  tempOrder = this.ensureTempOrder();
4664
+ this.repairDuplicateProductLineIdentities(tempOrder);
4544
4665
  identityLookup = {
4545
4666
  product_id: product_id,
4546
4667
  product_variant_id: product_variant_id
@@ -4566,11 +4687,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4566
4687
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
4567
4688
  }
4568
4689
  if (!(productIndex === -1)) {
4569
- _context27.next = 12;
4690
+ _context25.next = 13;
4570
4691
  break;
4571
4692
  }
4572
4693
  throw new Error('[Order] 目标商品不存在,无法更新数量');
4573
- case 12:
4694
+ case 13:
4574
4695
  targetProduct = tempOrder.products[productIndex];
4575
4696
  normalizedProduct = normalizeOrderProduct(_objectSpread(_objectSpread({}, targetProduct), {}, {
4576
4697
  num: getSafeProductNum(num),
@@ -4580,28 +4701,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4580
4701
  }));
4581
4702
  normalizedProduct.discount_list = normalizeOrderProductDiscountList(normalizedProduct.discount_list);
4582
4703
  tempOrder.products[productIndex] = normalizedProduct;
4583
- _context27.next = 18;
4704
+ _context25.next = 19;
4584
4705
  return this.applyPromotion();
4585
- case 18:
4706
+ case 19:
4586
4707
  this.applyDiscount();
4587
4708
  this.sanitizeTempOrderProducts(tempOrder);
4588
- _context27.next = 22;
4709
+ _context25.next = 23;
4589
4710
  return this.recalculateSummary({
4590
4711
  createIfMissing: true
4591
4712
  });
4592
- case 22:
4713
+ case 23:
4593
4714
  this.persistTempOrder();
4594
4715
  this.logInfo('updateOrderProductQuantity success', {
4595
4716
  params: params
4596
4717
  });
4597
- return _context27.abrupt("return", tempOrder.products);
4598
- case 25:
4718
+ return _context25.abrupt("return", tempOrder.products);
4719
+ case 26:
4599
4720
  case "end":
4600
- return _context27.stop();
4721
+ return _context25.stop();
4601
4722
  }
4602
- }, _callee25, this);
4723
+ }, _callee23, this);
4603
4724
  }));
4604
- function updateOrderProductQuantity(_x33) {
4725
+ function updateOrderProductQuantity(_x28) {
4605
4726
  return _updateOrderProductQuantity.apply(this, arguments);
4606
4727
  }
4607
4728
  return updateOrderProductQuantity;
@@ -4642,19 +4763,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4642
4763
  }, {
4643
4764
  key: "finalizeAfterProductsMutation",
4644
4765
  value: (function () {
4645
- var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(tempOrder, options) {
4646
- return _regeneratorRuntime().wrap(function _callee26$(_context28) {
4647
- while (1) switch (_context28.prev = _context28.next) {
4766
+ var _finalizeAfterProductsMutation = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(tempOrder, options) {
4767
+ return _regeneratorRuntime().wrap(function _callee24$(_context26) {
4768
+ while (1) switch (_context26.prev = _context26.next) {
4648
4769
  case 0:
4649
4770
  this.syncTempOrderHolderFromBookings(tempOrder);
4650
- _context28.next = 3;
4771
+ _context26.next = 3;
4651
4772
  return this.applyPromotion();
4652
4773
  case 3:
4653
4774
  this.applyDiscount({
4654
4775
  reapplyBookingDiscountProductUids: options === null || options === void 0 ? void 0 : options.reapplyBookingDiscountProductUids
4655
4776
  });
4656
4777
  this.sanitizeTempOrderProducts(tempOrder);
4657
- _context28.next = 7;
4778
+ _context26.next = 7;
4658
4779
  return this.recalculateSummary({
4659
4780
  createIfMissing: true
4660
4781
  });
@@ -4662,11 +4783,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4662
4783
  this.persistTempOrder();
4663
4784
  case 8:
4664
4785
  case "end":
4665
- return _context28.stop();
4786
+ return _context26.stop();
4666
4787
  }
4667
- }, _callee26, this);
4788
+ }, _callee24, this);
4668
4789
  }));
4669
- function finalizeAfterProductsMutation(_x34, _x35) {
4790
+ function finalizeAfterProductsMutation(_x29, _x30) {
4670
4791
  return _finalizeAfterProductsMutation.apply(this, arguments);
4671
4792
  }
4672
4793
  return finalizeAfterProductsMutation;
@@ -4681,19 +4802,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4681
4802
  }, {
4682
4803
  key: "removeProductsFromOrder",
4683
4804
  value: (function () {
4684
- var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(identities, options) {
4685
- var _this29 = this;
4805
+ var _removeProductsFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(identities, options) {
4806
+ var _this30 = this;
4686
4807
  var tempOrder, productsBeforeRemove, bookingsBeforeRemove, preserveDisplayPosition, anchorIndex, productsAfterAnchor, matchedProducts, removedProducts, _i2, _removedProducts, product, linkedBookingUidsToRemove, _iterator21, _step21, _loop3, remainingProductIndex, remainingProduct, nextProduct, productsWithoutRemaining, nextProductIndex;
4687
- return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4688
- while (1) switch (_context30.prev = _context30.next) {
4808
+ return _regeneratorRuntime().wrap(function _callee25$(_context28) {
4809
+ while (1) switch (_context28.prev = _context28.next) {
4689
4810
  case 0:
4690
4811
  tempOrder = this.ensureTempOrder();
4812
+ this.repairDuplicateProductLineIdentities(tempOrder);
4691
4813
  if (identities.length) {
4692
- _context30.next = 3;
4814
+ _context28.next = 4;
4693
4815
  break;
4694
4816
  }
4695
- return _context30.abrupt("return", tempOrder.products);
4696
- case 3:
4817
+ return _context28.abrupt("return", tempOrder.products);
4818
+ case 4:
4697
4819
  productsBeforeRemove = tempOrder.products || [];
4698
4820
  bookingsBeforeRemove = tempOrder.bookings || [];
4699
4821
  preserveDisplayPosition = options === null || options === void 0 ? void 0 : options.preserveDisplayPosition;
@@ -4722,29 +4844,29 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4722
4844
  }
4723
4845
  linkedBookingUidsToRemove = new Set();
4724
4846
  _iterator21 = _createForOfIteratorHelper(matchedProducts);
4725
- _context30.prev = 14;
4847
+ _context28.prev = 15;
4726
4848
  _loop3 = /*#__PURE__*/_regeneratorRuntime().mark(function _loop3() {
4727
4849
  var _metadata11, _metadata12, _metadata13, _metadata14;
4728
4850
  var product, productUid, productBookingUid, isAddTimeProduct;
4729
- return _regeneratorRuntime().wrap(function _loop3$(_context29) {
4730
- while (1) switch (_context29.prev = _context29.next) {
4851
+ return _regeneratorRuntime().wrap(function _loop3$(_context27) {
4852
+ while (1) switch (_context27.prev = _context27.next) {
4731
4853
  case 0:
4732
4854
  product = _step21.value;
4733
4855
  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);
4734
4856
  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);
4735
4857
  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;
4736
4858
  if (!isAddTimeProduct) {
4737
- _context29.next = 6;
4859
+ _context27.next = 6;
4738
4860
  break;
4739
4861
  }
4740
- return _context29.abrupt("return", 1);
4862
+ return _context27.abrupt("return", 1);
4741
4863
  case 6:
4742
4864
  if (productBookingUid !== undefined && productBookingUid !== null && productBookingUid !== '') {
4743
4865
  linkedBookingUidsToRemove.add(String(productBookingUid));
4744
4866
  }
4745
4867
  if (productUid !== undefined && productUid !== null && productUid !== '') {
4746
4868
  bookingsBeforeRemove.forEach(function (booking) {
4747
- var bookingUid = _this29.getBookingUniqueIdentificationNumber(booking);
4869
+ var bookingUid = _this30.getBookingUniqueIdentificationNumber(booking);
4748
4870
  if (bookingUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) {
4749
4871
  linkedBookingUidsToRemove.add(bookingUid);
4750
4872
  }
@@ -4752,38 +4874,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4752
4874
  }
4753
4875
  case 8:
4754
4876
  case "end":
4755
- return _context29.stop();
4877
+ return _context27.stop();
4756
4878
  }
4757
4879
  }, _loop3);
4758
4880
  });
4759
4881
  _iterator21.s();
4760
- case 17:
4882
+ case 18:
4761
4883
  if ((_step21 = _iterator21.n()).done) {
4762
- _context30.next = 23;
4884
+ _context28.next = 24;
4763
4885
  break;
4764
4886
  }
4765
- return _context30.delegateYield(_loop3(), "t0", 19);
4766
- case 19:
4767
- if (!_context30.t0) {
4768
- _context30.next = 21;
4887
+ return _context28.delegateYield(_loop3(), "t0", 20);
4888
+ case 20:
4889
+ if (!_context28.t0) {
4890
+ _context28.next = 22;
4769
4891
  break;
4770
4892
  }
4771
- return _context30.abrupt("continue", 21);
4772
- case 21:
4773
- _context30.next = 17;
4893
+ return _context28.abrupt("continue", 22);
4894
+ case 22:
4895
+ _context28.next = 18;
4774
4896
  break;
4775
- case 23:
4776
- _context30.next = 28;
4897
+ case 24:
4898
+ _context28.next = 29;
4777
4899
  break;
4778
- case 25:
4779
- _context30.prev = 25;
4780
- _context30.t1 = _context30["catch"](14);
4781
- _iterator21.e(_context30.t1);
4782
- case 28:
4783
- _context30.prev = 28;
4900
+ case 26:
4901
+ _context28.prev = 26;
4902
+ _context28.t1 = _context28["catch"](15);
4903
+ _iterator21.e(_context28.t1);
4904
+ case 29:
4905
+ _context28.prev = 29;
4784
4906
  _iterator21.f();
4785
- return _context30.finish(28);
4786
- case 31:
4907
+ return _context28.finish(29);
4908
+ case 32:
4787
4909
  if (linkedBookingUidsToRemove.size > 0) {
4788
4910
  // 删除主预约商品时,同步移除挂在同一 booking_uid 下的加时商品,避免残留孤儿行。
4789
4911
  tempOrder.products = (tempOrder.products || []).filter(function (line) {
@@ -4809,20 +4931,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4809
4931
  tempOrder.products = nextProductIndex >= 0 ? [].concat(_toConsumableArray(productsWithoutRemaining.slice(0, nextProductIndex)), [remainingProduct], _toConsumableArray(productsWithoutRemaining.slice(nextProductIndex))) : [].concat(_toConsumableArray(productsWithoutRemaining), [remainingProduct]);
4810
4932
  }
4811
4933
  }
4812
- _context30.next = 35;
4934
+ _context28.next = 36;
4813
4935
  return this.finalizeAfterProductsMutation(tempOrder);
4814
- case 35:
4936
+ case 36:
4815
4937
  this.logInfo('removeProductsFromOrder success', {
4816
4938
  identities: identities
4817
4939
  });
4818
- return _context30.abrupt("return", tempOrder.products);
4819
- case 37:
4940
+ return _context28.abrupt("return", tempOrder.products);
4941
+ case 38:
4820
4942
  case "end":
4821
- return _context30.stop();
4943
+ return _context28.stop();
4822
4944
  }
4823
- }, _callee27, this, [[14, 25, 28, 31]]);
4945
+ }, _callee25, this, [[15, 26, 29, 32]]);
4824
4946
  }));
4825
- function removeProductsFromOrder(_x36, _x37) {
4947
+ function removeProductsFromOrder(_x31, _x32) {
4826
4948
  return _removeProductsFromOrder.apply(this, arguments);
4827
4949
  }
4828
4950
  return removeProductsFromOrder;
@@ -4830,18 +4952,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4830
4952
  }, {
4831
4953
  key: "removeProductFromOrder",
4832
4954
  value: function () {
4833
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(identity, options) {
4834
- return _regeneratorRuntime().wrap(function _callee28$(_context31) {
4835
- while (1) switch (_context31.prev = _context31.next) {
4955
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(identity, options) {
4956
+ return _regeneratorRuntime().wrap(function _callee26$(_context29) {
4957
+ while (1) switch (_context29.prev = _context29.next) {
4836
4958
  case 0:
4837
- return _context31.abrupt("return", this.removeProductsFromOrder([identity], options));
4959
+ return _context29.abrupt("return", this.removeProductsFromOrder([identity], options));
4838
4960
  case 1:
4839
4961
  case "end":
4840
- return _context31.stop();
4962
+ return _context29.stop();
4841
4963
  }
4842
- }, _callee28, this);
4964
+ }, _callee26, this);
4843
4965
  }));
4844
- function removeProductFromOrder(_x38, _x39) {
4966
+ function removeProductFromOrder(_x33, _x34) {
4845
4967
  return _removeProductFromOrder.apply(this, arguments);
4846
4968
  }
4847
4969
  return removeProductFromOrder;
@@ -4853,10 +4975,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4853
4975
  }, {
4854
4976
  key: "clearOrderCartLines",
4855
4977
  value: (function () {
4856
- var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29() {
4978
+ var _clearOrderCartLines = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27() {
4857
4979
  var tempOrder;
4858
- return _regeneratorRuntime().wrap(function _callee29$(_context32) {
4859
- while (1) switch (_context32.prev = _context32.next) {
4980
+ return _regeneratorRuntime().wrap(function _callee27$(_context30) {
4981
+ while (1) switch (_context30.prev = _context30.next) {
4860
4982
  case 0:
4861
4983
  tempOrder = this.ensureTempOrder();
4862
4984
  tempOrder.products = [];
@@ -4867,24 +4989,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4867
4989
  productsByUid: {}
4868
4990
  });
4869
4991
  }
4870
- _context32.next = 7;
4992
+ _context30.next = 7;
4871
4993
  return this.applyPromotion();
4872
4994
  case 7:
4873
4995
  this.applyDiscount();
4874
4996
  this.sanitizeTempOrderProducts(tempOrder);
4875
- _context32.next = 11;
4997
+ _context30.next = 11;
4876
4998
  return this.recalculateSummary({
4877
4999
  createIfMissing: true
4878
5000
  });
4879
5001
  case 11:
4880
5002
  this.persistTempOrder();
4881
5003
  this.logInfo('clearOrderCartLines success', {});
4882
- return _context32.abrupt("return", tempOrder);
5004
+ return _context30.abrupt("return", tempOrder);
4883
5005
  case 14:
4884
5006
  case "end":
4885
- return _context32.stop();
5007
+ return _context30.stop();
4886
5008
  }
4887
- }, _callee29, this);
5009
+ }, _callee27, this);
4888
5010
  }));
4889
5011
  function clearOrderCartLines() {
4890
5012
  return _clearOrderCartLines.apply(this, arguments);
@@ -4922,17 +5044,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4922
5044
  }, {
4923
5045
  key: "applyLocalPrintOrderNumbers",
4924
5046
  value: function () {
4925
- var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(order) {
5047
+ var _applyLocalPrintOrderNumbers = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(order) {
4926
5048
  var tempOrder, shopOrderNumber, shopFullOrderNumber;
4927
- return _regeneratorRuntime().wrap(function _callee30$(_context33) {
4928
- while (1) switch (_context33.prev = _context33.next) {
5049
+ return _regeneratorRuntime().wrap(function _callee28$(_context31) {
5050
+ while (1) switch (_context31.prev = _context31.next) {
4929
5051
  case 0:
4930
5052
  tempOrder = this.ensureTempOrder();
4931
5053
  if (!(!order || _typeof(order) !== 'object')) {
4932
- _context33.next = 3;
5054
+ _context31.next = 3;
4933
5055
  break;
4934
5056
  }
4935
- return _context33.abrupt("return", tempOrder);
5057
+ return _context31.abrupt("return", tempOrder);
4936
5058
  case 3:
4937
5059
  shopOrderNumber = order.shop_order_number;
4938
5060
  shopFullOrderNumber = order.shop_full_order_number;
@@ -4943,17 +5065,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4943
5065
  tempOrder.shop_full_order_number = String(shopFullOrderNumber);
4944
5066
  }
4945
5067
  this.persistTempOrder();
4946
- _context33.next = 10;
5068
+ _context31.next = 10;
4947
5069
  return this.saveDraft();
4948
5070
  case 10:
4949
- return _context33.abrupt("return", tempOrder);
5071
+ return _context31.abrupt("return", tempOrder);
4950
5072
  case 11:
4951
5073
  case "end":
4952
- return _context33.stop();
5074
+ return _context31.stop();
4953
5075
  }
4954
- }, _callee30, this);
5076
+ }, _callee28, this);
4955
5077
  }));
4956
- function applyLocalPrintOrderNumbers(_x40) {
5078
+ function applyLocalPrintOrderNumbers(_x35) {
4957
5079
  return _applyLocalPrintOrderNumbers.apply(this, arguments);
4958
5080
  }
4959
5081
  return applyLocalPrintOrderNumbers;
@@ -4961,35 +5083,35 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
4961
5083
  }, {
4962
5084
  key: "saveTempOrderAsDraft",
4963
5085
  value: function () {
4964
- var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
5086
+ var _saveTempOrderAsDraft = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(params) {
4965
5087
  var _params$cacheId2, _this$otherParams6, _this$otherParams7, _this$otherParams8, _params$type, _this$otherParams9, _payload$products;
4966
5088
  var tempOrder, latestSummary, payload;
4967
- return _regeneratorRuntime().wrap(function _callee31$(_context34) {
4968
- while (1) switch (_context34.prev = _context34.next) {
5089
+ return _regeneratorRuntime().wrap(function _callee29$(_context32) {
5090
+ while (1) switch (_context32.prev = _context32.next) {
4969
5091
  case 0:
4970
5092
  tempOrder = this.ensureTempOrder();
4971
5093
  this.ensureExternalSaleNumber(tempOrder);
4972
5094
  this.persistTempOrder();
4973
- _context34.next = 5;
5095
+ _context32.next = 5;
4974
5096
  return this.recalculateSummary({
4975
5097
  createIfMissing: true
4976
5098
  });
4977
5099
  case 5:
4978
- _context34.t1 = _context34.sent;
4979
- if (_context34.t1) {
4980
- _context34.next = 8;
5100
+ _context32.t1 = _context32.sent;
5101
+ if (_context32.t1) {
5102
+ _context32.next = 8;
4981
5103
  break;
4982
5104
  }
4983
- _context34.t1 = this.store.summary;
5105
+ _context32.t1 = this.store.summary;
4984
5106
  case 8:
4985
- _context34.t0 = _context34.t1;
4986
- if (_context34.t0) {
4987
- _context34.next = 11;
5107
+ _context32.t0 = _context32.t1;
5108
+ if (_context32.t0) {
5109
+ _context32.next = 11;
4988
5110
  break;
4989
5111
  }
4990
- _context34.t0 = createEmptySummary();
5112
+ _context32.t0 = createEmptySummary();
4991
5113
  case 11:
4992
- latestSummary = _context34.t0;
5114
+ latestSummary = _context32.t0;
4993
5115
  payload = buildSubmitPayload({
4994
5116
  tempOrder: tempOrder,
4995
5117
  cacheId: (_params$cacheId2 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId2 !== void 0 ? _params$cacheId2 : this.cacheId,
@@ -5010,17 +5132,17 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5010
5132
  externalSaleNumber: payload.external_sale_number,
5011
5133
  productsCount: ((_payload$products = payload.products) === null || _payload$products === void 0 ? void 0 : _payload$products.length) || 0
5012
5134
  });
5013
- return _context34.abrupt("return", this.request.post('/order/sales/draft', payload, {
5135
+ return _context32.abrupt("return", this.request.post('/order/sales/draft', payload, {
5014
5136
  osServer: true,
5015
5137
  customToast: function customToast() {}
5016
5138
  }));
5017
5139
  case 18:
5018
5140
  case "end":
5019
- return _context34.stop();
5141
+ return _context32.stop();
5020
5142
  }
5021
- }, _callee31, this);
5143
+ }, _callee29, this);
5022
5144
  }));
5023
- function saveTempOrderAsDraft(_x41) {
5145
+ function saveTempOrderAsDraft(_x36) {
5024
5146
  return _saveTempOrderAsDraft.apply(this, arguments);
5025
5147
  }
5026
5148
  return saveTempOrderAsDraft;
@@ -5034,18 +5156,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5034
5156
  }, {
5035
5157
  key: "submitTempOrder",
5036
5158
  value: (function () {
5037
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5038
- return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5039
- while (1) switch (_context35.prev = _context35.next) {
5159
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee30(params) {
5160
+ return _regeneratorRuntime().wrap(function _callee30$(_context33) {
5161
+ while (1) switch (_context33.prev = _context33.next) {
5040
5162
  case 0:
5041
- return _context35.abrupt("return", this.runSubmitTempOrder(params));
5163
+ return _context33.abrupt("return", this.runSubmitTempOrder(params));
5042
5164
  case 1:
5043
5165
  case "end":
5044
- return _context35.stop();
5166
+ return _context33.stop();
5045
5167
  }
5046
- }, _callee32, this);
5168
+ }, _callee30, this);
5047
5169
  }));
5048
- function submitTempOrder(_x42) {
5170
+ function submitTempOrder(_x37) {
5049
5171
  return _submitTempOrder.apply(this, arguments);
5050
5172
  }
5051
5173
  return submitTempOrder;
@@ -5053,20 +5175,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5053
5175
  }, {
5054
5176
  key: "submitTempOrderAsync",
5055
5177
  value: function () {
5056
- var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(params) {
5057
- return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5058
- while (1) switch (_context36.prev = _context36.next) {
5178
+ var _submitTempOrderAsync = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee31(params) {
5179
+ return _regeneratorRuntime().wrap(function _callee31$(_context34) {
5180
+ while (1) switch (_context34.prev = _context34.next) {
5059
5181
  case 0:
5060
- return _context36.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5182
+ return _context34.abrupt("return", this.runSubmitTempOrder(_objectSpread(_objectSpread({}, params), {}, {
5061
5183
  syncMode: true
5062
5184
  })));
5063
5185
  case 1:
5064
5186
  case "end":
5065
- return _context36.stop();
5187
+ return _context34.stop();
5066
5188
  }
5067
- }, _callee33, this);
5189
+ }, _callee31, this);
5068
5190
  }));
5069
- function submitTempOrderAsync(_x43) {
5191
+ function submitTempOrderAsync(_x38) {
5070
5192
  return _submitTempOrderAsync.apply(this, arguments);
5071
5193
  }
5072
5194
  return submitTempOrderAsync;
@@ -5074,11 +5196,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5074
5196
  }, {
5075
5197
  key: "runSubmitTempOrder",
5076
5198
  value: function () {
5077
- var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5199
+ var _runSubmitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee32(params) {
5078
5200
  var _params$cacheId3, _this$otherParams10, _ref73, _ref74, _submitSnapshot$busin, _this$otherParams11, _this$otherParams12, _submitSnapshot$type;
5079
5201
  var tempOrder, shouldConfirmPendingVoucherPayments, hasPaymentOverride, preparedPaymentOverride, latestSummary, effectiveCacheId, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, submitSnapshot, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
5080
- return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5081
- while (1) switch (_context37.prev = _context37.next) {
5202
+ return _regeneratorRuntime().wrap(function _callee32$(_context35) {
5203
+ while (1) switch (_context35.prev = _context35.next) {
5082
5204
  case 0:
5083
5205
  tempOrder = this.ensureTempOrder();
5084
5206
  shouldConfirmPendingVoucherPayments = (params === null || params === void 0 ? void 0 : params.confirmPendingVoucherPayments) !== false;
@@ -5098,26 +5220,26 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5098
5220
  }
5099
5221
  }
5100
5222
  this.persistTempOrder();
5101
- _context37.next = 8;
5223
+ _context35.next = 8;
5102
5224
  return this.recalculateSummary({
5103
5225
  createIfMissing: true
5104
5226
  });
5105
5227
  case 8:
5106
- _context37.t1 = _context37.sent;
5107
- if (_context37.t1) {
5108
- _context37.next = 11;
5228
+ _context35.t1 = _context35.sent;
5229
+ if (_context35.t1) {
5230
+ _context35.next = 11;
5109
5231
  break;
5110
5232
  }
5111
- _context37.t1 = this.store.summary;
5233
+ _context35.t1 = this.store.summary;
5112
5234
  case 11:
5113
- _context37.t0 = _context37.t1;
5114
- if (_context37.t0) {
5115
- _context37.next = 14;
5235
+ _context35.t0 = _context35.t1;
5236
+ if (_context35.t0) {
5237
+ _context35.next = 14;
5116
5238
  break;
5117
5239
  }
5118
- _context37.t0 = createEmptySummary();
5240
+ _context35.t0 = createEmptySummary();
5119
5241
  case 14:
5120
- latestSummary = _context37.t0;
5242
+ latestSummary = _context35.t0;
5121
5243
  effectiveCacheId = (_params$cacheId3 = params === null || params === void 0 ? void 0 : params.cacheId) !== null && _params$cacheId3 !== void 0 ? _params$cacheId3 : this.cacheId;
5122
5244
  hasPaymentStatusOverride = (params === null || params === void 0 ? void 0 : params.paymentStatus) !== undefined;
5123
5245
  hasSmallTicketDataFlagOverride = (params === null || params === void 0 ? void 0 : params.smallTicketDataFlag) !== undefined;
@@ -5152,10 +5274,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5152
5274
  if (!payload.created_at) {
5153
5275
  payload.created_at = dayjs().format('YYYY-MM-DD HH:mm:ss');
5154
5276
  }
5155
- _context37.next = 26;
5277
+ _context35.next = 26;
5156
5278
  return this.saveDraft();
5157
5279
  case 26:
5158
- _context37.prev = 26;
5280
+ _context35.prev = 26;
5159
5281
  this.logInfo('submitTempOrder calling sales checkout', {
5160
5282
  orderId: payload.order_id,
5161
5283
  externalSaleNumber: payload.external_sale_number,
@@ -5165,43 +5287,43 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5165
5287
  smallTicketDataFlag: payload.small_ticket_data_flag,
5166
5288
  syncMode: payload.sync_mode
5167
5289
  });
5168
- _context37.next = 30;
5290
+ _context35.next = 30;
5169
5291
  return this.submitSalesOrder({
5170
5292
  query: payload
5171
5293
  });
5172
5294
  case 30:
5173
- result = _context37.sent;
5174
- _context37.next = 43;
5295
+ result = _context35.sent;
5296
+ _context35.next = 43;
5175
5297
  break;
5176
5298
  case 33:
5177
- _context37.prev = 33;
5178
- _context37.t2 = _context37["catch"](26);
5179
- backendErrorResponse = this.extractSubmitErrorResponse(_context37.t2);
5299
+ _context35.prev = 33;
5300
+ _context35.t2 = _context35["catch"](26);
5301
+ backendErrorResponse = this.extractSubmitErrorResponse(_context35.t2);
5180
5302
  if (!backendErrorResponse) {
5181
- _context37.next = 40;
5303
+ _context35.next = 40;
5182
5304
  break;
5183
5305
  }
5184
5306
  this.store.syncState = 'failed';
5185
5307
  this.logSubmitBackendRejected(backendErrorResponse, payload);
5186
- return _context37.abrupt("return", backendErrorResponse);
5308
+ return _context35.abrupt("return", backendErrorResponse);
5187
5309
  case 40:
5188
5310
  this.store.syncState = 'failed';
5189
5311
  this.logError('submitTempOrder failed', {
5190
- error: _context37.t2 instanceof Error ? _context37.t2.message : String(_context37.t2),
5312
+ error: _context35.t2 instanceof Error ? _context35.t2.message : String(_context35.t2),
5191
5313
  orderId: payload.order_id,
5192
5314
  externalSaleNumber: payload.external_sale_number,
5193
5315
  paymentStatus: payload.payment_status,
5194
5316
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
5195
5317
  });
5196
- throw _context37.t2;
5318
+ throw _context35.t2;
5197
5319
  case 43:
5198
5320
  if (!this.isSubmitResponseRejected(result)) {
5199
- _context37.next = 47;
5321
+ _context35.next = 47;
5200
5322
  break;
5201
5323
  }
5202
5324
  this.store.syncState = 'failed';
5203
5325
  this.logSubmitBackendRejected(result, payload);
5204
- return _context37.abrupt("return", result);
5326
+ return _context35.abrupt("return", result);
5205
5327
  case 47:
5206
5328
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
5207
5329
  this.logInfo('runSubmitTempOrder: 提交成功', {
@@ -5212,15 +5334,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5212
5334
  })
5213
5335
  });
5214
5336
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
5215
- _context37.next = 56;
5337
+ _context35.next = 56;
5216
5338
  break;
5217
5339
  }
5218
5340
  tempOrder.order_id = submittedOrderId;
5219
5341
  resultRecord = result;
5220
- _context37.next = 54;
5342
+ _context35.next = 54;
5221
5343
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
5222
5344
  case 54:
5223
- _context37.next = 57;
5345
+ _context35.next = 57;
5224
5346
  break;
5225
5347
  case 56:
5226
5348
  if (this.isLocalPendingSubmitResult(result)) {
@@ -5229,14 +5351,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5229
5351
  this.store.syncState = 'submitted';
5230
5352
  }
5231
5353
  case 57:
5232
- return _context37.abrupt("return", result);
5354
+ return _context35.abrupt("return", result);
5233
5355
  case 58:
5234
5356
  case "end":
5235
- return _context37.stop();
5357
+ return _context35.stop();
5236
5358
  }
5237
- }, _callee34, this, [[26, 33]]);
5359
+ }, _callee32, this, [[26, 33]]);
5238
5360
  }));
5239
- function runSubmitTempOrder(_x44) {
5361
+ function runSubmitTempOrder(_x39) {
5240
5362
  return _runSubmitTempOrder.apply(this, arguments);
5241
5363
  }
5242
5364
  return runSubmitTempOrder;
@@ -5244,10 +5366,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5244
5366
  }, {
5245
5367
  key: "markLocalOrderSynced",
5246
5368
  value: function () {
5247
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(orderId, remoteOrder) {
5369
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee33(orderId, remoteOrder) {
5248
5370
  var tempOrder;
5249
- return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5250
- while (1) switch (_context38.prev = _context38.next) {
5371
+ return _regeneratorRuntime().wrap(function _callee33$(_context36) {
5372
+ while (1) switch (_context36.prev = _context36.next) {
5251
5373
  case 0:
5252
5374
  tempOrder = this.ensureTempOrder();
5253
5375
  tempOrder.order_id = orderId;
@@ -5255,15 +5377,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5255
5377
  this.store.lastOrderInfo = remoteOrder;
5256
5378
  this.store.syncState = 'submitted';
5257
5379
  this.persistTempOrder();
5258
- _context38.next = 8;
5380
+ _context36.next = 8;
5259
5381
  return this.saveDraft();
5260
5382
  case 8:
5261
5383
  case "end":
5262
- return _context38.stop();
5384
+ return _context36.stop();
5263
5385
  }
5264
- }, _callee35, this);
5386
+ }, _callee33, this);
5265
5387
  }));
5266
- function markLocalOrderSynced(_x45, _x46) {
5388
+ function markLocalOrderSynced(_x40, _x41) {
5267
5389
  return _markLocalOrderSynced.apply(this, arguments);
5268
5390
  }
5269
5391
  return markLocalOrderSynced;
@@ -5306,10 +5428,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5306
5428
  value: function extractSubmitErrorResponse(error) {
5307
5429
  var _error$response,
5308
5430
  _error$response2,
5309
- _this30 = this;
5431
+ _this31 = this;
5310
5432
  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];
5311
5433
  return candidates.find(function (candidate) {
5312
- return _this30.isSubmitErrorResponse(candidate);
5434
+ return _this31.isSubmitErrorResponse(candidate);
5313
5435
  }) || null;
5314
5436
  }
5315
5437
  }, {
@@ -5336,33 +5458,33 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5336
5458
  }, {
5337
5459
  key: "syncPaymentsToOrder",
5338
5460
  value: function () {
5339
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5340
- var _this31 = this,
5461
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee34(params) {
5462
+ var _this32 = this,
5341
5463
  _params$confirmPendin;
5342
- var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitResult;
5343
- return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5344
- while (1) switch (_context39.prev = _context39.next) {
5464
+ var tempOrder, needsPaymentNumber, devicePrefix, mappedPayments, shouldConfirmPendingVoucherPayments, effectivePayments, completion, orderPaidPaymentTotal, paymentStatus, paymentSyncIdempotencyToken, submitParams, submitResult;
5465
+ return _regeneratorRuntime().wrap(function _callee34$(_context37) {
5466
+ while (1) switch (_context37.prev = _context37.next) {
5345
5467
  case 0:
5346
5468
  tempOrder = this.ensureTempOrder();
5347
5469
  needsPaymentNumber = (params.payments || []).some(function (payment) {
5348
5470
  return String(payment.payment_number || '').trim() === '';
5349
5471
  });
5350
5472
  if (!needsPaymentNumber) {
5351
- _context39.next = 8;
5473
+ _context37.next = 8;
5352
5474
  break;
5353
5475
  }
5354
- _context39.next = 5;
5476
+ _context37.next = 5;
5355
5477
  return this.getPaymentNumberDevicePrefixAsync();
5356
5478
  case 5:
5357
- _context39.t0 = _context39.sent;
5358
- _context39.next = 9;
5479
+ _context37.t0 = _context37.sent;
5480
+ _context37.next = 9;
5359
5481
  break;
5360
5482
  case 8:
5361
- _context39.t0 = 'LOCAL';
5483
+ _context37.t0 = 'LOCAL';
5362
5484
  case 9:
5363
- devicePrefix = _context39.t0;
5485
+ devicePrefix = _context37.t0;
5364
5486
  mappedPayments = mapPaymentItemsToOrderPayments((params.payments || []).map(function (payment) {
5365
- return _this31.normalizePaymentSource(payment, {
5487
+ return _this32.normalizePaymentSource(payment, {
5366
5488
  defaultPaid: false,
5367
5489
  devicePrefix: devicePrefix
5368
5490
  });
@@ -5375,25 +5497,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5375
5497
  tempOrder.payments = effectivePayments;
5376
5498
  tempOrder.payment_status = paymentStatus;
5377
5499
  this.persistTempOrder();
5378
- _context39.next = 21;
5500
+ _context37.next = 21;
5379
5501
  return this.saveDraft();
5380
5502
  case 21:
5381
5503
  if (params.submitWhenPaid) {
5382
- _context39.next = 23;
5504
+ _context37.next = 23;
5383
5505
  break;
5384
5506
  }
5385
- return _context39.abrupt("return", completion);
5507
+ return _context37.abrupt("return", completion);
5386
5508
  case 23:
5387
5509
  if (!(this.store.syncState === 'submitting')) {
5388
- _context39.next = 25;
5510
+ _context37.next = 25;
5389
5511
  break;
5390
5512
  }
5391
- return _context39.abrupt("return", completion);
5513
+ return _context37.abrupt("return", completion);
5392
5514
  case 25:
5393
5515
  this.store.syncState = 'submitting';
5394
5516
  paymentSyncIdempotencyToken = this.buildPaymentSyncIdempotencyToken(tempOrder, effectivePayments);
5395
- _context39.next = 29;
5396
- return this.submitTempOrder({
5517
+ submitParams = {
5397
5518
  payments: effectivePayments,
5398
5519
  paymentStatus: paymentStatus,
5399
5520
  smallTicketDataFlag: params.smallTicketDataFlag,
@@ -5406,19 +5527,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5406
5527
  });
5407
5528
  return nextPayload;
5408
5529
  }
5409
- });
5410
- case 29:
5411
- submitResult = _context39.sent;
5412
- return _context39.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5530
+ };
5531
+ if (!(params.checkoutSyncTaskEnabled === false)) {
5532
+ _context37.next = 34;
5533
+ break;
5534
+ }
5535
+ _context37.next = 31;
5536
+ return this.submitTempOrderAsync(submitParams);
5537
+ case 31:
5538
+ _context37.t1 = _context37.sent;
5539
+ _context37.next = 37;
5540
+ break;
5541
+ case 34:
5542
+ _context37.next = 36;
5543
+ return this.submitTempOrder(submitParams);
5544
+ case 36:
5545
+ _context37.t1 = _context37.sent;
5546
+ case 37:
5547
+ submitResult = _context37.t1;
5548
+ return _context37.abrupt("return", _objectSpread(_objectSpread({}, completion), {}, {
5413
5549
  submitResult: submitResult
5414
5550
  }));
5415
- case 31:
5551
+ case 39:
5416
5552
  case "end":
5417
- return _context39.stop();
5553
+ return _context37.stop();
5418
5554
  }
5419
- }, _callee36, this);
5555
+ }, _callee34, this);
5420
5556
  }));
5421
- function syncPaymentsToOrder(_x47) {
5557
+ function syncPaymentsToOrder(_x42) {
5422
5558
  return _syncPaymentsToOrder.apply(this, arguments);
5423
5559
  }
5424
5560
  return syncPaymentsToOrder;
@@ -5426,6 +5562,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5426
5562
  }, {
5427
5563
  key: "createOrder",
5428
5564
  value: function createOrder(params) {
5565
+ var _this33 = this;
5429
5566
  var order = _objectSpread({
5430
5567
  type: (params === null || params === void 0 ? void 0 : params.type) || 'appointment_booking',
5431
5568
  // 要从外面拿,virtual
@@ -5437,11 +5574,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5437
5574
  schedule_date: '',
5438
5575
  is_deposit: 0,
5439
5576
  relation_products: [],
5440
- relation_forms: []
5577
+ relation_forms: [],
5578
+ business_code: params === null || params === void 0 ? void 0 : params.business_code
5441
5579
  }, (params === null || params === void 0 ? void 0 : params.extraData) || {});
5442
5580
  var is_deposit = 0; // 是否存在定金,0 不存在,1 存在
5443
5581
  if (params.cartItems.length > 0) {
5444
5582
  params.cartItems.forEach(function (item) {
5583
+ var _params$extraData;
5445
5584
  if (!item._origin.duration) {
5446
5585
  var _generateDuration = generateDuration(item),
5447
5586
  duration = _generateDuration.duration,
@@ -5453,6 +5592,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5453
5592
  var discountList = getAllDiscountList(item);
5454
5593
  item._origin.product.discount_list = discountList;
5455
5594
 
5595
+ // 为预约补齐 holder 信息
5596
+ if (params !== null && params !== void 0 && (_params$extraData = params.extraData) !== null && _params$extraData !== void 0 && _params$extraData.is_add_holder_info) {
5597
+ ensureCartItemOriginHolder(item, _this33.window);
5598
+ }
5599
+
5456
5600
  // 购物车是否为普通商品
5457
5601
  if (isNormalProduct(item._origin)) {
5458
5602
  var _order$relation_forms;
@@ -5507,11 +5651,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5507
5651
  }, {
5508
5652
  key: "submitOrder",
5509
5653
  value: function () {
5510
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(order) {
5654
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee35(order) {
5511
5655
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
5512
5656
  var url, query, fetchUrl, params;
5513
- return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5514
- while (1) switch (_context40.prev = _context40.next) {
5657
+ return _regeneratorRuntime().wrap(function _callee35$(_context38) {
5658
+ while (1) switch (_context38.prev = _context38.next) {
5515
5659
  case 0:
5516
5660
  this.logInfo('submitOrder called', {
5517
5661
  url: order.url,
@@ -5531,14 +5675,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5531
5675
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
5532
5676
  scheduleDate: params.schedule_date
5533
5677
  });
5534
- return _context40.abrupt("return", this.request.post(fetchUrl, params));
5678
+ return _context38.abrupt("return", this.request.post(fetchUrl, params));
5535
5679
  case 6:
5536
5680
  case "end":
5537
- return _context40.stop();
5681
+ return _context38.stop();
5538
5682
  }
5539
- }, _callee37, this);
5683
+ }, _callee35, this);
5540
5684
  }));
5541
- function submitOrder(_x48) {
5685
+ function submitOrder(_x43) {
5542
5686
  return _submitOrder.apply(this, arguments);
5543
5687
  }
5544
5688
  return submitOrder;
@@ -5546,13 +5690,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5546
5690
  }, {
5547
5691
  key: "cancelOrder",
5548
5692
  value: function () {
5549
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5693
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee36(params) {
5550
5694
  var payload;
5551
- return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5552
- while (1) switch (_context41.prev = _context41.next) {
5695
+ return _regeneratorRuntime().wrap(function _callee36$(_context39) {
5696
+ while (1) switch (_context39.prev = _context39.next) {
5553
5697
  case 0:
5554
5698
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
5555
- _context41.next = 2;
5699
+ _context39.next = 2;
5556
5700
  break;
5557
5701
  }
5558
5702
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -5568,16 +5712,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5568
5712
  method: 'PUT',
5569
5713
  orderIdsCount: params.order_ids.length
5570
5714
  });
5571
- return _context41.abrupt("return", this.request.put('/order/update-status', payload, {
5715
+ return _context39.abrupt("return", this.request.put('/order/update-status', payload, {
5572
5716
  isShopApi: true
5573
5717
  }));
5574
5718
  case 5:
5575
5719
  case "end":
5576
- return _context41.stop();
5720
+ return _context39.stop();
5577
5721
  }
5578
- }, _callee38, this);
5722
+ }, _callee36, this);
5579
5723
  }));
5580
- function cancelOrder(_x49) {
5724
+ function cancelOrder(_x44) {
5581
5725
  return _cancelOrder.apply(this, arguments);
5582
5726
  }
5583
5727
  return cancelOrder;
@@ -5585,19 +5729,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5585
5729
  }, {
5586
5730
  key: "changeBookingStatus",
5587
5731
  value: function () {
5588
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5732
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee37(params) {
5589
5733
  var url, payload;
5590
- return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5591
- while (1) switch (_context42.prev = _context42.next) {
5734
+ return _regeneratorRuntime().wrap(function _callee37$(_context40) {
5735
+ while (1) switch (_context40.prev = _context40.next) {
5592
5736
  case 0:
5593
5737
  if (params.booking_id) {
5594
- _context42.next = 2;
5738
+ _context40.next = 2;
5595
5739
  break;
5596
5740
  }
5597
5741
  throw new Error('变更预约状态失败:booking_id 不能为空');
5598
5742
  case 2:
5599
5743
  if (params.appointment_status) {
5600
- _context42.next = 4;
5744
+ _context40.next = 4;
5601
5745
  break;
5602
5746
  }
5603
5747
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -5612,16 +5756,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5612
5756
  bookingId: params.booking_id,
5613
5757
  appointmentStatus: params.appointment_status
5614
5758
  });
5615
- return _context42.abrupt("return", this.request.put(url, payload, {
5759
+ return _context40.abrupt("return", this.request.put(url, payload, {
5616
5760
  isShopApi: true
5617
5761
  }));
5618
5762
  case 8:
5619
5763
  case "end":
5620
- return _context42.stop();
5764
+ return _context40.stop();
5621
5765
  }
5622
- }, _callee39, this);
5766
+ }, _callee37, this);
5623
5767
  }));
5624
- function changeBookingStatus(_x50) {
5768
+ function changeBookingStatus(_x45) {
5625
5769
  return _changeBookingStatus.apply(this, arguments);
5626
5770
  }
5627
5771
  return changeBookingStatus;
@@ -5639,11 +5783,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5639
5783
  }, {
5640
5784
  key: "createOrderByCheckout",
5641
5785
  value: (function () {
5642
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5786
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee38(params) {
5643
5787
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
5644
5788
  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;
5645
- return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5646
- while (1) switch (_context43.prev = _context43.next) {
5789
+ return _regeneratorRuntime().wrap(function _callee38$(_context41) {
5790
+ while (1) switch (_context41.prev = _context41.next) {
5647
5791
  case 0:
5648
5792
  // 过滤掉由在线店铺下单的 payment 支付数据
5649
5793
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -5677,7 +5821,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5677
5821
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
5678
5822
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
5679
5823
  });
5680
- _context43.prev = 4;
5824
+ _context41.prev = 4;
5681
5825
  // 构建订单数据,设置默认值并允许 params 覆盖
5682
5826
  orderData = _objectSpread({
5683
5827
  sales_channel: 'my_pisel',
@@ -5739,13 +5883,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5739
5883
  hasOrderId: !!orderData.order_id,
5740
5884
  smallTicketDataFlag: orderData.small_ticket_data_flag
5741
5885
  });
5742
- _context43.next = 12;
5886
+ _context41.next = 12;
5743
5887
  return this.request.post('/order/checkout', orderData, {
5744
5888
  osServer: true,
5745
5889
  customToast: function customToast() {}
5746
5890
  });
5747
5891
  case 12:
5748
- response = _context43.sent;
5892
+ response = _context41.sent;
5749
5893
  this.logInfo('Order API called successfully', {
5750
5894
  response: response
5751
5895
  });
@@ -5753,22 +5897,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5753
5897
  success: !!response,
5754
5898
  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)
5755
5899
  });
5756
- return _context43.abrupt("return", response);
5900
+ return _context41.abrupt("return", response);
5757
5901
  case 18:
5758
- _context43.prev = 18;
5759
- _context43.t0 = _context43["catch"](4);
5760
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context43.t0);
5902
+ _context41.prev = 18;
5903
+ _context41.t0 = _context41["catch"](4);
5904
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context41.t0);
5761
5905
  this.logInfo('Order API called failed', {
5762
- error: _context43.t0 instanceof Error ? _context43.t0.message : String(_context43.t0)
5906
+ error: _context41.t0 instanceof Error ? _context41.t0.message : String(_context41.t0)
5763
5907
  });
5764
- throw _context43.t0;
5908
+ throw _context41.t0;
5765
5909
  case 23:
5766
5910
  case "end":
5767
- return _context43.stop();
5911
+ return _context41.stop();
5768
5912
  }
5769
- }, _callee40, this, [[4, 18]]);
5913
+ }, _callee38, this, [[4, 18]]);
5770
5914
  }));
5771
- function createOrderByCheckout(_x51) {
5915
+ function createOrderByCheckout(_x46) {
5772
5916
  return _createOrderByCheckout.apply(this, arguments);
5773
5917
  }
5774
5918
  return createOrderByCheckout;
@@ -5776,24 +5920,24 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5776
5920
  }, {
5777
5921
  key: "submitSalesOrder",
5778
5922
  value: function () {
5779
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5923
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee39(params) {
5780
5924
  var url, query, fetchUrl;
5781
- return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5782
- while (1) switch (_context44.prev = _context44.next) {
5925
+ return _regeneratorRuntime().wrap(function _callee39$(_context42) {
5926
+ while (1) switch (_context42.prev = _context42.next) {
5783
5927
  case 0:
5784
5928
  url = params.url, query = params.query;
5785
5929
  fetchUrl = url || '/order/sales/checkout';
5786
- return _context44.abrupt("return", this.request.post(fetchUrl, query, {
5930
+ return _context42.abrupt("return", this.request.post(fetchUrl, query, {
5787
5931
  osServer: true,
5788
5932
  customToast: function customToast() {}
5789
5933
  }));
5790
5934
  case 3:
5791
5935
  case "end":
5792
- return _context44.stop();
5936
+ return _context42.stop();
5793
5937
  }
5794
- }, _callee41, this);
5938
+ }, _callee39, this);
5795
5939
  }));
5796
- function submitSalesOrder(_x52) {
5940
+ function submitSalesOrder(_x47) {
5797
5941
  return _submitSalesOrder.apply(this, arguments);
5798
5942
  }
5799
5943
  return submitSalesOrder;
@@ -5807,37 +5951,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5807
5951
  }, {
5808
5952
  key: "sendCustomerPayLink",
5809
5953
  value: (function () {
5810
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(params) {
5954
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee40(params) {
5811
5955
  var _params$emails;
5812
5956
  var orderIds;
5813
- return _regeneratorRuntime().wrap(function _callee42$(_context45) {
5814
- while (1) switch (_context45.prev = _context45.next) {
5957
+ return _regeneratorRuntime().wrap(function _callee40$(_context43) {
5958
+ while (1) switch (_context43.prev = _context43.next) {
5815
5959
  case 0:
5816
5960
  orderIds = params.order_ids || params.orderIds || [];
5817
5961
  if (orderIds.length) {
5818
- _context45.next = 3;
5962
+ _context43.next = 3;
5819
5963
  break;
5820
5964
  }
5821
5965
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
5822
5966
  case 3:
5823
5967
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
5824
- _context45.next = 5;
5968
+ _context43.next = 5;
5825
5969
  break;
5826
5970
  }
5827
5971
  throw new Error('发送支付链接需要至少一个邮箱');
5828
5972
  case 5:
5829
- return _context45.abrupt("return", this.request.post('/order/batch-email', {
5973
+ return _context43.abrupt("return", this.request.post('/order/batch-email', {
5830
5974
  order_ids: orderIds,
5831
5975
  notify_action: params.notify_action || 'order_payment_reminder',
5832
5976
  emails: params.emails
5833
5977
  }));
5834
5978
  case 6:
5835
5979
  case "end":
5836
- return _context45.stop();
5980
+ return _context43.stop();
5837
5981
  }
5838
- }, _callee42, this);
5982
+ }, _callee40, this);
5839
5983
  }));
5840
- function sendCustomerPayLink(_x53) {
5984
+ function sendCustomerPayLink(_x48) {
5841
5985
  return _sendCustomerPayLink.apply(this, arguments);
5842
5986
  }
5843
5987
  return sendCustomerPayLink;
@@ -5845,14 +5989,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5845
5989
  }, {
5846
5990
  key: "getSalesOrderByLookup",
5847
5991
  value: function () {
5848
- var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(params) {
5992
+ var _getSalesOrderByLookup = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee41(params) {
5849
5993
  var lookup, res;
5850
- return _regeneratorRuntime().wrap(function _callee43$(_context46) {
5851
- while (1) switch (_context46.prev = _context46.next) {
5994
+ return _regeneratorRuntime().wrap(function _callee41$(_context44) {
5995
+ while (1) switch (_context44.prev = _context44.next) {
5852
5996
  case 0:
5853
5997
  lookup = params.lookup === undefined || params.lookup === null ? '' : String(params.lookup).trim();
5854
5998
  if (lookup) {
5855
- _context46.next = 3;
5999
+ _context44.next = 3;
5856
6000
  break;
5857
6001
  }
5858
6002
  throw new Error('加载销售详情需要 lookup');
@@ -5861,7 +6005,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5861
6005
  if (lookup.startsWith('LOCAL_')) {
5862
6006
  params.forceRemote = false;
5863
6007
  }
5864
- _context46.next = 6;
6008
+ _context44.next = 6;
5865
6009
  return this.request.get("/order/sales/".concat(encodeURIComponent(lookup)), _objectSpread({
5866
6010
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info', 'refunds']
5867
6011
  }, params.forceRemote ? {
@@ -5870,18 +6014,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5870
6014
  osServer: true
5871
6015
  });
5872
6016
  case 6:
5873
- res = _context46.sent;
6017
+ res = _context44.sent;
5874
6018
  if (res.code === 200) {
5875
6019
  this.store.lastOrderInfo = res.data;
5876
6020
  }
5877
- return _context46.abrupt("return", res);
6021
+ return _context44.abrupt("return", res);
5878
6022
  case 9:
5879
6023
  case "end":
5880
- return _context46.stop();
6024
+ return _context44.stop();
5881
6025
  }
5882
- }, _callee43, this);
6026
+ }, _callee41, this);
5883
6027
  }));
5884
- function getSalesOrderByLookup(_x54) {
6028
+ function getSalesOrderByLookup(_x49) {
5885
6029
  return _getSalesOrderByLookup.apply(this, arguments);
5886
6030
  }
5887
6031
  return getSalesOrderByLookup;
@@ -5895,37 +6039,84 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5895
6039
  }, {
5896
6040
  key: "hydrateTempOrderFromRecord",
5897
6041
  value: (function () {
5898
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee44(record, options) {
5899
- var _this$store$discount20;
5900
- var sourceRaw, identityReadySource, normalizedCollections, raw, hasIdentityChanges, identityLogMetadata, hasIdentityWarnings, nextTempOrder, sourceLastOrderInfo, isDraftOrder, syntheticIdentityOptions, rawSummary, summarySurcharges, hadSyntheticDraftOrderId, hydratedEditDiscounts, currentDiscounts, currentScanDiscounts, hydratedDiscountIds, retainedScanDiscounts, nextDiscounts, shouldSkipEmptyDiscountSync, _this$store$discount21, _this$store$discount22;
5901
- return _regeneratorRuntime().wrap(function _callee44$(_context47) {
5902
- while (1) switch (_context47.prev = _context47.next) {
6042
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee42(record, options) {
6043
+ var _sourceRaw$_extend, _this$store$discount22;
6044
+ var sourceRaw, duplicateProductIdentityRepair, duplicateIdentityReadySource, 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;
6045
+ return _regeneratorRuntime().wrap(function _callee42$(_context45) {
6046
+ while (1) switch (_context45.prev = _context45.next) {
5903
6047
  case 0:
5904
6048
  sourceRaw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
5905
- identityReadySource = this.seedAnonymousBookingUidsFromProducts(sourceRaw);
6049
+ duplicateProductIdentityRepair = repairDuplicateOrderProductLineIdentities(Array.isArray(sourceRaw.products) ? sourceRaw.products : [], (_sourceRaw$_extend = sourceRaw._extend) === null || _sourceRaw$_extend === void 0 ? void 0 : _sourceRaw$_extend.productsByUid);
6050
+ duplicateIdentityReadySource = duplicateProductIdentityRepair.repairs.length ? _objectSpread(_objectSpread({}, sourceRaw), {}, {
6051
+ products: duplicateProductIdentityRepair.products
6052
+ }, duplicateProductIdentityRepair.productsByUid ? {
6053
+ _extend: _objectSpread(_objectSpread({}, sourceRaw._extend || {}), {}, {
6054
+ productsByUid: duplicateProductIdentityRepair.productsByUid
6055
+ })
6056
+ } : {}) : sourceRaw;
6057
+ identityReadySource = this.seedAnonymousBookingUidsFromProducts(duplicateIdentityReadySource);
5906
6058
  normalizedCollections = normalizeOrderCollections(identityReadySource);
5907
6059
  raw = normalizedCollections.order;
5908
- hasIdentityChanges = Object.values(normalizedCollections.stats).some(function (stats) {
6060
+ hasIdentityChanges = duplicateProductIdentityRepair.repairs.length > 0 || Object.values(normalizedCollections.stats).some(function (stats) {
5909
6061
  return stats.backfilledUidCount > 0 || stats.collapsedDuplicateCount > 0 || stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
5910
6062
  });
5911
6063
  if (hasIdentityChanges) {
5912
6064
  identityLogMetadata = {
5913
6065
  collections: normalizedCollections.stats,
5914
- uidRemapCount: normalizedCollections.uidRemaps.length
6066
+ uidRemapCount: normalizedCollections.uidRemaps.length,
6067
+ duplicateProductUidRepairCount: duplicateProductIdentityRepair.repairs.length
5915
6068
  };
5916
6069
  hasIdentityWarnings = Object.values(normalizedCollections.stats).some(function (stats) {
5917
6070
  return stats.uidConflictCount > 0 || stats.anonymousRowCount > 0;
5918
- });
6071
+ }) || duplicateProductIdentityRepair.repairs.length > 0;
5919
6072
  if (hasIdentityWarnings) {
5920
6073
  this.logWarning('Normalized hydrated order collection identities', identityLogMetadata);
5921
6074
  } else {
5922
6075
  this.logInfo('Normalized hydrated order collection identities', identityLogMetadata);
5923
6076
  }
5924
6077
  }
6078
+ isSessionStorageHydrate = (options === null || options === void 0 ? void 0 : options.source) === 'sessionStorage';
5925
6079
  nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
5926
- makeEditMark: true
5927
- }); // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
5928
- sourceLastOrderInfo = raw.lastOrderInfo || raw;
6080
+ makeEditMark: !isSessionStorageHydrate
6081
+ });
6082
+ this.store.tempOrder = nextTempOrder;
6083
+ if (!isSessionStorageHydrate) {
6084
+ _context45.next = 29;
6085
+ break;
6086
+ }
6087
+ // 会话快照是未提交购物车,不应获得编辑订单的 saved/edit 标记与服务端基线。
6088
+ restoredSessionDiscounts = Array.isArray(raw.discount_list) ? cloneDeep(raw.discount_list) : [];
6089
+ nextExtend = _objectSpread({}, nextTempOrder._extend || {});
6090
+ delete nextExtend.originalSalesSnapshot;
6091
+ nextTempOrder._extend = nextExtend;
6092
+ nextTempOrder.products.forEach(function (product) {
6093
+ if (product.metadata) {
6094
+ delete product.metadata.is_edit_for_runtime;
6095
+ }
6096
+ });
6097
+ nextTempOrder.discount_list = restoredSessionDiscounts;
6098
+ this.store.summary = createEmptySummary();
6099
+ this.store.lastOrderInfo = undefined;
6100
+ _context45.next = 22;
6101
+ return (_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.setOriginalDiscountList(cloneDeep(restoredSessionDiscounts));
6102
+ case 22:
6103
+ _context45.next = 24;
6104
+ return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setDiscountList(cloneDeep(restoredSessionDiscounts));
6105
+ case 24:
6106
+ if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
6107
+ _context45.next = 27;
6108
+ break;
6109
+ }
6110
+ _context45.next = 27;
6111
+ return this.recalculateSummary({
6112
+ createIfMissing: false
6113
+ });
6114
+ case 27:
6115
+ this.persistTempOrder();
6116
+ return _context45.abrupt("return", nextTempOrder);
6117
+ case 29:
6118
+ // Server list compatibility may synthesize order_id from external_sale_number; tempOrder must not.
6119
+ sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
5929
6120
  isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
5930
6121
  syntheticIdentityOptions = {
5931
6122
  isDraftOrder: isDraftOrder,
@@ -5935,7 +6126,6 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5935
6126
  summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map(function (s) {
5936
6127
  return _objectSpread({}, s || {});
5937
6128
  }) : cloneDeep(nextTempOrder.surcharges || []);
5938
- this.store.tempOrder = nextTempOrder;
5939
6129
  this.store.summary = _objectSpread(_objectSpread(_objectSpread({}, createEmptySummary()), rawSummary), {}, {
5940
6130
  surcharges: summarySurcharges
5941
6131
  });
@@ -5956,7 +6146,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5956
6146
  this.store.syncState = 'local';
5957
6147
  }
5958
6148
  hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
5959
- currentDiscounts = typeof ((_this$store$discount20 = this.store.discount) === null || _this$store$discount20 === void 0 ? void 0 : _this$store$discount20.getDiscountList) === 'function' ? this.store.discount.getDiscountList() || [] : [];
6149
+ 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() || [] : [];
5960
6150
  currentScanDiscounts = currentDiscounts.filter(function (discount) {
5961
6151
  return discount === null || discount === void 0 ? void 0 : discount.isScan;
5962
6152
  });
@@ -5969,34 +6159,34 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
5969
6159
  nextDiscounts = [].concat(_toConsumableArray(hydratedEditDiscounts), _toConsumableArray(retainedScanDiscounts));
5970
6160
  shouldSkipEmptyDiscountSync = nextDiscounts.length === 0 && currentDiscounts.length === 0;
5971
6161
  if (shouldSkipEmptyDiscountSync) {
5972
- _context47.next = 31;
6162
+ _context45.next = 52;
5973
6163
  break;
5974
6164
  }
5975
6165
  OrderModule.populateSavedAmounts(nextTempOrder.products, nextDiscounts);
5976
- _context47.next = 29;
5977
- return (_this$store$discount21 = this.store.discount) === null || _this$store$discount21 === void 0 ? void 0 : _this$store$discount21.setOriginalDiscountList(nextDiscounts);
5978
- case 29:
5979
- _context47.next = 31;
5980
- return (_this$store$discount22 = this.store.discount) === null || _this$store$discount22 === void 0 ? void 0 : _this$store$discount22.setDiscountList(nextDiscounts);
5981
- case 31:
6166
+ _context45.next = 50;
6167
+ return (_this$store$discount23 = this.store.discount) === null || _this$store$discount23 === void 0 ? void 0 : _this$store$discount23.setOriginalDiscountList(nextDiscounts);
6168
+ case 50:
6169
+ _context45.next = 52;
6170
+ return (_this$store$discount24 = this.store.discount) === null || _this$store$discount24 === void 0 ? void 0 : _this$store$discount24.setDiscountList(nextDiscounts);
6171
+ case 52:
5982
6172
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
5983
- _context47.next = 34;
6173
+ _context45.next = 55;
5984
6174
  break;
5985
6175
  }
5986
- _context47.next = 34;
6176
+ _context45.next = 55;
5987
6177
  return this.recalculateSummary({
5988
6178
  createIfMissing: false
5989
6179
  });
5990
- case 34:
6180
+ case 55:
5991
6181
  this.persistTempOrder();
5992
- return _context47.abrupt("return", nextTempOrder);
5993
- case 36:
6182
+ return _context45.abrupt("return", nextTempOrder);
6183
+ case 57:
5994
6184
  case "end":
5995
- return _context47.stop();
6185
+ return _context45.stop();
5996
6186
  }
5997
- }, _callee44, this);
6187
+ }, _callee42, this);
5998
6188
  }));
5999
- function hydrateTempOrderFromRecord(_x55, _x56) {
6189
+ function hydrateTempOrderFromRecord(_x50, _x51) {
6000
6190
  return _hydrateTempOrderFromRecord.apply(this, arguments);
6001
6191
  }
6002
6192
  return hydrateTempOrderFromRecord;
@@ -6049,10 +6239,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6049
6239
  _step22;
6050
6240
  try {
6051
6241
  for (_iterator22.s(); !(_step22 = _iterator22.n()).done;) {
6052
- var _product$metadata10;
6242
+ var _product$metadata8;
6053
6243
  var product = _step22.value;
6054
6244
  var productUid = getOrderCollectionUid('product', product);
6055
- var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.booking_uid);
6245
+ 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);
6056
6246
  if (!productUid || bookingUid === undefined || bookingUid === null || bookingUid === '') {
6057
6247
  continue;
6058
6248
  }
@@ -6110,7 +6300,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6110
6300
  }, {
6111
6301
  key: "normalizeTempOrderForRuntime",
6112
6302
  value: function normalizeTempOrderForRuntime(raw, options) {
6113
- var _this32 = this;
6303
+ var _this34 = this;
6114
6304
  var runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
6115
6305
  var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), runtimeRaw || {});
6116
6306
  // ES 列表详情使用 id 表示订单主键;OS 详情态统一依赖 order_id 驱动操作按钮。
@@ -6134,12 +6324,12 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6134
6324
  nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
6135
6325
  var rawProducts = Array.isArray(raw.products) ? raw.products : [];
6136
6326
  nextTempOrder.products = rawProducts.length > 0 ? rawProducts.map(function (p) {
6137
- return _this32.normalizeHydratedOrderProduct(p, {
6327
+ return _this34.normalizeHydratedOrderProduct(p, {
6138
6328
  makeEditMark: options === null || options === void 0 ? void 0 : options.makeEditMark
6139
6329
  });
6140
6330
  }) : [];
6141
6331
  nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
6142
- var booking = _this32.normalizeHydratedBookingHolder(b || {});
6332
+ var booking = _this34.normalizeHydratedBookingHolder(b || {});
6143
6333
  return _objectSpread(_objectSpread({}, booking), {}, {
6144
6334
  is_all: normalizeBookingIsAll(booking),
6145
6335
  sub_type: normalizeBookingSubType(booking)
@@ -6169,11 +6359,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6169
6359
  _step24;
6170
6360
  try {
6171
6361
  for (_iterator24.s(); !(_step24 = _iterator24.n()).done;) {
6172
- var _product$metadata11, _ref75, _ref76, _existed$origin, _rawProduct$metadata;
6362
+ var _product$metadata9, _ref75, _ref76, _existed$origin, _rawProduct$metadata;
6173
6363
  var _step24$value = _slicedToArray(_step24.value, 2),
6174
6364
  index = _step24$value[0],
6175
6365
  product = _step24$value[1];
6176
- var uid = (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number;
6366
+ var uid = (_product$metadata9 = product.metadata) === null || _product$metadata9 === void 0 ? void 0 : _product$metadata9.unique_identification_number;
6177
6367
  if (!uid) continue;
6178
6368
  var existed = productsByUid[uid] && _typeof(productsByUid[uid]) === 'object' ? productsByUid[uid] : {};
6179
6369
  var rawProduct = rawProducts[index] && _typeof(rawProducts[index]) === 'object' ? rawProducts[index] : product;
@@ -6228,8 +6418,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6228
6418
  var bookingUidByProductUid = new Map();
6229
6419
  var productByUid = new Map();
6230
6420
  (tempOrder.products || []).forEach(function (product) {
6231
- var _product$metadata12;
6232
- var productUid = (product === null || product === void 0 || (_product$metadata12 = product.metadata) === null || _product$metadata12 === void 0 ? void 0 : _product$metadata12.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6421
+ var _product$metadata10;
6422
+ var productUid = (product === null || product === void 0 || (_product$metadata10 = product.metadata) === null || _product$metadata10 === void 0 ? void 0 : _product$metadata10.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6233
6423
  if (productUid !== undefined && productUid !== null && String(productUid) !== '') {
6234
6424
  productByUid.set(String(productUid), product);
6235
6425
  }
@@ -6250,8 +6440,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6250
6440
  bookingUidByProductUid.set(String(productUid), bookingUid);
6251
6441
  });
6252
6442
  (tempOrder.products || []).forEach(function (product) {
6253
- var _product$metadata13;
6254
- var productUid = (product === null || product === void 0 || (_product$metadata13 = product.metadata) === null || _product$metadata13 === void 0 ? void 0 : _product$metadata13.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6443
+ var _product$metadata11;
6444
+ var productUid = (product === null || product === void 0 || (_product$metadata11 = product.metadata) === null || _product$metadata11 === void 0 ? void 0 : _product$metadata11.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
6255
6445
  if (productUid === undefined || productUid === null || String(productUid) === '') return;
6256
6446
  var bookingUid = bookingUidByProductUid.get(String(productUid));
6257
6447
  if (!bookingUid) return;
@@ -6326,7 +6516,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6326
6516
  }, {
6327
6517
  key: "normalizeHydratedOrderProduct",
6328
6518
  value: function normalizeHydratedOrderProduct(product, options) {
6329
- var _this33 = this;
6519
+ var _this35 = this;
6330
6520
  var row = _objectSpread({}, product || {});
6331
6521
  if (row.num === undefined && row.product_quantity !== undefined) {
6332
6522
  row.num = row.product_quantity;
@@ -6334,12 +6524,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6334
6524
  var productSku = ensureProductSku(row);
6335
6525
  row.product_sku = _objectSpread(_objectSpread({}, productSku), {}, {
6336
6526
  option: normalizeProductSkuOptions(productSku.option.map(function (optionItem) {
6337
- return _this33.normalizeHydratedProductOptionItem(optionItem || {});
6527
+ return _this35.normalizeHydratedProductOptionItem(optionItem || {});
6338
6528
  }))
6339
6529
  });
6340
6530
  delete row["product_".concat('option', "_item")];
6341
6531
  if (!Array.isArray(row.product_bundle)) row.product_bundle = [];
6342
- if (!row.metadata || _typeof(row.metadata) !== 'object') row.metadata = {};
6532
+ row.metadata = row.metadata && _typeof(row.metadata) === 'object' ? _objectSpread({}, row.metadata) : {};
6533
+ // bundle_edit 只描述当前编辑会话中的套餐修改状态,不能从本地缓存或详情响应带入新会话。
6534
+ delete row.bundle_edit;
6535
+ delete row.metadata.bundle_edit;
6343
6536
  if (row.booking_uid && !row.metadata.booking_uid) {
6344
6537
  row.metadata.booking_uid = row.booking_uid;
6345
6538
  }
@@ -6371,27 +6564,27 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
6371
6564
  }, {
6372
6565
  key: "getOrderInfo",
6373
6566
  value: function () {
6374
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee45(order_id) {
6567
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee43(order_id) {
6375
6568
  var res;
6376
- return _regeneratorRuntime().wrap(function _callee45$(_context48) {
6377
- while (1) switch (_context48.prev = _context48.next) {
6569
+ return _regeneratorRuntime().wrap(function _callee43$(_context46) {
6570
+ while (1) switch (_context46.prev = _context46.next) {
6378
6571
  case 0:
6379
- _context48.next = 2;
6572
+ _context46.next = 2;
6380
6573
  return this.request.get("/order/sales/".concat(order_id), {
6381
6574
  with: ['products', 'bookings']
6382
6575
  }, {
6383
6576
  osServer: true
6384
6577
  });
6385
6578
  case 2:
6386
- res = _context48.sent;
6387
- return _context48.abrupt("return", res);
6579
+ res = _context46.sent;
6580
+ return _context46.abrupt("return", res);
6388
6581
  case 4:
6389
6582
  case "end":
6390
- return _context48.stop();
6583
+ return _context46.stop();
6391
6584
  }
6392
- }, _callee45, this);
6585
+ }, _callee43, this);
6393
6586
  }));
6394
- function getOrderInfo(_x57) {
6587
+ function getOrderInfo(_x52) {
6395
6588
  return _getOrderInfo.apply(this, arguments);
6396
6589
  }
6397
6590
  return getOrderInfo;