@pisell/pisellos 0.0.480 → 0.0.481

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 (147) hide show
  1. package/dist/core/index.d.ts +3 -2
  2. package/dist/core/index.js +7 -0
  3. package/dist/effects/index.d.ts +2 -2
  4. package/dist/effects/index.js +34 -81
  5. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  6. package/dist/model/strategy/adapter/walletPass/type.d.ts +9 -2
  7. package/dist/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  8. package/dist/model/strategy/adapter/walletPass/utils.js +104 -77
  9. package/dist/modules/Customer/index.js +1 -1
  10. package/dist/modules/Discount/index.d.ts +6 -2
  11. package/dist/modules/Discount/index.js +14 -8
  12. package/dist/modules/Order/index.d.ts +1 -1
  13. package/dist/modules/Order/index.js +18 -13
  14. package/dist/modules/Payment/index.d.ts +4 -0
  15. package/dist/modules/Payment/index.js +774 -649
  16. package/dist/modules/Payment/walletpass.js +44 -17
  17. package/dist/modules/Product/index.d.ts +1 -1
  18. package/dist/modules/Product/types.d.ts +2 -0
  19. package/dist/modules/ProductList/index.d.ts +3 -0
  20. package/dist/modules/ProductList/index.js +9 -7
  21. package/dist/modules/Rules/index.d.ts +2 -2
  22. package/dist/modules/Rules/index.js +37 -31
  23. package/dist/modules/Rules/types.d.ts +2 -2
  24. package/dist/modules/Schedule/index.d.ts +9 -0
  25. package/dist/modules/Schedule/index.js +15 -2
  26. package/dist/plugins/app-types/app/app.d.ts +1 -0
  27. package/dist/plugins/request.d.ts +2 -0
  28. package/dist/server/index.d.ts +107 -2
  29. package/dist/server/index.js +1507 -279
  30. package/dist/server/modules/index.d.ts +6 -0
  31. package/dist/server/modules/index.js +7 -0
  32. package/dist/server/modules/menu/index.d.ts +19 -0
  33. package/dist/server/modules/menu/index.js +221 -71
  34. package/dist/server/modules/order/index.d.ts +87 -0
  35. package/dist/server/modules/order/index.js +916 -0
  36. package/dist/server/modules/order/types.d.ts +530 -0
  37. package/dist/server/modules/order/types.js +141 -0
  38. package/dist/server/modules/order/utils/filterBookings.d.ts +6 -0
  39. package/dist/server/modules/order/utils/filterBookings.js +350 -0
  40. package/dist/server/modules/order/utils/filterOrders.d.ts +15 -0
  41. package/dist/server/modules/order/utils/filterOrders.js +226 -0
  42. package/dist/server/modules/products/index.d.ts +117 -5
  43. package/dist/server/modules/products/index.js +1450 -240
  44. package/dist/server/modules/products/types.d.ts +25 -1
  45. package/dist/server/modules/products/types.js +3 -0
  46. package/dist/server/modules/resource/index.d.ts +86 -0
  47. package/dist/server/modules/resource/index.js +1128 -0
  48. package/dist/server/modules/resource/types.d.ts +121 -0
  49. package/dist/server/modules/resource/types.js +47 -0
  50. package/dist/server/modules/schedule/index.d.ts +19 -0
  51. package/dist/server/modules/schedule/index.js +229 -68
  52. package/dist/server/utils/product.d.ts +5 -0
  53. package/dist/server/utils/product.js +71 -31
  54. package/dist/solution/BookingTicket/index.d.ts +10 -2
  55. package/dist/solution/BookingTicket/index.js +41 -28
  56. package/dist/solution/BookingTicket/utils/scan/index.js +1 -1
  57. package/dist/solution/Checkout/index.d.ts +1 -0
  58. package/dist/solution/Checkout/index.js +286 -188
  59. package/dist/solution/Checkout/utils/index.d.ts +2 -1
  60. package/dist/solution/Checkout/utils/index.js +6 -4
  61. package/dist/solution/RegisterAndLogin/config.js +340 -1
  62. package/dist/solution/Sales/index.d.ts +96 -0
  63. package/dist/solution/Sales/index.js +566 -0
  64. package/dist/solution/Sales/types.d.ts +67 -0
  65. package/dist/solution/Sales/types.js +26 -0
  66. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  67. package/dist/solution/ShopDiscount/index.js +35 -22
  68. package/dist/solution/ShopDiscount/types.d.ts +6 -0
  69. package/dist/solution/ShopDiscount/utils.d.ts +9 -0
  70. package/dist/solution/ShopDiscount/utils.js +21 -27
  71. package/dist/solution/index.d.ts +2 -1
  72. package/dist/solution/index.js +2 -1
  73. package/dist/types/index.d.ts +5 -0
  74. package/lib/core/index.d.ts +3 -2
  75. package/lib/core/index.js +4 -0
  76. package/lib/effects/index.d.ts +2 -2
  77. package/lib/effects/index.js +22 -31
  78. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  79. package/lib/model/strategy/adapter/walletPass/type.d.ts +9 -2
  80. package/lib/model/strategy/adapter/walletPass/utils.d.ts +6 -6
  81. package/lib/model/strategy/adapter/walletPass/utils.js +113 -49
  82. package/lib/modules/Customer/index.js +1 -1
  83. package/lib/modules/Discount/index.d.ts +6 -2
  84. package/lib/modules/Discount/index.js +3 -1
  85. package/lib/modules/Order/index.d.ts +1 -1
  86. package/lib/modules/Order/index.js +20 -18
  87. package/lib/modules/Payment/index.d.ts +4 -0
  88. package/lib/modules/Payment/index.js +134 -66
  89. package/lib/modules/Payment/walletpass.js +23 -4
  90. package/lib/modules/Product/index.d.ts +1 -1
  91. package/lib/modules/Product/types.d.ts +2 -0
  92. package/lib/modules/ProductList/index.d.ts +3 -0
  93. package/lib/modules/ProductList/index.js +2 -2
  94. package/lib/modules/Rules/index.d.ts +2 -2
  95. package/lib/modules/Rules/index.js +69 -73
  96. package/lib/modules/Rules/types.d.ts +2 -2
  97. package/lib/modules/Schedule/index.d.ts +9 -0
  98. package/lib/modules/Schedule/index.js +11 -0
  99. package/lib/plugins/app-types/app/app.d.ts +1 -0
  100. package/lib/plugins/request.d.ts +2 -0
  101. package/lib/server/index.d.ts +107 -2
  102. package/lib/server/index.js +773 -51
  103. package/lib/server/modules/index.d.ts +6 -0
  104. package/lib/server/modules/index.js +16 -2
  105. package/lib/server/modules/menu/index.d.ts +19 -0
  106. package/lib/server/modules/menu/index.js +121 -2
  107. package/lib/server/modules/order/index.d.ts +87 -0
  108. package/lib/server/modules/order/index.js +543 -0
  109. package/lib/server/modules/order/types.d.ts +530 -0
  110. package/lib/server/modules/order/types.js +34 -0
  111. package/lib/server/modules/order/utils/filterBookings.d.ts +6 -0
  112. package/lib/server/modules/order/utils/filterBookings.js +320 -0
  113. package/lib/server/modules/order/utils/filterOrders.d.ts +15 -0
  114. package/lib/server/modules/order/utils/filterOrders.js +197 -0
  115. package/lib/server/modules/products/index.d.ts +117 -5
  116. package/lib/server/modules/products/index.js +799 -62
  117. package/lib/server/modules/products/types.d.ts +25 -1
  118. package/lib/server/modules/products/types.js +1 -0
  119. package/lib/server/modules/resource/index.d.ts +86 -0
  120. package/lib/server/modules/resource/index.js +557 -0
  121. package/lib/server/modules/resource/types.d.ts +121 -0
  122. package/lib/server/modules/resource/types.js +35 -0
  123. package/lib/server/modules/schedule/index.d.ts +19 -0
  124. package/lib/server/modules/schedule/index.js +141 -12
  125. package/lib/server/utils/product.d.ts +5 -0
  126. package/lib/server/utils/product.js +56 -27
  127. package/lib/solution/BookingTicket/index.d.ts +10 -2
  128. package/lib/solution/BookingTicket/index.js +10 -2
  129. package/lib/solution/BookingTicket/utils/scan/index.js +0 -1
  130. package/lib/solution/Checkout/index.d.ts +1 -0
  131. package/lib/solution/Checkout/index.js +399 -331
  132. package/lib/solution/Checkout/utils/index.d.ts +2 -1
  133. package/lib/solution/Checkout/utils/index.js +6 -4
  134. package/lib/solution/RegisterAndLogin/config.js +266 -1
  135. package/lib/solution/Sales/index.d.ts +96 -0
  136. package/lib/solution/Sales/index.js +416 -0
  137. package/lib/solution/Sales/types.d.ts +67 -0
  138. package/lib/solution/Sales/types.js +35 -0
  139. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  140. package/lib/solution/ShopDiscount/index.js +14 -6
  141. package/lib/solution/ShopDiscount/types.d.ts +6 -0
  142. package/lib/solution/ShopDiscount/utils.d.ts +9 -0
  143. package/lib/solution/ShopDiscount/utils.js +6 -10
  144. package/lib/solution/index.d.ts +2 -1
  145. package/lib/solution/index.js +4 -2
  146. package/lib/types/index.d.ts +5 -0
  147. package/package.json +1 -1
@@ -42,10 +42,72 @@ __export(utils_exports, {
42
42
  getProductQuantity: () => getProductQuantity,
43
43
  getTaxAndFeeRoundingRemainder: () => getTaxAndFeeRoundingRemainder,
44
44
  processVouchers: () => processVouchers,
45
- recalculateVouchers: () => recalculateVouchers
45
+ recalculateVouchers: () => recalculateVouchers,
46
+ resolveWalletPassLineKey: () => resolveWalletPassLineKey
46
47
  });
47
48
  module.exports = __toCommonJS(utils_exports);
48
49
  var import_decimal = __toESM(require("decimal.js"));
50
+ var getProductQuantity = (product) => {
51
+ return product.quantity || product.product_quantity || 1;
52
+ };
53
+ function resolveWalletPassLineKey(product, indexInOrder) {
54
+ const m = (product == null ? void 0 : product.metadata) || {};
55
+ const u1 = m.product_unique;
56
+ if (u1 != null && String(u1).length > 0)
57
+ return String(u1);
58
+ const u2 = m.unique_identification_number;
59
+ if (u2 != null && String(u2).length > 0)
60
+ return String(u2);
61
+ if ((product == null ? void 0 : product.id) != null && String(product.id).length > 0)
62
+ return `order_item:${product.id}`;
63
+ if ((product == null ? void 0 : product.product_unique_string) != null && String(product.product_unique_string).length > 0) {
64
+ return String(product.product_unique_string);
65
+ }
66
+ return `order_line_${indexInOrder}`;
67
+ }
68
+ function getExpandedOrderLineQuantity(p) {
69
+ if ((p == null ? void 0 : p._orderLineQuantity) != null && p._orderLineQuantity > 0)
70
+ return p._orderLineQuantity;
71
+ return getProductQuantity(p);
72
+ }
73
+ function getMaxPassSlotsForExpandedLine(maxPassesPerItem, p) {
74
+ if (maxPassesPerItem <= 0)
75
+ return Infinity;
76
+ return maxPassesPerItem * getExpandedOrderLineQuantity(p);
77
+ }
78
+ function computePassSlotsIncrement(deductAmount, deductQty, maxPassesPerItem, orderLineQuantity, currentUsage) {
79
+ if (maxPassesPerItem <= 0 || !deductAmount.greaterThan(0))
80
+ return 0;
81
+ const cap = maxPassesPerItem * orderLineQuantity;
82
+ const room = Math.max(0, cap - currentUsage);
83
+ if (room <= 0)
84
+ return 0;
85
+ const raw = Math.max(1, Math.ceil(Number(deductQty)) || 1);
86
+ return Math.min(raw, room);
87
+ }
88
+ function applyMaxPassUsageIncrements(usageMap, walletPassProductId, maxPassesPerItem, deductionDetails) {
89
+ deductionDetails.forEach((detail) => {
90
+ var _a;
91
+ const lineKey = detail.lineKey;
92
+ if (!lineKey || maxPassesPerItem <= 0)
93
+ return;
94
+ const orderLineQty = detail.orderLineQuantity != null && detail.orderLineQuantity > 0 ? detail.orderLineQuantity : 1;
95
+ const cur = ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(lineKey)) || 0;
96
+ const inc = computePassSlotsIncrement(
97
+ new import_decimal.default(detail.deductAmount),
98
+ detail.deductQuantity,
99
+ maxPassesPerItem,
100
+ orderLineQty,
101
+ cur
102
+ );
103
+ if (inc <= 0)
104
+ return;
105
+ if (!usageMap.has(walletPassProductId))
106
+ usageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
107
+ const inner = usageMap.get(walletPassProductId);
108
+ inner.set(lineKey, cur + inc);
109
+ });
110
+ }
49
111
  var getRecommendedAmount = (voucher) => {
50
112
  console.log("voucher312", voucher);
51
113
  const { config, recommended_usage_amount, recommended_pure_product_usage_amount } = voucher;
@@ -86,30 +148,23 @@ var getApplicableProducts = (voucher, productsData) => {
86
148
  }
87
149
  return productsData.filter((p) => applicableProductIds.includes(p.product_id));
88
150
  };
89
- var getTotalQuantityByProductId = (allProducts, productId) => {
90
- return allProducts.filter((p) => p.product_id === productId).reduce((sum, p) => sum + getProductQuantity(p), 0);
91
- };
92
151
  function processVouchers(applicableVouchers, orderTotalAmount, products) {
93
152
  console.log(products, "products123");
94
153
  const productsCopy = expandProductsWithBundleItems(products, true);
95
154
  let remainingOrderAmount = new import_decimal.default(orderTotalAmount);
96
- const getItemPassUsage = (usageMap, walletPassProductId, orderItemProductId) => {
155
+ const getItemPassUsage = (usageMap, walletPassProductId, lineKey) => {
97
156
  var _a;
98
- return ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(orderItemProductId)) || 0;
99
- };
100
- const incrementItemPassUsage = (usageMap, walletPassProductId, orderItemProductId, count = 1) => {
101
- if (!usageMap.has(walletPassProductId)) {
102
- usageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
103
- }
104
- const innerMap = usageMap.get(walletPassProductId);
105
- innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
157
+ return ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(lineKey)) || 0;
106
158
  };
107
- const filterByMaxPassesPerItem = (products2, allProducts, usageMap, walletPassProductId, maxPassesPerItem) => {
159
+ const filterByMaxPassesPerItem = (products2, usageMap, walletPassProductId, maxPassesPerItem) => {
108
160
  if (maxPassesPerItem <= 0)
109
161
  return products2;
110
- return products2.filter(
111
- (p) => getItemPassUsage(usageMap, walletPassProductId, p.product_id) < maxPassesPerItem * getTotalQuantityByProductId(allProducts, p.product_id)
112
- );
162
+ return products2.filter((p) => {
163
+ const lineKey = p._walletPassLineKey;
164
+ if (!lineKey)
165
+ return true;
166
+ return getItemPassUsage(usageMap, walletPassProductId, lineKey) < getMaxPassSlotsForExpandedLine(maxPassesPerItem, p);
167
+ });
113
168
  };
114
169
  const calculateAvailableMaxAmount = (voucher, productsData, itemPassUsage) => {
115
170
  const { config } = voucher;
@@ -123,7 +178,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
123
178
  const amountField = deductTaxAndFee ? "remainingAmountWithTax" : "remainingAmountPure";
124
179
  let applicableProducts = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0));
125
180
  if (itemPassUsage) {
126
- applicableProducts = filterByMaxPassesPerItem(applicableProducts, productsData, itemPassUsage, voucher.product_id, maxPassesPerItem);
181
+ applicableProducts = filterByMaxPassesPerItem(applicableProducts, itemPassUsage, voucher.product_id, maxPassesPerItem);
127
182
  }
128
183
  if (applicableProducts.length === 0) {
129
184
  return new import_decimal.default(0);
@@ -189,7 +244,12 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
189
244
  if (maxPassesPerItem > 0 && itemPassUsage) {
190
245
  const deductTaxAndFee = (config == null ? void 0 : config.deductTaxAndFee) ?? true;
191
246
  const amountField = deductTaxAndFee ? "remainingAmountWithTax" : "remainingAmountPure";
192
- const availableAfterPassLimit = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0)).filter((p) => getItemPassUsage(itemPassUsage, product_id, p.product_id) < maxPassesPerItem * getTotalQuantityByProductId(productsData, p.product_id));
247
+ const availableAfterPassLimit = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0)).filter((p) => {
248
+ const lineKey = p._walletPassLineKey;
249
+ if (!lineKey)
250
+ return true;
251
+ return getItemPassUsage(itemPassUsage, product_id, lineKey) < getMaxPassSlotsForExpandedLine(maxPassesPerItem, p);
252
+ });
193
253
  if (availableAfterPassLimit.length === 0) {
194
254
  return { isAvailable: false, reasonCode: "max_passes_per_item_reached" };
195
255
  }
@@ -239,7 +299,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
239
299
  voucher,
240
300
  productsForRecommendation
241
301
  ).filter((p) => p[amountField].greaterThan(0));
242
- applicableProducts = filterByMaxPassesPerItem(applicableProducts, productsForRecommendation, itemPassUsageMap, product_id, maxPassesPerItem);
302
+ applicableProducts = filterByMaxPassesPerItem(applicableProducts, itemPassUsageMap, product_id, maxPassesPerItem);
243
303
  if (applicableProducts.length === 0)
244
304
  return false;
245
305
  const usageAmount = typeof voucher.edit_current_amount === "number" ? voucher.edit_current_amount : getRecommendedAmount(voucher);
@@ -317,6 +377,8 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
317
377
  product_id: product.product_id,
318
378
  parent_product_id: product.parent_product_id || null,
319
379
  is_bundle_item: product.is_bundle_item || false,
380
+ lineKey: product._walletPassLineKey,
381
+ orderLineQuantity: getExpandedOrderLineQuantity(product),
320
382
  deductAmount: actualDeductAmount.toNumber(),
321
383
  // 转换为数字
322
384
  deductQuantity: actualDeductQty
@@ -342,6 +404,8 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
342
404
  product_id: targetProduct.product_id,
343
405
  parent_product_id: targetProduct.parent_product_id || null,
344
406
  is_bundle_item: targetProduct.is_bundle_item || false,
407
+ lineKey: targetProduct._walletPassLineKey,
408
+ orderLineQuantity: getExpandedOrderLineQuantity(targetProduct),
345
409
  deductAmount: actualDeductAmount.toNumber(),
346
410
  deductQuantity: actualDeductQty
347
411
  });
@@ -350,9 +414,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
350
414
  if (totalDeducted.greaterThan(0)) {
351
415
  remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
352
416
  usedVoucherCounts.set(product_id, (usedVoucherCounts.get(product_id) || 0) + 1);
353
- deductionDetails.forEach((detail) => {
354
- incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id, detail.deductQuantity);
355
- });
417
+ applyMaxPassUsageIncrements(itemPassUsageMap, product_id, maxPassesPerItem, deductionDetails);
356
418
  recommendedVouchers.push({
357
419
  ...voucher,
358
420
  actualDeduction: totalDeducted.toNumber(),
@@ -395,23 +457,19 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
395
457
  let remainingOrderAmount = new import_decimal.default(orderTotalAmount);
396
458
  const selectedWithDetails = [];
397
459
  const itemPassUsageMap = /* @__PURE__ */ new Map();
398
- const getItemPassUsage = (walletPassProductId, orderItemProductId) => {
460
+ const getItemPassUsageRecalc = (walletPassProductId, lineKey) => {
399
461
  var _a;
400
- return ((_a = itemPassUsageMap.get(walletPassProductId)) == null ? void 0 : _a.get(orderItemProductId)) || 0;
462
+ return ((_a = itemPassUsageMap.get(walletPassProductId)) == null ? void 0 : _a.get(lineKey)) || 0;
401
463
  };
402
- const incrementItemPassUsage = (walletPassProductId, orderItemProductId, count = 1) => {
403
- if (!itemPassUsageMap.has(walletPassProductId)) {
404
- itemPassUsageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
405
- }
406
- const innerMap = itemPassUsageMap.get(walletPassProductId);
407
- innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
408
- };
409
- const filterByMaxPassesPerItem = (products2, walletPassProductId, maxPassesPerItem) => {
464
+ const filterByMaxPassesPerItemRecalc = (products2, walletPassProductId, maxPassesPerItem) => {
410
465
  if (maxPassesPerItem <= 0)
411
466
  return products2;
412
- return products2.filter(
413
- (p) => getItemPassUsage(walletPassProductId, p.product_id) < maxPassesPerItem * getTotalQuantityByProductId(productsForCalc, p.product_id)
414
- );
467
+ return products2.filter((p) => {
468
+ const lineKey = p._walletPassLineKey;
469
+ if (!lineKey)
470
+ return true;
471
+ return getItemPassUsageRecalc(walletPassProductId, lineKey) < getMaxPassSlotsForExpandedLine(maxPassesPerItem, p);
472
+ });
415
473
  };
416
474
  selectedVouchers.forEach((selectedVoucher) => {
417
475
  const { config, id } = selectedVoucher;
@@ -422,7 +480,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
422
480
  selectedVoucher,
423
481
  productsForCalc
424
482
  ).filter((p) => p[amountField].greaterThan(0));
425
- applicableProducts = filterByMaxPassesPerItem(applicableProducts, selectedVoucher.product_id, maxPassesPerItem);
483
+ applicableProducts = filterByMaxPassesPerItemRecalc(applicableProducts, selectedVoucher.product_id, maxPassesPerItem);
426
484
  if (applicableProducts.length === 0) {
427
485
  selectedWithDetails.push({
428
486
  ...selectedVoucher,
@@ -465,6 +523,8 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
465
523
  product_id: product.product_id,
466
524
  parent_product_id: product.parent_product_id || null,
467
525
  is_bundle_item: product.is_bundle_item || false,
526
+ lineKey: product._walletPassLineKey,
527
+ orderLineQuantity: getExpandedOrderLineQuantity(product),
468
528
  deductAmount: actualDeductAmount.toNumber(),
469
529
  // 转换为数字
470
530
  deductQuantity: actualDeductQty
@@ -490,15 +550,15 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
490
550
  product_id: targetProduct.product_id,
491
551
  parent_product_id: targetProduct.parent_product_id || null,
492
552
  is_bundle_item: targetProduct.is_bundle_item || false,
553
+ lineKey: targetProduct._walletPassLineKey,
554
+ orderLineQuantity: getExpandedOrderLineQuantity(targetProduct),
493
555
  deductAmount: actualDeductAmount.toNumber(),
494
556
  deductQuantity: actualDeductQty
495
557
  });
496
558
  }
497
559
  const totalDeducted = maxDeduction.minus(deductionLeft);
498
560
  remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
499
- deductionDetails.forEach((detail) => {
500
- incrementItemPassUsage(selectedVoucher.product_id, detail.product_id, detail.deductQuantity);
501
- });
561
+ applyMaxPassUsageIncrements(itemPassUsageMap, selectedVoucher.product_id, maxPassesPerItem, deductionDetails);
502
562
  selectedWithDetails.push({
503
563
  ...selectedVoucher,
504
564
  actualDeduction: totalDeducted.toNumber(),
@@ -548,7 +608,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
548
608
  voucher,
549
609
  productsForCalc
550
610
  ).filter((p) => p[amountField].greaterThan(0));
551
- applicableProducts = filterByMaxPassesPerItem(applicableProducts, product_id, maxPassesPerItem);
611
+ applicableProducts = filterByMaxPassesPerItemRecalc(applicableProducts, product_id, maxPassesPerItem);
552
612
  if (applicableProducts.length === 0) {
553
613
  isAvailable = false;
554
614
  reasonCode = "not_meet_the_required_conditions";
@@ -634,7 +694,7 @@ var getProductDiscountDifference = (product) => {
634
694
  return new import_decimal.default(((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.product_discount_difference) || 0).toNumber();
635
695
  };
636
696
  var getMainProductPrice = (product, isDeductTaxAndFee) => {
637
- var _a, _b, _c;
697
+ var _a, _b, _c, _d;
638
698
  let mainProductPrice = new import_decimal.default((product == null ? void 0 : product.main_product_selling_price) || ((_a = product.metadata) == null ? void 0 : _a.main_product_selling_price) || 0);
639
699
  for (let bundleItem of (product == null ? void 0 : product.product_bundle) || []) {
640
700
  if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
@@ -642,11 +702,11 @@ var getMainProductPrice = (product, isDeductTaxAndFee) => {
642
702
  mainProductPrice = mainProductPrice.add(bundleItemPrice.times(bundleItem.num));
643
703
  }
644
704
  }
645
- let taxFee = new import_decimal.default((product == null ? void 0 : product.tax_fee) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.main_product_attached_bundle_tax_fee) || 0);
705
+ let taxFee = new import_decimal.default((product == null ? void 0 : product.tax_fee) || ((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.main_product_attached_bundle_tax_fee) || 0).add(((_c = product == null ? void 0 : product.metadata) == null ? void 0 : _c.tax_fee_rounding_remainder) || 0);
646
706
  if (product.is_price_include_tax === 1) {
647
707
  taxFee = new import_decimal.default(0);
648
708
  }
649
- const surchargeFee = new import_decimal.default(((_c = product == null ? void 0 : product.metadata) == null ? void 0 : _c.main_product_attached_bundle_surcharge_fee) || 0);
709
+ const surchargeFee = new import_decimal.default(((_d = product == null ? void 0 : product.metadata) == null ? void 0 : _d.main_product_attached_bundle_surcharge_fee) || 0);
650
710
  const taxAndFeeTotal = taxFee.add(surchargeFee);
651
711
  if (isDeductTaxAndFee) {
652
712
  mainProductPrice = mainProductPrice.add(taxAndFeeTotal);
@@ -685,8 +745,9 @@ var getBundleItemPrice = (bundleItem, parentQuantity, isDeductTaxAndFee) => {
685
745
  };
686
746
  var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
687
747
  const expandedProducts = [];
688
- products.forEach((product) => {
748
+ products.forEach((product, indexInOrder) => {
689
749
  const productQuantity = getProductQuantity(product);
750
+ const parentLineKey = resolveWalletPassLineKey(product, indexInOrder);
690
751
  const unitPriceWithTax = getMainProductPrice(product, true);
691
752
  const unitPricePure = getMainProductPrice(product, false);
692
753
  const roundingRemainderWithTax = getTaxAndFeeRoundingRemainder(product, true);
@@ -695,6 +756,8 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
695
756
  ...product,
696
757
  is_bundle_item: false,
697
758
  parent_product_id: null,
759
+ _walletPassLineKey: parentLineKey,
760
+ _orderLineQuantity: productQuantity,
698
761
  // 单价(用于按 quantity 计算抵扣)
699
762
  unitPriceWithTax: new import_decimal.default(unitPriceWithTax),
700
763
  unitPricePure: new import_decimal.default(unitPricePure),
@@ -709,6 +772,7 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
709
772
  product.product_bundle.forEach((bundleItem) => {
710
773
  if (getBundleItemIsOriginalPrice(bundleItem)) {
711
774
  const bundleQuantity = bundleItem.num * productQuantity;
775
+ const bundleLineKey = `${parentLineKey}#bundle:${bundleItem.bundle_id}:${bundleItem.bundle_product_id}`;
712
776
  const bundleUnitPriceWithTax = new import_decimal.default(getBundleItemPrice(bundleItem, 1, true)).dividedBy(bundleItem.num);
713
777
  const bundleUnitPricePure = new import_decimal.default(getBundleItemPrice(bundleItem, 1, false)).dividedBy(bundleItem.num);
714
778
  const bundleRoundingRemainder = getBundleItemTaxAndFeeRoundingRemainder(bundleItem, true);
@@ -721,6 +785,8 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
721
785
  parent_product_id: product.product_id,
722
786
  quantity: bundleQuantity,
723
787
  // 子商品数量 * 主商品数量
788
+ _walletPassLineKey: bundleLineKey,
789
+ _orderLineQuantity: bundleQuantity,
724
790
  // 单价(用于按 quantity 计算抵扣)
725
791
  unitPriceWithTax: bundleUnitPriceWithTax,
726
792
  unitPricePure: bundleUnitPricePure,
@@ -737,9 +803,6 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
737
803
  });
738
804
  return expandedProducts;
739
805
  };
740
- var getProductQuantity = (product) => {
741
- return product.quantity || product.product_quantity || 1;
742
- };
743
806
  var getBundleItemIsOriginalPrice = (item) => {
744
807
  return (item == null ? void 0 : item.price_type) === "markup" && (item == null ? void 0 : item.price_type_ext) === "product_price";
745
808
  };
@@ -767,5 +830,6 @@ var getBundleItemIsMarkupOrDiscountPrice = (item) => {
767
830
  getProductQuantity,
768
831
  getTaxAndFeeRoundingRemainder,
769
832
  processVouchers,
770
- recalculateVouchers
833
+ recalculateVouchers,
834
+ resolveWalletPassLineKey
771
835
  });
@@ -116,7 +116,7 @@ var CustomerModule = class extends import_BaseModule.BaseModule {
116
116
  const res = await this.request.get(url, queryParams, {
117
117
  cache: {
118
118
  mode: import_plugins.RequestModeENUM.REMOTE_LOCAL,
119
- type: "indexDB"
119
+ type: "memory"
120
120
  }
121
121
  });
122
122
  if ((res == null ? void 0 : res.code) !== 200) {
@@ -17,14 +17,18 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
17
17
  setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
18
18
  getOriginalDiscountList(): Discount[];
19
19
  loadPrepareConfig(params: {
20
- action?: 'create';
20
+ action?: 'create' | 'update';
21
21
  with_good_pass: 0 | 1;
22
22
  with_discount_card: 0 | 1;
23
23
  customer_id: number;
24
24
  with_wallet_pass_holder: 0 | 1;
25
25
  request_timezone: string;
26
+ order_id?: number;
27
+ }): Promise<Discount[]>;
28
+ batchSearch(code: string, options?: {
29
+ customerId?: number;
30
+ orderId?: number;
26
31
  }): Promise<Discount[]>;
27
- batchSearch(code: string, customerId?: number): Promise<Discount[]>;
28
32
  batchSearchByProductIds(productIds: number[]): Promise<any>;
29
33
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
30
34
  private checkUsageCreditsLimit;
@@ -102,7 +102,8 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
102
102
  ) || [];
103
103
  return goodPassList;
104
104
  }
105
- async batchSearch(code, customerId) {
105
+ async batchSearch(code, options) {
106
+ const { customerId, orderId } = options || {};
106
107
  const result = await this.request.get(`/machinecode/batch-search`, {
107
108
  code,
108
109
  translate_flag: 1,
@@ -112,6 +113,7 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
112
113
  with: ["extensionData", "customScheduleSnapshot", "holder.detail"],
113
114
  order_behavior_count: 1,
114
115
  order_behavior_count_customer_id: customerId || 1,
116
+ ...orderId ? { order_behavior_count_order_id: orderId } : {},
115
117
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
116
118
  });
117
119
  const resultDiscountList = this.filterEnabledDiscountList((result == null ? void 0 : result.data) || []) || [];
@@ -23,7 +23,7 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
23
23
  */
24
24
  private logError;
25
25
  createOrder(params: CommitOrderParams['query']): {
26
- type: "virtual" | "appointment_booking";
26
+ type: "appointment_booking" | "virtual";
27
27
  platform: string;
28
28
  sales_channel: string;
29
29
  order_sales_channel: string;
@@ -195,31 +195,33 @@ var OrderModule = class extends import_BaseModule.BaseModule {
195
195
  * @returns 后端返回的订单数据(包含订单ID等)
196
196
  */
197
197
  async createOrderByCheckout(params) {
198
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q;
198
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
199
+ const onlineStorePaymentCodeList = ["WXPAY", "WECHAT", "ALIPAY", "APPLE_PAY", "CREDIT_CARD_3DS", "CREDIT_CARD_TOKEN", "GOOGLE_PAY", "GOOGLE_PAY_3DS", "CREDIT_CARD"];
200
+ params.payments = (_a = params.payments) == null ? void 0 : _a.filter((p) => !onlineStorePaymentCodeList.includes(p.code));
199
201
  this.logInfo("createOrderByCheckout called", {
200
202
  type: params.type,
201
203
  platform: params.platform,
202
204
  is_deposit: params.is_deposit,
203
205
  customer_id: params.customer_id,
204
- bookingsCount: ((_a = params.bookings) == null ? void 0 : _a.length) || 0,
205
- relationProductsCount: ((_b = params.relation_products) == null ? void 0 : _b.length) || 0,
206
- paymentsCount: ((_c = params.payments) == null ? void 0 : _c.length) || 0,
206
+ bookingsCount: ((_b = params.bookings) == null ? void 0 : _b.length) || 0,
207
+ relationProductsCount: ((_c = params.relation_products) == null ? void 0 : _c.length) || 0,
208
+ paymentsCount: ((_d = params.payments) == null ? void 0 : _d.length) || 0,
207
209
  depositAmount: params.deposit_amount,
208
210
  productTaxFee: params.product_tax_fee,
209
211
  note: params.note,
210
212
  scheduleDate: params.schedule_date,
211
213
  hasOrderId: !!params.order_id,
212
214
  orderIdIncluded: params.order_id,
213
- paymentMethods: ((_d = params.payments) == null ? void 0 : _d.map((p) => p.code)) || []
215
+ paymentMethods: ((_e = params.payments) == null ? void 0 : _e.map((p) => p.code)) || []
214
216
  });
215
217
  console.log("[Order] createOrderByCheckout 开始创建订单:", {
216
218
  type: params.type,
217
219
  platform: params.platform,
218
220
  is_deposit: params.is_deposit,
219
221
  customer_id: params.customer_id,
220
- bookingsCount: ((_e = params.bookings) == null ? void 0 : _e.length) || 0,
221
- relationProductsCount: ((_f = params.relation_products) == null ? void 0 : _f.length) || 0,
222
- paymentsCount: ((_g = params.payments) == null ? void 0 : _g.length) || 0
222
+ bookingsCount: ((_f = params.bookings) == null ? void 0 : _f.length) || 0,
223
+ relationProductsCount: ((_g = params.relation_products) == null ? void 0 : _g.length) || 0,
224
+ paymentsCount: ((_h = params.payments) == null ? void 0 : _h.length) || 0
223
225
  });
224
226
  try {
225
227
  const orderData = {
@@ -236,7 +238,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
236
238
  ...params
237
239
  // 使用传入的参数覆盖默认值
238
240
  };
239
- if ((_h = orderData.payments) == null ? void 0 : _h.length) {
241
+ if ((_i = orderData.payments) == null ? void 0 : _i.length) {
240
242
  orderData.small_ticket_data_flag = 1;
241
243
  }
242
244
  if (!params.order_id && !orderData.schedule_date) {
@@ -248,10 +250,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
248
250
  platform: orderData.platform,
249
251
  isDeposit: orderData.is_deposit,
250
252
  customerId: orderData.customer_id,
251
- bookingsCount: ((_i = orderData.bookings) == null ? void 0 : _i.length) || 0,
252
- relationProductsCount: ((_j = orderData.relation_products) == null ? void 0 : _j.length) || 0,
253
- paymentsCount: ((_k = orderData.payments) == null ? void 0 : _k.length) || 0,
254
- paymentsMethods: ((_l = orderData.payments) == null ? void 0 : _l.map((p) => p.code)) || []
253
+ bookingsCount: ((_j = orderData.bookings) == null ? void 0 : _j.length) || 0,
254
+ relationProductsCount: ((_k = orderData.relation_products) == null ? void 0 : _k.length) || 0,
255
+ paymentsCount: ((_l = orderData.payments) == null ? void 0 : _l.length) || 0,
256
+ paymentsMethods: ((_m = orderData.payments) == null ? void 0 : _m.map((p) => p.code)) || []
255
257
  });
256
258
  this.logInfo("Calling backend checkout API", {
257
259
  url: "/order/checkout",
@@ -260,10 +262,10 @@ var OrderModule = class extends import_BaseModule.BaseModule {
260
262
  isDeposit: orderData.is_deposit,
261
263
  customerId: orderData.customer_id,
262
264
  depositAmount: orderData.deposit_amount,
263
- bookingsCount: ((_m = orderData.bookings) == null ? void 0 : _m.length) || 0,
264
- relationProductsCount: ((_n = orderData.relation_products) == null ? void 0 : _n.length) || 0,
265
- paymentsCount: ((_o = orderData.payments) == null ? void 0 : _o.length) || 0,
266
- paymentMethods: ((_p = orderData.payments) == null ? void 0 : _p.map((p) => ({
265
+ bookingsCount: ((_n = orderData.bookings) == null ? void 0 : _n.length) || 0,
266
+ relationProductsCount: ((_o = orderData.relation_products) == null ? void 0 : _o.length) || 0,
267
+ paymentsCount: ((_p = orderData.payments) == null ? void 0 : _p.length) || 0,
268
+ paymentMethods: ((_q = orderData.payments) == null ? void 0 : _q.map((p) => ({
267
269
  code: p.code,
268
270
  amount: p.amount,
269
271
  type: p.type,
@@ -282,7 +284,7 @@ var OrderModule = class extends import_BaseModule.BaseModule {
282
284
  });
283
285
  console.log("[Order] 订单创建成功,后端响应:", {
284
286
  success: !!response,
285
- hasOrderId: !!(((_q = response == null ? void 0 : response.data) == null ? void 0 : _q.order_id) || (response == null ? void 0 : response.order_id))
287
+ hasOrderId: !!(((_r = response == null ? void 0 : response.data) == null ? void 0 : _r.order_id) || (response == null ? void 0 : response.order_id))
286
288
  });
287
289
  return response;
288
290
  } catch (error) {
@@ -24,11 +24,14 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
24
24
  window: WindowPlugin;
25
25
  private dbManager;
26
26
  private logger;
27
+ private voucherUpdateLockByOrderUuid;
27
28
  protected otherParams: any;
28
29
  cash: CashPayment;
29
30
  eftpos: EftposPayment;
30
31
  wallet: WalletPassPayment;
31
32
  constructor(name?: string, version?: string);
33
+ private runVoucherUpdateLocked;
34
+ private normalizeVoucherPaymentItems;
32
35
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
33
36
  /**
34
37
  * 记录信息日志
@@ -51,6 +54,7 @@ export declare class PaymentModule extends BaseModule implements Module, Payment
51
54
  *
52
55
  */
53
56
  private registerNetworkHandlers;
57
+ private filterPayMethods;
54
58
  /**
55
59
  * 获取支付方式列表
56
60
  */