@pisell/pisellos 2.2.170 → 2.2.171

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 (149) hide show
  1. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  2. package/dist/modules/Customer/index.d.ts +0 -6
  3. package/dist/modules/Customer/index.js +83 -129
  4. package/dist/modules/Customer/types.d.ts +0 -2
  5. package/dist/modules/Discount/index.d.ts +4 -2
  6. package/dist/modules/Discount/index.js +93 -8
  7. package/dist/modules/Discount/types.d.ts +7 -1
  8. package/dist/modules/Order/index.d.ts +15 -27
  9. package/dist/modules/Order/index.js +322 -695
  10. package/dist/modules/Order/types.d.ts +14 -49
  11. package/dist/modules/Order/types.js +0 -2
  12. package/dist/modules/Order/utils.d.ts +0 -17
  13. package/dist/modules/Order/utils.js +26 -97
  14. package/dist/modules/Rules/index.d.ts +0 -4
  15. package/dist/modules/Rules/index.js +10 -26
  16. package/dist/modules/SalesSummary/index.js +2 -4
  17. package/dist/modules/index.d.ts +0 -1
  18. package/dist/modules/index.js +1 -2
  19. package/dist/server/modules/order/utils/filterOrders.js +6 -20
  20. package/dist/solution/BaseSales/index.d.ts +7 -46
  21. package/dist/solution/BaseSales/index.js +315 -1009
  22. package/dist/solution/BaseSales/types.d.ts +1 -53
  23. package/dist/solution/BaseSales/types.js +1 -3
  24. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +15 -65
  25. package/dist/solution/BaseSales/utils.js +8 -46
  26. package/dist/solution/BookingByStep/index.d.ts +1 -1
  27. package/dist/solution/BookingTicket/index.d.ts +1 -133
  28. package/dist/solution/BookingTicket/index.js +175 -768
  29. package/dist/solution/BookingTicket/types.d.ts +0 -2
  30. package/dist/solution/BookingTicket/types.js +0 -3
  31. package/dist/solution/ScanOrder/index.d.ts +3 -9
  32. package/dist/solution/ScanOrder/index.js +128 -231
  33. package/dist/solution/ScanOrder/utils.js +8 -46
  34. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  35. package/dist/solution/ShopDiscount/index.js +23 -18
  36. package/dist/solution/VenueBooking/index.d.ts +9 -5
  37. package/dist/solution/VenueBooking/index.js +55 -103
  38. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  39. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
  40. package/lib/modules/Customer/index.d.ts +0 -6
  41. package/lib/modules/Customer/index.js +11 -26
  42. package/lib/modules/Customer/types.d.ts +0 -2
  43. package/lib/modules/Discount/index.d.ts +4 -2
  44. package/lib/modules/Discount/index.js +63 -8
  45. package/lib/modules/Discount/types.d.ts +7 -1
  46. package/lib/modules/Order/index.d.ts +15 -27
  47. package/lib/modules/Order/index.js +84 -336
  48. package/lib/modules/Order/types.d.ts +14 -49
  49. package/lib/modules/Order/utils.d.ts +0 -17
  50. package/lib/modules/Order/utils.js +18 -105
  51. package/lib/modules/Rules/index.d.ts +0 -4
  52. package/lib/modules/Rules/index.js +14 -22
  53. package/lib/modules/SalesSummary/index.js +2 -4
  54. package/lib/modules/index.d.ts +0 -1
  55. package/lib/modules/index.js +1 -3
  56. package/lib/server/modules/order/utils/filterOrders.js +4 -12
  57. package/lib/solution/BaseSales/index.d.ts +7 -46
  58. package/lib/solution/BaseSales/index.js +20 -434
  59. package/lib/solution/BaseSales/types.d.ts +1 -53
  60. package/lib/solution/BaseSales/types.js +1 -3
  61. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +11 -70
  62. package/lib/solution/BaseSales/utils.js +6 -46
  63. package/lib/solution/BookingByStep/index.d.ts +1 -1
  64. package/lib/solution/BookingTicket/index.d.ts +1 -133
  65. package/lib/solution/BookingTicket/index.js +8 -341
  66. package/lib/solution/BookingTicket/types.d.ts +0 -2
  67. package/lib/solution/BookingTicket/types.js +0 -6
  68. package/lib/solution/ScanOrder/index.d.ts +3 -9
  69. package/lib/solution/ScanOrder/index.js +66 -147
  70. package/lib/solution/ScanOrder/utils.js +6 -46
  71. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  72. package/lib/solution/ShopDiscount/index.js +4 -2
  73. package/lib/solution/VenueBooking/index.d.ts +9 -5
  74. package/lib/solution/VenueBooking/index.js +14 -50
  75. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  76. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  77. package/package.json +2 -2
  78. package/dist/modules/BookingContext/index.d.ts +0 -37
  79. package/dist/modules/BookingContext/index.js +0 -436
  80. package/dist/modules/BookingContext/types.d.ts +0 -102
  81. package/dist/modules/BookingContext/types.js +0 -51
  82. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  83. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -193
  84. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  85. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -137
  86. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  87. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -215
  88. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  89. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  90. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  91. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  92. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  93. package/dist/modules/BookingContext/utils/index.js +0 -11
  94. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  95. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  96. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  97. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  98. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  99. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  100. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  101. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  102. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  103. package/dist/modules/BookingContext/utils/resources.js +0 -486
  104. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  105. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  106. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  107. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  108. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  109. package/dist/modules/Order/utils/manualProductDiscount.js +0 -212
  110. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  111. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -159
  112. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  113. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  114. package/lib/modules/BookingContext/index.d.ts +0 -37
  115. package/lib/modules/BookingContext/index.js +0 -297
  116. package/lib/modules/BookingContext/types.d.ts +0 -102
  117. package/lib/modules/BookingContext/types.js +0 -34
  118. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  119. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -207
  120. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  121. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -141
  122. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  123. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -198
  124. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  125. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  126. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  127. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  128. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  129. package/lib/modules/BookingContext/utils/index.js +0 -43
  130. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  131. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  132. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  133. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  134. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  135. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  136. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  137. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  138. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  139. package/lib/modules/BookingContext/utils/resources.js +0 -377
  140. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  141. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  142. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  143. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  144. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  145. package/lib/modules/Order/utils/manualProductDiscount.js +0 -207
  146. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  147. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -201
  148. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  149. package/lib/solution/BookingTicket/utils/addProductDecision.js +0 -318
@@ -38,7 +38,6 @@ var import_utils = require("./utils");
38
38
  var import_utils2 = require("../Product/utils");
39
39
  var import_dayjs = __toESM(require("dayjs"));
40
40
  var import_utils3 = require("../../solution/ScanOrder/utils");
41
- var import_manualProductDiscount = require("./utils/manualProductDiscount");
42
41
  var import_Discount = require("../Discount");
43
42
  var import_Rules = require("../Rules");
44
43
  var import_types2 = require("../Rules/types");
@@ -175,25 +174,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
175
174
  }
176
175
  // ─── Discount: 公共 API ───
177
176
  async loadDiscountConfig(params) {
178
- var _a, _b, _c, _d, _e, _f;
179
- const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
180
- const discountList = await ((_b = this.store.discount) == null ? void 0 : _b.loadPrepareConfig({
177
+ var _a, _b, _c, _d;
178
+ const discountList = await ((_a = this.store.discount) == null ? void 0 : _a.loadPrepareConfig({
181
179
  customer_id: params.customerId,
182
- action: params.action || (orderId ? "edit" : "create"),
180
+ action: params.action || "create",
183
181
  with_good_pass: 1,
184
182
  with_discount_card: 1,
185
183
  with_wallet_pass_holder: 1,
186
- request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
187
- ...orderId ? { order_id: orderId } : {}
184
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
188
185
  }));
189
186
  if (discountList) {
190
- await ((_c = this.store.discount) == null ? void 0 : _c.setOriginalDiscountList(discountList));
191
- await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(discountList));
187
+ (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(discountList);
192
188
  }
193
- if (params.apply !== false && ((_f = (_e = this.store.tempOrder) == null ? void 0 : _e.products) == null ? void 0 : _f.length)) {
189
+ if ((_d = (_c = this.store.tempOrder) == null ? void 0 : _c.products) == null ? void 0 : _d.length) {
194
190
  this.applyDiscount();
195
191
  }
196
- return this.getDiscountList();
197
192
  }
198
193
  getDiscountList() {
199
194
  var _a;
@@ -201,14 +196,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
201
196
  }
202
197
  async scanCode(code, customerId) {
203
198
  var _a, _b, _c, _d, _e;
204
- const resultDiscountList = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || [];
199
+ const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
200
+ const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
205
201
  const rulesModule = this.store.rules;
206
202
  if (!rulesModule) {
207
203
  return {
208
204
  type: "clientCalc",
209
205
  isAvailable: false,
210
206
  discountList: this.getDiscountList(),
211
- scannedDiscountList: resultDiscountList,
212
207
  unavailableReason: import_types2.UnavailableReason.Unknown
213
208
  };
214
209
  }
@@ -217,7 +212,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
217
212
  type: "server",
218
213
  isAvailable: false,
219
214
  discountList: this.getDiscountList(),
220
- scannedDiscountList: resultDiscountList
215
+ unavailableReasonKey
221
216
  };
222
217
  }
223
218
  const withScanList = resultDiscountList.map((item) => ({
@@ -229,8 +224,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
229
224
  return {
230
225
  type: "clientCalc",
231
226
  isAvailable: true,
232
- discountList: this.getDiscountList(),
233
- scannedDiscountList: resultDiscountList
227
+ discountList: this.getDiscountList()
234
228
  };
235
229
  }
236
230
  const tempOrder = this.store.tempOrder;
@@ -251,7 +245,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
251
245
  type: "clientCalc",
252
246
  isAvailable: isAvailable || false,
253
247
  discountList: newDiscountList || this.getDiscountList(),
254
- scannedDiscountList: resultDiscountList,
255
248
  unavailableReason
256
249
  };
257
250
  }
@@ -273,13 +266,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
273
266
  orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
274
267
  });
275
268
  if (result == null ? void 0 : result.productList) {
276
- tempOrder.products = (result.productList || []).map((product) => ({
277
- ...product,
278
- discount_list: (0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
279
- product.discount_list,
280
- product.num
281
- )
282
- }));
269
+ tempOrder.products = result.productList;
283
270
  }
284
271
  if (result == null ? void 0 : result.discountList) {
285
272
  OrderModule.populateSavedAmounts(
@@ -506,9 +493,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
506
493
  });
507
494
  }
508
495
  }
509
- saveDraftInBackground() {
510
- void this.saveDraft();
511
- }
512
496
  async hydrateTempOrderFromLocalRecord(record) {
513
497
  return this.hydrateTempOrderFromRecord(record);
514
498
  }
@@ -575,43 +559,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
575
559
  return newOrder;
576
560
  }
577
561
  restoreOrder() {
578
- var _a, _b;
579
562
  const freshTempOrder = this.createDefaultTempOrderInstance();
580
563
  this.ensureExternalSaleNumber(freshTempOrder);
581
564
  this.store.tempOrder = freshTempOrder;
582
565
  this.store.summary = (0, import_utils.createEmptySummary)();
583
566
  this.store.lastOrderInfo = void 0;
584
- this.store.syncState = void 0;
585
- void ((_a = this.store.discount) == null ? void 0 : _a.setOriginalDiscountList([]));
586
- void ((_b = this.store.discount) == null ? void 0 : _b.setDiscountList([]));
587
567
  this.persistTempOrder();
588
568
  return freshTempOrder;
589
569
  }
590
570
  getTempOrder() {
591
571
  return this.store.tempOrder;
592
572
  }
593
- async replaceTempOrder(tempOrder, options) {
594
- if (!(0, import_utils.isTempOrder)(tempOrder)) {
595
- throw new Error("无效的 tempOrder 数据");
596
- }
597
- const nextTempOrder = this.normalizeTempOrderForRuntime(
598
- (0, import_lodash_es.cloneDeep)(tempOrder),
599
- { ensureIdentity: false }
600
- );
601
- this.store.tempOrder = nextTempOrder;
602
- if ((options == null ? void 0 : options.recalculateSummary) !== false) {
603
- await this.recalculateSummary({ createIfMissing: false });
604
- } else {
605
- this.store.summary = (0, import_utils.createEmptySummary)();
606
- }
607
- if ((options == null ? void 0 : options.persist) !== false) {
608
- this.persistTempOrder();
609
- }
610
- if (options == null ? void 0 : options.saveDraft) {
611
- await this.saveDraft();
612
- }
613
- return nextTempOrder;
614
- }
615
573
  getOrderIdentity() {
616
574
  var _a;
617
575
  const tempOrder = this.store.tempOrder;
@@ -760,33 +718,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
760
718
  }
761
719
  };
762
720
  }
763
- getBookingUniqueIdentificationNumber(booking) {
764
- var _a;
765
- const uid = (_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.unique_identification_number;
766
- if (uid === void 0 || uid === null || uid === "")
767
- return null;
768
- return String(uid);
769
- }
770
- findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
771
- return (tempOrder.bookings || []).findIndex((booking) => {
772
- return this.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
773
- });
774
- }
775
- removeLinkedBookingsForProduct(tempOrder, product) {
776
- var _a, _b;
777
- const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
778
- const bookingUid = (product == null ? void 0 : product.booking_uid) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.booking_uid);
779
- if (!productUid && !bookingUid)
780
- return;
781
- tempOrder.bookings = (tempOrder.bookings || []).filter((booking) => {
782
- const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
783
- if (bookingUid && currentBookingUid === String(bookingUid))
784
- return false;
785
- if (productUid && String((booking == null ? void 0 : booking.product_uid) || "") === String(productUid))
786
- return false;
787
- return true;
788
- });
789
- }
790
721
  // ─── TempOrder: 金额汇总 ───
791
722
  getSalesSummary() {
792
723
  if (!this.salesSummaryModuleName)
@@ -846,22 +777,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
846
777
  this.persistTempOrder();
847
778
  return summary;
848
779
  }
849
- updateTempOrderNote(note, sync = false) {
780
+ // ─── TempOrder: 备注 ───
781
+ updateTempOrderNote(note) {
850
782
  const tempOrder = this.ensureTempOrder();
851
783
  tempOrder.note = String(note || "");
852
784
  this.persistTempOrder();
853
- if (sync) {
854
- const orderId = tempOrder.order_id;
855
- if (!orderId)
856
- return tempOrder.note;
857
- return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
858
- }
859
785
  return tempOrder.note;
860
786
  }
861
- async syncTempOrderNoteToRemote(orderId, note) {
862
- await this.request.put(`/order/order/${orderId}/note`, { note });
863
- return note;
864
- }
865
787
  getTempOrderNote() {
866
788
  var _a;
867
789
  return ((_a = this.store.tempOrder) == null ? void 0 : _a.note) || "";
@@ -885,29 +807,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
885
807
  this.persistTempOrder();
886
808
  return tempOrder.contacts_info;
887
809
  }
888
- buildTempOrderCustomer(params) {
889
- if (!params.customerId)
890
- return null;
891
- const source = params.source ? (0, import_lodash_es.cloneDeep)(params.source) : {};
892
- const name = source.name ?? source.display_name ?? source.customerName ?? source.customer_name ?? params.customerName;
893
- const customerName = source.customer_name ?? source.customerName ?? source.display_name ?? source.name ?? params.customerName;
894
- return {
895
- ...source,
896
- id: source.id ?? params.customerId,
897
- customer_id: source.customer_id ?? params.customerId,
898
- name: String(name || ""),
899
- customer_name: String(customerName || ""),
900
- country_calling_code: String(
901
- source.country_calling_code ?? source.countryCallingCode ?? params.countryCallingCode
902
- ),
903
- phone: String(source.phone ?? params.phone),
904
- email: String(source.email ?? params.email)
905
- };
906
- }
907
810
  /**
908
811
  * 更新当前 tempOrder 的客户协议字段。
909
812
  *
910
- * PaymentModal 只需要修改订单里的客户事实;如果外部还有客户模块需要同步,
813
+ * PaymentModal 只需要修改订单里的客户字段;如果外部还有客户模块需要同步,
911
814
  * 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
912
815
  */
913
816
  updateTempOrderCustomer(customer) {
@@ -921,14 +824,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
921
824
  );
922
825
  tempOrder.phone = String(customer.phone || "");
923
826
  tempOrder.email = String(customer.email || "");
924
- tempOrder.customer = this.buildTempOrderCustomer({
925
- source: customer,
926
- customerId: tempOrder.customer_id,
927
- customerName: tempOrder.customer_name,
928
- countryCallingCode: tempOrder.country_calling_code,
929
- phone: tempOrder.phone,
930
- email: tempOrder.email
931
- });
932
827
  this.persistTempOrder();
933
828
  return {
934
829
  customerId: tempOrder.customer_id,
@@ -948,14 +843,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
948
843
  tempOrder.country_calling_code = String(patch.country_calling_code || "");
949
844
  tempOrder.phone = String(patch.phone || "");
950
845
  tempOrder.email = String(patch.email || "");
951
- tempOrder.customer = this.buildTempOrderCustomer({
952
- source: snapshot || null,
953
- customerId: tempOrder.customer_id,
954
- customerName: tempOrder.customer_name,
955
- countryCallingCode: tempOrder.country_calling_code,
956
- phone: tempOrder.phone,
957
- email: tempOrder.email
958
- });
959
846
  if (snapshot !== void 0) {
960
847
  const extend = this.ensureExtend(tempOrder);
961
848
  if (snapshot === null)
@@ -964,12 +851,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
964
851
  extend.customerSnapshot = (0, import_lodash_es.cloneDeep)(snapshot);
965
852
  }
966
853
  this.persistTempOrder();
967
- this.saveDraftInBackground();
968
854
  this.emitOrderCustomerChange();
969
855
  }
970
856
  getOrderCustomer() {
971
857
  const tempOrder = this.store.tempOrder;
972
- if (!tempOrder || !tempOrder.customer_id) {
858
+ if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === void 0) {
973
859
  return null;
974
860
  }
975
861
  return {
@@ -992,11 +878,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
992
878
  tempOrder.country_calling_code = "";
993
879
  tempOrder.phone = "";
994
880
  tempOrder.email = "";
995
- tempOrder.customer = null;
996
881
  if (tempOrder._extend)
997
882
  delete tempOrder._extend.customerSnapshot;
998
883
  this.persistTempOrder();
999
- this.saveDraftInBackground();
1000
884
  this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
1001
885
  }
1002
886
  emitOrderCustomerChange() {
@@ -1036,9 +920,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1036
920
  }
1037
921
  /** 追加单个支付项,并立即持久化当前 tempOrder。 */
1038
922
  addOrderPayment(payment) {
1039
- this.logInfo("addOrderPayment", {
1040
- payment
1041
- });
1042
923
  const tempOrder = this.ensureTempOrder();
1043
924
  const mapped = (0, import_utils.mapPaymentItemsToOrderPayments)([payment]);
1044
925
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -1246,17 +1127,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1246
1127
  (item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
1247
1128
  );
1248
1129
  }
1249
- async updateOrderProduct(params) {
1250
- var _a, _b, _c, _d, _e, _f, _g;
1130
+ async updateProductInOrder(params) {
1131
+ var _a, _b, _c, _d, _e;
1251
1132
  const {
1252
1133
  product_id,
1253
1134
  product_variant_id,
1254
1135
  updates,
1255
1136
  unique_identification_number,
1256
- identity_key,
1257
1137
  product_option_item,
1258
- product_bundle,
1259
- booking
1138
+ product_bundle
1260
1139
  } = params;
1261
1140
  const tempOrder = this.ensureTempOrder();
1262
1141
  const identityLookup = {
@@ -1265,30 +1144,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1265
1144
  };
1266
1145
  if (unique_identification_number !== void 0) {
1267
1146
  identityLookup.unique_identification_number = unique_identification_number;
1268
- if (identity_key === void 0) {
1269
- identityLookup.identity_key = unique_identification_number;
1270
- }
1271
- }
1272
- if (identity_key !== void 0) {
1273
- identityLookup.identity_key = identity_key;
1274
1147
  }
1275
1148
  if (product_option_item !== void 0)
1276
1149
  identityLookup.product_option_item = product_option_item;
1277
1150
  if (product_bundle !== void 0)
1278
1151
  identityLookup.product_bundle = product_bundle;
1279
- let productIndex = -1;
1280
- if (unique_identification_number !== void 0) {
1281
- const targetUid = String(unique_identification_number);
1282
- productIndex = tempOrder.products.findIndex((item) => {
1283
- var _a2;
1284
- return String(
1285
- ((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
1286
- ) === targetUid;
1287
- });
1288
- }
1289
- if (productIndex === -1) {
1290
- productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1291
- }
1152
+ const productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1292
1153
  if (productIndex === -1) {
1293
1154
  throw new Error("[Order] 目标商品不存在,无法更新");
1294
1155
  }
@@ -1315,169 +1176,28 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1315
1176
  delete nextProduct.metadata.main_product_original_price;
1316
1177
  delete nextProduct.metadata.price_schema_version;
1317
1178
  }
1318
- let normalizedProduct = (0, import_utils3.normalizeOrderProduct)(nextProduct);
1319
- if (booking) {
1320
- const productUid = String(
1321
- ((_e = normalizedProduct.metadata) == null ? void 0 : _e.unique_identification_number) || ((_f = targetProduct.metadata) == null ? void 0 : _f.unique_identification_number) || unique_identification_number || (0, import_utils.createUuidV4)()
1322
- );
1323
- normalizedProduct.metadata = {
1324
- ...normalizedProduct.metadata || {},
1325
- unique_identification_number: productUid
1326
- };
1327
- const linked = this.createLinkedProductAndBooking({
1328
- product: {
1329
- ...normalizedProduct,
1330
- unique_identification_number: productUid
1331
- },
1332
- booking
1333
- });
1334
- this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
1335
- normalizedProduct = {
1336
- ...normalizedProduct,
1337
- booking_uid: linked.bookingUid,
1338
- metadata: {
1339
- ...normalizedProduct.metadata || {},
1340
- booking_uid: linked.bookingUid,
1341
- unique_identification_number: productUid
1342
- }
1343
- };
1344
- tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
1345
- }
1346
- tempOrder.products[productIndex] = normalizedProduct;
1179
+ tempOrder.products[productIndex] = (0, import_utils3.normalizeOrderProduct)(nextProduct);
1347
1180
  this.captureProductRuntime(
1348
1181
  tempOrder,
1349
1182
  updates,
1350
1183
  tempOrder.products[productIndex],
1351
- (_g = tempOrder.products[productIndex].metadata) == null ? void 0 : _g.unique_identification_number
1184
+ (_e = tempOrder.products[productIndex].metadata) == null ? void 0 : _e.unique_identification_number
1352
1185
  );
1353
1186
  this.applyDiscount();
1354
1187
  await this.recalculateSummary({ createIfMissing: true });
1355
1188
  this.persistTempOrder();
1356
1189
  return tempOrder.products;
1357
1190
  }
1358
- async updateOrderProductQuantity(params) {
1359
- var _a;
1360
- const {
1361
- product_id,
1362
- product_variant_id,
1363
- num,
1364
- unique_identification_number,
1365
- identity_key,
1366
- product_option_item,
1367
- product_bundle
1368
- } = params;
1369
- const tempOrder = this.ensureTempOrder();
1370
- const identityLookup = {
1371
- product_id,
1372
- product_variant_id
1373
- };
1374
- if (unique_identification_number !== void 0) {
1375
- identityLookup.unique_identification_number = unique_identification_number;
1376
- if (identity_key === void 0) {
1377
- identityLookup.identity_key = unique_identification_number;
1378
- }
1379
- }
1380
- if (identity_key !== void 0)
1381
- identityLookup.identity_key = identity_key;
1382
- if (product_option_item !== void 0)
1383
- identityLookup.product_option_item = product_option_item;
1384
- if (product_bundle !== void 0)
1385
- identityLookup.product_bundle = product_bundle;
1386
- let productIndex = -1;
1387
- if (unique_identification_number !== void 0) {
1388
- const targetUid = String(unique_identification_number);
1389
- productIndex = tempOrder.products.findIndex((item) => {
1390
- var _a2;
1391
- return String(
1392
- ((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
1393
- ) === targetUid;
1394
- });
1395
- }
1396
- if (productIndex === -1) {
1397
- productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1398
- }
1399
- if (productIndex === -1) {
1400
- throw new Error("[Order] 目标商品不存在,无法更新数量");
1401
- }
1402
- const targetProduct = tempOrder.products[productIndex];
1403
- const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
1404
- ...targetProduct,
1405
- num: (0, import_utils3.getSafeProductNum)(num),
1406
- metadata: {
1407
- ...targetProduct.metadata || {},
1408
- unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
1409
- }
1410
- });
1411
- tempOrder.products[productIndex] = normalizedProduct;
1412
- this.applyDiscount();
1413
- await this.recalculateSummary({ createIfMissing: true });
1414
- this.persistTempOrder();
1415
- return tempOrder.products;
1416
- }
1417
- updateOrderBooking(params) {
1418
- const { unique_identification_number, updates } = params;
1419
- const tempOrder = this.ensureTempOrder();
1420
- const bookingUid = String(unique_identification_number || "");
1421
- const bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(
1422
- tempOrder,
1423
- bookingUid
1424
- );
1425
- if (!bookingUid || bookingIndex === -1) {
1426
- throw new Error("[Order] 目标 booking 不存在,无法更新");
1427
- }
1428
- const targetBooking = tempOrder.bookings[bookingIndex] || {};
1429
- const nextBooking = {
1430
- ...targetBooking,
1431
- ...updates,
1432
- metadata: {
1433
- ...targetBooking.metadata || {},
1434
- ...updates.metadata || {},
1435
- unique_identification_number: bookingUid
1436
- }
1437
- };
1438
- nextBooking.is_all = (0, import_utils.normalizeBookingIsAll)(nextBooking);
1439
- nextBooking.sub_type = (0, import_utils.normalizeBookingSubType)(nextBooking);
1440
- tempOrder.bookings[bookingIndex] = nextBooking;
1441
- this.persistTempOrder();
1442
- return tempOrder.bookings;
1443
- }
1444
1191
  async removeProductFromOrder(identity) {
1445
1192
  const tempOrder = this.ensureTempOrder();
1446
- const removedProducts = [];
1447
- tempOrder.products = tempOrder.products.filter((item) => {
1448
- const shouldRemove = (0, import_utils3.isIdentityMatch)(item, identity);
1449
- if (shouldRemove)
1450
- removedProducts.push(item);
1451
- return !shouldRemove;
1452
- });
1453
- for (const product of removedProducts) {
1454
- this.removeLinkedBookingsForProduct(tempOrder, product);
1455
- }
1193
+ tempOrder.products = tempOrder.products.filter(
1194
+ (item) => !(0, import_utils3.isIdentityMatch)(item, identity)
1195
+ );
1456
1196
  this.applyDiscount();
1457
1197
  await this.recalculateSummary({ createIfMissing: true });
1458
1198
  this.persistTempOrder();
1459
1199
  return tempOrder.products;
1460
1200
  }
1461
- /**
1462
- * 仅清空购物车行(products / bookings / discount_list),不重置整单。
1463
- * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
1464
- */
1465
- async clearOrderCartLines() {
1466
- const tempOrder = this.ensureTempOrder();
1467
- tempOrder.products = [];
1468
- tempOrder.bookings = [];
1469
- tempOrder.discount_list = [];
1470
- if (tempOrder._extend && typeof tempOrder._extend === "object") {
1471
- tempOrder._extend = {
1472
- ...tempOrder._extend,
1473
- productsByUid: {}
1474
- };
1475
- }
1476
- this.applyDiscount();
1477
- await this.recalculateSummary({ createIfMissing: true });
1478
- this.persistTempOrder();
1479
- return tempOrder;
1480
- }
1481
1201
  // ─── TempOrder: 提交 ───
1482
1202
  /**
1483
1203
  * 提交当前 Sales tempOrder。
@@ -1607,26 +1327,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1607
1327
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
1608
1328
  params.payments || []
1609
1329
  );
1610
- const paymentTotal = this.calculatePaymentTotal(mappedPayments);
1611
- const targetAmount = this.getPaymentTargetAmount();
1612
- const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
1613
- const paymentStatus = isFullyPaid ? params.paymentStatus || "paid" : "partially_paid";
1614
1330
  tempOrder.payments = mappedPayments;
1615
- tempOrder.payment_status = paymentStatus;
1331
+ if (params.paymentStatus)
1332
+ tempOrder.payment_status = params.paymentStatus;
1616
1333
  this.persistTempOrder();
1617
1334
  await this.saveDraft();
1618
- if (!params.submitWhenPaid) {
1619
- return { isFullyPaid };
1620
- }
1621
- if (this.store.syncState === "submitting") {
1335
+ const paymentTotal = this.calculatePaymentTotal(mappedPayments);
1336
+ const targetAmount = this.getPaymentTargetAmount();
1337
+ const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
1338
+ if (!isFullyPaid || !params.submitWhenPaid) {
1622
1339
  return { isFullyPaid };
1623
1340
  }
1624
- this.store.syncState = "submitting";
1625
1341
  const submitResult = await this.submitTempOrder({
1626
1342
  payments: mappedPayments,
1627
- paymentStatus,
1628
- smallTicketDataFlag: params.smallTicketDataFlag,
1629
- channel: params.channel
1343
+ paymentStatus: params.paymentStatus || "paid",
1344
+ smallTicketDataFlag: params.smallTicketDataFlag
1630
1345
  });
1631
1346
  return { isFullyPaid, submitResult };
1632
1347
  }
@@ -1926,25 +1641,53 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1926
1641
  */
1927
1642
  async hydrateTempOrderFromRecord(record, options) {
1928
1643
  const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
1929
- const nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
1930
- ensureIdentity: true
1931
- });
1932
- this.store.tempOrder = nextTempOrder;
1933
- this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
1934
- this.store.lastOrderInfo = raw.lastOrderInfo || raw;
1935
- if (options == null ? void 0 : options.recalcOnHydrate) {
1936
- await this.recalculateSummary({ createIfMissing: false });
1937
- }
1938
- this.persistTempOrder();
1939
- return nextTempOrder;
1940
- }
1941
- normalizeTempOrderForRuntime(raw, options) {
1644
+ const defaults = this.createDefaultTempOrderInstance();
1942
1645
  const nextTempOrder = {
1943
- ...this.createDefaultTempOrderInstance(),
1944
- ...raw || {}
1646
+ ...defaults
1945
1647
  };
1946
- delete nextTempOrder.summary;
1947
- delete nextTempOrder.lastOrderInfo;
1648
+ const TEMP_ORDER_KEYS = [
1649
+ "order_id",
1650
+ "external_sale_number",
1651
+ "order_number",
1652
+ "shop_order_number",
1653
+ "shop_full_order_number",
1654
+ "type",
1655
+ "business_code",
1656
+ "platform",
1657
+ "sales_channel",
1658
+ "order_sales_channel",
1659
+ "status",
1660
+ "payment_status",
1661
+ "shipping_status",
1662
+ "customer_id",
1663
+ "customer_name",
1664
+ "country_calling_code",
1665
+ "phone",
1666
+ "email",
1667
+ "customer",
1668
+ "is_price_include_tax",
1669
+ "tax_title",
1670
+ "tax_country_code",
1671
+ "currency_code",
1672
+ "currency_symbol",
1673
+ "currency_format",
1674
+ "is_deposit",
1675
+ "deposit_amount",
1676
+ "shop_discount",
1677
+ "surcharge_fee",
1678
+ "note",
1679
+ "buzzer",
1680
+ "delivery_type",
1681
+ "table_number",
1682
+ "schedule_date",
1683
+ "created_at",
1684
+ "request_unique_idempotency_token"
1685
+ ];
1686
+ TEMP_ORDER_KEYS.forEach((key) => {
1687
+ if (raw[key] !== void 0) {
1688
+ nextTempOrder[key] = raw[key];
1689
+ }
1690
+ });
1948
1691
  nextTempOrder.metadata = raw.metadata && typeof raw.metadata === "object" ? { ...raw.metadata } : {};
1949
1692
  nextTempOrder.holder = raw.holder && typeof raw.holder === "object" ? { ...raw.holder } : null;
1950
1693
  nextTempOrder.products = Array.isArray(raw.products) ? raw.products.map((p) => this.normalizeHydratedOrderProduct(p)) : [];
@@ -1963,9 +1706,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1963
1706
  ...raw._extend,
1964
1707
  productsByUid: raw._extend.productsByUid || {}
1965
1708
  } : { productsByUid: {} };
1966
- if ((options == null ? void 0 : options.ensureIdentity) !== false) {
1967
- this.ensureExternalSaleNumber(nextTempOrder);
1709
+ this.ensureExternalSaleNumber(nextTempOrder);
1710
+ this.store.tempOrder = nextTempOrder;
1711
+ this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
1712
+ this.store.lastOrderInfo = raw.lastOrderInfo || raw;
1713
+ if (options == null ? void 0 : options.recalcOnHydrate) {
1714
+ await this.recalculateSummary({ createIfMissing: false });
1968
1715
  }
1716
+ this.persistTempOrder();
1969
1717
  return nextTempOrder;
1970
1718
  }
1971
1719
  normalizeHydratedOrderProduct(product) {