@pisell/pisellos 2.2.173 → 2.2.175

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 (159) 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 +17 -33
  9. package/dist/modules/Order/index.js +395 -757
  10. package/dist/modules/Order/types.d.ts +17 -58
  11. package/dist/modules/Order/types.js +0 -2
  12. package/dist/modules/Order/utils.d.ts +1 -39
  13. package/dist/modules/Order/utils.js +31 -219
  14. package/dist/modules/Quotation/index.js +5 -16
  15. package/dist/modules/Rules/index.d.ts +0 -4
  16. package/dist/modules/Rules/index.js +10 -26
  17. package/dist/modules/SalesSummary/index.js +2 -4
  18. package/dist/modules/Schedule/index.js +2 -6
  19. package/dist/modules/index.d.ts +0 -1
  20. package/dist/modules/index.js +1 -2
  21. package/dist/server/index.js +6 -10
  22. package/dist/server/modules/order/utils/filterOrders.js +6 -20
  23. package/dist/server/modules/products/index.js +94 -113
  24. package/dist/server/modules/schedule/index.js +6 -13
  25. package/dist/solution/BaseSales/index.d.ts +7 -53
  26. package/dist/solution/BaseSales/index.js +339 -1160
  27. package/dist/solution/BaseSales/types.d.ts +1 -67
  28. package/dist/solution/BaseSales/types.js +1 -3
  29. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +15 -65
  30. package/dist/solution/BaseSales/utils.js +8 -46
  31. package/dist/solution/BookingByStep/index.d.ts +1 -1
  32. package/dist/solution/BookingTicket/index.d.ts +1 -133
  33. package/dist/solution/BookingTicket/index.js +175 -776
  34. package/dist/solution/BookingTicket/types.d.ts +0 -2
  35. package/dist/solution/BookingTicket/types.js +0 -3
  36. package/dist/solution/ScanOrder/index.d.ts +3 -9
  37. package/dist/solution/ScanOrder/index.js +128 -231
  38. package/dist/solution/ScanOrder/utils.js +8 -46
  39. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  40. package/dist/solution/ShopDiscount/index.js +23 -18
  41. package/dist/solution/VenueBooking/index.d.ts +9 -5
  42. package/dist/solution/VenueBooking/index.js +55 -103
  43. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  44. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -10
  45. package/lib/modules/Customer/index.d.ts +0 -6
  46. package/lib/modules/Customer/index.js +11 -26
  47. package/lib/modules/Customer/types.d.ts +0 -2
  48. package/lib/modules/Discount/index.d.ts +4 -2
  49. package/lib/modules/Discount/index.js +63 -8
  50. package/lib/modules/Discount/types.d.ts +7 -1
  51. package/lib/modules/Order/index.d.ts +17 -33
  52. package/lib/modules/Order/index.js +148 -402
  53. package/lib/modules/Order/types.d.ts +17 -58
  54. package/lib/modules/Order/utils.d.ts +1 -39
  55. package/lib/modules/Order/utils.js +22 -197
  56. package/lib/modules/Quotation/index.js +6 -17
  57. package/lib/modules/Rules/index.d.ts +0 -4
  58. package/lib/modules/Rules/index.js +14 -22
  59. package/lib/modules/SalesSummary/index.js +2 -4
  60. package/lib/modules/Schedule/index.js +1 -3
  61. package/lib/modules/index.d.ts +0 -1
  62. package/lib/modules/index.js +1 -3
  63. package/lib/server/index.js +0 -2
  64. package/lib/server/modules/order/utils/filterOrders.js +4 -12
  65. package/lib/server/modules/products/index.js +12 -23
  66. package/lib/server/modules/schedule/index.js +1 -2
  67. package/lib/solution/BaseSales/index.d.ts +7 -53
  68. package/lib/solution/BaseSales/index.js +20 -527
  69. package/lib/solution/BaseSales/types.d.ts +1 -67
  70. package/lib/solution/BaseSales/types.js +1 -3
  71. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +11 -70
  72. package/lib/solution/BaseSales/utils.js +6 -46
  73. package/lib/solution/BookingByStep/index.d.ts +1 -1
  74. package/lib/solution/BookingTicket/index.d.ts +1 -133
  75. package/lib/solution/BookingTicket/index.js +8 -349
  76. package/lib/solution/BookingTicket/types.d.ts +0 -2
  77. package/lib/solution/BookingTicket/types.js +0 -6
  78. package/lib/solution/ScanOrder/index.d.ts +3 -9
  79. package/lib/solution/ScanOrder/index.js +66 -147
  80. package/lib/solution/ScanOrder/utils.js +6 -46
  81. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  82. package/lib/solution/ShopDiscount/index.js +4 -2
  83. package/lib/solution/VenueBooking/index.d.ts +9 -5
  84. package/lib/solution/VenueBooking/index.js +14 -50
  85. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -4
  86. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -10
  87. package/package.json +2 -2
  88. package/dist/modules/BookingContext/index.d.ts +0 -37
  89. package/dist/modules/BookingContext/index.js +0 -436
  90. package/dist/modules/BookingContext/types.d.ts +0 -102
  91. package/dist/modules/BookingContext/types.js +0 -51
  92. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  93. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -193
  94. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  95. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -137
  96. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  97. package/dist/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -215
  98. package/dist/modules/BookingContext/utils/flexible.d.ts +0 -28
  99. package/dist/modules/BookingContext/utils/flexible.js +0 -56
  100. package/dist/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  101. package/dist/modules/BookingContext/utils/formatResourceList.js +0 -38
  102. package/dist/modules/BookingContext/utils/index.d.ts +0 -11
  103. package/dist/modules/BookingContext/utils/index.js +0 -11
  104. package/dist/modules/BookingContext/utils/noResource.d.ts +0 -13
  105. package/dist/modules/BookingContext/utils/noResource.js +0 -77
  106. package/dist/modules/BookingContext/utils/productExtend.d.ts +0 -72
  107. package/dist/modules/BookingContext/utils/productExtend.js +0 -339
  108. package/dist/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  109. package/dist/modules/BookingContext/utils/resourceErrors.js +0 -74
  110. package/dist/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  111. package/dist/modules/BookingContext/utils/resourceSelection.js +0 -24
  112. package/dist/modules/BookingContext/utils/resources.d.ts +0 -80
  113. package/dist/modules/BookingContext/utils/resources.js +0 -486
  114. package/dist/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  115. package/dist/modules/BookingContext/utils/serviceTimes.js +0 -151
  116. package/dist/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  117. package/dist/modules/BookingContext/utils/timeSlices.js +0 -100
  118. package/dist/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  119. package/dist/modules/Order/utils/manualProductDiscount.js +0 -212
  120. package/dist/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  121. package/dist/solution/BaseSales/utils/quotationPrice.js +0 -237
  122. package/dist/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  123. package/dist/solution/BookingTicket/utils/addProductDecision.js +0 -346
  124. package/lib/modules/BookingContext/index.d.ts +0 -37
  125. package/lib/modules/BookingContext/index.js +0 -297
  126. package/lib/modules/BookingContext/types.d.ts +0 -102
  127. package/lib/modules/BookingContext/types.js +0 -34
  128. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.d.ts +0 -16
  129. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +0 -207
  130. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.d.ts +0 -8
  131. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +0 -141
  132. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.d.ts +0 -75
  133. package/lib/modules/BookingContext/utils/cacheItemToBookingInput.js +0 -198
  134. package/lib/modules/BookingContext/utils/flexible.d.ts +0 -28
  135. package/lib/modules/BookingContext/utils/flexible.js +0 -80
  136. package/lib/modules/BookingContext/utils/formatResourceList.d.ts +0 -8
  137. package/lib/modules/BookingContext/utils/formatResourceList.js +0 -50
  138. package/lib/modules/BookingContext/utils/index.d.ts +0 -11
  139. package/lib/modules/BookingContext/utils/index.js +0 -43
  140. package/lib/modules/BookingContext/utils/noResource.d.ts +0 -13
  141. package/lib/modules/BookingContext/utils/noResource.js +0 -90
  142. package/lib/modules/BookingContext/utils/productExtend.d.ts +0 -72
  143. package/lib/modules/BookingContext/utils/productExtend.js +0 -283
  144. package/lib/modules/BookingContext/utils/resourceErrors.d.ts +0 -41
  145. package/lib/modules/BookingContext/utils/resourceErrors.js +0 -80
  146. package/lib/modules/BookingContext/utils/resourceSelection.d.ts +0 -7
  147. package/lib/modules/BookingContext/utils/resourceSelection.js +0 -46
  148. package/lib/modules/BookingContext/utils/resources.d.ts +0 -80
  149. package/lib/modules/BookingContext/utils/resources.js +0 -377
  150. package/lib/modules/BookingContext/utils/serviceTimes.d.ts +0 -55
  151. package/lib/modules/BookingContext/utils/serviceTimes.js +0 -162
  152. package/lib/modules/BookingContext/utils/timeSlices.d.ts +0 -42
  153. package/lib/modules/BookingContext/utils/timeSlices.js +0 -124
  154. package/lib/modules/Order/utils/manualProductDiscount.d.ts +0 -106
  155. package/lib/modules/Order/utils/manualProductDiscount.js +0 -207
  156. package/lib/solution/BaseSales/utils/quotationPrice.d.ts +0 -7
  157. package/lib/solution/BaseSales/utils/quotationPrice.js +0 -277
  158. package/lib/solution/BookingTicket/utils/addProductDecision.d.ts +0 -113
  159. 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");
@@ -76,30 +75,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
76
75
  d.savedAmount = d.isSelected && key != null && savedMap.has(key) ? savedMap.get(key).toNumber() : 0;
77
76
  }
78
77
  }
79
- applyProductDiscountPrices(products) {
80
- return (products || []).map((product) => {
81
- var _a, _b, _c;
82
- if ((_a = product.metadata) == null ? void 0 : _a.is_manual_discount)
83
- return product;
84
- const totalPerUnitDiscount = (product.discount_list || []).reduce(
85
- (sum, discount) => sum + Number(discount.amount || 0),
86
- 0
87
- );
88
- const optionSum = (0, import_utils.sumOptionUnitPrice)(product.product_option_item);
89
- const sourcePrice = ((_b = product.metadata) == null ? void 0 : _b.source_product_price) ?? (((_c = product.metadata) == null ? void 0 : _c.main_product_original_price) != null ? new import_decimal.default(Number(product.metadata.main_product_original_price) || 0).minus(optionSum).toFixed(2) : product.original_price ?? "0");
90
- const newSourceSellingPrice = new import_decimal.default(Number(sourcePrice) || 0).minus(totalPerUnitDiscount).toDecimalPlaces(2).toString();
91
- const newMainSellingPrice = new import_decimal.default(Number(newSourceSellingPrice) || 0).plus(optionSum).toDecimalPlaces(2).toFixed(2);
92
- if (product.metadata) {
93
- product.metadata.main_product_selling_price = newMainSellingPrice;
94
- product.metadata.price_schema_version = 2;
95
- }
96
- product.selling_price = (0, import_utils.composeLinePrice)({
97
- mainPrice: newMainSellingPrice,
98
- bundle: product.product_bundle
99
- });
100
- return product;
101
- });
102
- }
103
78
  async initialize(core, options) {
104
79
  var _a, _b, _c;
105
80
  this.core = core;
@@ -126,6 +101,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
126
101
  this.orderHooks = options.hooks || ((_b = otherParams.order) == null ? void 0 : _b.hooks) || ((_c = otherParams.hooks) == null ? void 0 : _c.order);
127
102
  this.otherParams = otherParams;
128
103
  this.registerDiscountModules(options);
104
+ this.restoreTempOrderFromStorage();
129
105
  this.logInfo("OrderModule initialized successfully");
130
106
  }
131
107
  /**
@@ -198,25 +174,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
198
174
  }
199
175
  // ─── Discount: 公共 API ───
200
176
  async loadDiscountConfig(params) {
201
- var _a, _b, _c, _d, _e, _f;
202
- const orderId = params.orderId || ((_a = this.store.tempOrder) == null ? void 0 : _a.order_id) || void 0;
203
- 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({
204
179
  customer_id: params.customerId,
205
- action: params.action || (orderId ? "edit" : "create"),
180
+ action: params.action || "create",
206
181
  with_good_pass: 1,
207
182
  with_discount_card: 1,
208
183
  with_wallet_pass_holder: 1,
209
- request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone,
210
- ...orderId ? { order_id: orderId } : {}
184
+ request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
211
185
  }));
212
186
  if (discountList) {
213
- await ((_c = this.store.discount) == null ? void 0 : _c.setOriginalDiscountList(discountList));
214
- await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(discountList));
187
+ (_b = this.store.discount) == null ? void 0 : _b.setDiscountList(discountList);
215
188
  }
216
- 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) {
217
190
  this.applyDiscount();
218
191
  }
219
- return this.getDiscountList();
220
192
  }
221
193
  getDiscountList() {
222
194
  var _a;
@@ -224,14 +196,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
224
196
  }
225
197
  async scanCode(code, customerId) {
226
198
  var _a, _b, _c, _d, _e;
227
- 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;
228
201
  const rulesModule = this.store.rules;
229
202
  if (!rulesModule) {
230
203
  return {
231
204
  type: "clientCalc",
232
205
  isAvailable: false,
233
206
  discountList: this.getDiscountList(),
234
- scannedDiscountList: resultDiscountList,
235
207
  unavailableReason: import_types2.UnavailableReason.Unknown
236
208
  };
237
209
  }
@@ -240,7 +212,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
240
212
  type: "server",
241
213
  isAvailable: false,
242
214
  discountList: this.getDiscountList(),
243
- scannedDiscountList: resultDiscountList
215
+ unavailableReasonKey
244
216
  };
245
217
  }
246
218
  const withScanList = resultDiscountList.map((item) => ({
@@ -252,8 +224,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
252
224
  return {
253
225
  type: "clientCalc",
254
226
  isAvailable: true,
255
- discountList: this.getDiscountList(),
256
- scannedDiscountList: resultDiscountList
227
+ discountList: this.getDiscountList()
257
228
  };
258
229
  }
259
230
  const tempOrder = this.store.tempOrder;
@@ -274,7 +245,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
274
245
  type: "clientCalc",
275
246
  isAvailable: isAvailable || false,
276
247
  discountList: newDiscountList || this.getDiscountList(),
277
- scannedDiscountList: resultDiscountList,
278
248
  unavailableReason
279
249
  };
280
250
  }
@@ -283,7 +253,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
283
253
  const tempOrder = this.store.tempOrder;
284
254
  if (!tempOrder)
285
255
  return;
286
- delete tempOrder.discount_list;
287
256
  const rulesModule = this.store.rules;
288
257
  if (!rulesModule)
289
258
  return;
@@ -297,17 +266,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
297
266
  orderTotalAmount: Number(((_d = this.store.summary) == null ? void 0 : _d.total_amount) || 0)
298
267
  });
299
268
  if (result == null ? void 0 : result.productList) {
300
- tempOrder.products = this.applyProductDiscountPrices(
301
- (result.productList || []).map((product) => ({
302
- ...product,
303
- discount_list: (0, import_utils.normalizeOrderProductDiscountList)(
304
- (0, import_manualProductDiscount.syncManualProductDiscountProductNum)(
305
- product.discount_list,
306
- product.num
307
- )
308
- )
309
- }))
310
- );
269
+ tempOrder.products = result.productList;
311
270
  }
312
271
  if (result == null ? void 0 : result.discountList) {
313
272
  OrderModule.populateSavedAmounts(
@@ -315,6 +274,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
315
274
  result.discountList
316
275
  );
317
276
  (_e = this.store.discount) == null ? void 0 : _e.setDiscountList(result.discountList);
277
+ tempOrder.discount_list = result.discountList.filter(
278
+ (d) => d.isSelected
279
+ );
318
280
  }
319
281
  }
320
282
  // ─── TempOrder: 初始化入口 ───
@@ -323,16 +285,69 @@ var OrderModule = class extends import_BaseModule.BaseModule {
323
285
  this.cacheId = params.cacheId;
324
286
  if (params.salesSummaryModuleName !== void 0)
325
287
  this.salesSummaryModuleName = params.salesSummaryModuleName;
288
+ this.restoreTempOrderFromStorage();
326
289
  }
327
- /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
328
- setEnableTempOrderPersist(_enabled) {
290
+ // ─── TempOrder: localStorage 持久化 ───
291
+ getTempOrderStorageKey() {
292
+ if (!this.cacheId)
293
+ return null;
294
+ return `scanOrder:tempOrder:${this.cacheId}`;
329
295
  }
330
- /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化。 */
331
- isTempOrderPersistEnabled() {
332
- return false;
296
+ restoreTempOrderFromStorage() {
297
+ var _a, _b;
298
+ const key = this.getTempOrderStorageKey();
299
+ if (!key)
300
+ return;
301
+ if (!this.window)
302
+ return;
303
+ const cachedData = this.window.localStorage.getItem(key);
304
+ if (!cachedData)
305
+ return;
306
+ try {
307
+ const parsedData = JSON.parse(cachedData);
308
+ if (!(0, import_utils.isTempOrder)(parsedData)) {
309
+ this.window.localStorage.removeItem(key);
310
+ return;
311
+ }
312
+ if (Array.isArray(parsedData.products)) {
313
+ for (let i = 0; i < parsedData.products.length; i++) {
314
+ const p = parsedData.products[i];
315
+ if (!p || typeof p !== "object")
316
+ continue;
317
+ if (!Array.isArray(p.product_option_item)) {
318
+ p.product_option_item = [];
319
+ }
320
+ if (!Array.isArray(p.product_bundle)) {
321
+ p.product_bundle = [];
322
+ }
323
+ const row = p;
324
+ parsedData.products[i] = (0, import_utils3.normalizeOrderProduct)(row);
325
+ }
326
+ }
327
+ const parsedRecord = parsedData;
328
+ this.store.summary = parsedRecord.summary || (0, import_utils.createEmptySummary)();
329
+ delete parsedData.summary;
330
+ if (parsedRecord.lastOrderInfo) {
331
+ this.store.lastOrderInfo = parsedRecord.lastOrderInfo;
332
+ delete parsedData.lastOrderInfo;
333
+ }
334
+ if (!parsedData._extend || typeof parsedData._extend !== "object") {
335
+ parsedData._extend = { productsByUid: {} };
336
+ } else if (!parsedData._extend.productsByUid) {
337
+ parsedData._extend.productsByUid = {};
338
+ }
339
+ this.store.tempOrder = parsedData;
340
+ } catch {
341
+ (_b = (_a = this.window) == null ? void 0 : _a.localStorage) == null ? void 0 : _b.removeItem(key);
342
+ }
333
343
  }
334
- /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
335
344
  persistTempOrder() {
345
+ const key = this.getTempOrderStorageKey();
346
+ if (!key || !this.store.tempOrder)
347
+ return;
348
+ if (!this.window)
349
+ return;
350
+ this.window.localStorage.setItem(key, JSON.stringify(this.store.tempOrder));
336
351
  }
337
352
  // ─── TempOrder: 创建 & 获取 ───
338
353
  createDefaultTempOrderInstance() {
@@ -478,9 +493,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
478
493
  });
479
494
  }
480
495
  }
481
- saveDraftInBackground() {
482
- void this.saveDraft();
483
- }
484
496
  async hydrateTempOrderFromLocalRecord(record) {
485
497
  return this.hydrateTempOrderFromRecord(record);
486
498
  }
@@ -547,43 +559,17 @@ var OrderModule = class extends import_BaseModule.BaseModule {
547
559
  return newOrder;
548
560
  }
549
561
  restoreOrder() {
550
- var _a, _b;
551
562
  const freshTempOrder = this.createDefaultTempOrderInstance();
552
563
  this.ensureExternalSaleNumber(freshTempOrder);
553
564
  this.store.tempOrder = freshTempOrder;
554
565
  this.store.summary = (0, import_utils.createEmptySummary)();
555
566
  this.store.lastOrderInfo = void 0;
556
- this.store.syncState = void 0;
557
- void ((_a = this.store.discount) == null ? void 0 : _a.setOriginalDiscountList([]));
558
- void ((_b = this.store.discount) == null ? void 0 : _b.setDiscountList([]));
559
567
  this.persistTempOrder();
560
568
  return freshTempOrder;
561
569
  }
562
570
  getTempOrder() {
563
571
  return this.store.tempOrder;
564
572
  }
565
- async replaceTempOrder(tempOrder, options) {
566
- if (!(0, import_utils.isTempOrder)(tempOrder)) {
567
- throw new Error("无效的 tempOrder 数据");
568
- }
569
- const nextTempOrder = this.normalizeTempOrderForRuntime(
570
- (0, import_lodash_es.cloneDeep)(tempOrder),
571
- { ensureIdentity: false }
572
- );
573
- this.store.tempOrder = nextTempOrder;
574
- if ((options == null ? void 0 : options.recalculateSummary) !== false) {
575
- await this.recalculateSummary({ createIfMissing: false });
576
- } else {
577
- this.store.summary = (0, import_utils.createEmptySummary)();
578
- }
579
- if ((options == null ? void 0 : options.persist) !== false) {
580
- this.persistTempOrder();
581
- }
582
- if (options == null ? void 0 : options.saveDraft) {
583
- await this.saveDraft();
584
- }
585
- return nextTempOrder;
586
- }
587
573
  getOrderIdentity() {
588
574
  var _a;
589
575
  const tempOrder = this.store.tempOrder;
@@ -732,33 +718,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
732
718
  }
733
719
  };
734
720
  }
735
- getBookingUniqueIdentificationNumber(booking) {
736
- var _a;
737
- const uid = (_a = booking == null ? void 0 : booking.metadata) == null ? void 0 : _a.unique_identification_number;
738
- if (uid === void 0 || uid === null || uid === "")
739
- return null;
740
- return String(uid);
741
- }
742
- findBookingIndexByUniqueIdentificationNumber(tempOrder, uniqueIdentificationNumber) {
743
- return (tempOrder.bookings || []).findIndex((booking) => {
744
- return this.getBookingUniqueIdentificationNumber(booking) === uniqueIdentificationNumber;
745
- });
746
- }
747
- removeLinkedBookingsForProduct(tempOrder, product) {
748
- var _a, _b;
749
- const productUid = ((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.unique_identification_number) || (product == null ? void 0 : product.unique_identification_number);
750
- const bookingUid = (product == null ? void 0 : product.booking_uid) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.booking_uid);
751
- if (!productUid && !bookingUid)
752
- return;
753
- tempOrder.bookings = (tempOrder.bookings || []).filter((booking) => {
754
- const currentBookingUid = this.getBookingUniqueIdentificationNumber(booking);
755
- if (bookingUid && currentBookingUid === String(bookingUid))
756
- return false;
757
- if (productUid && String((booking == null ? void 0 : booking.product_uid) || "") === String(productUid))
758
- return false;
759
- return true;
760
- });
761
- }
762
721
  // ─── TempOrder: 金额汇总 ───
763
722
  getSalesSummary() {
764
723
  if (!this.salesSummaryModuleName)
@@ -818,22 +777,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
818
777
  this.persistTempOrder();
819
778
  return summary;
820
779
  }
821
- updateTempOrderNote(note, sync = false) {
780
+ // ─── TempOrder: 备注 ───
781
+ updateTempOrderNote(note) {
822
782
  const tempOrder = this.ensureTempOrder();
823
783
  tempOrder.note = String(note || "");
824
784
  this.persistTempOrder();
825
- if (sync) {
826
- const orderId = tempOrder.order_id;
827
- if (!orderId)
828
- return tempOrder.note;
829
- return this.syncTempOrderNoteToRemote(orderId, tempOrder.note);
830
- }
831
785
  return tempOrder.note;
832
786
  }
833
- async syncTempOrderNoteToRemote(orderId, note) {
834
- await this.request.put(`/order/order/${orderId}/note`, { note });
835
- return note;
836
- }
837
787
  getTempOrderNote() {
838
788
  var _a;
839
789
  return ((_a = this.store.tempOrder) == null ? void 0 : _a.note) || "";
@@ -857,29 +807,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
857
807
  this.persistTempOrder();
858
808
  return tempOrder.contacts_info;
859
809
  }
860
- buildTempOrderCustomer(params) {
861
- if (!params.customerId)
862
- return null;
863
- const source = params.source ? (0, import_lodash_es.cloneDeep)(params.source) : {};
864
- const name = source.name ?? source.display_name ?? source.customerName ?? source.customer_name ?? params.customerName;
865
- const customerName = source.customer_name ?? source.customerName ?? source.display_name ?? source.name ?? params.customerName;
866
- return {
867
- ...source,
868
- id: source.id ?? params.customerId,
869
- customer_id: source.customer_id ?? params.customerId,
870
- name: String(name || ""),
871
- customer_name: String(customerName || ""),
872
- country_calling_code: String(
873
- source.country_calling_code ?? source.countryCallingCode ?? params.countryCallingCode
874
- ),
875
- phone: String(source.phone ?? params.phone),
876
- email: String(source.email ?? params.email)
877
- };
878
- }
879
810
  /**
880
811
  * 更新当前 tempOrder 的客户协议字段。
881
812
  *
882
- * PaymentModal 只需要修改订单里的客户事实;如果外部还有客户模块需要同步,
813
+ * PaymentModal 只需要修改订单里的客户字段;如果外部还有客户模块需要同步,
883
814
  * 应由调用方通过回调处理,不能把外部 UI 状态写进 tempOrder。
884
815
  */
885
816
  updateTempOrderCustomer(customer) {
@@ -893,14 +824,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
893
824
  );
894
825
  tempOrder.phone = String(customer.phone || "");
895
826
  tempOrder.email = String(customer.email || "");
896
- tempOrder.customer = this.buildTempOrderCustomer({
897
- source: customer,
898
- customerId: tempOrder.customer_id,
899
- customerName: tempOrder.customer_name,
900
- countryCallingCode: tempOrder.country_calling_code,
901
- phone: tempOrder.phone,
902
- email: tempOrder.email
903
- });
904
827
  this.persistTempOrder();
905
828
  return {
906
829
  customerId: tempOrder.customer_id,
@@ -915,20 +838,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
915
838
  return;
916
839
  }
917
840
  const tempOrder = this.ensureTempOrder();
918
- const previousCustomerId = tempOrder.customer_id ?? null;
919
841
  tempOrder.customer_id = patch.customer_id || patch.id || null;
920
842
  tempOrder.customer_name = String(patch.customer_name || "");
921
843
  tempOrder.country_calling_code = String(patch.country_calling_code || "");
922
844
  tempOrder.phone = String(patch.phone || "");
923
845
  tempOrder.email = String(patch.email || "");
924
- tempOrder.customer = this.buildTempOrderCustomer({
925
- source: snapshot || null,
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
846
  if (snapshot !== void 0) {
933
847
  const extend = this.ensureExtend(tempOrder);
934
848
  if (snapshot === null)
@@ -936,17 +850,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
936
850
  else
937
851
  extend.customerSnapshot = (0, import_lodash_es.cloneDeep)(snapshot);
938
852
  }
939
- const nextCustomerId = tempOrder.customer_id ?? null;
940
- if (String(previousCustomerId ?? "") !== String(nextCustomerId ?? "")) {
941
- (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
942
- }
943
853
  this.persistTempOrder();
944
- this.saveDraftInBackground();
945
854
  this.emitOrderCustomerChange();
946
855
  }
947
856
  getOrderCustomer() {
948
857
  const tempOrder = this.store.tempOrder;
949
- if (!tempOrder || !tempOrder.customer_id) {
858
+ if (!tempOrder || tempOrder.customer_id === null || tempOrder.customer_id === void 0) {
950
859
  return null;
951
860
  }
952
861
  return {
@@ -964,17 +873,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
964
873
  }
965
874
  clearOrderCustomer() {
966
875
  const tempOrder = this.ensureTempOrder();
967
- (0, import_utils.clearTempOrderHolderAssignments)(tempOrder);
968
876
  tempOrder.customer_id = null;
969
877
  tempOrder.customer_name = "";
970
878
  tempOrder.country_calling_code = "";
971
879
  tempOrder.phone = "";
972
880
  tempOrder.email = "";
973
- tempOrder.customer = null;
974
881
  if (tempOrder._extend)
975
882
  delete tempOrder._extend.customerSnapshot;
976
883
  this.persistTempOrder();
977
- this.saveDraftInBackground();
978
884
  this.core.effects.emit(import_types.OrderHooks.OnOrderCustomerChange, null);
979
885
  }
980
886
  emitOrderCustomerChange() {
@@ -1014,9 +920,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1014
920
  }
1015
921
  /** 追加单个支付项,并立即持久化当前 tempOrder。 */
1016
922
  addOrderPayment(payment) {
1017
- this.logInfo("addOrderPayment", {
1018
- payment
1019
- });
1020
923
  const tempOrder = this.ensureTempOrder();
1021
924
  const mapped = (0, import_utils.mapPaymentItemsToOrderPayments)([payment]);
1022
925
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -1123,9 +1026,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1123
1026
  productToAdd.product_bundle
1124
1027
  );
1125
1028
  const normalizedIncoming = (0, import_utils3.normalizeOrderProduct)(productToAdd);
1126
- normalizedIncoming.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
1127
- normalizedIncoming.discount_list
1128
- );
1129
1029
  const hasIncomingGoodPass = this.hasGoodPassDiscount(
1130
1030
  normalizedIncoming
1131
1031
  );
@@ -1182,9 +1082,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1182
1082
  unique_identification_number: targetUid
1183
1083
  }
1184
1084
  });
1185
- normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
1186
- normalizedProduct.discount_list
1187
- );
1188
1085
  tempOrder.products[matchedIndex] = {
1189
1086
  ...targetProduct,
1190
1087
  ...normalizedProduct,
@@ -1230,17 +1127,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1230
1127
  (item) => (item == null ? void 0 : item.type) === "good_pass" || (item == null ? void 0 : item.tag) === "good_pass"
1231
1128
  );
1232
1129
  }
1233
- async updateOrderProduct(params) {
1234
- var _a, _b, _c, _d, _e, _f, _g;
1130
+ async updateProductInOrder(params) {
1131
+ var _a, _b, _c, _d, _e;
1235
1132
  const {
1236
1133
  product_id,
1237
1134
  product_variant_id,
1238
1135
  updates,
1239
1136
  unique_identification_number,
1240
- identity_key,
1241
1137
  product_option_item,
1242
- product_bundle,
1243
- booking
1138
+ product_bundle
1244
1139
  } = params;
1245
1140
  const tempOrder = this.ensureTempOrder();
1246
1141
  const identityLookup = {
@@ -1249,30 +1144,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1249
1144
  };
1250
1145
  if (unique_identification_number !== void 0) {
1251
1146
  identityLookup.unique_identification_number = unique_identification_number;
1252
- if (identity_key === void 0) {
1253
- identityLookup.identity_key = unique_identification_number;
1254
- }
1255
- }
1256
- if (identity_key !== void 0) {
1257
- identityLookup.identity_key = identity_key;
1258
1147
  }
1259
1148
  if (product_option_item !== void 0)
1260
1149
  identityLookup.product_option_item = product_option_item;
1261
1150
  if (product_bundle !== void 0)
1262
1151
  identityLookup.product_bundle = product_bundle;
1263
- let productIndex = -1;
1264
- if (unique_identification_number !== void 0) {
1265
- const targetUid = String(unique_identification_number);
1266
- productIndex = tempOrder.products.findIndex((item) => {
1267
- var _a2;
1268
- return String(
1269
- ((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
1270
- ) === targetUid;
1271
- });
1272
- }
1273
- if (productIndex === -1) {
1274
- productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1275
- }
1152
+ const productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1276
1153
  if (productIndex === -1) {
1277
1154
  throw new Error("[Order] 目标商品不存在,无法更新");
1278
1155
  }
@@ -1299,174 +1176,28 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1299
1176
  delete nextProduct.metadata.main_product_original_price;
1300
1177
  delete nextProduct.metadata.price_schema_version;
1301
1178
  }
1302
- let normalizedProduct = (0, import_utils3.normalizeOrderProduct)(nextProduct);
1303
- normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
1304
- normalizedProduct.discount_list
1305
- );
1306
- if (booking) {
1307
- const productUid = String(
1308
- ((_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)()
1309
- );
1310
- normalizedProduct.metadata = {
1311
- ...normalizedProduct.metadata || {},
1312
- unique_identification_number: productUid
1313
- };
1314
- const linked = this.createLinkedProductAndBooking({
1315
- product: {
1316
- ...normalizedProduct,
1317
- unique_identification_number: productUid
1318
- },
1319
- booking
1320
- });
1321
- this.removeLinkedBookingsForProduct(tempOrder, targetProduct);
1322
- normalizedProduct = {
1323
- ...normalizedProduct,
1324
- booking_uid: linked.bookingUid,
1325
- metadata: {
1326
- ...normalizedProduct.metadata || {},
1327
- booking_uid: linked.bookingUid,
1328
- unique_identification_number: productUid
1329
- }
1330
- };
1331
- tempOrder.bookings = [...tempOrder.bookings || [], linked.booking];
1332
- }
1333
- tempOrder.products[productIndex] = normalizedProduct;
1179
+ tempOrder.products[productIndex] = (0, import_utils3.normalizeOrderProduct)(nextProduct);
1334
1180
  this.captureProductRuntime(
1335
1181
  tempOrder,
1336
1182
  updates,
1337
1183
  tempOrder.products[productIndex],
1338
- (_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
1339
1185
  );
1340
1186
  this.applyDiscount();
1341
1187
  await this.recalculateSummary({ createIfMissing: true });
1342
1188
  this.persistTempOrder();
1343
1189
  return tempOrder.products;
1344
1190
  }
1345
- async updateOrderProductQuantity(params) {
1346
- var _a;
1347
- const {
1348
- product_id,
1349
- product_variant_id,
1350
- num,
1351
- unique_identification_number,
1352
- identity_key,
1353
- product_option_item,
1354
- product_bundle
1355
- } = params;
1356
- const tempOrder = this.ensureTempOrder();
1357
- const identityLookup = {
1358
- product_id,
1359
- product_variant_id
1360
- };
1361
- if (unique_identification_number !== void 0) {
1362
- identityLookup.unique_identification_number = unique_identification_number;
1363
- if (identity_key === void 0) {
1364
- identityLookup.identity_key = unique_identification_number;
1365
- }
1366
- }
1367
- if (identity_key !== void 0)
1368
- identityLookup.identity_key = identity_key;
1369
- if (product_option_item !== void 0)
1370
- identityLookup.product_option_item = product_option_item;
1371
- if (product_bundle !== void 0)
1372
- identityLookup.product_bundle = product_bundle;
1373
- let productIndex = -1;
1374
- if (unique_identification_number !== void 0) {
1375
- const targetUid = String(unique_identification_number);
1376
- productIndex = tempOrder.products.findIndex((item) => {
1377
- var _a2;
1378
- return String(
1379
- ((_a2 = item.metadata) == null ? void 0 : _a2.unique_identification_number) || item.unique_identification_number || ""
1380
- ) === targetUid;
1381
- });
1382
- }
1383
- if (productIndex === -1) {
1384
- productIndex = (0, import_utils3.getProductIdentityIndex)(tempOrder.products, identityLookup);
1385
- }
1386
- if (productIndex === -1) {
1387
- throw new Error("[Order] 目标商品不存在,无法更新数量");
1388
- }
1389
- const targetProduct = tempOrder.products[productIndex];
1390
- const normalizedProduct = (0, import_utils3.normalizeOrderProduct)({
1391
- ...targetProduct,
1392
- num: (0, import_utils3.getSafeProductNum)(num),
1393
- metadata: {
1394
- ...targetProduct.metadata || {},
1395
- unique_identification_number: ((_a = targetProduct.metadata) == null ? void 0 : _a.unique_identification_number) || unique_identification_number
1396
- }
1397
- });
1398
- normalizedProduct.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
1399
- normalizedProduct.discount_list
1400
- );
1401
- tempOrder.products[productIndex] = normalizedProduct;
1402
- this.applyDiscount();
1403
- await this.recalculateSummary({ createIfMissing: true });
1404
- this.persistTempOrder();
1405
- return tempOrder.products;
1406
- }
1407
- updateOrderBooking(params) {
1408
- const { unique_identification_number, updates } = params;
1409
- const tempOrder = this.ensureTempOrder();
1410
- const bookingUid = String(unique_identification_number || "");
1411
- const bookingIndex = this.findBookingIndexByUniqueIdentificationNumber(
1412
- tempOrder,
1413
- bookingUid
1414
- );
1415
- if (!bookingUid || bookingIndex === -1) {
1416
- throw new Error("[Order] 目标 booking 不存在,无法更新");
1417
- }
1418
- const targetBooking = tempOrder.bookings[bookingIndex] || {};
1419
- const nextBooking = {
1420
- ...targetBooking,
1421
- ...updates,
1422
- metadata: {
1423
- ...targetBooking.metadata || {},
1424
- ...updates.metadata || {},
1425
- unique_identification_number: bookingUid
1426
- }
1427
- };
1428
- nextBooking.is_all = (0, import_utils.normalizeBookingIsAll)(nextBooking);
1429
- nextBooking.sub_type = (0, import_utils.normalizeBookingSubType)(nextBooking);
1430
- tempOrder.bookings[bookingIndex] = nextBooking;
1431
- this.persistTempOrder();
1432
- return tempOrder.bookings;
1433
- }
1434
1191
  async removeProductFromOrder(identity) {
1435
1192
  const tempOrder = this.ensureTempOrder();
1436
- const removedProducts = [];
1437
- tempOrder.products = tempOrder.products.filter((item) => {
1438
- const shouldRemove = (0, import_utils3.isIdentityMatch)(item, identity);
1439
- if (shouldRemove)
1440
- removedProducts.push(item);
1441
- return !shouldRemove;
1442
- });
1443
- for (const product of removedProducts) {
1444
- this.removeLinkedBookingsForProduct(tempOrder, product);
1445
- }
1193
+ tempOrder.products = tempOrder.products.filter(
1194
+ (item) => !(0, import_utils3.isIdentityMatch)(item, identity)
1195
+ );
1446
1196
  this.applyDiscount();
1447
1197
  await this.recalculateSummary({ createIfMissing: true });
1448
1198
  this.persistTempOrder();
1449
1199
  return tempOrder.products;
1450
1200
  }
1451
- /**
1452
- * 仅清空购物车行(products / bookings),不重置整单。
1453
- * 用于「仅清空商品」;客户、备注、支付等协议字段保持不变。
1454
- */
1455
- async clearOrderCartLines() {
1456
- const tempOrder = this.ensureTempOrder();
1457
- tempOrder.products = [];
1458
- tempOrder.bookings = [];
1459
- if (tempOrder._extend && typeof tempOrder._extend === "object") {
1460
- tempOrder._extend = {
1461
- ...tempOrder._extend,
1462
- productsByUid: {}
1463
- };
1464
- }
1465
- this.applyDiscount();
1466
- await this.recalculateSummary({ createIfMissing: true });
1467
- this.persistTempOrder();
1468
- return tempOrder;
1469
- }
1470
1201
  // ─── TempOrder: 提交 ───
1471
1202
  /**
1472
1203
  * 提交当前 Sales tempOrder。
@@ -1596,26 +1327,21 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1596
1327
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
1597
1328
  params.payments || []
1598
1329
  );
1599
- const paymentTotal = this.calculatePaymentTotal(mappedPayments);
1600
- const targetAmount = this.getPaymentTargetAmount();
1601
- const isFullyPaid = targetAmount.lte(0) ? false : paymentTotal.gte(targetAmount);
1602
- const paymentStatus = isFullyPaid ? params.paymentStatus || "paid" : "partially_paid";
1603
1330
  tempOrder.payments = mappedPayments;
1604
- tempOrder.payment_status = paymentStatus;
1331
+ if (params.paymentStatus)
1332
+ tempOrder.payment_status = params.paymentStatus;
1605
1333
  this.persistTempOrder();
1606
1334
  await this.saveDraft();
1607
- if (!params.submitWhenPaid) {
1608
- return { isFullyPaid };
1609
- }
1610
- 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) {
1611
1339
  return { isFullyPaid };
1612
1340
  }
1613
- this.store.syncState = "submitting";
1614
1341
  const submitResult = await this.submitTempOrder({
1615
1342
  payments: mappedPayments,
1616
- paymentStatus,
1617
- smallTicketDataFlag: params.smallTicketDataFlag,
1618
- channel: params.channel
1343
+ paymentStatus: params.paymentStatus || "paid",
1344
+ smallTicketDataFlag: params.smallTicketDataFlag
1619
1345
  });
1620
1346
  return { isFullyPaid, submitResult };
1621
1347
  }
@@ -1915,36 +1641,53 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1915
1641
  */
1916
1642
  async hydrateTempOrderFromRecord(record, options) {
1917
1643
  const raw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
1918
- const nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
1919
- ensureIdentity: true
1920
- });
1921
- this.store.tempOrder = nextTempOrder;
1922
- this.store.summary = raw.summary && typeof raw.summary === "object" ? { ...(0, import_utils.createEmptySummary)(), ...raw.summary } : (0, import_utils.createEmptySummary)();
1923
- this.store.lastOrderInfo = raw.lastOrderInfo || raw;
1924
- if (options == null ? void 0 : options.recalcOnHydrate) {
1925
- await this.recalculateSummary({ createIfMissing: false });
1926
- }
1927
- this.persistTempOrder();
1928
- return nextTempOrder;
1929
- }
1930
- normalizeTempOrderForRuntime(raw, options) {
1644
+ const defaults = this.createDefaultTempOrderInstance();
1931
1645
  const nextTempOrder = {
1932
- ...this.createDefaultTempOrderInstance(),
1933
- ...raw || {}
1646
+ ...defaults
1934
1647
  };
1935
- delete nextTempOrder.summary;
1936
- delete nextTempOrder.lastOrderInfo;
1937
- delete nextTempOrder.discount_list;
1938
- delete nextTempOrder.shop_id;
1939
- delete nextTempOrder.create_date;
1940
- delete nextTempOrder.total_amount;
1941
- delete nextTempOrder.expect_amount;
1942
- delete nextTempOrder.paid_amount;
1943
- delete nextTempOrder.shop_note;
1944
- delete nextTempOrder.start_time;
1945
- delete nextTempOrder.tax_fee;
1946
- delete nextTempOrder.total_refund_amount;
1947
- delete nextTempOrder.holder_id;
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)) : [];
@@ -1955,6 +1698,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1955
1698
  })) : [];
1956
1699
  nextTempOrder.payments = Array.isArray(raw.payments) ? raw.payments.map((p) => ({ ...p || {} })) : [];
1957
1700
  nextTempOrder.surcharges = Array.isArray(raw.surcharges) ? raw.surcharges.map((s) => ({ ...s || {} })) : [];
1701
+ nextTempOrder.discount_list = Array.isArray(raw.discount_list) ? raw.discount_list.map((d) => ({ ...d || {} })) : [];
1958
1702
  nextTempOrder.relation_forms = Array.isArray(raw.relation_forms) ? raw.relation_forms.map((f) => ({ ...f || {} })) : [];
1959
1703
  nextTempOrder.contacts = Array.isArray(raw.contacts) ? raw.contacts.map((c) => ({ ...c || {} })) : [];
1960
1704
  nextTempOrder.contacts_info = raw.contacts_info && typeof raw.contacts_info === "object" && !Array.isArray(raw.contacts_info) ? { ...raw.contacts_info } : null;
@@ -1962,9 +1706,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1962
1706
  ...raw._extend,
1963
1707
  productsByUid: raw._extend.productsByUid || {}
1964
1708
  } : { productsByUid: {} };
1965
- if ((options == null ? void 0 : options.ensureIdentity) !== false) {
1966
- 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 });
1967
1715
  }
1716
+ this.persistTempOrder();
1968
1717
  return nextTempOrder;
1969
1718
  }
1970
1719
  normalizeHydratedOrderProduct(product) {
@@ -1983,9 +1732,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1983
1732
  row.metadata.unique_identification_number = (0, import_utils.createUuidV4)();
1984
1733
  }
1985
1734
  const normalized = (0, import_utils3.normalizeOrderProduct)(row);
1986
- normalized.discount_list = (0, import_utils.normalizeOrderProductDiscountList)(
1987
- normalized.discount_list
1988
- );
1989
1735
  const result = {
1990
1736
  ...row,
1991
1737
  ...normalized,