@pisell/pisellos 2.2.162 → 2.2.164

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 (116) hide show
  1. package/dist/modules/BookingContext/index.d.ts +37 -0
  2. package/dist/modules/BookingContext/index.js +436 -0
  3. package/dist/modules/BookingContext/types.d.ts +102 -0
  4. package/dist/modules/BookingContext/types.js +51 -0
  5. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  6. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +157 -0
  7. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  8. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +107 -0
  9. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  10. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +191 -0
  11. package/dist/modules/BookingContext/utils/flexible.d.ts +28 -0
  12. package/dist/modules/BookingContext/utils/flexible.js +56 -0
  13. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  14. package/dist/modules/BookingContext/utils/formatResourceList.js +38 -0
  15. package/dist/modules/BookingContext/utils/index.d.ts +11 -0
  16. package/dist/modules/BookingContext/utils/index.js +11 -0
  17. package/dist/modules/BookingContext/utils/noResource.d.ts +13 -0
  18. package/dist/modules/BookingContext/utils/noResource.js +77 -0
  19. package/dist/modules/BookingContext/utils/productExtend.d.ts +72 -0
  20. package/dist/modules/BookingContext/utils/productExtend.js +339 -0
  21. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  22. package/dist/modules/BookingContext/utils/resourceErrors.js +74 -0
  23. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  24. package/dist/modules/BookingContext/utils/resourceSelection.js +24 -0
  25. package/dist/modules/BookingContext/utils/resources.d.ts +80 -0
  26. package/dist/modules/BookingContext/utils/resources.js +486 -0
  27. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  28. package/dist/modules/BookingContext/utils/serviceTimes.js +151 -0
  29. package/dist/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  30. package/dist/modules/BookingContext/utils/timeSlices.js +100 -0
  31. package/dist/modules/Customer/index.js +23 -22
  32. package/dist/modules/Discount/index.js +4 -3
  33. package/dist/modules/Order/index.d.ts +17 -6
  34. package/dist/modules/Order/index.js +474 -287
  35. package/dist/modules/Order/types.d.ts +32 -12
  36. package/dist/modules/Order/utils.js +9 -8
  37. package/dist/modules/SalesSummary/index.js +4 -2
  38. package/dist/modules/index.d.ts +1 -0
  39. package/dist/modules/index.js +2 -1
  40. package/dist/solution/BaseSales/index.d.ts +38 -7
  41. package/dist/solution/BaseSales/index.js +797 -310
  42. package/dist/solution/BaseSales/types.d.ts +48 -1
  43. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  44. package/dist/solution/BaseSales/utils/quotationPrice.js +159 -0
  45. package/dist/solution/BookingByStep/index.d.ts +2 -2
  46. package/dist/solution/BookingTicket/index.d.ts +121 -1
  47. package/dist/solution/BookingTicket/index.js +401 -72
  48. package/dist/solution/BookingTicket/types.d.ts +2 -0
  49. package/dist/solution/BookingTicket/types.js +3 -0
  50. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  51. package/dist/solution/BookingTicket/utils/addProductDecision.js +326 -0
  52. package/dist/solution/ScanOrder/index.d.ts +9 -3
  53. package/dist/solution/ScanOrder/index.js +231 -128
  54. package/dist/solution/VenueBooking/index.d.ts +4 -2
  55. package/dist/solution/VenueBooking/index.js +103 -55
  56. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  57. package/dist/solution/VenueBooking/utils/slotMerge.js +10 -0
  58. package/lib/model/strategy/adapter/promotion/index.js +0 -49
  59. package/lib/modules/BookingContext/index.d.ts +37 -0
  60. package/lib/modules/BookingContext/index.js +297 -0
  61. package/lib/modules/BookingContext/types.d.ts +102 -0
  62. package/lib/modules/BookingContext/types.js +34 -0
  63. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +16 -0
  64. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +174 -0
  65. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +8 -0
  66. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +115 -0
  67. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +65 -0
  68. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +177 -0
  69. package/lib/modules/BookingContext/utils/flexible.d.ts +28 -0
  70. package/lib/modules/BookingContext/utils/flexible.js +80 -0
  71. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +8 -0
  72. package/lib/modules/BookingContext/utils/formatResourceList.js +50 -0
  73. package/lib/modules/BookingContext/utils/index.d.ts +11 -0
  74. package/lib/modules/BookingContext/utils/index.js +43 -0
  75. package/lib/modules/BookingContext/utils/noResource.d.ts +13 -0
  76. package/lib/modules/BookingContext/utils/noResource.js +90 -0
  77. package/lib/modules/BookingContext/utils/productExtend.d.ts +72 -0
  78. package/lib/modules/BookingContext/utils/productExtend.js +283 -0
  79. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +41 -0
  80. package/lib/modules/BookingContext/utils/resourceErrors.js +80 -0
  81. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +7 -0
  82. package/lib/modules/BookingContext/utils/resourceSelection.js +46 -0
  83. package/lib/modules/BookingContext/utils/resources.d.ts +80 -0
  84. package/lib/modules/BookingContext/utils/resources.js +377 -0
  85. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +55 -0
  86. package/lib/modules/BookingContext/utils/serviceTimes.js +162 -0
  87. package/lib/modules/BookingContext/utils/timeSlices.d.ts +42 -0
  88. package/lib/modules/BookingContext/utils/timeSlices.js +124 -0
  89. package/lib/modules/Customer/index.js +8 -8
  90. package/lib/modules/Discount/index.js +5 -1
  91. package/lib/modules/Order/index.d.ts +17 -6
  92. package/lib/modules/Order/index.js +164 -68
  93. package/lib/modules/Order/types.d.ts +32 -12
  94. package/lib/modules/Order/utils.js +8 -6
  95. package/lib/modules/SalesSummary/index.js +4 -2
  96. package/lib/modules/index.d.ts +1 -0
  97. package/lib/modules/index.js +3 -1
  98. package/lib/solution/BaseSales/index.d.ts +38 -7
  99. package/lib/solution/BaseSales/index.js +304 -14
  100. package/lib/solution/BaseSales/types.d.ts +48 -1
  101. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +7 -0
  102. package/lib/solution/BaseSales/utils/quotationPrice.js +201 -0
  103. package/lib/solution/BookingByStep/index.d.ts +2 -2
  104. package/lib/solution/BookingTicket/index.d.ts +121 -1
  105. package/lib/solution/BookingTicket/index.js +207 -2
  106. package/lib/solution/BookingTicket/types.d.ts +2 -0
  107. package/lib/solution/BookingTicket/types.js +6 -0
  108. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +111 -0
  109. package/lib/solution/BookingTicket/utils/addProductDecision.js +300 -0
  110. package/lib/solution/ScanOrder/index.d.ts +9 -3
  111. package/lib/solution/ScanOrder/index.js +147 -66
  112. package/lib/solution/VenueBooking/index.d.ts +4 -2
  113. package/lib/solution/VenueBooking/index.js +50 -14
  114. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +4 -0
  115. package/lib/solution/VenueBooking/utils/slotMerge.js +10 -0
  116. package/package.json +1 -1
@@ -196,29 +196,40 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
196
196
  key: "loadDiscountConfig",
197
197
  value: function () {
198
198
  var _loadDiscountConfig = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee2(params) {
199
- var _this$store$discount, _this$store$tempOrder;
200
- var discountList, _this$store$discount2;
199
+ var _this$store$tempOrder, _this$store$discount, _this$store$tempOrder2;
200
+ var orderId, discountList, _this$store$discount2, _this$store$discount3;
201
201
  return _regeneratorRuntime().wrap(function _callee2$(_context2) {
202
202
  while (1) switch (_context2.prev = _context2.next) {
203
203
  case 0:
204
- _context2.next = 2;
205
- return (_this$store$discount = this.store.discount) === null || _this$store$discount === void 0 ? void 0 : _this$store$discount.loadPrepareConfig({
204
+ orderId = params.orderId || ((_this$store$tempOrder = this.store.tempOrder) === null || _this$store$tempOrder === void 0 ? void 0 : _this$store$tempOrder.order_id) || undefined;
205
+ _context2.next = 3;
206
+ return (_this$store$discount = this.store.discount) === null || _this$store$discount === void 0 ? void 0 : _this$store$discount.loadPrepareConfig(_objectSpread({
206
207
  customer_id: params.customerId,
207
- action: params.action || 'create',
208
+ action: params.action || (orderId ? 'edit' : 'create'),
208
209
  with_good_pass: 1,
209
210
  with_discount_card: 1,
210
211
  with_wallet_pass_holder: 1,
211
212
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
212
- });
213
- case 2:
213
+ }, orderId ? {
214
+ order_id: orderId
215
+ } : {}));
216
+ case 3:
214
217
  discountList = _context2.sent;
215
- if (discountList) {
216
- (_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 || _this$store$discount2.setDiscountList(discountList);
218
+ if (!discountList) {
219
+ _context2.next = 9;
220
+ break;
217
221
  }
218
- if ((_this$store$tempOrder = this.store.tempOrder) !== null && _this$store$tempOrder !== void 0 && (_this$store$tempOrder = _this$store$tempOrder.products) !== null && _this$store$tempOrder !== void 0 && _this$store$tempOrder.length) {
222
+ _context2.next = 7;
223
+ return (_this$store$discount2 = this.store.discount) === null || _this$store$discount2 === void 0 ? void 0 : _this$store$discount2.setOriginalDiscountList(discountList);
224
+ case 7:
225
+ _context2.next = 9;
226
+ return (_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.setDiscountList(discountList);
227
+ case 9:
228
+ if (params.apply !== false && (_this$store$tempOrder2 = this.store.tempOrder) !== null && _this$store$tempOrder2 !== void 0 && (_this$store$tempOrder2 = _this$store$tempOrder2.products) !== null && _this$store$tempOrder2 !== void 0 && _this$store$tempOrder2.length) {
219
229
  this.applyDiscount();
220
230
  }
221
- case 5:
231
+ return _context2.abrupt("return", this.getDiscountList());
232
+ case 11:
222
233
  case "end":
223
234
  return _context2.stop();
224
235
  }
@@ -232,20 +243,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
232
243
  }, {
233
244
  key: "getDiscountList",
234
245
  value: function getDiscountList() {
235
- var _this$store$discount3;
236
- return ((_this$store$discount3 = this.store.discount) === null || _this$store$discount3 === void 0 ? void 0 : _this$store$discount3.getDiscountList()) || [];
246
+ var _this$store$discount4;
247
+ return ((_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.getDiscountList()) || [];
237
248
  }
238
249
  }, {
239
250
  key: "scanCode",
240
251
  value: function () {
241
252
  var _scanCode = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee3(code, customerId) {
242
- var _this$store$discount4, _tempOrder$holder, _this$store$summary, _tempOrder$holder2;
243
- var resultDiscountList, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref, isAvailable, newDiscountList, unavailableReason, _this$store$discount5;
253
+ var _this$store$discount5, _tempOrder$holder, _this$store$summary, _tempOrder$holder2;
254
+ var resultDiscountList, rulesModule, withScanList, currentSelected, tempOrder, holders, _ref, isAvailable, newDiscountList, unavailableReason, _this$store$discount6;
244
255
  return _regeneratorRuntime().wrap(function _callee3$(_context3) {
245
256
  while (1) switch (_context3.prev = _context3.next) {
246
257
  case 0:
247
258
  _context3.next = 2;
248
- return (_this$store$discount4 = this.store.discount) === null || _this$store$discount4 === void 0 ? void 0 : _this$store$discount4.batchSearch(code, {
259
+ return (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 ? void 0 : _this$store$discount5.batchSearch(code, {
249
260
  customerId: customerId
250
261
  });
251
262
  case 2:
@@ -317,7 +328,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
317
328
  discountList: this.getDiscountList()
318
329
  }, isAvailable = _ref.isAvailable, newDiscountList = _ref.discountList, unavailableReason = _ref.unavailableReason;
319
330
  if (isAvailable && newDiscountList) {
320
- (_this$store$discount5 = this.store.discount) === null || _this$store$discount5 === void 0 || _this$store$discount5.setDiscountList(newDiscountList);
331
+ (_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 || _this$store$discount6.setDiscountList(newDiscountList);
321
332
  this.applyDiscount();
322
333
  }
323
334
  return _context3.abrupt("return", {
@@ -340,7 +351,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
340
351
  }, {
341
352
  key: "applyDiscount",
342
353
  value: function applyDiscount() {
343
- var _this$store$discount6, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
354
+ var _this$store$discount7, _tempOrder$holder3, _tempOrder$holder4, _this$store$summary2;
344
355
  var tempOrder = this.store.tempOrder;
345
356
  // 任意 products CRUD 后都应当重算 discount 状态;即使 products 为空,
346
357
  // 也需要让 Rules.calcDiscount 把 DiscountModule 的 isSelected / isAvailable /
@@ -348,7 +359,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
348
359
  if (!tempOrder) return;
349
360
  var rulesModule = this.store.rules;
350
361
  if (!rulesModule) return;
351
- var discountList = ((_this$store$discount6 = this.store.discount) === null || _this$store$discount6 === void 0 ? void 0 : _this$store$discount6.getDiscountList()) || [];
362
+ var discountList = ((_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 ? void 0 : _this$store$discount7.getDiscountList()) || [];
352
363
  var holders = (_tempOrder$holder3 = tempOrder.holder) !== null && _tempOrder$holder3 !== void 0 && _tempOrder$holder3.form_record_id ? [{
353
364
  form_record_id: tempOrder.holder.form_record_id
354
365
  }] : [];
@@ -363,9 +374,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
363
374
  tempOrder.products = result.productList;
364
375
  }
365
376
  if (result !== null && result !== void 0 && result.discountList) {
366
- var _this$store$discount7;
377
+ var _this$store$discount8;
367
378
  OrderModule.populateSavedAmounts(result.productList || tempOrder.products, result.discountList);
368
- (_this$store$discount7 = this.store.discount) === null || _this$store$discount7 === void 0 || _this$store$discount7.setDiscountList(result.discountList);
379
+ (_this$store$discount8 = this.store.discount) === null || _this$store$discount8 === void 0 || _this$store$discount8.setDiscountList(result.discountList);
369
380
  tempOrder.discount_list = result.discountList.filter(function (d) {
370
381
  return d.isSelected;
371
382
  });
@@ -820,6 +831,60 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
820
831
  value: function getTempOrder() {
821
832
  return this.store.tempOrder;
822
833
  }
834
+ }, {
835
+ key: "replaceTempOrder",
836
+ value: function () {
837
+ var _replaceTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9(tempOrder, options) {
838
+ var nextTempOrder;
839
+ return _regeneratorRuntime().wrap(function _callee9$(_context9) {
840
+ while (1) switch (_context9.prev = _context9.next) {
841
+ case 0:
842
+ if (isTempOrder(tempOrder)) {
843
+ _context9.next = 2;
844
+ break;
845
+ }
846
+ throw new Error('无效的 tempOrder 数据');
847
+ case 2:
848
+ nextTempOrder = this.normalizeTempOrderForRuntime(cloneDeep(tempOrder), {
849
+ ensureIdentity: false
850
+ });
851
+ this.store.tempOrder = nextTempOrder;
852
+ if (!((options === null || options === void 0 ? void 0 : options.recalculateSummary) !== false)) {
853
+ _context9.next = 9;
854
+ break;
855
+ }
856
+ _context9.next = 7;
857
+ return this.recalculateSummary({
858
+ createIfMissing: false
859
+ });
860
+ case 7:
861
+ _context9.next = 10;
862
+ break;
863
+ case 9:
864
+ this.store.summary = createEmptySummary();
865
+ case 10:
866
+ if ((options === null || options === void 0 ? void 0 : options.persist) !== false) {
867
+ this.persistTempOrder();
868
+ }
869
+ if (!(options !== null && options !== void 0 && options.saveDraft)) {
870
+ _context9.next = 14;
871
+ break;
872
+ }
873
+ _context9.next = 14;
874
+ return this.saveDraft();
875
+ case 14:
876
+ return _context9.abrupt("return", nextTempOrder);
877
+ case 15:
878
+ case "end":
879
+ return _context9.stop();
880
+ }
881
+ }, _callee9, this);
882
+ }));
883
+ function replaceTempOrder(_x10, _x11) {
884
+ return _replaceTempOrder.apply(this, arguments);
885
+ }
886
+ return replaceTempOrder;
887
+ }()
823
888
  }, {
824
889
  key: "getOrderIdentity",
825
890
  value: function getOrderIdentity() {
@@ -898,28 +963,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
898
963
  }, {
899
964
  key: "addNewOrder",
900
965
  value: function () {
901
- var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee9() {
966
+ var _addNewOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10() {
902
967
  var tempOrder;
903
- return _regeneratorRuntime().wrap(function _callee9$(_context9) {
904
- while (1) switch (_context9.prev = _context9.next) {
968
+ return _regeneratorRuntime().wrap(function _callee10$(_context10) {
969
+ while (1) switch (_context10.prev = _context10.next) {
905
970
  case 0:
906
971
  tempOrder = this.ensureTempOrder();
907
972
  this.ensureExternalSaleNumber(tempOrder);
908
- _context9.next = 4;
973
+ _context10.next = 4;
909
974
  return this.recalculateSummary({
910
975
  createIfMissing: true
911
976
  });
912
977
  case 4:
913
978
  this.persistTempOrder();
914
- _context9.next = 7;
979
+ _context10.next = 7;
915
980
  return this.saveDraft();
916
981
  case 7:
917
- return _context9.abrupt("return", tempOrder);
982
+ return _context10.abrupt("return", tempOrder);
918
983
  case 8:
919
984
  case "end":
920
- return _context9.stop();
985
+ return _context10.stop();
921
986
  }
922
- }, _callee9, this);
987
+ }, _callee10, this);
923
988
  }));
924
989
  function addNewOrder() {
925
990
  return _addNewOrder.apply(this, arguments);
@@ -995,6 +1060,38 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
995
1060
  })
996
1061
  };
997
1062
  }
1063
+ }, {
1064
+ key: "getBookingUniqueIdentificationNumber",
1065
+ value: function getBookingUniqueIdentificationNumber(booking) {
1066
+ var _booking$metadata;
1067
+ var uid = booking === null || booking === void 0 || (_booking$metadata = booking.metadata) === null || _booking$metadata === void 0 ? void 0 : _booking$metadata.unique_identification_number;
1068
+ if (uid === undefined || uid === null || uid === '') return null;
1069
+ return String(uid);
1070
+ }
1071
+ }, {
1072
+ key: "findBookingIndexByUniqueIdentificationNumber",
1073
+ value: function findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
1074
+ var _this3 = this;
1075
+ return (tempOrder.bookings || []).findIndex(function (booking) {
1076
+ return _this3.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
1077
+ });
1078
+ }
1079
+ }, {
1080
+ key: "removeLinkedBookingsForProduct",
1081
+ value: function removeLinkedBookingsForProduct(tempOrder, product) {
1082
+ var _product$metadata,
1083
+ _product$metadata2,
1084
+ _this4 = this;
1085
+ var productUid = (product === null || product === void 0 || (_product$metadata = product.metadata) === null || _product$metadata === void 0 ? void 0 : _product$metadata.unique_identification_number) || (product === null || product === void 0 ? void 0 : product.unique_identification_number);
1086
+ var bookingUid = (product === null || product === void 0 ? void 0 : product.booking_uid) || (product === null || product === void 0 || (_product$metadata2 = product.metadata) === null || _product$metadata2 === void 0 ? void 0 : _product$metadata2.booking_uid);
1087
+ if (!productUid && !bookingUid) return;
1088
+ tempOrder.bookings = (tempOrder.bookings || []).filter(function (booking) {
1089
+ var currentBookingUid = _this4.getBookingUniqueIdentificationNumber(booking);
1090
+ if (bookingUid && currentBookingUid === String(bookingUid)) return false;
1091
+ if (productUid && String((booking === null || booking === void 0 ? void 0 : booking.product_uid) || '') === String(productUid)) return false;
1092
+ return true;
1093
+ });
1094
+ }
998
1095
 
999
1096
  // ─── TempOrder: 金额汇总 ───
1000
1097
  }, {
@@ -1006,23 +1103,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1006
1103
  }, {
1007
1104
  key: "recalculateSummary",
1008
1105
  value: function () {
1009
- var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee10(options) {
1106
+ var _recalculateSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11(options) {
1010
1107
  var tempOrder, salesSummary, existedSummary, paidPaymentSummary, emptySummary, salesSummaryResult, summary;
1011
- return _regeneratorRuntime().wrap(function _callee10$(_context10) {
1012
- while (1) switch (_context10.prev = _context10.next) {
1108
+ return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1109
+ while (1) switch (_context11.prev = _context11.next) {
1013
1110
  case 0:
1014
1111
  tempOrder = options !== null && options !== void 0 && options.createIfMissing ? this.ensureTempOrder() : this.store.tempOrder;
1015
1112
  if (tempOrder) {
1016
- _context10.next = 3;
1113
+ _context11.next = 3;
1017
1114
  break;
1018
1115
  }
1019
- return _context10.abrupt("return", null);
1116
+ return _context11.abrupt("return", null);
1020
1117
  case 3:
1021
1118
  salesSummary = this.getSalesSummary();
1022
1119
  existedSummary = this.store.summary || createEmptySummary();
1023
1120
  paidPaymentSummary = this.calculatePaidPaymentSummary(tempOrder.payments || []);
1024
1121
  if (salesSummary) {
1025
- _context10.next = 11;
1122
+ _context11.next = 11;
1026
1123
  break;
1027
1124
  }
1028
1125
  emptySummary = _objectSpread(_objectSpread({}, createEmptySummary()), {}, {
@@ -1033,16 +1130,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1033
1130
  });
1034
1131
  this.store.summary = emptySummary;
1035
1132
  tempOrder.surcharge_fee = emptySummary.surcharge_fee;
1036
- return _context10.abrupt("return", this.store.summary);
1133
+ return _context11.abrupt("return", this.store.summary);
1037
1134
  case 11:
1038
- _context10.next = 13;
1135
+ _context11.next = 13;
1039
1136
  return salesSummary.getSummary({
1040
1137
  products: tempOrder.products,
1041
1138
  isPriceIncludeTax: tempOrder.is_price_include_tax,
1042
1139
  shopDiscount: tempOrder.shop_discount
1043
1140
  });
1044
1141
  case 13:
1045
- salesSummaryResult = _context10.sent;
1142
+ salesSummaryResult = _context11.sent;
1046
1143
  summary = _objectSpread(_objectSpread({}, salesSummaryResult), {}, {
1047
1144
  total_refund_amount: existedSummary.total_refund_amount || '0.00',
1048
1145
  customer_paid_amount: paidPaymentSummary.customerPaidAmount.toFixed(2),
@@ -1060,14 +1157,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1060
1157
  tempOrder.surcharges = summary.surcharges || [];
1061
1158
  tempOrder.deposit_amount = summary.deposit_amount || '0.00';
1062
1159
  tempOrder.is_deposit = summary.deposit_amount !== '0.00' ? 1 : 0;
1063
- return _context10.abrupt("return", this.store.summary);
1160
+ return _context11.abrupt("return", this.store.summary);
1064
1161
  case 23:
1065
1162
  case "end":
1066
- return _context10.stop();
1163
+ return _context11.stop();
1067
1164
  }
1068
- }, _callee10, this);
1165
+ }, _callee11, this);
1069
1166
  }));
1070
- function recalculateSummary(_x10) {
1167
+ function recalculateSummary(_x12) {
1071
1168
  return _recalculateSummary.apply(this, arguments);
1072
1169
  }
1073
1170
  return recalculateSummary;
@@ -1075,30 +1172,30 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1075
1172
  }, {
1076
1173
  key: "getOrderSummary",
1077
1174
  value: function () {
1078
- var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee11() {
1175
+ var _getOrderSummary = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12() {
1079
1176
  var summary;
1080
- return _regeneratorRuntime().wrap(function _callee11$(_context11) {
1081
- while (1) switch (_context11.prev = _context11.next) {
1177
+ return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1178
+ while (1) switch (_context12.prev = _context12.next) {
1082
1179
  case 0:
1083
- _context11.next = 2;
1180
+ _context12.next = 2;
1084
1181
  return this.recalculateSummary({
1085
1182
  createIfMissing: true
1086
1183
  });
1087
1184
  case 2:
1088
- summary = _context11.sent;
1185
+ summary = _context12.sent;
1089
1186
  if (summary) {
1090
- _context11.next = 5;
1187
+ _context12.next = 5;
1091
1188
  break;
1092
1189
  }
1093
- return _context11.abrupt("return", createEmptySummary());
1190
+ return _context12.abrupt("return", createEmptySummary());
1094
1191
  case 5:
1095
1192
  this.persistTempOrder();
1096
- return _context11.abrupt("return", summary);
1193
+ return _context12.abrupt("return", summary);
1097
1194
  case 7:
1098
1195
  case "end":
1099
- return _context11.stop();
1196
+ return _context12.stop();
1100
1197
  }
1101
- }, _callee11, this);
1198
+ }, _callee12, this);
1102
1199
  }));
1103
1200
  function getOrderSummary() {
1104
1201
  return _getOrderSummary.apply(this, arguments);
@@ -1108,16 +1205,46 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1108
1205
  }, {
1109
1206
  key: "updateTempOrderNote",
1110
1207
  value: function updateTempOrderNote(note) {
1208
+ var sync = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
1111
1209
  var tempOrder = this.ensureTempOrder();
1112
1210
  tempOrder.note = String(note || '');
1113
1211
  this.persistTempOrder();
1212
+ if (sync) {
1213
+ var orderId = tempOrder.order_id;
1214
+ if (!orderId) return tempOrder.note;
1215
+ return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
1216
+ }
1114
1217
  return tempOrder.note;
1115
1218
  }
1219
+ }, {
1220
+ key: "syncTempOrderNoteToRemote",
1221
+ value: function () {
1222
+ var _syncTempOrderNoteToRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(orderId, note) {
1223
+ return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1224
+ while (1) switch (_context13.prev = _context13.next) {
1225
+ case 0:
1226
+ _context13.next = 2;
1227
+ return this.request.put("/order/order/".concat(orderId, "/note"), {
1228
+ note: note
1229
+ });
1230
+ case 2:
1231
+ return _context13.abrupt("return", note);
1232
+ case 3:
1233
+ case "end":
1234
+ return _context13.stop();
1235
+ }
1236
+ }, _callee13, this);
1237
+ }));
1238
+ function syncTempOrderNoteToRemote(_x13, _x14) {
1239
+ return _syncTempOrderNoteToRemote.apply(this, arguments);
1240
+ }
1241
+ return syncTempOrderNoteToRemote;
1242
+ }()
1116
1243
  }, {
1117
1244
  key: "getTempOrderNote",
1118
1245
  value: function getTempOrderNote() {
1119
- var _this$store$tempOrder2;
1120
- return ((_this$store$tempOrder2 = this.store.tempOrder) === null || _this$store$tempOrder2 === void 0 ? void 0 : _this$store$tempOrder2.note) || '';
1246
+ var _this$store$tempOrder3;
1247
+ return ((_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.note) || '';
1121
1248
  }
1122
1249
  }, {
1123
1250
  key: "updateTempOrderShopDiscount",
@@ -1209,8 +1336,8 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1209
1336
  }, {
1210
1337
  key: "getOrderCustomerSnapshot",
1211
1338
  value: function getOrderCustomerSnapshot() {
1212
- var _this$store$tempOrder3;
1213
- var snapshot = (_this$store$tempOrder3 = this.store.tempOrder) === null || _this$store$tempOrder3 === void 0 || (_this$store$tempOrder3 = _this$store$tempOrder3._extend) === null || _this$store$tempOrder3 === void 0 ? void 0 : _this$store$tempOrder3.customerSnapshot;
1339
+ var _this$store$tempOrder4;
1340
+ var snapshot = (_this$store$tempOrder4 = this.store.tempOrder) === null || _this$store$tempOrder4 === void 0 || (_this$store$tempOrder4 = _this$store$tempOrder4._extend) === null || _this$store$tempOrder4 === void 0 ? void 0 : _this$store$tempOrder4.customerSnapshot;
1214
1341
  return snapshot ? cloneDeep(snapshot) : null;
1215
1342
  }
1216
1343
  }, {
@@ -1353,45 +1480,45 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1353
1480
  }, {
1354
1481
  key: "shouldMergeProductToOrder",
1355
1482
  value: function () {
1356
- var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee12(params) {
1483
+ var _shouldMergeProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
1357
1484
  var _this$orderHooks;
1358
1485
  var onBeforeMergeProductToOrder, result;
1359
- return _regeneratorRuntime().wrap(function _callee12$(_context12) {
1360
- while (1) switch (_context12.prev = _context12.next) {
1486
+ return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1487
+ while (1) switch (_context14.prev = _context14.next) {
1361
1488
  case 0:
1362
1489
  onBeforeMergeProductToOrder = (_this$orderHooks = this.orderHooks) === null || _this$orderHooks === void 0 ? void 0 : _this$orderHooks.onBeforeMergeProductToOrder;
1363
1490
  if (onBeforeMergeProductToOrder) {
1364
- _context12.next = 3;
1491
+ _context14.next = 3;
1365
1492
  break;
1366
1493
  }
1367
- return _context12.abrupt("return", true);
1494
+ return _context14.abrupt("return", true);
1368
1495
  case 3:
1369
- _context12.next = 5;
1496
+ _context14.next = 5;
1370
1497
  return onBeforeMergeProductToOrder(_objectSpread(_objectSpread({}, params), {}, {
1371
1498
  defaultShouldMerge: true
1372
1499
  }));
1373
1500
  case 5:
1374
- result = _context12.sent;
1501
+ result = _context14.sent;
1375
1502
  if (!(typeof result === 'boolean')) {
1376
- _context12.next = 8;
1503
+ _context14.next = 8;
1377
1504
  break;
1378
1505
  }
1379
- return _context12.abrupt("return", result);
1506
+ return _context14.abrupt("return", result);
1380
1507
  case 8:
1381
1508
  if (!(result && _typeof(result) === 'object' && typeof result.shouldMerge === 'boolean')) {
1382
- _context12.next = 10;
1509
+ _context14.next = 10;
1383
1510
  break;
1384
1511
  }
1385
- return _context12.abrupt("return", result.shouldMerge);
1512
+ return _context14.abrupt("return", result.shouldMerge);
1386
1513
  case 10:
1387
- return _context12.abrupt("return", true);
1514
+ return _context14.abrupt("return", true);
1388
1515
  case 11:
1389
1516
  case "end":
1390
- return _context12.stop();
1517
+ return _context14.stop();
1391
1518
  }
1392
- }, _callee12, this);
1519
+ }, _callee14, this);
1393
1520
  }));
1394
- function shouldMergeProductToOrder(_x11) {
1521
+ function shouldMergeProductToOrder(_x15) {
1395
1522
  return _shouldMergeProductToOrder.apply(this, arguments);
1396
1523
  }
1397
1524
  return shouldMergeProductToOrder;
@@ -1399,11 +1526,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1399
1526
  }, {
1400
1527
  key: "addProductToOrder",
1401
1528
  value: function () {
1402
- var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee13(product, booking) {
1403
- var _this3 = this;
1529
+ var _addProductToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(product, booking) {
1530
+ var _this5 = this;
1404
1531
  var tempOrder, linked, productToAdd, incomingFingerprint, normalizedIncoming, hasIncomingGoodPass, shouldForceNewLine, matchedIndex, matchedProduct, existedFingerprint, shouldMerge, _targetProduct$metada, targetProduct, targetUid, normalizedProduct;
1405
- return _regeneratorRuntime().wrap(function _callee13$(_context13) {
1406
- while (1) switch (_context13.prev = _context13.next) {
1532
+ return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1533
+ while (1) switch (_context15.prev = _context15.next) {
1407
1534
  case 0:
1408
1535
  tempOrder = this.ensureTempOrder();
1409
1536
  linked = booking ? this.createLinkedProductAndBooking({
@@ -1416,7 +1543,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1416
1543
  hasIncomingGoodPass = this.hasGoodPassDiscount(normalizedIncoming);
1417
1544
  shouldForceNewLine = !!booking;
1418
1545
  matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex(function (item) {
1419
- if (_this3.hasGoodPassDiscount(item)) return false;
1546
+ if (_this5.hasGoodPassDiscount(item)) return false;
1420
1547
  if (item.product_id !== productToAdd.product_id) return false;
1421
1548
  if (item.product_variant_id !== productToAdd.product_variant_id) return false;
1422
1549
  var existedFingerprint = buildProductLineFingerprint(item.product_option_item, item.product_bundle);
@@ -1425,10 +1552,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1425
1552
  matchedProduct = matchedIndex === -1 ? null : tempOrder.products[matchedIndex];
1426
1553
  existedFingerprint = matchedProduct ? buildProductLineFingerprint(matchedProduct.product_option_item, matchedProduct.product_bundle) : '';
1427
1554
  if (!matchedProduct) {
1428
- _context13.next = 16;
1555
+ _context15.next = 16;
1429
1556
  break;
1430
1557
  }
1431
- _context13.next = 13;
1558
+ _context15.next = 13;
1432
1559
  return this.shouldMergeProductToOrder({
1433
1560
  incomingProduct: productToAdd,
1434
1561
  normalizedIncoming: normalizedIncoming,
@@ -1440,13 +1567,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1440
1567
  booking: booking
1441
1568
  });
1442
1569
  case 13:
1443
- _context13.t0 = _context13.sent;
1444
- _context13.next = 17;
1570
+ _context15.t0 = _context15.sent;
1571
+ _context15.next = 17;
1445
1572
  break;
1446
1573
  case 16:
1447
- _context13.t0 = false;
1574
+ _context15.t0 = false;
1448
1575
  case 17:
1449
- shouldMerge = _context13.t0;
1576
+ shouldMerge = _context15.t0;
1450
1577
  if (matchedIndex === -1 || !matchedProduct || !shouldMerge) {
1451
1578
  this.captureProductRuntime(tempOrder, productToAdd, normalizedIncoming);
1452
1579
  if (linked) {
@@ -1478,20 +1605,20 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1478
1605
  tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
1479
1606
  }
1480
1607
  this.applyDiscount();
1481
- _context13.next = 23;
1608
+ _context15.next = 23;
1482
1609
  return this.recalculateSummary({
1483
1610
  createIfMissing: true
1484
1611
  });
1485
1612
  case 23:
1486
1613
  this.persistTempOrder();
1487
- return _context13.abrupt("return", tempOrder.products);
1614
+ return _context15.abrupt("return", tempOrder.products);
1488
1615
  case 25:
1489
1616
  case "end":
1490
- return _context13.stop();
1617
+ return _context15.stop();
1491
1618
  }
1492
- }, _callee13, this);
1619
+ }, _callee15, this);
1493
1620
  }));
1494
- function addProductToOrder(_x12, _x13) {
1621
+ function addProductToOrder(_x16, _x17) {
1495
1622
  return _addProductToOrder.apply(this, arguments);
1496
1623
  }
1497
1624
  return addProductToOrder;
@@ -1516,15 +1643,15 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1516
1643
  });
1517
1644
  }
1518
1645
  }, {
1519
- key: "updateProductInOrder",
1646
+ key: "updateOrderProduct",
1520
1647
  value: function () {
1521
- var _updateProductInOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee14(params) {
1648
+ var _updateOrderProduct = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
1522
1649
  var _targetProduct$metada2, _metadata, _metadata2, _metadata3, _tempOrder$products$p;
1523
- var product_id, product_variant_id, updates, unique_identification_number, product_option_item, product_bundle, tempOrder, identityLookup, productIndex, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, existedMeta;
1524
- return _regeneratorRuntime().wrap(function _callee14$(_context14) {
1525
- while (1) switch (_context14.prev = _context14.next) {
1650
+ var product_id, product_variant_id, updates, unique_identification_number, identity_key, product_option_item, product_bundle, booking, tempOrder, identityLookup, productIndex, targetProduct, nextProduct, callerUpdatesTopPrice, callerUpdatesMainMeta, existedMeta, normalizedProduct, _normalizedProduct$me, _targetProduct$metada3, productUid, linked;
1651
+ return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1652
+ while (1) switch (_context16.prev = _context16.next) {
1526
1653
  case 0:
1527
- product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates, unique_identification_number = params.unique_identification_number, product_option_item = params.product_option_item, product_bundle = params.product_bundle;
1654
+ product_id = params.product_id, product_variant_id = params.product_variant_id, updates = params.updates, unique_identification_number = params.unique_identification_number, identity_key = params.identity_key, product_option_item = params.product_option_item, product_bundle = params.product_bundle, booking = params.booking;
1528
1655
  tempOrder = this.ensureTempOrder();
1529
1656
  identityLookup = {
1530
1657
  product_id: product_id,
@@ -1533,15 +1660,18 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1533
1660
  if (unique_identification_number !== undefined) {
1534
1661
  identityLookup.unique_identification_number = unique_identification_number;
1535
1662
  }
1663
+ if (identity_key !== undefined) {
1664
+ identityLookup.identity_key = identity_key;
1665
+ }
1536
1666
  if (product_option_item !== undefined) identityLookup.product_option_item = product_option_item;
1537
1667
  if (product_bundle !== undefined) identityLookup.product_bundle = product_bundle;
1538
1668
  productIndex = getProductIdentityIndex(tempOrder.products, identityLookup);
1539
1669
  if (!(productIndex === -1)) {
1540
- _context14.next = 9;
1670
+ _context16.next = 10;
1541
1671
  break;
1542
1672
  }
1543
1673
  throw new Error('[Order] 目标商品不存在,无法更新');
1544
- case 9:
1674
+ case 10:
1545
1675
  targetProduct = tempOrder.products[productIndex];
1546
1676
  nextProduct = _objectSpread(_objectSpread(_objectSpread({}, targetProduct), updates), {}, {
1547
1677
  product_id: product_id,
@@ -1569,54 +1699,106 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1569
1699
  }
1570
1700
  // normalizeOrderProduct 幂等:v2 metadata 存在 → 保留 main_product_* 折扣重算 composite;
1571
1701
  // 否则 → 把顶层 selling_price 视作 source,派生 main_product_* 并写 price_schema_version: 2。
1572
- tempOrder.products[productIndex] = normalizeOrderProduct(nextProduct);
1702
+ normalizedProduct = normalizeOrderProduct(nextProduct);
1703
+ if (booking) {
1704
+ productUid = String(((_normalizedProduct$me = normalizedProduct.metadata) === null || _normalizedProduct$me === void 0 ? void 0 : _normalizedProduct$me.unique_identification_number) || ((_targetProduct$metada3 = targetProduct.metadata) === null || _targetProduct$metada3 === void 0 ? void 0 : _targetProduct$metada3.unique_identification_number) || unique_identification_number || createUuidV4());
1705
+ normalizedProduct.metadata = _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
1706
+ unique_identification_number: productUid
1707
+ });
1708
+ linked = this.createLinkedProductAndBooking({
1709
+ product: _objectSpread(_objectSpread({}, normalizedProduct), {}, {
1710
+ unique_identification_number: productUid
1711
+ }),
1712
+ booking: booking
1713
+ });
1714
+ this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
1715
+ normalizedProduct = _objectSpread(_objectSpread({}, normalizedProduct), {}, {
1716
+ booking_uid: linked.bookingUid,
1717
+ metadata: _objectSpread(_objectSpread({}, normalizedProduct.metadata || {}), {}, {
1718
+ booking_uid: linked.bookingUid,
1719
+ unique_identification_number: productUid
1720
+ })
1721
+ });
1722
+ tempOrder.bookings = [].concat(_toConsumableArray(tempOrder.bookings || []), [linked.booking]);
1723
+ }
1724
+ tempOrder.products[productIndex] = normalizedProduct;
1573
1725
  this.captureProductRuntime(tempOrder, updates, tempOrder.products[productIndex], (_tempOrder$products$p = tempOrder.products[productIndex].metadata) === null || _tempOrder$products$p === void 0 ? void 0 : _tempOrder$products$p.unique_identification_number);
1574
1726
  this.applyDiscount();
1575
- _context14.next = 20;
1727
+ _context16.next = 23;
1576
1728
  return this.recalculateSummary({
1577
1729
  createIfMissing: true
1578
1730
  });
1579
- case 20:
1731
+ case 23:
1580
1732
  this.persistTempOrder();
1581
- return _context14.abrupt("return", tempOrder.products);
1582
- case 22:
1733
+ return _context16.abrupt("return", tempOrder.products);
1734
+ case 25:
1583
1735
  case "end":
1584
- return _context14.stop();
1736
+ return _context16.stop();
1585
1737
  }
1586
- }, _callee14, this);
1738
+ }, _callee16, this);
1587
1739
  }));
1588
- function updateProductInOrder(_x14) {
1589
- return _updateProductInOrder.apply(this, arguments);
1740
+ function updateOrderProduct(_x18) {
1741
+ return _updateOrderProduct.apply(this, arguments);
1590
1742
  }
1591
- return updateProductInOrder;
1743
+ return updateOrderProduct;
1592
1744
  }()
1745
+ }, {
1746
+ key: "updateOrderBooking",
1747
+ value: function updateOrderBooking(params) {
1748
+ var unique_identification_number = params.unique_identification_number,
1749
+ updates = params.updates;
1750
+ var tempOrder = this.ensureTempOrder();
1751
+ var bookingUid = String(unique_identification_number || '');
1752
+ var bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(tempOrder, bookingUid);
1753
+ if (!bookingUid || bookingIndex === -1) {
1754
+ throw new Error('[Order] 目标 booking 不存在,无法更新');
1755
+ }
1756
+ var targetBooking = tempOrder.bookings[bookingIndex] || {};
1757
+ var nextBooking = _objectSpread(_objectSpread(_objectSpread({}, targetBooking), updates), {}, {
1758
+ metadata: _objectSpread(_objectSpread(_objectSpread({}, targetBooking.metadata || {}), updates.metadata || {}), {}, {
1759
+ unique_identification_number: bookingUid
1760
+ })
1761
+ });
1762
+ nextBooking.is_all = normalizeBookingIsAll(nextBooking);
1763
+ nextBooking.sub_type = normalizeBookingSubType(nextBooking);
1764
+ tempOrder.bookings[bookingIndex] = nextBooking;
1765
+ this.persistTempOrder();
1766
+ return tempOrder.bookings;
1767
+ }
1593
1768
  }, {
1594
1769
  key: "removeProductFromOrder",
1595
1770
  value: function () {
1596
- var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee15(identity) {
1597
- var tempOrder;
1598
- return _regeneratorRuntime().wrap(function _callee15$(_context15) {
1599
- while (1) switch (_context15.prev = _context15.next) {
1771
+ var _removeProductFromOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(identity) {
1772
+ var tempOrder, removedProducts, _i, _removedProducts, product;
1773
+ return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1774
+ while (1) switch (_context17.prev = _context17.next) {
1600
1775
  case 0:
1601
1776
  tempOrder = this.ensureTempOrder();
1777
+ removedProducts = [];
1602
1778
  tempOrder.products = tempOrder.products.filter(function (item) {
1603
- return !isIdentityMatch(item, identity);
1779
+ var shouldRemove = isIdentityMatch(item, identity);
1780
+ if (shouldRemove) removedProducts.push(item);
1781
+ return !shouldRemove;
1604
1782
  });
1783
+ for (_i = 0, _removedProducts = removedProducts; _i < _removedProducts.length; _i++) {
1784
+ product = _removedProducts[_i];
1785
+ this.removeLinkedBookingsForProduct(tempOrder, product);
1786
+ }
1605
1787
  this.applyDiscount();
1606
- _context15.next = 5;
1788
+ _context17.next = 7;
1607
1789
  return this.recalculateSummary({
1608
1790
  createIfMissing: true
1609
1791
  });
1610
- case 5:
1611
- this.persistTempOrder();
1612
- return _context15.abrupt("return", tempOrder.products);
1613
1792
  case 7:
1793
+ this.persistTempOrder();
1794
+ return _context17.abrupt("return", tempOrder.products);
1795
+ case 9:
1614
1796
  case "end":
1615
- return _context15.stop();
1797
+ return _context17.stop();
1616
1798
  }
1617
- }, _callee15, this);
1799
+ }, _callee17, this);
1618
1800
  }));
1619
- function removeProductFromOrder(_x15) {
1801
+ function removeProductFromOrder(_x19) {
1620
1802
  return _removeProductFromOrder.apply(this, arguments);
1621
1803
  }
1622
1804
  return removeProductFromOrder;
@@ -1630,11 +1812,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1630
1812
  }, {
1631
1813
  key: "submitTempOrder",
1632
1814
  value: function () {
1633
- var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee16(params) {
1815
+ var _submitTempOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1634
1816
  var _params$cacheId, _this$otherParams;
1635
1817
  var tempOrder, effectiveCacheId, hasPaymentOverride, hasPaymentStatusOverride, hasSmallTicketDataFlagOverride, enhancePayload, payload, result, _payload$payments, _payload$payments2, backendErrorResponse, submittedOrderId, resultRecord;
1636
- return _regeneratorRuntime().wrap(function _callee16$(_context16) {
1637
- while (1) switch (_context16.prev = _context16.next) {
1818
+ return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1819
+ while (1) switch (_context18.prev = _context18.next) {
1638
1820
  case 0:
1639
1821
  tempOrder = this.ensureTempOrder();
1640
1822
  this.persistTempOrder();
@@ -1661,10 +1843,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1661
1843
  type: params === null || params === void 0 ? void 0 : params.type,
1662
1844
  enhance: enhancePayload
1663
1845
  });
1664
- _context16.next = 10;
1846
+ _context18.next = 10;
1665
1847
  return this.saveDraft();
1666
1848
  case 10:
1667
- _context16.prev = 10;
1849
+ _context18.prev = 10;
1668
1850
  this.logInfo('submitTempOrder calling sales checkout', {
1669
1851
  orderId: payload.order_id,
1670
1852
  externalSaleNumber: payload.external_sale_number,
@@ -1672,62 +1854,62 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1672
1854
  paymentsCount: ((_payload$payments = payload.payments) === null || _payload$payments === void 0 ? void 0 : _payload$payments.length) || 0,
1673
1855
  smallTicketDataFlag: payload.small_ticket_data_flag
1674
1856
  });
1675
- _context16.next = 14;
1857
+ _context18.next = 14;
1676
1858
  return this.submitSalesOrder({
1677
1859
  query: payload
1678
1860
  });
1679
1861
  case 14:
1680
- result = _context16.sent;
1681
- _context16.next = 27;
1862
+ result = _context18.sent;
1863
+ _context18.next = 27;
1682
1864
  break;
1683
1865
  case 17:
1684
- _context16.prev = 17;
1685
- _context16.t0 = _context16["catch"](10);
1686
- backendErrorResponse = this.extractSubmitErrorResponse(_context16.t0);
1866
+ _context18.prev = 17;
1867
+ _context18.t0 = _context18["catch"](10);
1868
+ backendErrorResponse = this.extractSubmitErrorResponse(_context18.t0);
1687
1869
  if (!backendErrorResponse) {
1688
- _context16.next = 24;
1870
+ _context18.next = 24;
1689
1871
  break;
1690
1872
  }
1691
1873
  this.store.syncState = 'failed';
1692
1874
  this.logSubmitBackendRejected(backendErrorResponse, payload);
1693
- return _context16.abrupt("return", backendErrorResponse);
1875
+ return _context18.abrupt("return", backendErrorResponse);
1694
1876
  case 24:
1695
1877
  this.store.syncState = 'failed';
1696
1878
  this.logError('submitTempOrder failed', {
1697
- error: _context16.t0 instanceof Error ? _context16.t0.message : String(_context16.t0),
1879
+ error: _context18.t0 instanceof Error ? _context18.t0.message : String(_context18.t0),
1698
1880
  orderId: payload.order_id,
1699
1881
  externalSaleNumber: payload.external_sale_number,
1700
1882
  paymentStatus: payload.payment_status,
1701
1883
  paymentsCount: ((_payload$payments2 = payload.payments) === null || _payload$payments2 === void 0 ? void 0 : _payload$payments2.length) || 0
1702
1884
  });
1703
- throw _context16.t0;
1885
+ throw _context18.t0;
1704
1886
  case 27:
1705
1887
  if (!this.isSubmitResponseRejected(result)) {
1706
- _context16.next = 31;
1888
+ _context18.next = 31;
1707
1889
  break;
1708
1890
  }
1709
1891
  this.store.syncState = 'failed';
1710
1892
  this.logSubmitBackendRejected(result, payload);
1711
- return _context16.abrupt("return", result);
1893
+ return _context18.abrupt("return", result);
1712
1894
  case 31:
1713
1895
  submittedOrderId = this.extractOrderIdFromSubmitResult(result);
1714
1896
  if (!(submittedOrderId !== null && submittedOrderId !== undefined)) {
1715
- _context16.next = 37;
1897
+ _context18.next = 37;
1716
1898
  break;
1717
1899
  }
1718
1900
  tempOrder.order_id = submittedOrderId;
1719
1901
  resultRecord = result;
1720
- _context16.next = 37;
1902
+ _context18.next = 37;
1721
1903
  return this.markLocalOrderSynced(submittedOrderId, (resultRecord === null || resultRecord === void 0 ? void 0 : resultRecord.data) || resultRecord || {});
1722
1904
  case 37:
1723
- return _context16.abrupt("return", result);
1905
+ return _context18.abrupt("return", result);
1724
1906
  case 38:
1725
1907
  case "end":
1726
- return _context16.stop();
1908
+ return _context18.stop();
1727
1909
  }
1728
- }, _callee16, this, [[10, 17]]);
1910
+ }, _callee18, this, [[10, 17]]);
1729
1911
  }));
1730
- function submitTempOrder(_x16) {
1912
+ function submitTempOrder(_x20) {
1731
1913
  return _submitTempOrder.apply(this, arguments);
1732
1914
  }
1733
1915
  return submitTempOrder;
@@ -1735,25 +1917,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1735
1917
  }, {
1736
1918
  key: "markLocalOrderSynced",
1737
1919
  value: function () {
1738
- var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee17(orderId, remoteOrder) {
1920
+ var _markLocalOrderSynced = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(orderId, remoteOrder) {
1739
1921
  var tempOrder;
1740
- return _regeneratorRuntime().wrap(function _callee17$(_context17) {
1741
- while (1) switch (_context17.prev = _context17.next) {
1922
+ return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1923
+ while (1) switch (_context19.prev = _context19.next) {
1742
1924
  case 0:
1743
1925
  tempOrder = this.ensureTempOrder();
1744
1926
  tempOrder.order_id = orderId;
1745
1927
  this.store.lastOrderInfo = remoteOrder;
1746
1928
  this.store.syncState = 'submitted';
1747
1929
  this.persistTempOrder();
1748
- _context17.next = 7;
1930
+ _context19.next = 7;
1749
1931
  return this.saveDraft();
1750
1932
  case 7:
1751
1933
  case "end":
1752
- return _context17.stop();
1934
+ return _context19.stop();
1753
1935
  }
1754
- }, _callee17, this);
1936
+ }, _callee19, this);
1755
1937
  }));
1756
- function markLocalOrderSynced(_x17, _x18) {
1938
+ function markLocalOrderSynced(_x21, _x22) {
1757
1939
  return _markLocalOrderSynced.apply(this, arguments);
1758
1940
  }
1759
1941
  return markLocalOrderSynced;
@@ -1777,10 +1959,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1777
1959
  value: function extractSubmitErrorResponse(error) {
1778
1960
  var _error$response,
1779
1961
  _error$response2,
1780
- _this4 = this;
1962
+ _this6 = this;
1781
1963
  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];
1782
1964
  return candidates.find(function (candidate) {
1783
- return _this4.isSubmitErrorResponse(candidate);
1965
+ return _this6.isSubmitErrorResponse(candidate);
1784
1966
  }) || null;
1785
1967
  }
1786
1968
  }, {
@@ -1800,49 +1982,49 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1800
1982
  }, {
1801
1983
  key: "syncPaymentsToOrder",
1802
1984
  value: function () {
1803
- var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee18(params) {
1985
+ var _syncPaymentsToOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
1804
1986
  var tempOrder, mappedPayments, paymentTotal, targetAmount, isFullyPaid, submitResult;
1805
- return _regeneratorRuntime().wrap(function _callee18$(_context18) {
1806
- while (1) switch (_context18.prev = _context18.next) {
1987
+ return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1988
+ while (1) switch (_context20.prev = _context20.next) {
1807
1989
  case 0:
1808
1990
  tempOrder = this.ensureTempOrder();
1809
1991
  mappedPayments = mapPaymentItemsToOrderPayments(params.payments || []);
1810
1992
  tempOrder.payments = mappedPayments;
1811
1993
  if (params.paymentStatus) tempOrder.payment_status = params.paymentStatus;
1812
1994
  this.persistTempOrder();
1813
- _context18.next = 7;
1995
+ _context20.next = 7;
1814
1996
  return this.saveDraft();
1815
1997
  case 7:
1816
1998
  paymentTotal = this.calculatePaymentTotal(mappedPayments);
1817
1999
  targetAmount = this.getPaymentTargetAmount();
1818
2000
  isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
1819
2001
  if (!(!isFullyPaid || !params.submitWhenPaid)) {
1820
- _context18.next = 12;
2002
+ _context20.next = 12;
1821
2003
  break;
1822
2004
  }
1823
- return _context18.abrupt("return", {
2005
+ return _context20.abrupt("return", {
1824
2006
  isFullyPaid: isFullyPaid
1825
2007
  });
1826
2008
  case 12:
1827
- _context18.next = 14;
2009
+ _context20.next = 14;
1828
2010
  return this.submitTempOrder({
1829
2011
  payments: mappedPayments,
1830
2012
  paymentStatus: params.paymentStatus || 'paid',
1831
2013
  smallTicketDataFlag: params.smallTicketDataFlag
1832
2014
  });
1833
2015
  case 14:
1834
- submitResult = _context18.sent;
1835
- return _context18.abrupt("return", {
2016
+ submitResult = _context20.sent;
2017
+ return _context20.abrupt("return", {
1836
2018
  isFullyPaid: isFullyPaid,
1837
2019
  submitResult: submitResult
1838
2020
  });
1839
2021
  case 16:
1840
2022
  case "end":
1841
- return _context18.stop();
2023
+ return _context20.stop();
1842
2024
  }
1843
- }, _callee18, this);
2025
+ }, _callee20, this);
1844
2026
  }));
1845
- function syncPaymentsToOrder(_x19) {
2027
+ function syncPaymentsToOrder(_x23) {
1846
2028
  return _syncPaymentsToOrder.apply(this, arguments);
1847
2029
  }
1848
2030
  return syncPaymentsToOrder;
@@ -1931,11 +2113,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1931
2113
  }, {
1932
2114
  key: "submitOrder",
1933
2115
  value: function () {
1934
- var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee19(order) {
2116
+ var _submitOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(order) {
1935
2117
  var _order$query$cartItem, _params$bookings, _params$relation_prod;
1936
2118
  var url, query, fetchUrl, params;
1937
- return _regeneratorRuntime().wrap(function _callee19$(_context19) {
1938
- while (1) switch (_context19.prev = _context19.next) {
2119
+ return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2120
+ while (1) switch (_context21.prev = _context21.next) {
1939
2121
  case 0:
1940
2122
  this.logInfo('submitOrder called', {
1941
2123
  url: order.url,
@@ -1955,14 +2137,14 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1955
2137
  relationProductsCount: ((_params$relation_prod = params.relation_products) === null || _params$relation_prod === void 0 ? void 0 : _params$relation_prod.length) || 0,
1956
2138
  scheduleDate: params.schedule_date
1957
2139
  });
1958
- return _context19.abrupt("return", this.request.post(fetchUrl, params));
2140
+ return _context21.abrupt("return", this.request.post(fetchUrl, params));
1959
2141
  case 6:
1960
2142
  case "end":
1961
- return _context19.stop();
2143
+ return _context21.stop();
1962
2144
  }
1963
- }, _callee19, this);
2145
+ }, _callee21, this);
1964
2146
  }));
1965
- function submitOrder(_x20) {
2147
+ function submitOrder(_x24) {
1966
2148
  return _submitOrder.apply(this, arguments);
1967
2149
  }
1968
2150
  return submitOrder;
@@ -1970,13 +2152,13 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1970
2152
  }, {
1971
2153
  key: "cancelOrder",
1972
2154
  value: function () {
1973
- var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee20(params) {
2155
+ var _cancelOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
1974
2156
  var payload;
1975
- return _regeneratorRuntime().wrap(function _callee20$(_context20) {
1976
- while (1) switch (_context20.prev = _context20.next) {
2157
+ return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2158
+ while (1) switch (_context22.prev = _context22.next) {
1977
2159
  case 0:
1978
2160
  if (!(!Array.isArray(params.order_ids) || params.order_ids.length === 0)) {
1979
- _context20.next = 2;
2161
+ _context22.next = 2;
1980
2162
  break;
1981
2163
  }
1982
2164
  throw new Error('取消订单失败:order_ids 不能为空');
@@ -1992,16 +2174,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
1992
2174
  method: 'PUT',
1993
2175
  orderIdsCount: params.order_ids.length
1994
2176
  });
1995
- return _context20.abrupt("return", this.request.put('/order/update-status', payload, {
2177
+ return _context22.abrupt("return", this.request.put('/order/update-status', payload, {
1996
2178
  isShopApi: true
1997
2179
  }));
1998
2180
  case 5:
1999
2181
  case "end":
2000
- return _context20.stop();
2182
+ return _context22.stop();
2001
2183
  }
2002
- }, _callee20, this);
2184
+ }, _callee22, this);
2003
2185
  }));
2004
- function cancelOrder(_x21) {
2186
+ function cancelOrder(_x25) {
2005
2187
  return _cancelOrder.apply(this, arguments);
2006
2188
  }
2007
2189
  return cancelOrder;
@@ -2009,19 +2191,19 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2009
2191
  }, {
2010
2192
  key: "changeBookingStatus",
2011
2193
  value: function () {
2012
- var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee21(params) {
2194
+ var _changeBookingStatus = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2013
2195
  var url, payload;
2014
- return _regeneratorRuntime().wrap(function _callee21$(_context21) {
2015
- while (1) switch (_context21.prev = _context21.next) {
2196
+ return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2197
+ while (1) switch (_context23.prev = _context23.next) {
2016
2198
  case 0:
2017
2199
  if (params.booking_id) {
2018
- _context21.next = 2;
2200
+ _context23.next = 2;
2019
2201
  break;
2020
2202
  }
2021
2203
  throw new Error('变更预约状态失败:booking_id 不能为空');
2022
2204
  case 2:
2023
2205
  if (params.appointment_status) {
2024
- _context21.next = 4;
2206
+ _context23.next = 4;
2025
2207
  break;
2026
2208
  }
2027
2209
  throw new Error('变更预约状态失败:appointment_status 不能为空');
@@ -2036,16 +2218,16 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2036
2218
  bookingId: params.booking_id,
2037
2219
  appointmentStatus: params.appointment_status
2038
2220
  });
2039
- return _context21.abrupt("return", this.request.put(url, payload, {
2221
+ return _context23.abrupt("return", this.request.put(url, payload, {
2040
2222
  isShopApi: true
2041
2223
  }));
2042
2224
  case 8:
2043
2225
  case "end":
2044
- return _context21.stop();
2226
+ return _context23.stop();
2045
2227
  }
2046
- }, _callee21, this);
2228
+ }, _callee23, this);
2047
2229
  }));
2048
- function changeBookingStatus(_x22) {
2230
+ function changeBookingStatus(_x26) {
2049
2231
  return _changeBookingStatus.apply(this, arguments);
2050
2232
  }
2051
2233
  return changeBookingStatus;
@@ -2063,11 +2245,11 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2063
2245
  }, {
2064
2246
  key: "createOrderByCheckout",
2065
2247
  value: (function () {
2066
- var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee22(params) {
2248
+ var _createOrderByCheckout = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2067
2249
  var _params$payments, _params$bookings2, _params$relation_prod2, _params$payments2, _params$payments3, _params$bookings3, _params$relation_prod3, _params$payments4;
2068
2250
  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;
2069
- return _regeneratorRuntime().wrap(function _callee22$(_context22) {
2070
- while (1) switch (_context22.prev = _context22.next) {
2251
+ return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2252
+ while (1) switch (_context24.prev = _context24.next) {
2071
2253
  case 0:
2072
2254
  // 过滤掉由在线店铺下单的 payment 支付数据
2073
2255
  onlineStorePaymentCodeList = ['WXPAY', 'WECHAT', 'ALIPAY', 'APPLE_PAY', 'CREDIT_CARD_3DS', 'CREDIT_CARD_TOKEN', 'GOOGLE_PAY', 'GOOGLE_PAY_3DS', 'CREDIT_CARD'];
@@ -2101,7 +2283,7 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2101
2283
  relationProductsCount: ((_params$relation_prod3 = params.relation_products) === null || _params$relation_prod3 === void 0 ? void 0 : _params$relation_prod3.length) || 0,
2102
2284
  paymentsCount: ((_params$payments4 = params.payments) === null || _params$payments4 === void 0 ? void 0 : _params$payments4.length) || 0
2103
2285
  });
2104
- _context22.prev = 4;
2286
+ _context24.prev = 4;
2105
2287
  // 构建订单数据,设置默认值并允许 params 覆盖
2106
2288
  orderData = _objectSpread({
2107
2289
  sales_channel: 'my_pisel',
@@ -2165,10 +2347,10 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2165
2347
  });
2166
2348
 
2167
2349
  // 调用后端接口
2168
- _context22.next = 12;
2350
+ _context24.next = 12;
2169
2351
  return this.request.post('/order/checkout', orderData);
2170
2352
  case 12:
2171
- response = _context22.sent;
2353
+ response = _context24.sent;
2172
2354
  this.logInfo('Order API called successfully', {
2173
2355
  response: response
2174
2356
  });
@@ -2176,22 +2358,22 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2176
2358
  success: !!response,
2177
2359
  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)
2178
2360
  });
2179
- return _context22.abrupt("return", response);
2361
+ return _context24.abrupt("return", response);
2180
2362
  case 18:
2181
- _context22.prev = 18;
2182
- _context22.t0 = _context22["catch"](4);
2183
- console.error('[Order] createOrderByCheckout 创建订单失败:', _context22.t0);
2363
+ _context24.prev = 18;
2364
+ _context24.t0 = _context24["catch"](4);
2365
+ console.error('[Order] createOrderByCheckout 创建订单失败:', _context24.t0);
2184
2366
  this.logInfo('Order API called failed', {
2185
- error: _context22.t0 instanceof Error ? _context22.t0.message : String(_context22.t0)
2367
+ error: _context24.t0 instanceof Error ? _context24.t0.message : String(_context24.t0)
2186
2368
  });
2187
- throw _context22.t0;
2369
+ throw _context24.t0;
2188
2370
  case 23:
2189
2371
  case "end":
2190
- return _context22.stop();
2372
+ return _context24.stop();
2191
2373
  }
2192
- }, _callee22, this, [[4, 18]]);
2374
+ }, _callee24, this, [[4, 18]]);
2193
2375
  }));
2194
- function createOrderByCheckout(_x23) {
2376
+ function createOrderByCheckout(_x27) {
2195
2377
  return _createOrderByCheckout.apply(this, arguments);
2196
2378
  }
2197
2379
  return createOrderByCheckout;
@@ -2199,23 +2381,23 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2199
2381
  }, {
2200
2382
  key: "submitSalesOrder",
2201
2383
  value: function () {
2202
- var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee23(params) {
2384
+ var _submitSalesOrder = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(params) {
2203
2385
  var url, query, fetchUrl;
2204
- return _regeneratorRuntime().wrap(function _callee23$(_context23) {
2205
- while (1) switch (_context23.prev = _context23.next) {
2386
+ return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2387
+ while (1) switch (_context25.prev = _context25.next) {
2206
2388
  case 0:
2207
2389
  url = params.url, query = params.query;
2208
2390
  fetchUrl = url || '/order/sales/checkout';
2209
- return _context23.abrupt("return", this.request.post(fetchUrl, query, {
2391
+ return _context25.abrupt("return", this.request.post(fetchUrl, query, {
2210
2392
  customToast: function customToast() {}
2211
2393
  }));
2212
2394
  case 3:
2213
2395
  case "end":
2214
- return _context23.stop();
2396
+ return _context25.stop();
2215
2397
  }
2216
- }, _callee23, this);
2398
+ }, _callee25, this);
2217
2399
  }));
2218
- function submitSalesOrder(_x24) {
2400
+ function submitSalesOrder(_x28) {
2219
2401
  return _submitSalesOrder.apply(this, arguments);
2220
2402
  }
2221
2403
  return submitSalesOrder;
@@ -2229,37 +2411,37 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2229
2411
  }, {
2230
2412
  key: "sendCustomerPayLink",
2231
2413
  value: (function () {
2232
- var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee24(params) {
2414
+ var _sendCustomerPayLink = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(params) {
2233
2415
  var _params$emails;
2234
2416
  var orderIds;
2235
- return _regeneratorRuntime().wrap(function _callee24$(_context24) {
2236
- while (1) switch (_context24.prev = _context24.next) {
2417
+ return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2418
+ while (1) switch (_context26.prev = _context26.next) {
2237
2419
  case 0:
2238
2420
  orderIds = params.order_ids || params.orderIds || [];
2239
2421
  if (orderIds.length) {
2240
- _context24.next = 3;
2422
+ _context26.next = 3;
2241
2423
  break;
2242
2424
  }
2243
2425
  throw new Error('发送支付链接前必须先提交本地订单并取得订单 ID');
2244
2426
  case 3:
2245
2427
  if ((_params$emails = params.emails) !== null && _params$emails !== void 0 && _params$emails.length) {
2246
- _context24.next = 5;
2428
+ _context26.next = 5;
2247
2429
  break;
2248
2430
  }
2249
2431
  throw new Error('发送支付链接需要至少一个邮箱');
2250
2432
  case 5:
2251
- return _context24.abrupt("return", this.request.post('/order/batch-email', {
2433
+ return _context26.abrupt("return", this.request.post('/order/batch-email', {
2252
2434
  order_ids: orderIds,
2253
2435
  notify_action: params.notify_action || 'order_payment_reminder',
2254
2436
  emails: params.emails
2255
2437
  }));
2256
2438
  case 6:
2257
2439
  case "end":
2258
- return _context24.stop();
2440
+ return _context26.stop();
2259
2441
  }
2260
- }, _callee24, this);
2442
+ }, _callee26, this);
2261
2443
  }));
2262
- function sendCustomerPayLink(_x25) {
2444
+ function sendCustomerPayLink(_x29) {
2263
2445
  return _sendCustomerPayLink.apply(this, arguments);
2264
2446
  }
2265
2447
  return sendCustomerPayLink;
@@ -2268,28 +2450,28 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2268
2450
  }, {
2269
2451
  key: "getOrderInfoByRemote",
2270
2452
  value: function () {
2271
- var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee25(order_id) {
2453
+ var _getOrderInfoByRemote = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order_id) {
2272
2454
  var res;
2273
- return _regeneratorRuntime().wrap(function _callee25$(_context25) {
2274
- while (1) switch (_context25.prev = _context25.next) {
2455
+ return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2456
+ while (1) switch (_context27.prev = _context27.next) {
2275
2457
  case 0:
2276
- _context25.next = 2;
2458
+ _context27.next = 2;
2277
2459
  return this.request.get("/order/sales/".concat(order_id), {
2278
2460
  with: ['products', 'bookings', 'payments', 'customer', 'summary', 'contacts_info']
2279
2461
  });
2280
2462
  case 2:
2281
- res = _context25.sent;
2463
+ res = _context27.sent;
2282
2464
  if (res.code === 200) {
2283
2465
  this.store.lastOrderInfo = res.data;
2284
2466
  }
2285
- return _context25.abrupt("return", res);
2467
+ return _context27.abrupt("return", res);
2286
2468
  case 5:
2287
2469
  case "end":
2288
- return _context25.stop();
2470
+ return _context27.stop();
2289
2471
  }
2290
- }, _callee25, this);
2472
+ }, _callee27, this);
2291
2473
  }));
2292
- function getOrderInfoByRemote(_x26) {
2474
+ function getOrderInfoByRemote(_x30) {
2293
2475
  return _getOrderInfoByRemote.apply(this, arguments);
2294
2476
  }
2295
2477
  return getOrderInfoByRemote;
@@ -2303,79 +2485,84 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2303
2485
  }, {
2304
2486
  key: "hydrateTempOrderFromRecord",
2305
2487
  value: (function () {
2306
- var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee26(record, options) {
2307
- var _this5 = this;
2308
- var raw, defaults, nextTempOrder, TEMP_ORDER_KEYS;
2309
- return _regeneratorRuntime().wrap(function _callee26$(_context26) {
2310
- while (1) switch (_context26.prev = _context26.next) {
2488
+ var _hydrateTempOrderFromRecord = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee28(record, options) {
2489
+ var raw, nextTempOrder;
2490
+ return _regeneratorRuntime().wrap(function _callee28$(_context28) {
2491
+ while (1) switch (_context28.prev = _context28.next) {
2311
2492
  case 0:
2312
2493
  raw = record && _typeof(record) === 'object' && record.data && record.order_id == null ? record.data : record || {};
2313
- defaults = this.createDefaultTempOrderInstance();
2314
- nextTempOrder = _objectSpread({}, defaults);
2315
- TEMP_ORDER_KEYS = ['order_id', 'external_sale_number', 'order_number', 'shop_order_number', 'shop_full_order_number', 'type', 'business_code', 'platform', 'sales_channel', 'order_sales_channel', 'status', 'payment_status', 'shipping_status', 'customer_id', 'customer_name', 'country_calling_code', 'phone', 'email', 'customer', 'is_price_include_tax', 'tax_title', 'tax_country_code', 'currency_code', 'currency_symbol', 'currency_format', 'is_deposit', 'deposit_amount', 'shop_discount', 'surcharge_fee', 'note', 'buzzer', 'delivery_type', 'table_number', 'schedule_date', 'created_at', 'request_unique_idempotency_token'];
2316
- TEMP_ORDER_KEYS.forEach(function (key) {
2317
- if (raw[key] !== undefined) {
2318
- nextTempOrder[key] = raw[key];
2319
- }
2494
+ nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
2495
+ ensureIdentity: true
2320
2496
  });
2321
- nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
2322
- nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
2323
- nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
2324
- return _this5.normalizeHydratedOrderProduct(p);
2325
- }) : [];
2326
- nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
2327
- return _objectSpread(_objectSpread({}, b || {}), {}, {
2328
- is_all: normalizeBookingIsAll(b || {}),
2329
- sub_type: normalizeBookingSubType(b || {})
2330
- });
2331
- }) : [];
2332
- nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
2333
- return _objectSpread({}, p || {});
2334
- }) : [];
2335
- nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
2336
- return _objectSpread({}, s || {});
2337
- }) : [];
2338
- nextTempOrder.discount_list = Array.isArray(raw.discount_list) ? raw.discount_list.map(function (d) {
2339
- return _objectSpread({}, d || {});
2340
- }) : [];
2341
- nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map(function (f) {
2342
- return _objectSpread({}, f || {});
2343
- }) : [];
2344
- nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map(function (c) {
2345
- return _objectSpread({}, c || {});
2346
- }) : [];
2347
- nextTempOrder.contacts_info = raw.contacts_info && _typeof(raw.contacts_info) === 'object' && !Array.isArray(raw.contacts_info) ? _objectSpread({}, raw.contacts_info) : null;
2348
- nextTempOrder._extend = raw._extend && _typeof(raw._extend) === 'object' ? _objectSpread(_objectSpread({}, raw._extend), {}, {
2349
- productsByUid: raw._extend.productsByUid || {}
2350
- }) : {
2351
- productsByUid: {}
2352
- };
2353
- this.ensureExternalSaleNumber(nextTempOrder);
2354
2497
  this.store.tempOrder = nextTempOrder;
2355
2498
  this.store.summary = raw.summary && _typeof(raw.summary) === 'object' ? _objectSpread(_objectSpread({}, createEmptySummary()), raw.summary) : createEmptySummary();
2356
2499
  this.store.lastOrderInfo = raw.lastOrderInfo || raw;
2357
2500
  if (!(options !== null && options !== void 0 && options.recalcOnHydrate)) {
2358
- _context26.next = 23;
2501
+ _context28.next = 8;
2359
2502
  break;
2360
2503
  }
2361
- _context26.next = 23;
2504
+ _context28.next = 8;
2362
2505
  return this.recalculateSummary({
2363
2506
  createIfMissing: false
2364
2507
  });
2365
- case 23:
2508
+ case 8:
2366
2509
  this.persistTempOrder();
2367
- return _context26.abrupt("return", nextTempOrder);
2368
- case 25:
2510
+ return _context28.abrupt("return", nextTempOrder);
2511
+ case 10:
2369
2512
  case "end":
2370
- return _context26.stop();
2513
+ return _context28.stop();
2371
2514
  }
2372
- }, _callee26, this);
2515
+ }, _callee28, this);
2373
2516
  }));
2374
- function hydrateTempOrderFromRecord(_x27, _x28) {
2517
+ function hydrateTempOrderFromRecord(_x31, _x32) {
2375
2518
  return _hydrateTempOrderFromRecord.apply(this, arguments);
2376
2519
  }
2377
2520
  return hydrateTempOrderFromRecord;
2378
2521
  }())
2522
+ }, {
2523
+ key: "normalizeTempOrderForRuntime",
2524
+ value: function normalizeTempOrderForRuntime(raw, options) {
2525
+ var _this7 = this;
2526
+ var nextTempOrder = _objectSpread(_objectSpread({}, this.createDefaultTempOrderInstance()), raw || {});
2527
+ delete nextTempOrder.summary;
2528
+ delete nextTempOrder.lastOrderInfo;
2529
+ nextTempOrder.metadata = raw.metadata && _typeof(raw.metadata) === 'object' ? _objectSpread({}, raw.metadata) : {};
2530
+ nextTempOrder.holder = raw.holder && _typeof(raw.holder) === 'object' ? _objectSpread({}, raw.holder) : null;
2531
+ nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map(function (p) {
2532
+ return _this7.normalizeHydratedOrderProduct(p);
2533
+ }) : [];
2534
+ nextTempOrder.bookings = Array.isArray(raw.bookings) ? raw.bookings.map(function (b) {
2535
+ return _objectSpread(_objectSpread({}, b || {}), {}, {
2536
+ is_all: normalizeBookingIsAll(b || {}),
2537
+ sub_type: normalizeBookingSubType(b || {})
2538
+ });
2539
+ }) : [];
2540
+ nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map(function (p) {
2541
+ return _objectSpread({}, p || {});
2542
+ }) : [];
2543
+ nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map(function (s) {
2544
+ return _objectSpread({}, s || {});
2545
+ }) : [];
2546
+ nextTempOrder.discount_list = Array.isArray(raw.discount_list) ? raw.discount_list.map(function (d) {
2547
+ return _objectSpread({}, d || {});
2548
+ }) : [];
2549
+ nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map(function (f) {
2550
+ return _objectSpread({}, f || {});
2551
+ }) : [];
2552
+ nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map(function (c) {
2553
+ return _objectSpread({}, c || {});
2554
+ }) : [];
2555
+ nextTempOrder.contacts_info = raw.contacts_info && _typeof(raw.contacts_info) === 'object' && !Array.isArray(raw.contacts_info) ? _objectSpread({}, raw.contacts_info) : null;
2556
+ nextTempOrder._extend = raw._extend && _typeof(raw._extend) === 'object' ? _objectSpread(_objectSpread({}, raw._extend), {}, {
2557
+ productsByUid: raw._extend.productsByUid || {}
2558
+ }) : {
2559
+ productsByUid: {}
2560
+ };
2561
+ if ((options === null || options === void 0 ? void 0 : options.ensureIdentity) !== false) {
2562
+ this.ensureExternalSaleNumber(nextTempOrder);
2563
+ }
2564
+ return nextTempOrder;
2565
+ }
2379
2566
  }, {
2380
2567
  key: "normalizeHydratedOrderProduct",
2381
2568
  value: function normalizeHydratedOrderProduct(product) {
@@ -2406,25 +2593,25 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
2406
2593
  }, {
2407
2594
  key: "getOrderInfo",
2408
2595
  value: function () {
2409
- var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee27(order_id) {
2596
+ var _getOrderInfo = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee29(order_id) {
2410
2597
  var res;
2411
- return _regeneratorRuntime().wrap(function _callee27$(_context27) {
2412
- while (1) switch (_context27.prev = _context27.next) {
2598
+ return _regeneratorRuntime().wrap(function _callee29$(_context29) {
2599
+ while (1) switch (_context29.prev = _context29.next) {
2413
2600
  case 0:
2414
- _context27.next = 2;
2601
+ _context29.next = 2;
2415
2602
  return this.request.get("/order/sales/".concat(order_id), {
2416
2603
  with: ['products', 'bookings']
2417
2604
  });
2418
2605
  case 2:
2419
- res = _context27.sent;
2420
- return _context27.abrupt("return", res);
2606
+ res = _context29.sent;
2607
+ return _context29.abrupt("return", res);
2421
2608
  case 4:
2422
2609
  case "end":
2423
- return _context27.stop();
2610
+ return _context29.stop();
2424
2611
  }
2425
- }, _callee27, this);
2612
+ }, _callee29, this);
2426
2613
  }));
2427
- function getOrderInfo(_x29) {
2614
+ function getOrderInfo(_x33) {
2428
2615
  return _getOrderInfo.apply(this, arguments);
2429
2616
  }
2430
2617
  return getOrderInfo;