@pisell/pisellos 0.10.2 → 0.10.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (139) hide show
  1. package/dist/core/index.d.ts +2 -0
  2. package/dist/core/index.js +7 -0
  3. package/dist/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  4. package/dist/model/strategy/adapter/promotion/adapter.js +23 -0
  5. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  6. package/dist/model/strategy/adapter/promotion/evaluator.js +279 -6
  7. package/dist/model/strategy/adapter/promotion/examples.d.ts +86 -0
  8. package/dist/model/strategy/adapter/promotion/examples.js +99 -0
  9. package/dist/model/strategy/adapter/promotion/index.d.ts +1 -1
  10. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  11. package/dist/model/strategy/adapter/promotion/type.d.ts +90 -2
  12. package/dist/model/strategy/adapter/promotion/type.js +45 -0
  13. package/dist/modules/BaseModule.d.ts +1 -0
  14. package/dist/modules/BaseModule.js +24 -28
  15. package/dist/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +5 -3
  16. package/dist/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +6 -3
  17. package/dist/modules/OpenData/index.d.ts +2 -0
  18. package/dist/modules/OpenData/index.js +8 -0
  19. package/dist/modules/Order/index.d.ts +41 -10
  20. package/dist/modules/Order/index.js +943 -546
  21. package/dist/modules/Order/payment-utils.d.ts +26 -0
  22. package/dist/modules/Order/payment-utils.js +225 -0
  23. package/dist/modules/Order/types.d.ts +43 -2
  24. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  25. package/dist/modules/Order/utils.js +10 -6
  26. package/dist/modules/Payment/index.d.ts +2 -0
  27. package/dist/modules/Payment/index.js +79 -50
  28. package/dist/modules/Payment/types.d.ts +107 -28
  29. package/dist/modules/Payment/types.js +20 -3
  30. package/dist/modules/Payment/walletpass.d.ts +38 -1
  31. package/dist/modules/Payment/walletpass.js +917 -114
  32. package/dist/modules/ProductList/index.js +1 -1
  33. package/dist/modules/Rules/index.d.ts +3 -0
  34. package/dist/modules/Rules/index.js +130 -99
  35. package/dist/server/index.d.ts +16 -0
  36. package/dist/server/index.js +2084 -1188
  37. package/dist/server/modules/index.d.ts +1 -1
  38. package/dist/server/modules/order/index.d.ts +70 -4
  39. package/dist/server/modules/order/index.js +1816 -728
  40. package/dist/server/modules/order/types.d.ts +25 -3
  41. package/dist/server/modules/order/types.js +7 -1
  42. package/dist/solution/BaseSales/index.d.ts +114 -14
  43. package/dist/solution/BaseSales/index.js +1848 -478
  44. package/dist/solution/BaseSales/types.d.ts +55 -1
  45. package/dist/solution/BaseSales/types.js +2 -1
  46. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  47. package/dist/solution/BaseSales/utils/cartPromotion.js +90 -31
  48. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  49. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +6 -3
  50. package/dist/solution/BookingByStep/index.d.ts +1 -1
  51. package/dist/solution/BookingTicket/index.d.ts +8 -16
  52. package/dist/solution/BookingTicket/index.js +138 -52
  53. package/dist/solution/BookingTicket/types.d.ts +1 -0
  54. package/dist/solution/BookingTicket/utils/addProductDecision.js +6 -0
  55. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  56. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  57. package/dist/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  58. package/dist/solution/BookingTicket/utils/weighingProductSku.js +45 -0
  59. package/dist/solution/Sales/index.d.ts +1 -0
  60. package/dist/solution/Sales/index.js +10 -2
  61. package/dist/solution/ScanOrder/index.js +31 -20
  62. package/dist/solution/UnifiedBookingSales/index.d.ts +3 -0
  63. package/dist/solution/UnifiedBookingSales/index.js +392 -304
  64. package/dist/solution/UnifiedBookingSales/types.d.ts +7 -0
  65. package/dist/solution/VenueBooking/index.d.ts +1 -0
  66. package/dist/solution/VenueBooking/index.js +34 -24
  67. package/dist/types/index.d.ts +1 -0
  68. package/dist/utils/payment-number.d.ts +9 -0
  69. package/dist/utils/payment-number.js +69 -0
  70. package/lib/core/index.d.ts +2 -0
  71. package/lib/core/index.js +4 -0
  72. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  73. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  74. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  75. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  76. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  77. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  78. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  79. package/lib/model/strategy/adapter/promotion/index.js +2 -0
  80. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  81. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  82. package/lib/modules/BaseModule.d.ts +1 -0
  83. package/lib/modules/BaseModule.js +24 -37
  84. package/lib/modules/BookingContext/utils/buildCacheItemFromOrderLine.js +2 -1
  85. package/lib/modules/BookingContext/utils/buildNormalProductCacheItemFromOrderLine.js +2 -1
  86. package/lib/modules/OpenData/index.d.ts +2 -0
  87. package/lib/modules/OpenData/index.js +5 -0
  88. package/lib/modules/Order/index.d.ts +41 -10
  89. package/lib/modules/Order/index.js +322 -86
  90. package/lib/modules/Order/payment-utils.d.ts +26 -0
  91. package/lib/modules/Order/payment-utils.js +224 -0
  92. package/lib/modules/Order/types.d.ts +43 -2
  93. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  94. package/lib/modules/Order/utils.js +11 -4
  95. package/lib/modules/Payment/index.d.ts +2 -0
  96. package/lib/modules/Payment/index.js +34 -13
  97. package/lib/modules/Payment/types.d.ts +107 -28
  98. package/lib/modules/Payment/types.js +4 -3
  99. package/lib/modules/Payment/walletpass.d.ts +38 -1
  100. package/lib/modules/Payment/walletpass.js +730 -21
  101. package/lib/modules/ProductList/index.js +9 -1
  102. package/lib/modules/Rules/index.d.ts +3 -0
  103. package/lib/modules/Rules/index.js +39 -10
  104. package/lib/server/index.d.ts +16 -0
  105. package/lib/server/index.js +677 -28
  106. package/lib/server/modules/index.d.ts +1 -1
  107. package/lib/server/modules/order/index.d.ts +70 -4
  108. package/lib/server/modules/order/index.js +818 -69
  109. package/lib/server/modules/order/types.d.ts +25 -3
  110. package/lib/server/modules/order/types.js +1 -0
  111. package/lib/solution/BaseSales/index.d.ts +114 -14
  112. package/lib/solution/BaseSales/index.js +907 -58
  113. package/lib/solution/BaseSales/types.d.ts +55 -1
  114. package/lib/solution/BaseSales/types.js +2 -1
  115. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  116. package/lib/solution/BaseSales/utils/cartPromotion.js +63 -12
  117. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  118. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +3 -2
  119. package/lib/solution/BookingByStep/index.d.ts +1 -1
  120. package/lib/solution/BookingTicket/index.d.ts +8 -16
  121. package/lib/solution/BookingTicket/index.js +63 -9
  122. package/lib/solution/BookingTicket/types.d.ts +1 -0
  123. package/lib/solution/BookingTicket/utils/addProductDecision.js +4 -0
  124. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  125. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  126. package/lib/solution/BookingTicket/utils/weighingProductSku.d.ts +5 -0
  127. package/lib/solution/BookingTicket/utils/weighingProductSku.js +63 -0
  128. package/lib/solution/Sales/index.d.ts +1 -0
  129. package/lib/solution/Sales/index.js +5 -3
  130. package/lib/solution/ScanOrder/index.js +8 -0
  131. package/lib/solution/UnifiedBookingSales/index.d.ts +3 -0
  132. package/lib/solution/UnifiedBookingSales/index.js +48 -2
  133. package/lib/solution/UnifiedBookingSales/types.d.ts +7 -0
  134. package/lib/solution/VenueBooking/index.d.ts +1 -0
  135. package/lib/solution/VenueBooking/index.js +13 -6
  136. package/lib/types/index.d.ts +1 -0
  137. package/lib/utils/payment-number.d.ts +9 -0
  138. package/lib/utils/payment-number.js +64 -0
  139. package/package.json +1 -1
@@ -37,6 +37,8 @@ var import_types = require("./types");
37
37
  var import_utils = require("./utils");
38
38
  var import_utils2 = require("../Product/utils");
39
39
  var import_dayjs = __toESM(require("dayjs"));
40
+ var import_payment_utils = require("./payment-utils");
41
+ var import_payment_number = require("../../utils/payment-number");
40
42
  var import_cartPromotion = require("../../solution/BaseSales/utils/cartPromotion");
41
43
  var import_utils3 = require("../../solution/ScanOrder/utils");
42
44
  var import_manualProductDiscount = require("./utils/manualProductDiscount");
@@ -68,6 +70,24 @@ function isManualProductDiscountProduct(product) {
68
70
  }
69
71
  var ORDER_PAYMENT_STATUS_PAID = "paid";
70
72
  var ORDER_PAYMENT_STATUS_PENDING = "payment_pending";
73
+ var CUSTOMER_PROMOTION_DISCOUNT_TAGS = /* @__PURE__ */ new Set([
74
+ "good_pass",
75
+ "product_discount_card",
76
+ "discount_card"
77
+ ]);
78
+ function isCustomerPromotionDiscount(discount) {
79
+ return CUSTOMER_PROMOTION_DISCOUNT_TAGS.has(
80
+ String((discount == null ? void 0 : discount.tag) || (discount == null ? void 0 : discount.type) || "").toLowerCase()
81
+ );
82
+ }
83
+ function markScannedDiscounts(discountList, scannedDiscountList) {
84
+ const scannedIds = new Set(
85
+ scannedDiscountList.map((discount) => discount == null ? void 0 : discount.id).filter((id) => id !== void 0 && id !== null).map(String)
86
+ );
87
+ return discountList.map(
88
+ (discount) => scannedIds.has(String(discount == null ? void 0 : discount.id)) ? { ...discount, isScan: true } : discount
89
+ );
90
+ }
71
91
  function isVoucherPaymentRecord(payment) {
72
92
  return (payment == null ? void 0 : payment.voucher_id) !== void 0 && Number(payment.voucher_id) !== 0;
73
93
  }
@@ -83,11 +103,19 @@ function isPaidPaymentRecord(payment) {
83
103
  function isCommittedVoucherPaymentRecord(payment) {
84
104
  return isVoucherPaymentRecord(payment) && (payment == null ? void 0 : payment.status) !== "voided" && (hasSyncedOrderPaymentRecord(payment) || isPaidPaymentRecord(payment));
85
105
  }
106
+ function getVoucherPaymentLifecycleKey(payment) {
107
+ if (!isVoucherPaymentRecord(payment))
108
+ return null;
109
+ return `${String(payment.voucher_id)}::${String(payment.status || "")}`;
110
+ }
86
111
  var OrderModule = class extends import_BaseModule.BaseModule {
87
112
  constructor(name, version) {
88
113
  super(name || "order", version);
89
114
  this.defaultName = "order";
90
115
  this.defaultVersion = "1.0.0";
116
+ this.openCache = false;
117
+ this.sessionStoragePersistEnabled = false;
118
+ this.sessionStorageRestoreRecord = null;
91
119
  // ─── 促销/赠品 ────────────────────────────────────
92
120
  /** 评估器引用;由 SalesSdkProvider 注入,未注入时 applyPromotion 静默跳过 */
93
121
  this.promotionEvaluator = null;
@@ -115,6 +143,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
115
143
  const type = (item == null ? void 0 : item.type) ?? (item == null ? void 0 : item.tag);
116
144
  if (!type || type === "product")
117
145
  continue;
146
+ const isDiscountCard = type === "discount_card" || type === "product_discount_card";
118
147
  const resourceId = ((_a = item == null ? void 0 : item.discount) == null ? void 0 : _a.resource_id) ?? (item == null ? void 0 : item.resource_id) ?? (item == null ? void 0 : item.discount_id) ?? (item == null ? void 0 : item.order_discount_id);
119
148
  if (resourceId === void 0 || resourceId === null || resourceId === "")
120
149
  continue;
@@ -137,7 +166,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
137
166
  if (existed) {
138
167
  existed.amount = Number(existed.amount || 0) + amount;
139
168
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
140
- existed.balance = String(Number(existed.balance || 0) + amount);
169
+ if (!isDiscountCard) {
170
+ existed.balance = String(Number(existed.balance || 0) + amount);
171
+ }
141
172
  const productIds = Array.isArray((_f = existed.limited_relation_product_data) == null ? void 0 : _f.product_ids) ? existed.limited_relation_product_data.product_ids : [];
142
173
  if ((product == null ? void 0 : product.product_id) !== void 0 && (product == null ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
143
174
  existed.limited_relation_product_data = {
@@ -174,7 +205,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
174
205
  filter: 0,
175
206
  exclude_product_ids: []
176
207
  },
177
- balance: String((item == null ? void 0 : item.amount) ?? "0"),
208
+ balance: isDiscountCard ? void 0 : String((item == null ? void 0 : item.amount) ?? "0"),
178
209
  format_title: title,
179
210
  product: {
180
211
  id: (product == null ? void 0 : product.product_id) ?? 0,
@@ -299,11 +330,32 @@ var OrderModule = class extends import_BaseModule.BaseModule {
299
330
  return product;
300
331
  });
301
332
  }
333
+ syncSessionStorageOptions(otherParams) {
334
+ this.cacheId = otherParams.cacheId;
335
+ this.fatherModule = otherParams.fatherModule;
336
+ this.openCache = Boolean(
337
+ this.cacheId && otherParams.openCache !== false
338
+ );
339
+ this.sessionStoragePersistEnabled = Boolean(
340
+ this.openCache && otherParams.enableSessionStoragePersist === true
341
+ );
342
+ }
302
343
  async initialize(core, options) {
303
344
  var _a, _b, _c, _d;
304
345
  this.core = core;
305
346
  this.store = options.store;
306
- if (!this.store.tempOrder) {
347
+ const otherParams = options.otherParams || {};
348
+ this.syncSessionStorageOptions(otherParams);
349
+ if (this.sessionStoragePersistEnabled) {
350
+ const cachedTempOrder = this.store.tempOrder;
351
+ this.sessionStorageRestoreRecord = (0, import_utils.isTempOrder)(cachedTempOrder) ? (0, import_lodash_es.cloneDeep)(cachedTempOrder) : null;
352
+ this.store.tempOrder = null;
353
+ this.store.summary = (0, import_utils.createEmptySummary)();
354
+ this.store.availableWalletIds = [];
355
+ this.store.lastOrderInfo = void 0;
356
+ this.store.syncState = void 0;
357
+ this.store.discountList = [];
358
+ } else if (!this.store.tempOrder) {
307
359
  this.store.tempOrder = null;
308
360
  }
309
361
  if (!this.store.summary) {
@@ -320,8 +372,6 @@ var OrderModule = class extends import_BaseModule.BaseModule {
320
372
  const app = (_a = appPlugin == null ? void 0 : appPlugin.getApp) == null ? void 0 : _a.call(appPlugin);
321
373
  this.logger = app == null ? void 0 : app.logger;
322
374
  this.window = this.core.getPlugin("window");
323
- const otherParams = options.otherParams || {};
324
- this.cacheId = otherParams.cacheId;
325
375
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
326
376
  this.rulesHooksOverride = (_b = otherParams.rules) == null ? void 0 : _b.hooks;
327
377
  this.moduleHooksOverride = options.hooks;
@@ -332,6 +382,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
332
382
  }
333
383
  async destroy() {
334
384
  var _a, _b;
385
+ this.sessionStorageRestoreRecord = null;
335
386
  const childModules = [(_a = this.store) == null ? void 0 : _a.discount, (_b = this.store) == null ? void 0 : _b.rules];
336
387
  for (const childModule of childModules) {
337
388
  if (!childModule || typeof childModule.destroy !== "function")
@@ -361,7 +412,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
361
412
  updateOtherParams(params) {
362
413
  var _a, _b, _c;
363
414
  const otherParams = params || {};
364
- this.cacheId = otherParams.cacheId;
415
+ this.syncSessionStorageOptions(otherParams);
365
416
  this.salesSummaryModuleName = otherParams.salesSummaryModuleName;
366
417
  this.rulesHooksOverride = (_a = otherParams.rules) == null ? void 0 : _a.hooks;
367
418
  this.orderHooks = this.moduleHooksOverride || ((_b = otherParams.order) == null ? void 0 : _b.hooks) || ((_c = otherParams.hooks) == null ? void 0 : _c.order);
@@ -406,14 +457,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
406
457
  // ─── Discount: 子模块注册 ───
407
458
  registerDiscountModules(options) {
408
459
  let targetCacheData = {};
409
- if (this.cacheId && this.window) {
410
- const sessionData = this.window.sessionStorage.getItem(this.name);
411
- if (sessionData) {
412
- try {
460
+ if (!this.sessionStoragePersistEnabled && this.openCache && this.cacheId && this.window) {
461
+ try {
462
+ const sessionData = this.window.sessionStorage.getItem(this.name);
463
+ if (sessionData) {
413
464
  const data = JSON.parse(sessionData);
414
465
  targetCacheData = (data == null ? void 0 : data[this.cacheId]) || {};
415
- } catch {
416
466
  }
467
+ } catch {
417
468
  }
418
469
  }
419
470
  const discount = new import_Discount.DiscountModule(`${this.name}_discount`);
@@ -421,7 +472,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
421
472
  initialState: targetCacheData == null ? void 0 : targetCacheData[discount.name],
422
473
  otherParams: {
423
474
  fatherModule: this.name,
424
- openCache: !!this.cacheId,
475
+ // Unified 的单快照由 Order 管理;其他 Solution 保持原有 Discount 缓存语义。
476
+ openCache: this.openCache && !this.sessionStoragePersistEnabled,
425
477
  cacheId: this.cacheId
426
478
  }
427
479
  });
@@ -521,7 +573,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
521
573
  });
522
574
  }
523
575
  async scanCode(code, customerId) {
524
- var _a, _b, _c, _d;
576
+ var _a, _b, _c, _d, _e;
525
577
  const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
526
578
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
527
579
  const rulesModule = this.store.rules;
@@ -529,6 +581,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
529
581
  return {
530
582
  type: "clientCalc",
531
583
  isAvailable: false,
584
+ isAccepted: false,
532
585
  discountList: this.getDiscountList(),
533
586
  scannedDiscountList: resultDiscountList,
534
587
  unavailableReason: import_types2.UnavailableReason.Unknown
@@ -538,6 +591,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
538
591
  return {
539
592
  type: "server",
540
593
  isAvailable: false,
594
+ isAccepted: false,
541
595
  discountList: this.getDiscountList(),
542
596
  scannedDiscountList: resultDiscountList,
543
597
  unavailableReasonKey
@@ -553,13 +607,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
553
607
  return {
554
608
  type: "clientCalc",
555
609
  isAvailable: true,
610
+ isAccepted: true,
556
611
  discountList: this.getDiscountList(),
557
612
  scannedDiscountList: resultDiscountList
558
613
  };
559
614
  }
560
615
  const tempOrder = this.store.tempOrder;
561
616
  const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record) || [];
562
- const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
617
+ const {
618
+ isAvailable,
619
+ discountList: newDiscountList,
620
+ evaluatedDiscountList,
621
+ unavailableReason
622
+ } = rulesModule.isDiscountListAvailable({
563
623
  productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
564
624
  oldDiscountList: this.getDiscountList(),
565
625
  newDiscountList: withScanList,
@@ -567,15 +627,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
567
627
  holders,
568
628
  isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product)
569
629
  }) || { isAvailable: false, discountList: this.getDiscountList() };
570
- if (isAvailable && newDiscountList) {
571
- (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
630
+ const shouldRetainForLater = !isAvailable && unavailableReason === import_types2.UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
631
+ const normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : void 0;
632
+ const retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
633
+ let resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
634
+ if (isAvailable && normalizedNewDiscountList) {
635
+ await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(normalizedNewDiscountList));
572
636
  this.applyDiscount();
573
637
  await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
638
+ resolvedDiscountList = this.getDiscountList();
639
+ } else if (shouldRetainForLater && retainedDiscountList) {
640
+ await ((_e = this.store.discount) == null ? void 0 : _e.setDiscountList(retainedDiscountList));
641
+ await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
642
+ resolvedDiscountList = this.getDiscountList();
574
643
  }
575
644
  return {
576
645
  type: "clientCalc",
577
646
  isAvailable: isAvailable || false,
578
- discountList: newDiscountList || this.getDiscountList(),
647
+ isAccepted: Boolean(isAvailable || shouldRetainForLater),
648
+ discountList: resolvedDiscountList,
579
649
  scannedDiscountList: resultDiscountList,
580
650
  unavailableReason
581
651
  };
@@ -819,7 +889,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
819
889
  }
820
890
  /**
821
891
  * 控制 IndexedDB 草稿(saveDraft)是否写入。
822
- * localStorage tempOrder 持久化已废弃,此方法仅影响 saveDraft。
892
+ * 此开关仅影响 saveDraft;可选 sessionStorage 会话恢复由
893
+ * enableSessionStoragePersist 独立控制。
823
894
  *
824
895
  * @example
825
896
  * order.setEnableTempOrderPersist(false); // BigSale 弹窗:跳过 ~1s 的 dbUpdate
@@ -831,8 +902,24 @@ var OrderModule = class extends import_BaseModule.BaseModule {
831
902
  isTempOrderPersistEnabled() {
832
903
  return this.draftPersistEnabled;
833
904
  }
834
- /** @deprecated OrderModule 不再负责 tempOrder localStorage 持久化;草稿保存请使用 IndexedDB saveDraft。 */
905
+ /**
906
+ * 在 UnifiedBookingSales 显式开启会话恢复时,将完整 tempOrder 写入
907
+ * sessionStorage 的 cacheId 分桶。写入失败由 BaseModule 静默降级。
908
+ */
835
909
  persistTempOrder() {
910
+ if (!this.sessionStoragePersistEnabled || !this.store.tempOrder)
911
+ return;
912
+ this.checkSaveCache({
913
+ cacheId: this.cacheId,
914
+ fatherModule: this.fatherModule,
915
+ store: { tempOrder: this.store.tempOrder },
916
+ cacheKey: ["tempOrder"]
917
+ });
918
+ }
919
+ consumeSessionStorageRestore() {
920
+ const record = this.sessionStorageRestoreRecord;
921
+ this.sessionStorageRestoreRecord = null;
922
+ return record ? (0, import_lodash_es.cloneDeep)(record) : null;
836
923
  }
837
924
  notifyTempOrderChanged() {
838
925
  if (!this.store.tempOrder)
@@ -1063,17 +1150,40 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1063
1150
  const depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1064
1151
  return depositPaidAmount.lt(depositAmount) ? "deposit" : "normal";
1065
1152
  }
1153
+ getPaymentNumberAppData(key) {
1154
+ var _a, _b, _c, _d, _e;
1155
+ const appPlugin = this.appPlugin;
1156
+ if (!appPlugin)
1157
+ return void 0;
1158
+ const getData = (_a = appPlugin.getData) == null ? void 0 : _a.call(appPlugin);
1159
+ if (typeof getData === "function")
1160
+ return getData(key);
1161
+ const app = appPlugin.getApp();
1162
+ const coreData = (_e = (_c = (_b = app == null ? void 0 : app.models) == null ? void 0 : _b.getStore) == null ? void 0 : (_d = _c.call(_b)).getDataByModel) == null ? void 0 : _e.call(_d, "core", "core");
1163
+ return coreData == null ? void 0 : coreData[key];
1164
+ }
1165
+ getPaymentNumberDevicePrefixSync() {
1166
+ return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)(
1167
+ (key) => this.getPaymentNumberAppData(key)
1168
+ );
1169
+ }
1170
+ getPaymentNumberDevicePrefixAsync() {
1171
+ return (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
1172
+ (key) => this.getPaymentNumberAppData(key)
1173
+ );
1174
+ }
1066
1175
  normalizePaymentSource(payment, options) {
1067
1176
  const paymentRecord = payment;
1068
1177
  const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
1069
- if (!metadata.unique_payment_number) {
1070
- metadata.unique_payment_number = (0, import_utils.createUuidV4)();
1071
- }
1072
- const normalized = {
1073
- ...paymentRecord,
1074
- metadata,
1075
- origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1076
- };
1178
+ const normalized = (0, import_payment_utils.ensureOrderPaymentNumber)(
1179
+ {
1180
+ ...paymentRecord,
1181
+ metadata,
1182
+ origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1183
+ },
1184
+ (options == null ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(),
1185
+ import_utils.createUuidV4
1186
+ );
1077
1187
  if (paymentRecord.status !== void 0) {
1078
1188
  normalized.status = paymentRecord.status;
1079
1189
  } else if ((options == null ? void 0 : options.defaultPaid) !== false) {
@@ -1664,6 +1774,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1664
1774
  restoreOrder() {
1665
1775
  var _a, _b;
1666
1776
  this.logInfo("restoreOrder start", {});
1777
+ this.sessionStorageRestoreRecord = null;
1667
1778
  const freshTempOrder = this.createDefaultTempOrderInstance();
1668
1779
  this.ensureExternalSaleNumber(freshTempOrder);
1669
1780
  this.store.tempOrder = freshTempOrder;
@@ -1682,6 +1793,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1682
1793
  if (!(0, import_utils.isTempOrder)(tempOrder)) {
1683
1794
  throw new Error("无效的 tempOrder 数据");
1684
1795
  }
1796
+ this.sessionStorageRestoreRecord = null;
1685
1797
  const nextTempOrder = this.normalizeTempOrderForRuntime(
1686
1798
  (0, import_lodash_es.cloneDeep)(tempOrder),
1687
1799
  { ensureIdentity: false }
@@ -2494,17 +2606,36 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2494
2606
  * 用一组支付来源覆盖当前订单支付项。
2495
2607
  *
2496
2608
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
2497
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
2609
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
2498
2610
  * isSynced 等运行态字段不会进入 tempOrder.payments。
2499
2611
  */
2500
2612
  setOrderPayments(payments) {
2501
2613
  const tempOrder = this.ensureTempOrder();
2502
- tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments);
2614
+ tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(
2615
+ (payments || []).map((payment) => this.normalizePaymentSource(payment, { defaultPaid: false }))
2616
+ );
2503
2617
  this.persistTempOrder();
2504
2618
  return tempOrder.payments;
2505
2619
  }
2506
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
2620
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
2507
2621
  addOrderPayment(payment) {
2622
+ const hasPaymentNumber = String(
2623
+ payment.payment_number || ""
2624
+ ).trim() !== "";
2625
+ return this.addOrderPaymentWithDevicePrefix(
2626
+ payment,
2627
+ hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
2628
+ );
2629
+ }
2630
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
2631
+ async addOrderPaymentAsync(payment) {
2632
+ const hasPaymentNumber = String(
2633
+ payment.payment_number || ""
2634
+ ).trim() !== "";
2635
+ const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
2636
+ return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
2637
+ }
2638
+ addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
2508
2639
  this.logInfo("addOrderPayment", {
2509
2640
  payment
2510
2641
  });
@@ -2517,7 +2648,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2517
2648
  type: orderPaymentType,
2518
2649
  order_payment_type: orderPaymentType
2519
2650
  },
2520
- { defaultPaid: true }
2651
+ { defaultPaid: true, devicePrefix }
2521
2652
  )
2522
2653
  ]);
2523
2654
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -2530,57 +2661,55 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2530
2661
  return tempOrder.payments;
2531
2662
  }
2532
2663
  /**
2533
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
2534
- *
2535
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
2536
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
2664
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
2665
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
2537
2666
  */
2538
- updateOrderPayment(paymentIdentity, updates) {
2667
+ async updateOrderPayment(paymentIdentity, updates, options = {}) {
2539
2668
  const tempOrder = this.ensureTempOrder();
2540
2669
  const identity = String(paymentIdentity);
2541
- tempOrder.payments = (tempOrder.payments || []).map((payment) => {
2542
- var _a;
2543
- const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2544
- const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2545
- const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2546
- const uuid = payment == null ? void 0 : payment.uuid;
2547
- const matched = [
2548
- uniquePaymentNumber,
2549
- orderPaymentId,
2550
- customPaymentId,
2551
- uuid
2552
- ].some((value) => value !== void 0 && String(value) === identity);
2553
- if (!matched)
2670
+ const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
2671
+ const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2672
+ tempOrder.payments || [],
2673
+ identity,
2674
+ matchMode
2675
+ );
2676
+ if (!matchedPayment) {
2677
+ throw new Error(`未找到支付项: ${identity}`);
2678
+ }
2679
+ let updatedPayment = null;
2680
+ tempOrder.payments = (tempOrder.payments || []).map((payment, index) => {
2681
+ if (index !== matchedPayment.index)
2554
2682
  return payment;
2555
- return {
2556
- ...payment,
2683
+ const nextPayment = (0, import_payment_utils.mergeOrderPaymentRecord)(payment, {
2557
2684
  ...updates,
2558
- metadata: {
2559
- ...payment.metadata || {},
2560
- ...updates.metadata || {}
2561
- }
2562
- };
2685
+ updated_at: updates.updated_at || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
2686
+ });
2687
+ updatedPayment = nextPayment;
2688
+ return nextPayment;
2563
2689
  });
2564
2690
  this.persistTempOrder();
2565
- return tempOrder.payments;
2691
+ const summary = await this.recalculateSummary({ createIfMissing: true });
2692
+ this.persistTempOrder();
2693
+ const payments = tempOrder.payments;
2694
+ return {
2695
+ updated: true,
2696
+ payment: payments[matchedPayment.index] || updatedPayment,
2697
+ payments,
2698
+ summary
2699
+ };
2566
2700
  }
2567
2701
  /** 从当前订单支付项中移除指定支付项。 */
2568
2702
  deleteOrderPayment(paymentIdentity) {
2569
2703
  const tempOrder = this.ensureTempOrder();
2570
2704
  const identity = String(paymentIdentity);
2571
- tempOrder.payments = (tempOrder.payments || []).filter((payment) => {
2572
- var _a;
2573
- const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2574
- const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2575
- const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2576
- const uuid = payment == null ? void 0 : payment.uuid;
2577
- return ![
2578
- uniquePaymentNumber,
2579
- orderPaymentId,
2580
- customPaymentId,
2581
- uuid
2582
- ].some((value) => value !== void 0 && String(value) === identity);
2583
- });
2705
+ const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2706
+ tempOrder.payments || [],
2707
+ identity,
2708
+ "compat"
2709
+ );
2710
+ if (!matchedPayment)
2711
+ return tempOrder.payments;
2712
+ tempOrder.payments = (tempOrder.payments || []).filter((_, index) => index !== matchedPayment.index);
2584
2713
  this.persistTempOrder();
2585
2714
  return tempOrder.payments;
2586
2715
  }
@@ -2689,7 +2818,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2689
2818
  payments.map(
2690
2819
  (payment) => this.normalizePaymentSource(
2691
2820
  normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
2692
- { defaultPaid: false }
2821
+ {
2822
+ defaultPaid: false,
2823
+ devicePrefix: options == null ? void 0 : options.devicePrefix
2824
+ }
2693
2825
  )
2694
2826
  )
2695
2827
  ).filter((payment) => {
@@ -2711,14 +2843,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2711
2843
  const committedVoucherPaymentIds = new Set(
2712
2844
  committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
2713
2845
  );
2714
- const committedVoucherIds = new Set(
2715
- committedVoucherPayments.map((payment) => String(payment.voucher_id))
2846
+ const committedVoucherLifecycleKeys = new Set(
2847
+ committedVoucherPayments.map((payment) => getVoucherPaymentLifecycleKey(payment)).filter((key) => key !== null)
2716
2848
  );
2717
2849
  const replaceableVouchers = mappedVouchers.filter((payment) => {
2718
2850
  if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
2719
2851
  return false;
2720
2852
  }
2721
- if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
2853
+ const lifecycleKey = getVoucherPaymentLifecycleKey(payment);
2854
+ if (lifecycleKey && committedVoucherLifecycleKeys.has(lifecycleKey)) {
2722
2855
  return false;
2723
2856
  }
2724
2857
  return true;
@@ -2740,6 +2873,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2740
2873
  });
2741
2874
  return tempOrder.payments;
2742
2875
  }
2876
+ async updateVoucherOrderPaymentsAsync(payments, options) {
2877
+ const needsPaymentNumber = (payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
2878
+ const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
2879
+ return this.updateVoucherOrderPayments(payments, {
2880
+ ...options,
2881
+ devicePrefix
2882
+ });
2883
+ }
2743
2884
  async shouldMergeProductToOrder(params) {
2744
2885
  var _a;
2745
2886
  const onBeforeMergeProductToOrder = (_a = this.orderHooks) == null ? void 0 : _a.onBeforeMergeProductToOrder;
@@ -3570,6 +3711,38 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3570
3711
  await this.saveDraft();
3571
3712
  return tempOrder;
3572
3713
  }
3714
+ async saveTempOrderAsDraft(params) {
3715
+ var _a, _b, _c, _d, _e;
3716
+ const tempOrder = this.ensureTempOrder();
3717
+ this.ensureExternalSaleNumber(tempOrder);
3718
+ this.persistTempOrder();
3719
+ const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
3720
+ const payload = (0, import_utils.buildSubmitPayload)({
3721
+ tempOrder,
3722
+ cacheId: (params == null ? void 0 : params.cacheId) ?? this.cacheId,
3723
+ platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
3724
+ businessCode: (params == null ? void 0 : params.businessCode) || ((_b = this.otherParams) == null ? void 0 : _b.businessCode) || ((_c = this.otherParams) == null ? void 0 : _c.business_code) || tempOrder.business_code,
3725
+ channel: params == null ? void 0 : params.channel,
3726
+ type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
3727
+ summary: latestSummary,
3728
+ enhance: params == null ? void 0 : params.enhancePayload
3729
+ });
3730
+ if (!payload.created_at) {
3731
+ payload.created_at = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
3732
+ }
3733
+ payload.need_sync = 0;
3734
+ payload.is_draft_order = 1;
3735
+ this.logInfo("saveTempOrderAsDraft calling sales draft", {
3736
+ orderId: payload.order_id,
3737
+ externalSaleNumber: payload.external_sale_number,
3738
+ productsCount: ((_e = payload.products) == null ? void 0 : _e.length) || 0
3739
+ });
3740
+ return this.request.post("/order/sales/draft", payload, {
3741
+ osServer: true,
3742
+ customToast: () => {
3743
+ }
3744
+ });
3745
+ }
3573
3746
  /**
3574
3747
  * 提交当前 Sales tempOrder。
3575
3748
  *
@@ -3770,8 +3943,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3770
3943
  }
3771
3944
  async syncPaymentsToOrder(params) {
3772
3945
  const tempOrder = this.ensureTempOrder();
3946
+ const needsPaymentNumber = (params.payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
3947
+ const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
3773
3948
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3774
- params.payments || []
3949
+ (params.payments || []).map((payment) => this.normalizePaymentSource(payment, {
3950
+ defaultPaid: false,
3951
+ devicePrefix
3952
+ }))
3775
3953
  );
3776
3954
  const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
3777
3955
  const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
@@ -4107,7 +4285,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4107
4285
  params.forceRemote = false;
4108
4286
  }
4109
4287
  const res = await this.request.get(`/order/sales/${encodeURIComponent(lookup)}`, {
4110
- with: ["products", "bookings", "payments", "customer", "summary", "contacts_info"],
4288
+ with: ["products", "bookings", "payments", "customer", "summary", "contacts_info", "refunds"],
4111
4289
  ...params.forceRemote ? { forceRemote: true } : {}
4112
4290
  }, { osServer: true });
4113
4291
  if (res.code === 200) {
@@ -4122,7 +4300,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4122
4300
  * 例如数组字段、商品行唯一值、价格 metadata、summary 派生状态和 _extend。
4123
4301
  */
4124
4302
  async hydrateTempOrderFromRecord(record, options) {
4125
- var _a, _b, _c;
4303
+ var _a, _b, _c, _d, _e;
4126
4304
  const sourceRaw = record && typeof record === "object" && record.data && record.order_id == null ? record.data : record || {};
4127
4305
  const identityReadySource = this.seedAnonymousBookingUidsFromProducts(
4128
4306
  sourceRaw
@@ -4152,10 +4330,44 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4152
4330
  );
4153
4331
  }
4154
4332
  }
4155
- const nextTempOrder = this.normalizeTempOrderForRuntime(raw, { makeEditMark: true });
4333
+ const isSessionStorageHydrate = (options == null ? void 0 : options.source) === "sessionStorage";
4334
+ const nextTempOrder = this.normalizeTempOrderForRuntime(raw, {
4335
+ makeEditMark: !isSessionStorageHydrate
4336
+ });
4337
+ this.store.tempOrder = nextTempOrder;
4338
+ if (isSessionStorageHydrate) {
4339
+ const restoredSessionDiscounts = Array.isArray(raw.discount_list) ? (0, import_lodash_es.cloneDeep)(raw.discount_list) : [];
4340
+ const nextExtend = { ...nextTempOrder._extend || {} };
4341
+ delete nextExtend.originalSalesSnapshot;
4342
+ nextTempOrder._extend = nextExtend;
4343
+ nextTempOrder.products.forEach((product) => {
4344
+ if (product.metadata) {
4345
+ delete product.metadata.is_edit_for_runtime;
4346
+ }
4347
+ });
4348
+ nextTempOrder.discount_list = restoredSessionDiscounts;
4349
+ this.store.summary = (0, import_utils.createEmptySummary)();
4350
+ this.store.lastOrderInfo = void 0;
4351
+ await ((_a = this.store.discount) == null ? void 0 : _a.setOriginalDiscountList(
4352
+ (0, import_lodash_es.cloneDeep)(restoredSessionDiscounts)
4353
+ ));
4354
+ await ((_b = this.store.discount) == null ? void 0 : _b.setDiscountList(
4355
+ (0, import_lodash_es.cloneDeep)(restoredSessionDiscounts)
4356
+ ));
4357
+ if (options == null ? void 0 : options.recalcOnHydrate) {
4358
+ await this.recalculateSummary({ createIfMissing: false });
4359
+ }
4360
+ this.persistTempOrder();
4361
+ return nextTempOrder;
4362
+ }
4363
+ const sourceLastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
4364
+ const isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
4365
+ const syntheticIdentityOptions = {
4366
+ isDraftOrder,
4367
+ externalSaleNumber: nextTempOrder.external_sale_number
4368
+ };
4156
4369
  const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
4157
4370
  const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
4158
- this.store.tempOrder = nextTempOrder;
4159
4371
  this.store.summary = {
4160
4372
  ...(0, import_utils.createEmptySummary)(),
4161
4373
  ...rawSummary,
@@ -4173,9 +4385,16 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4173
4385
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
4174
4386
  }
4175
4387
  };
4176
- this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
4388
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(
4389
+ sourceLastOrderInfo,
4390
+ syntheticIdentityOptions
4391
+ );
4392
+ const hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
4393
+ if (hadSyntheticDraftOrderId && this.store.syncState !== "submitting") {
4394
+ this.store.syncState = "local";
4395
+ }
4177
4396
  const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
4178
- const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
4397
+ const currentDiscounts = typeof ((_c = this.store.discount) == null ? void 0 : _c.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
4179
4398
  const currentScanDiscounts = currentDiscounts.filter((discount) => discount == null ? void 0 : discount.isScan);
4180
4399
  const hydratedDiscountIds = new Set(
4181
4400
  hydratedEditDiscounts.map((discount) => discount == null ? void 0 : discount.id)
@@ -4193,8 +4412,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4193
4412
  nextTempOrder.products,
4194
4413
  nextDiscounts
4195
4414
  );
4196
- await ((_b = this.store.discount) == null ? void 0 : _b.setOriginalDiscountList(nextDiscounts));
4197
- await ((_c = this.store.discount) == null ? void 0 : _c.setDiscountList(nextDiscounts));
4415
+ await ((_d = this.store.discount) == null ? void 0 : _d.setOriginalDiscountList(nextDiscounts));
4416
+ await ((_e = this.store.discount) == null ? void 0 : _e.setDiscountList(nextDiscounts));
4198
4417
  }
4199
4418
  if (options == null ? void 0 : options.recalcOnHydrate) {
4200
4419
  await this.recalculateSummary({ createIfMissing: false });
@@ -4286,12 +4505,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4286
4505
  }
4287
4506
  normalizeTempOrderForRuntime(raw, options) {
4288
4507
  var _a, _b;
4508
+ const runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
4289
4509
  const nextTempOrder = {
4290
4510
  ...this.createDefaultTempOrderInstance(),
4291
- ...raw || {}
4511
+ ...runtimeRaw || {}
4292
4512
  };
4293
- if ((nextTempOrder.order_id === void 0 || nextTempOrder.order_id === null) && (raw == null ? void 0 : raw.id) !== void 0 && (raw == null ? void 0 : raw.id) !== null) {
4294
- nextTempOrder.order_id = raw.id;
4513
+ if ((nextTempOrder.order_id === void 0 || nextTempOrder.order_id === null) && (runtimeRaw == null ? void 0 : runtimeRaw.id) !== void 0 && (runtimeRaw == null ? void 0 : runtimeRaw.id) !== null) {
4514
+ nextTempOrder.order_id = runtimeRaw.id;
4295
4515
  }
4296
4516
  delete nextTempOrder.summary;
4297
4517
  delete nextTempOrder.lastOrderInfo;
@@ -4359,6 +4579,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4359
4579
  nextTempOrder.vouchers = raw.vouchers || [];
4360
4580
  return nextTempOrder;
4361
4581
  }
4582
+ isSyntheticDraftOrderIdForRuntime(record, options) {
4583
+ const isDraftOrder = (options == null ? void 0 : options.isDraftOrder) ?? Number((record == null ? void 0 : record.is_draft_order) || 0) === 1;
4584
+ const externalSaleNumber = (record == null ? void 0 : record.external_sale_number) ?? (options == null ? void 0 : options.externalSaleNumber);
4585
+ const orderId = record == null ? void 0 : record.order_id;
4586
+ return Boolean(
4587
+ isDraftOrder && orderId !== void 0 && orderId !== null && orderId !== "" && externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "" && String(orderId) === String(externalSaleNumber)
4588
+ );
4589
+ }
4590
+ withoutSyntheticDraftOrderIdForRuntime(record, options) {
4591
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options))
4592
+ return record;
4593
+ return {
4594
+ ...record,
4595
+ order_id: null
4596
+ };
4597
+ }
4362
4598
  hydrateLinkedBookingIdentity(tempOrder) {
4363
4599
  const bookingUidByProductUid = /* @__PURE__ */ new Map();
4364
4600
  const productByUid = /* @__PURE__ */ new Map();