@pisell/pisellos 2.2.274 → 2.2.276

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 (117) 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 +1 -1
  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/OpenData/index.d.ts +2 -0
  14. package/dist/modules/OpenData/index.js +8 -0
  15. package/dist/modules/Order/index.d.ts +28 -8
  16. package/dist/modules/Order/index.js +907 -588
  17. package/dist/modules/Order/payment-utils.d.ts +26 -0
  18. package/dist/modules/Order/payment-utils.js +225 -0
  19. package/dist/modules/Order/types.d.ts +35 -1
  20. package/dist/modules/Order/utils/orderCollectionIdentity.js +7 -2
  21. package/dist/modules/Order/utils.js +10 -6
  22. package/dist/modules/Payment/index.d.ts +2 -0
  23. package/dist/modules/Payment/index.js +78 -49
  24. package/dist/modules/Payment/types.d.ts +104 -25
  25. package/dist/modules/Payment/types.js +17 -0
  26. package/dist/modules/Payment/walletpass.d.ts +38 -1
  27. package/dist/modules/Payment/walletpass.js +917 -114
  28. package/dist/modules/Rules/index.d.ts +3 -0
  29. package/dist/modules/Rules/index.js +100 -70
  30. package/dist/server/index.d.ts +25 -0
  31. package/dist/server/index.js +1993 -1061
  32. package/dist/server/modules/index.d.ts +1 -1
  33. package/dist/server/modules/order/index.d.ts +70 -4
  34. package/dist/server/modules/order/index.js +1816 -728
  35. package/dist/server/modules/order/types.d.ts +25 -3
  36. package/dist/server/modules/order/types.js +7 -1
  37. package/dist/solution/BaseSales/index.d.ts +104 -5
  38. package/dist/solution/BaseSales/index.js +1767 -436
  39. package/dist/solution/BaseSales/types.d.ts +55 -1
  40. package/dist/solution/BaseSales/types.js +2 -1
  41. package/dist/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  42. package/dist/solution/BaseSales/utils/cartPromotion.js +94 -32
  43. package/dist/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  44. package/dist/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +7 -4
  45. package/dist/solution/BookingByStep/index.d.ts +1 -1
  46. package/dist/solution/BookingTicket/index.d.ts +21 -5
  47. package/dist/solution/BookingTicket/index.js +139 -56
  48. package/dist/solution/BookingTicket/types.d.ts +1 -0
  49. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  50. package/dist/solution/BookingTicket/utils/scan/applyGlobalScan.js +173 -83
  51. package/dist/solution/Sales/index.d.ts +2 -0
  52. package/dist/solution/Sales/index.js +26 -4
  53. package/dist/solution/ScanOrder/index.js +31 -20
  54. package/dist/solution/VenueBooking/index.d.ts +1 -0
  55. package/dist/solution/VenueBooking/index.js +30 -19
  56. package/dist/types/index.d.ts +1 -0
  57. package/dist/utils/payment-number.d.ts +9 -0
  58. package/dist/utils/payment-number.js +69 -0
  59. package/lib/core/index.d.ts +2 -0
  60. package/lib/core/index.js +4 -0
  61. package/lib/model/strategy/adapter/promotion/adapter.d.ts +4 -0
  62. package/lib/model/strategy/adapter/promotion/adapter.js +20 -0
  63. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +17 -0
  64. package/lib/model/strategy/adapter/promotion/evaluator.js +235 -0
  65. package/lib/model/strategy/adapter/promotion/examples.d.ts +86 -0
  66. package/lib/model/strategy/adapter/promotion/examples.js +91 -0
  67. package/lib/model/strategy/adapter/promotion/index.d.ts +1 -1
  68. package/lib/model/strategy/adapter/promotion/index.js +2 -0
  69. package/lib/model/strategy/adapter/promotion/type.d.ts +90 -2
  70. package/lib/model/strategy/adapter/promotion/type.js +2 -0
  71. package/lib/modules/OpenData/index.d.ts +2 -0
  72. package/lib/modules/OpenData/index.js +5 -0
  73. package/lib/modules/Order/index.d.ts +28 -8
  74. package/lib/modules/Order/index.js +252 -84
  75. package/lib/modules/Order/payment-utils.d.ts +26 -0
  76. package/lib/modules/Order/payment-utils.js +224 -0
  77. package/lib/modules/Order/types.d.ts +35 -1
  78. package/lib/modules/Order/utils/orderCollectionIdentity.js +3 -0
  79. package/lib/modules/Order/utils.js +11 -4
  80. package/lib/modules/Payment/index.d.ts +2 -0
  81. package/lib/modules/Payment/index.js +33 -12
  82. package/lib/modules/Payment/types.d.ts +104 -25
  83. package/lib/modules/Payment/types.js +1 -0
  84. package/lib/modules/Payment/walletpass.d.ts +38 -1
  85. package/lib/modules/Payment/walletpass.js +730 -21
  86. package/lib/modules/Rules/index.d.ts +3 -0
  87. package/lib/modules/Rules/index.js +38 -9
  88. package/lib/server/index.d.ts +25 -0
  89. package/lib/server/index.js +726 -31
  90. package/lib/server/modules/index.d.ts +1 -1
  91. package/lib/server/modules/order/index.d.ts +70 -4
  92. package/lib/server/modules/order/index.js +818 -69
  93. package/lib/server/modules/order/types.d.ts +25 -3
  94. package/lib/server/modules/order/types.js +1 -0
  95. package/lib/solution/BaseSales/index.d.ts +104 -5
  96. package/lib/solution/BaseSales/index.js +858 -27
  97. package/lib/solution/BaseSales/types.d.ts +55 -1
  98. package/lib/solution/BaseSales/types.js +2 -1
  99. package/lib/solution/BaseSales/utils/cartPromotion.d.ts +3 -1
  100. package/lib/solution/BaseSales/utils/cartPromotion.js +66 -12
  101. package/lib/solution/BaseSales/utils/parseSalesResponse.d.ts +6 -1
  102. package/lib/solution/BaseSales/utils/transformBaseProductToOrderProduct.js +4 -3
  103. package/lib/solution/BookingByStep/index.d.ts +1 -1
  104. package/lib/solution/BookingTicket/index.d.ts +21 -5
  105. package/lib/solution/BookingTicket/index.js +64 -13
  106. package/lib/solution/BookingTicket/types.d.ts +1 -0
  107. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.d.ts +8 -0
  108. package/lib/solution/BookingTicket/utils/scan/applyGlobalScan.js +37 -5
  109. package/lib/solution/Sales/index.d.ts +2 -0
  110. package/lib/solution/Sales/index.js +20 -6
  111. package/lib/solution/ScanOrder/index.js +8 -0
  112. package/lib/solution/VenueBooking/index.d.ts +1 -0
  113. package/lib/solution/VenueBooking/index.js +8 -0
  114. package/lib/types/index.d.ts +1 -0
  115. package/lib/utils/payment-number.d.ts +9 -0
  116. package/lib/utils/payment-number.js +64 -0
  117. 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,6 +103,11 @@ 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);
@@ -108,13 +133,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
108
133
  this.draftPersistEnabled = true;
109
134
  }
110
135
  collectHydratedEditDiscounts(products) {
111
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
136
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
112
137
  const discountMap = /* @__PURE__ */ new Map();
113
138
  for (const product of (0, import_bundleDiscountHydration.expandHydratedProductsForDiscountCollection)(products)) {
114
139
  for (const item of (product == null ? void 0 : product.discount_list) || []) {
115
140
  const type = (item == null ? void 0 : item.type) ?? (item == null ? void 0 : item.tag);
116
141
  if (!type || type === "product")
117
142
  continue;
143
+ const isDiscountCard = type === "discount_card" || type === "product_discount_card";
118
144
  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
145
  if (resourceId === void 0 || resourceId === null || resourceId === "")
120
146
  continue;
@@ -122,23 +148,27 @@ var OrderModule = class extends import_BaseModule.BaseModule {
122
148
  const key = Number.isFinite(id) ? id : String(resourceId);
123
149
  const title = ((_b = item == null ? void 0 : item.discount) == null ? void 0 : _b.title) ?? {};
124
150
  const amount = Number((item == null ? void 0 : item.amount) || 0);
151
+ const discountCardType = (_c = item == null ? void 0 : item.discount) == null ? void 0 : _c.discount_card_type;
152
+ const parValue = isDiscountCard ? discountCardType === "fixed_amount" ? ((_d = item == null ? void 0 : item.discount) == null ? void 0 : _d.fixed_amount) ?? (item == null ? void 0 : item.amount) : (_e = item == null ? void 0 : item.discount) == null ? void 0 : _e.percent : "0";
125
153
  const detail = {
126
154
  amount: String((item == null ? void 0 : item.amount) ?? "0"),
127
155
  type,
128
156
  resource_id: key,
129
157
  title,
130
- original_amount: String(((_c = item == null ? void 0 : item.discount) == null ? void 0 : _c.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
131
- num: Number(((_d = item == null ? void 0 : item.metadata) == null ? void 0 : _d.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1,
158
+ original_amount: String(((_f = item == null ? void 0 : item.discount) == null ? void 0 : _f.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
159
+ num: Number(((_g = item == null ? void 0 : item.metadata) == null ? void 0 : _g.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1,
132
160
  metadata: item == null ? void 0 : item.metadata,
133
161
  discount: item == null ? void 0 : item.discount,
134
- _num: Number(((_e = item == null ? void 0 : item.metadata) == null ? void 0 : _e.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1
162
+ _num: Number(((_h = item == null ? void 0 : item.metadata) == null ? void 0 : _h.num) ?? (product == null ? void 0 : product.num) ?? (product == null ? void 0 : product.product_quantity) ?? 1) || 1
135
163
  };
136
164
  const existed = discountMap.get(key);
137
165
  if (existed) {
138
166
  existed.amount = Number(existed.amount || 0) + amount;
139
167
  existed.used_par_value = String(Number(existed.used_par_value || 0) + amount);
140
- existed.balance = String(Number(existed.balance || 0) + amount);
141
- const productIds = Array.isArray((_f = existed.limited_relation_product_data) == null ? void 0 : _f.product_ids) ? existed.limited_relation_product_data.product_ids : [];
168
+ if (!isDiscountCard) {
169
+ existed.balance = String(Number(existed.balance || 0) + amount);
170
+ }
171
+ const productIds = Array.isArray((_i = existed.limited_relation_product_data) == null ? void 0 : _i.product_ids) ? existed.limited_relation_product_data.product_ids : [];
142
172
  if ((product == null ? void 0 : product.product_id) !== void 0 && (product == null ? void 0 : product.product_id) !== null && !productIds.includes(product.product_id)) {
143
173
  existed.limited_relation_product_data = {
144
174
  ...existed.limited_relation_product_data || {},
@@ -161,9 +191,9 @@ var OrderModule = class extends import_BaseModule.BaseModule {
161
191
  encoded: "",
162
192
  code: "",
163
193
  tag: type,
164
- product_id: ((_g = item == null ? void 0 : item.discount) == null ? void 0 : _g.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
194
+ product_id: ((_j = item == null ? void 0 : item.discount) == null ? void 0 : _j.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
165
195
  relation_type: "",
166
- par_value: String(((_h = item == null ? void 0 : item.discount) == null ? void 0 : _h.original_amount) ?? (item == null ? void 0 : item.amount) ?? "0"),
196
+ par_value: String(parValue ?? "0"),
167
197
  used_par_value: String((item == null ? void 0 : item.amount) ?? "0"),
168
198
  limit_status: "enable",
169
199
  limited_relation_product_data: {
@@ -174,7 +204,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
174
204
  filter: 0,
175
205
  exclude_product_ids: []
176
206
  },
177
- balance: String((item == null ? void 0 : item.amount) ?? "0"),
207
+ balance: isDiscountCard ? void 0 : String((item == null ? void 0 : item.amount) ?? "0"),
178
208
  format_title: title,
179
209
  product: {
180
210
  id: (product == null ? void 0 : product.product_id) ?? 0,
@@ -193,8 +223,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
193
223
  discount: {
194
224
  ...(item == null ? void 0 : item.discount) || {},
195
225
  resource_id: key,
196
- discount_product_id: ((_i = item == null ? void 0 : item.discount) == null ? void 0 : _i.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
197
- discount_calculation_mode: ((_j = item == null ? void 0 : item.discount) == null ? void 0 : _j.discount_calculation_mode) ?? "item_level"
226
+ discount_product_id: ((_k = item == null ? void 0 : item.discount) == null ? void 0 : _k.discount_product_id) ?? (product == null ? void 0 : product.product_id) ?? 0,
227
+ discount_calculation_mode: ((_l = item == null ? void 0 : item.discount) == null ? void 0 : _l.discount_calculation_mode) ?? "item_level"
198
228
  },
199
229
  applicableProductDetails: [detail],
200
230
  appliedProductDetails: [detail]
@@ -246,7 +276,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
246
276
  const isPersistedBundleProduct = isPersistedProduct || Boolean(
247
277
  (bundle == null ? void 0 : bundle.order_detail_id) || (bundle == null ? void 0 : bundle.orderDetailId) || (bundle == null ? void 0 : bundle.booking_id)
248
278
  );
249
- const bundleQty = new import_decimal.default(Number(qty) || 1).times(Number((bundle == null ? void 0 : bundle.num) ?? (bundle == null ? void 0 : bundle.quantity) ?? 1) || 1).toNumber();
279
+ const bundleQty = Number(qty) || 1;
250
280
  for (const pd of (bundle == null ? void 0 : bundle.discount_list) || []) {
251
281
  addProductDiscountAmount(pd, bundleQty, isPersistedBundleProduct);
252
282
  }
@@ -313,11 +343,11 @@ var OrderModule = class extends import_BaseModule.BaseModule {
313
343
  this.store.availableWalletIds = [];
314
344
  }
315
345
  this.request = this.core.getPlugin("request");
316
- const appPlugin = this.core.getPlugin("app");
317
- if (!appPlugin) {
346
+ this.appPlugin = this.core.getPlugin("app");
347
+ if (!this.appPlugin) {
318
348
  throw new Error("Order 模块需要 app 插件支持");
319
349
  }
320
- const app = appPlugin.getApp();
350
+ const app = this.appPlugin.getApp();
321
351
  this.logger = app.logger;
322
352
  this.window = this.core.getPlugin("window");
323
353
  const otherParams = options.otherParams || {};
@@ -521,7 +551,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
521
551
  });
522
552
  }
523
553
  async scanCode(code, customerId) {
524
- var _a, _b, _c, _d;
554
+ var _a, _b, _c, _d, _e;
525
555
  const resultDiscountWithReason = await ((_a = this.store.discount) == null ? void 0 : _a.batchSearch(code, { customerId })) || { discountList: [], unavailableReasonKey: null };
526
556
  const { discountList: resultDiscountList, unavailableReasonKey } = resultDiscountWithReason;
527
557
  const rulesModule = this.store.rules;
@@ -529,6 +559,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
529
559
  return {
530
560
  type: "clientCalc",
531
561
  isAvailable: false,
562
+ isAccepted: false,
532
563
  discountList: this.getDiscountList(),
533
564
  scannedDiscountList: resultDiscountList,
534
565
  unavailableReason: import_types2.UnavailableReason.Unknown
@@ -538,6 +569,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
538
569
  return {
539
570
  type: "server",
540
571
  isAvailable: false,
572
+ isAccepted: false,
541
573
  discountList: this.getDiscountList(),
542
574
  scannedDiscountList: resultDiscountList,
543
575
  unavailableReasonKey
@@ -553,13 +585,19 @@ var OrderModule = class extends import_BaseModule.BaseModule {
553
585
  return {
554
586
  type: "clientCalc",
555
587
  isAvailable: true,
588
+ isAccepted: true,
556
589
  discountList: this.getDiscountList(),
557
590
  scannedDiscountList: resultDiscountList
558
591
  };
559
592
  }
560
593
  const tempOrder = this.store.tempOrder;
561
594
  const holders = ((_b = tempOrder == null ? void 0 : tempOrder.holder) == null ? void 0 : _b.form_record) || [];
562
- const { isAvailable, discountList: newDiscountList, unavailableReason } = rulesModule.isDiscountListAvailable({
595
+ const {
596
+ isAvailable,
597
+ discountList: newDiscountList,
598
+ evaluatedDiscountList,
599
+ unavailableReason
600
+ } = rulesModule.isDiscountListAvailable({
563
601
  productList: (tempOrder == null ? void 0 : tempOrder.products) || [],
564
602
  oldDiscountList: this.getDiscountList(),
565
603
  newDiscountList: withScanList,
@@ -567,15 +605,25 @@ var OrderModule = class extends import_BaseModule.BaseModule {
567
605
  holders,
568
606
  isFormSubject: (product) => (0, import_utils.resolveIsFormSubject)(tempOrder, product)
569
607
  }) || { isAvailable: false, discountList: this.getDiscountList() };
570
- if (isAvailable && newDiscountList) {
571
- (_d = this.store.discount) == null ? void 0 : _d.setDiscountList(newDiscountList);
608
+ const shouldRetainForLater = !isAvailable && unavailableReason === import_types2.UnavailableReason.ProductNotApplicable && withScanList.some(isCustomerPromotionDiscount);
609
+ const normalizedNewDiscountList = newDiscountList ? markScannedDiscounts(newDiscountList, withScanList) : void 0;
610
+ const retainedDiscountList = evaluatedDiscountList ? markScannedDiscounts(evaluatedDiscountList, withScanList) : normalizedNewDiscountList;
611
+ let resolvedDiscountList = normalizedNewDiscountList || this.getDiscountList();
612
+ if (isAvailable && normalizedNewDiscountList) {
613
+ await ((_d = this.store.discount) == null ? void 0 : _d.setDiscountList(normalizedNewDiscountList));
572
614
  this.applyDiscount();
573
615
  await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
616
+ resolvedDiscountList = this.getDiscountList();
617
+ } else if (shouldRetainForLater && retainedDiscountList) {
618
+ await ((_e = this.store.discount) == null ? void 0 : _e.setDiscountList(retainedDiscountList));
619
+ await this.syncScannedDiscountsToOriginalDiscountList(this.getDiscountList());
620
+ resolvedDiscountList = this.getDiscountList();
574
621
  }
575
622
  return {
576
623
  type: "clientCalc",
577
624
  isAvailable: isAvailable || false,
578
- discountList: newDiscountList || this.getDiscountList(),
625
+ isAccepted: Boolean(isAvailable || shouldRetainForLater),
626
+ discountList: resolvedDiscountList,
579
627
  scannedDiscountList: resultDiscountList,
580
628
  unavailableReason
581
629
  };
@@ -1053,17 +1101,40 @@ var OrderModule = class extends import_BaseModule.BaseModule {
1053
1101
  const depositPaidAmount = this.calculateDepositPaidAmount(tempOrder.payments || []);
1054
1102
  return depositPaidAmount.lt(depositAmount) ? "deposit" : "normal";
1055
1103
  }
1104
+ getPaymentNumberAppData(key) {
1105
+ var _a, _b, _c, _d, _e;
1106
+ const appPlugin = this.appPlugin;
1107
+ if (!appPlugin)
1108
+ return void 0;
1109
+ const getData = (_a = appPlugin.getData) == null ? void 0 : _a.call(appPlugin);
1110
+ if (typeof getData === "function")
1111
+ return getData(key);
1112
+ const app = appPlugin.getApp();
1113
+ 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");
1114
+ return coreData == null ? void 0 : coreData[key];
1115
+ }
1116
+ getPaymentNumberDevicePrefixSync() {
1117
+ return (0, import_payment_number.resolvePaymentNumberDevicePrefixFromDeviceId)(
1118
+ (key) => this.getPaymentNumberAppData(key)
1119
+ );
1120
+ }
1121
+ getPaymentNumberDevicePrefixAsync() {
1122
+ return (0, import_payment_number.resolvePaymentNumberDevicePrefix)(
1123
+ (key) => this.getPaymentNumberAppData(key)
1124
+ );
1125
+ }
1056
1126
  normalizePaymentSource(payment, options) {
1057
1127
  const paymentRecord = payment;
1058
1128
  const metadata = paymentRecord.metadata && typeof paymentRecord.metadata === "object" ? { ...paymentRecord.metadata } : {};
1059
- if (!metadata.unique_payment_number) {
1060
- metadata.unique_payment_number = (0, import_utils.createUuidV4)();
1061
- }
1062
- const normalized = {
1063
- ...paymentRecord,
1064
- metadata,
1065
- origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1066
- };
1129
+ const normalized = (0, import_payment_utils.ensureOrderPaymentNumber)(
1130
+ {
1131
+ ...paymentRecord,
1132
+ metadata,
1133
+ origin_amount: paymentRecord.origin_amount ?? paymentRecord.amount ?? "0.00"
1134
+ },
1135
+ (options == null ? void 0 : options.devicePrefix) || this.getPaymentNumberDevicePrefixSync(),
1136
+ import_utils.createUuidV4
1137
+ );
1067
1138
  if (paymentRecord.status !== void 0) {
1068
1139
  normalized.status = paymentRecord.status;
1069
1140
  } else if ((options == null ? void 0 : options.defaultPaid) !== false) {
@@ -2484,17 +2555,36 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2484
2555
  * 用一组支付来源覆盖当前订单支付项。
2485
2556
  *
2486
2557
  * 入参允许来自 PaymentModule 的 PaymentItem,内部统一映射为 Sales 协议:
2487
- * uuid -> metadata.unique_payment_number,id -> custom_payment_id,
2558
+ * 新支付来源的 uuid 会作为 payment_number 的唯一号段,id -> custom_payment_id,
2488
2559
  * isSynced 等运行态字段不会进入 tempOrder.payments。
2489
2560
  */
2490
2561
  setOrderPayments(payments) {
2491
2562
  const tempOrder = this.ensureTempOrder();
2492
- tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(payments);
2563
+ tempOrder.payments = (0, import_utils.mapPaymentItemsToOrderPayments)(
2564
+ (payments || []).map((payment) => this.normalizePaymentSource(payment, { defaultPaid: false }))
2565
+ );
2493
2566
  this.persistTempOrder();
2494
2567
  return tempOrder.payments;
2495
2568
  }
2496
- /** 追加单个支付项,并立即持久化当前 tempOrder。 */
2569
+ /** 同步兼容入口:按调用当下的 device_id 或 LOCAL 生成支付编号。 */
2497
2570
  addOrderPayment(payment) {
2571
+ const hasPaymentNumber = String(
2572
+ payment.payment_number || ""
2573
+ ).trim() !== "";
2574
+ return this.addOrderPaymentWithDevicePrefix(
2575
+ payment,
2576
+ hasPaymentNumber ? "LOCAL" : this.getPaymentNumberDevicePrefixSync()
2577
+ );
2578
+ }
2579
+ /** 异步入口:创建支付项时读取最新 IoT 设备短号。 */
2580
+ async addOrderPaymentAsync(payment) {
2581
+ const hasPaymentNumber = String(
2582
+ payment.payment_number || ""
2583
+ ).trim() !== "";
2584
+ const devicePrefix = hasPaymentNumber ? "LOCAL" : await this.getPaymentNumberDevicePrefixAsync();
2585
+ return this.addOrderPaymentWithDevicePrefix(payment, devicePrefix);
2586
+ }
2587
+ addOrderPaymentWithDevicePrefix(payment, devicePrefix) {
2498
2588
  this.logInfo("addOrderPayment", {
2499
2589
  payment
2500
2590
  });
@@ -2507,7 +2597,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2507
2597
  type: orderPaymentType,
2508
2598
  order_payment_type: orderPaymentType
2509
2599
  },
2510
- { defaultPaid: true }
2600
+ { defaultPaid: true, devicePrefix }
2511
2601
  )
2512
2602
  ]);
2513
2603
  tempOrder.payments = [...tempOrder.payments || [], ...mapped];
@@ -2520,57 +2610,55 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2520
2610
  return tempOrder.payments;
2521
2611
  }
2522
2612
  /**
2523
- * 按支付唯一号、后端支付 ID、自定义支付方式 ID 或旧 uuid 更新支付项。
2524
- *
2525
- * 该方法服务 PaymentModal 的 void / 编辑场景;更新 metadata 时会做浅合并,
2526
- * 避免覆盖 unique_payment_number、现金实付/找零等已有元数据。
2613
+ * 默认按支付唯一号精确更新;仅显式指定 legacy 时兼容历史支付标识。
2614
+ * metadata 与 transactions 会分别合并,避免覆盖支付会话号和已有交易记录。
2527
2615
  */
2528
- updateOrderPayment(paymentIdentity, updates) {
2616
+ async updateOrderPayment(paymentIdentity, updates, options = {}) {
2529
2617
  const tempOrder = this.ensureTempOrder();
2530
2618
  const identity = String(paymentIdentity);
2531
- tempOrder.payments = (tempOrder.payments || []).map((payment) => {
2532
- var _a;
2533
- const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2534
- const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2535
- const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2536
- const uuid = payment == null ? void 0 : payment.uuid;
2537
- const matched = [
2538
- uniquePaymentNumber,
2539
- orderPaymentId,
2540
- customPaymentId,
2541
- uuid
2542
- ].some((value) => value !== void 0 && String(value) === identity);
2543
- if (!matched)
2619
+ const matchMode = options.matchBy === "compat" || options.matchBy === "legacy" ? "compat" : "payment_number";
2620
+ const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2621
+ tempOrder.payments || [],
2622
+ identity,
2623
+ matchMode
2624
+ );
2625
+ if (!matchedPayment) {
2626
+ throw new Error(`未找到支付项: ${identity}`);
2627
+ }
2628
+ let updatedPayment = null;
2629
+ tempOrder.payments = (tempOrder.payments || []).map((payment, index) => {
2630
+ if (index !== matchedPayment.index)
2544
2631
  return payment;
2545
- return {
2546
- ...payment,
2632
+ const nextPayment = (0, import_payment_utils.mergeOrderPaymentRecord)(payment, {
2547
2633
  ...updates,
2548
- metadata: {
2549
- ...payment.metadata || {},
2550
- ...updates.metadata || {}
2551
- }
2552
- };
2634
+ updated_at: updates.updated_at || (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss")
2635
+ });
2636
+ updatedPayment = nextPayment;
2637
+ return nextPayment;
2553
2638
  });
2554
2639
  this.persistTempOrder();
2555
- return tempOrder.payments;
2640
+ const summary = await this.recalculateSummary({ createIfMissing: true });
2641
+ this.persistTempOrder();
2642
+ const payments = tempOrder.payments;
2643
+ return {
2644
+ updated: true,
2645
+ payment: payments[matchedPayment.index] || updatedPayment,
2646
+ payments,
2647
+ summary
2648
+ };
2556
2649
  }
2557
2650
  /** 从当前订单支付项中移除指定支付项。 */
2558
2651
  deleteOrderPayment(paymentIdentity) {
2559
2652
  const tempOrder = this.ensureTempOrder();
2560
2653
  const identity = String(paymentIdentity);
2561
- tempOrder.payments = (tempOrder.payments || []).filter((payment) => {
2562
- var _a;
2563
- const uniquePaymentNumber = (_a = payment == null ? void 0 : payment.metadata) == null ? void 0 : _a.unique_payment_number;
2564
- const orderPaymentId = payment == null ? void 0 : payment.order_payment_id;
2565
- const customPaymentId = payment == null ? void 0 : payment.custom_payment_id;
2566
- const uuid = payment == null ? void 0 : payment.uuid;
2567
- return ![
2568
- uniquePaymentNumber,
2569
- orderPaymentId,
2570
- customPaymentId,
2571
- uuid
2572
- ].some((value) => value !== void 0 && String(value) === identity);
2573
- });
2654
+ const matchedPayment = (0, import_payment_utils.resolveOrderPaymentIdentity)(
2655
+ tempOrder.payments || [],
2656
+ identity,
2657
+ "compat"
2658
+ );
2659
+ if (!matchedPayment)
2660
+ return tempOrder.payments;
2661
+ tempOrder.payments = (tempOrder.payments || []).filter((_, index) => index !== matchedPayment.index);
2574
2662
  this.persistTempOrder();
2575
2663
  return tempOrder.payments;
2576
2664
  }
@@ -2679,7 +2767,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2679
2767
  payments.map(
2680
2768
  (payment) => this.normalizePaymentSource(
2681
2769
  normalizeVoucherPaymentStatus(withVoucherPaymentType(payment)),
2682
- { defaultPaid: false }
2770
+ {
2771
+ defaultPaid: false,
2772
+ devicePrefix: options == null ? void 0 : options.devicePrefix
2773
+ }
2683
2774
  )
2684
2775
  )
2685
2776
  ).filter((payment) => {
@@ -2701,14 +2792,15 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2701
2792
  const committedVoucherPaymentIds = new Set(
2702
2793
  committedVoucherPayments.filter((payment) => hasSyncedOrderPaymentRecord(payment)).map((payment) => String(payment.order_payment_id))
2703
2794
  );
2704
- const committedVoucherIds = new Set(
2705
- committedVoucherPayments.map((payment) => String(payment.voucher_id))
2795
+ const committedVoucherLifecycleKeys = new Set(
2796
+ committedVoucherPayments.map((payment) => getVoucherPaymentLifecycleKey(payment)).filter((key) => key !== null)
2706
2797
  );
2707
2798
  const replaceableVouchers = mappedVouchers.filter((payment) => {
2708
2799
  if (hasSyncedOrderPaymentRecord(payment) && committedVoucherPaymentIds.has(String(payment.order_payment_id))) {
2709
2800
  return false;
2710
2801
  }
2711
- if (payment.voucher_id !== void 0 && committedVoucherIds.has(String(payment.voucher_id))) {
2802
+ const lifecycleKey = getVoucherPaymentLifecycleKey(payment);
2803
+ if (lifecycleKey && committedVoucherLifecycleKeys.has(lifecycleKey)) {
2712
2804
  return false;
2713
2805
  }
2714
2806
  return true;
@@ -2730,6 +2822,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2730
2822
  });
2731
2823
  return tempOrder.payments;
2732
2824
  }
2825
+ async updateVoucherOrderPaymentsAsync(payments, options) {
2826
+ const needsPaymentNumber = (payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
2827
+ const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
2828
+ return this.updateVoucherOrderPayments(payments, {
2829
+ ...options,
2830
+ devicePrefix
2831
+ });
2832
+ }
2733
2833
  async shouldMergeProductToOrder(params) {
2734
2834
  var _a;
2735
2835
  const onBeforeMergeProductToOrder = (_a = this.orderHooks) == null ? void 0 : _a.onBeforeMergeProductToOrder;
@@ -2790,7 +2890,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2790
2890
  * await this.appendProductLineToTempOrder(tempOrder, { product_id: 1, num: 1 }, booking);
2791
2891
  */
2792
2892
  async appendProductLineToTempOrder(tempOrder, product, booking, options) {
2793
- var _a, _b, _c, _d;
2893
+ var _a, _b, _c, _d, _e, _f, _g;
2794
2894
  const linked = booking ? this.createLinkedProductAndBooking({ product, booking }) : null;
2795
2895
  const productToAdd = (linked == null ? void 0 : linked.product) || product;
2796
2896
  const incomingFingerprint = (0, import_utils3.buildProductLineFingerprint)(
@@ -2822,7 +2922,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2822
2922
  );
2823
2923
  const hasIncomingProductNote = this.hasOrderProductLineNote(normalizedIncoming);
2824
2924
  const hasIncomingBookingUid = this.hasLinkedBookingUid(productToAdd) || this.hasLinkedBookingUid(normalizedIncoming);
2825
- const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid || isWeighingProduct;
2925
+ const isIncomingCustomItem = ((_e = (_d = productToAdd.metadata) == null ? void 0 : _d.origin) == null ? void 0 : _e.isCustomItem) === true || ((_f = productToAdd._origin) == null ? void 0 : _f.isCustomItem) === true;
2926
+ const shouldForceNewLine = !!booking || hasIncomingProductNote || hasIncomingBookingUid || isIncomingCustomItem || isWeighingProduct;
2826
2927
  const matchedIndex = hasIncomingGoodPass || shouldForceNewLine ? -1 : tempOrder.products.findIndex((item) => {
2827
2928
  var _a2;
2828
2929
  if (this.hasGoodPassDiscount(item))
@@ -2883,7 +2984,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
2883
2984
  }
2884
2985
  } else {
2885
2986
  const targetProduct = matchedProduct;
2886
- const targetUid = (_d = targetProduct.metadata) == null ? void 0 : _d.unique_identification_number;
2987
+ const targetUid = (_g = targetProduct.metadata) == null ? void 0 : _g.unique_identification_number;
2887
2988
  const normalizedProduct = (0, import_utils.mergeOrderProductDisplayFields)(
2888
2989
  targetProduct,
2889
2990
  (0, import_utils3.normalizeOrderProduct)({
@@ -3627,6 +3728,38 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3627
3728
  await this.saveDraft();
3628
3729
  return tempOrder;
3629
3730
  }
3731
+ async saveTempOrderAsDraft(params) {
3732
+ var _a, _b, _c, _d, _e;
3733
+ const tempOrder = this.ensureTempOrder();
3734
+ this.ensureExternalSaleNumber(tempOrder);
3735
+ this.persistTempOrder();
3736
+ const latestSummary = await this.recalculateSummary({ createIfMissing: true }) || this.store.summary || (0, import_utils.createEmptySummary)();
3737
+ const payload = (0, import_utils.buildSubmitPayload)({
3738
+ tempOrder,
3739
+ cacheId: (params == null ? void 0 : params.cacheId) ?? this.cacheId,
3740
+ platform: (params == null ? void 0 : params.platform) || ((_a = this.otherParams) == null ? void 0 : _a.platform),
3741
+ 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,
3742
+ channel: params == null ? void 0 : params.channel,
3743
+ type: (params == null ? void 0 : params.type) ?? ((_d = this.otherParams) == null ? void 0 : _d.type),
3744
+ summary: latestSummary,
3745
+ enhance: params == null ? void 0 : params.enhancePayload
3746
+ });
3747
+ if (!payload.created_at) {
3748
+ payload.created_at = (0, import_dayjs.default)().format("YYYY-MM-DD HH:mm:ss");
3749
+ }
3750
+ payload.need_sync = 0;
3751
+ payload.is_draft_order = 1;
3752
+ this.logInfo("saveTempOrderAsDraft calling sales draft", {
3753
+ orderId: payload.order_id,
3754
+ externalSaleNumber: payload.external_sale_number,
3755
+ productsCount: ((_e = payload.products) == null ? void 0 : _e.length) || 0
3756
+ });
3757
+ return this.request.post("/order/sales/draft", payload, {
3758
+ osServer: true,
3759
+ customToast: () => {
3760
+ }
3761
+ });
3762
+ }
3630
3763
  /**
3631
3764
  * 提交当前 Sales tempOrder。
3632
3765
  *
@@ -3827,8 +3960,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
3827
3960
  }
3828
3961
  async syncPaymentsToOrder(params) {
3829
3962
  const tempOrder = this.ensureTempOrder();
3963
+ const needsPaymentNumber = (params.payments || []).some((payment) => String(payment.payment_number || "").trim() === "");
3964
+ const devicePrefix = needsPaymentNumber ? await this.getPaymentNumberDevicePrefixAsync() : "LOCAL";
3830
3965
  const mappedPayments = (0, import_utils.mapPaymentItemsToOrderPayments)(
3831
- params.payments || []
3966
+ (params.payments || []).map((payment) => this.normalizePaymentSource(payment, {
3967
+ defaultPaid: false,
3968
+ devicePrefix
3969
+ }))
3832
3970
  );
3833
3971
  const shouldConfirmPendingVoucherPayments = params.confirmPendingVoucherPayments ?? params.submitWhenPaid === true;
3834
3972
  const effectivePayments = shouldConfirmPendingVoucherPayments ? this.confirmPendingVoucherPaymentsInList(mappedPayments) : params.confirmPendingVoucherPayments === false ? this.discardPendingVoucherPaymentsFromList(mappedPayments) : mappedPayments;
@@ -4158,7 +4296,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4158
4296
  params.forceRemote = false;
4159
4297
  }
4160
4298
  const res = await this.request.get(`/order/sales/${encodeURIComponent(lookup)}`, {
4161
- with: ["products", "bookings", "payments", "customer", "summary", "contacts_info"],
4299
+ with: ["products", "bookings", "payments", "customer", "summary", "contacts_info", "refunds"],
4162
4300
  ...params.forceRemote ? { forceRemote: true } : {}
4163
4301
  }, { osServer: true });
4164
4302
  if (res.code === 200) {
@@ -4204,6 +4342,12 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4204
4342
  }
4205
4343
  }
4206
4344
  const nextTempOrder = this.normalizeTempOrderForRuntime(raw, { makeEditMark: true });
4345
+ const sourceLastOrderInfo = raw.lastOrderInfo || raw;
4346
+ const isDraftOrder = Number(nextTempOrder.is_draft_order || 0) === 1;
4347
+ const syntheticIdentityOptions = {
4348
+ isDraftOrder,
4349
+ externalSaleNumber: nextTempOrder.external_sale_number
4350
+ };
4207
4351
  const rawSummary = raw.summary && typeof raw.summary === "object" ? raw.summary : {};
4208
4352
  const summarySurcharges = Array.isArray(rawSummary.surcharges) ? rawSummary.surcharges.map((s) => ({ ...s || {} })) : (0, import_lodash_es.cloneDeep)(nextTempOrder.surcharges || []);
4209
4353
  this.store.tempOrder = nextTempOrder;
@@ -4224,7 +4368,14 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4224
4368
  productFingerprint: this.buildOrderProductsFingerprint(nextTempOrder.products || [])
4225
4369
  }
4226
4370
  };
4227
- this.store.lastOrderInfo = sourceRaw.lastOrderInfo || sourceRaw;
4371
+ this.store.lastOrderInfo = this.withoutSyntheticDraftOrderIdForRuntime(
4372
+ sourceLastOrderInfo,
4373
+ syntheticIdentityOptions
4374
+ );
4375
+ const hadSyntheticDraftOrderId = this.isSyntheticDraftOrderIdForRuntime(raw, syntheticIdentityOptions) || this.isSyntheticDraftOrderIdForRuntime(sourceLastOrderInfo, syntheticIdentityOptions);
4376
+ if (hadSyntheticDraftOrderId && this.store.syncState !== "submitting") {
4377
+ this.store.syncState = "local";
4378
+ }
4228
4379
  const hydratedEditDiscounts = this.collectHydratedEditDiscounts(nextTempOrder.products);
4229
4380
  const currentDiscounts = typeof ((_a = this.store.discount) == null ? void 0 : _a.getDiscountList) === "function" ? this.store.discount.getDiscountList() || [] : [];
4230
4381
  const currentScanDiscounts = currentDiscounts.filter((discount) => discount == null ? void 0 : discount.isScan);
@@ -4337,12 +4488,13 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4337
4488
  }
4338
4489
  normalizeTempOrderForRuntime(raw, options) {
4339
4490
  var _a, _b;
4491
+ const runtimeRaw = this.withoutSyntheticDraftOrderIdForRuntime(raw);
4340
4492
  const nextTempOrder = {
4341
4493
  ...this.createDefaultTempOrderInstance(),
4342
- ...raw || {}
4494
+ ...runtimeRaw || {}
4343
4495
  };
4344
- 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) {
4345
- nextTempOrder.order_id = raw.id;
4496
+ 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) {
4497
+ nextTempOrder.order_id = runtimeRaw.id;
4346
4498
  }
4347
4499
  delete nextTempOrder.summary;
4348
4500
  delete nextTempOrder.lastOrderInfo;
@@ -4410,6 +4562,22 @@ var OrderModule = class extends import_BaseModule.BaseModule {
4410
4562
  nextTempOrder.vouchers = raw.vouchers || [];
4411
4563
  return nextTempOrder;
4412
4564
  }
4565
+ isSyntheticDraftOrderIdForRuntime(record, options) {
4566
+ const isDraftOrder = (options == null ? void 0 : options.isDraftOrder) ?? Number((record == null ? void 0 : record.is_draft_order) || 0) === 1;
4567
+ const externalSaleNumber = (record == null ? void 0 : record.external_sale_number) ?? (options == null ? void 0 : options.externalSaleNumber);
4568
+ const orderId = record == null ? void 0 : record.order_id;
4569
+ return Boolean(
4570
+ isDraftOrder && orderId !== void 0 && orderId !== null && orderId !== "" && externalSaleNumber !== void 0 && externalSaleNumber !== null && externalSaleNumber !== "" && String(orderId) === String(externalSaleNumber)
4571
+ );
4572
+ }
4573
+ withoutSyntheticDraftOrderIdForRuntime(record, options) {
4574
+ if (!this.isSyntheticDraftOrderIdForRuntime(record, options))
4575
+ return record;
4576
+ return {
4577
+ ...record,
4578
+ order_id: null
4579
+ };
4580
+ }
4413
4581
  hydrateLinkedBookingIdentity(tempOrder) {
4414
4582
  const bookingUidByProductUid = /* @__PURE__ */ new Map();
4415
4583
  const productByUid = /* @__PURE__ */ new Map();
@@ -0,0 +1,26 @@
1
+ export type OrderPaymentTransactionStatus = 'success' | 'fail';
2
+ export interface OrderPaymentTransaction {
3
+ number: string;
4
+ status: OrderPaymentTransactionStatus;
5
+ }
6
+ export type OrderPaymentIdentityType = 'order_payment_id' | 'payment_number' | 'unique_payment_number';
7
+ export interface OrderPaymentIdentityMatch<T> {
8
+ index: number;
9
+ payment: T;
10
+ matchedBy: OrderPaymentIdentityType;
11
+ }
12
+ export declare function getOrderPaymentIdentityKeys(payment: unknown): string[];
13
+ export declare function isPendingOrderPayment(payment: unknown): boolean;
14
+ export declare function isIdentifiedPendingOrderPayment(payment: unknown): boolean;
15
+ export declare function hasOrderPaymentIdentityOverlap(left: unknown, right: unknown): boolean;
16
+ export declare function resolveOrderPaymentIdentity<T extends Record<string, any>>(payments: T[] | null | undefined, identity: string | number, mode?: 'payment_number' | 'compat'): OrderPaymentIdentityMatch<T> | null;
17
+ export declare function ensureOrderPaymentNumber<T extends Record<string, any>>(payment: T, devicePrefix: string, createPaymentNumber: () => string): T & {
18
+ payment_number: string;
19
+ };
20
+ export declare function mergeOrderPaymentTransactions(current: unknown, incoming: unknown): OrderPaymentTransaction[];
21
+ export declare function mergeOrderPaymentRecord<T extends Record<string, any>>(payment: T, updates: Record<string, any>): T;
22
+ export declare function mergeOrderPaymentSnapshot<T extends Record<string, any>>(current: T, incoming: T): T;
23
+ export declare function mergeOrderPaymentListsByIdentity<T extends Record<string, any>>(existing: T[] | null | undefined, incoming: T[] | null | undefined, options?: {
24
+ preserveUnmatchedExisting?: boolean;
25
+ preserveUnmatchedExistingWhen?: (payment: T) => boolean;
26
+ }): T[];