@pisell/pisellos 0.0.479 → 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 +111 -72
  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 +115 -48
  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;
@@ -90,23 +152,19 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
90
152
  console.log(products, "products123");
91
153
  const productsCopy = expandProductsWithBundleItems(products, true);
92
154
  let remainingOrderAmount = new import_decimal.default(orderTotalAmount);
93
- const getItemPassUsage = (usageMap, walletPassProductId, orderItemProductId) => {
155
+ const getItemPassUsage = (usageMap, walletPassProductId, lineKey) => {
94
156
  var _a;
95
- return ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(orderItemProductId)) || 0;
96
- };
97
- const incrementItemPassUsage = (usageMap, walletPassProductId, orderItemProductId, count = 1) => {
98
- if (!usageMap.has(walletPassProductId)) {
99
- usageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
100
- }
101
- const innerMap = usageMap.get(walletPassProductId);
102
- innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
157
+ return ((_a = usageMap.get(walletPassProductId)) == null ? void 0 : _a.get(lineKey)) || 0;
103
158
  };
104
159
  const filterByMaxPassesPerItem = (products2, usageMap, walletPassProductId, maxPassesPerItem) => {
105
160
  if (maxPassesPerItem <= 0)
106
161
  return products2;
107
- return products2.filter(
108
- (p) => getItemPassUsage(usageMap, walletPassProductId, p.product_id) < maxPassesPerItem * getProductQuantity(p)
109
- );
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
+ });
110
168
  };
111
169
  const calculateAvailableMaxAmount = (voucher, productsData, itemPassUsage) => {
112
170
  const { config } = voucher;
@@ -150,7 +208,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
150
208
  }
151
209
  } else {
152
210
  const maxProduct = applicableProducts.reduce(
153
- (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
211
+ (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
154
212
  );
155
213
  if (maxPassesPerItem > 0) {
156
214
  finalApplicableAmount = import_decimal.default.min(
@@ -186,7 +244,12 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
186
244
  if (maxPassesPerItem > 0 && itemPassUsage) {
187
245
  const deductTaxAndFee = (config == null ? void 0 : config.deductTaxAndFee) ?? true;
188
246
  const amountField = deductTaxAndFee ? "remainingAmountWithTax" : "remainingAmountPure";
189
- const availableAfterPassLimit = getApplicableProducts(voucher, productsData).filter((p) => p[amountField].greaterThan(0)).filter((p) => getItemPassUsage(itemPassUsage, product_id, p.product_id) < maxPassesPerItem * getProductQuantity(p));
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
+ });
190
253
  if (availableAfterPassLimit.length === 0) {
191
254
  return { isAvailable: false, reasonCode: "max_passes_per_item_reached" };
192
255
  }
@@ -269,7 +332,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
269
332
  }
270
333
  } else {
271
334
  const maxProduct = applicableProducts.reduce(
272
- (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
335
+ (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
273
336
  );
274
337
  if (maxPassesPerItem > 0) {
275
338
  calculatedAvailableMaxAmount = import_decimal.default.min(
@@ -314,6 +377,8 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
314
377
  product_id: product.product_id,
315
378
  parent_product_id: product.parent_product_id || null,
316
379
  is_bundle_item: product.is_bundle_item || false,
380
+ lineKey: product._walletPassLineKey,
381
+ orderLineQuantity: getExpandedOrderLineQuantity(product),
317
382
  deductAmount: actualDeductAmount.toNumber(),
318
383
  // 转换为数字
319
384
  deductQuantity: actualDeductQty
@@ -322,7 +387,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
322
387
  }
323
388
  } else {
324
389
  const targetProduct = applicableProducts.reduce(
325
- (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
390
+ (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
326
391
  );
327
392
  let maxDeductForProduct = targetProduct[amountField];
328
393
  if (maxPassesPerItem > 0) {
@@ -339,6 +404,8 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
339
404
  product_id: targetProduct.product_id,
340
405
  parent_product_id: targetProduct.parent_product_id || null,
341
406
  is_bundle_item: targetProduct.is_bundle_item || false,
407
+ lineKey: targetProduct._walletPassLineKey,
408
+ orderLineQuantity: getExpandedOrderLineQuantity(targetProduct),
342
409
  deductAmount: actualDeductAmount.toNumber(),
343
410
  deductQuantity: actualDeductQty
344
411
  });
@@ -347,9 +414,7 @@ function processVouchers(applicableVouchers, orderTotalAmount, products) {
347
414
  if (totalDeducted.greaterThan(0)) {
348
415
  remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
349
416
  usedVoucherCounts.set(product_id, (usedVoucherCounts.get(product_id) || 0) + 1);
350
- deductionDetails.forEach((detail) => {
351
- incrementItemPassUsage(itemPassUsageMap, product_id, detail.product_id, detail.deductQuantity);
352
- });
417
+ applyMaxPassUsageIncrements(itemPassUsageMap, product_id, maxPassesPerItem, deductionDetails);
353
418
  recommendedVouchers.push({
354
419
  ...voucher,
355
420
  actualDeduction: totalDeducted.toNumber(),
@@ -392,23 +457,19 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
392
457
  let remainingOrderAmount = new import_decimal.default(orderTotalAmount);
393
458
  const selectedWithDetails = [];
394
459
  const itemPassUsageMap = /* @__PURE__ */ new Map();
395
- const getItemPassUsage = (walletPassProductId, orderItemProductId) => {
460
+ const getItemPassUsageRecalc = (walletPassProductId, lineKey) => {
396
461
  var _a;
397
- 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;
398
463
  };
399
- const incrementItemPassUsage = (walletPassProductId, orderItemProductId, count = 1) => {
400
- if (!itemPassUsageMap.has(walletPassProductId)) {
401
- itemPassUsageMap.set(walletPassProductId, /* @__PURE__ */ new Map());
402
- }
403
- const innerMap = itemPassUsageMap.get(walletPassProductId);
404
- innerMap.set(orderItemProductId, (innerMap.get(orderItemProductId) || 0) + count);
405
- };
406
- const filterByMaxPassesPerItem = (products2, walletPassProductId, maxPassesPerItem) => {
464
+ const filterByMaxPassesPerItemRecalc = (products2, walletPassProductId, maxPassesPerItem) => {
407
465
  if (maxPassesPerItem <= 0)
408
466
  return products2;
409
- return products2.filter(
410
- (p) => getItemPassUsage(walletPassProductId, p.product_id) < maxPassesPerItem * getProductQuantity(p)
411
- );
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
+ });
412
473
  };
413
474
  selectedVouchers.forEach((selectedVoucher) => {
414
475
  const { config, id } = selectedVoucher;
@@ -419,7 +480,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
419
480
  selectedVoucher,
420
481
  productsForCalc
421
482
  ).filter((p) => p[amountField].greaterThan(0));
422
- applicableProducts = filterByMaxPassesPerItem(applicableProducts, selectedVoucher.product_id, maxPassesPerItem);
483
+ applicableProducts = filterByMaxPassesPerItemRecalc(applicableProducts, selectedVoucher.product_id, maxPassesPerItem);
423
484
  if (applicableProducts.length === 0) {
424
485
  selectedWithDetails.push({
425
486
  ...selectedVoucher,
@@ -462,6 +523,8 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
462
523
  product_id: product.product_id,
463
524
  parent_product_id: product.parent_product_id || null,
464
525
  is_bundle_item: product.is_bundle_item || false,
526
+ lineKey: product._walletPassLineKey,
527
+ orderLineQuantity: getExpandedOrderLineQuantity(product),
465
528
  deductAmount: actualDeductAmount.toNumber(),
466
529
  // 转换为数字
467
530
  deductQuantity: actualDeductQty
@@ -470,7 +533,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
470
533
  }
471
534
  } else {
472
535
  const targetProduct = applicableProducts.reduce(
473
- (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
536
+ (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
474
537
  );
475
538
  let maxDeductForProduct = targetProduct[amountField];
476
539
  if (maxPassesPerItem > 0) {
@@ -487,15 +550,15 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
487
550
  product_id: targetProduct.product_id,
488
551
  parent_product_id: targetProduct.parent_product_id || null,
489
552
  is_bundle_item: targetProduct.is_bundle_item || false,
553
+ lineKey: targetProduct._walletPassLineKey,
554
+ orderLineQuantity: getExpandedOrderLineQuantity(targetProduct),
490
555
  deductAmount: actualDeductAmount.toNumber(),
491
556
  deductQuantity: actualDeductQty
492
557
  });
493
558
  }
494
559
  const totalDeducted = maxDeduction.minus(deductionLeft);
495
560
  remainingOrderAmount = remainingOrderAmount.minus(totalDeducted);
496
- deductionDetails.forEach((detail) => {
497
- incrementItemPassUsage(selectedVoucher.product_id, detail.product_id, detail.deductQuantity);
498
- });
561
+ applyMaxPassUsageIncrements(itemPassUsageMap, selectedVoucher.product_id, maxPassesPerItem, deductionDetails);
499
562
  selectedWithDetails.push({
500
563
  ...selectedVoucher,
501
564
  actualDeduction: totalDeducted.toNumber(),
@@ -545,7 +608,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
545
608
  voucher,
546
609
  productsForCalc
547
610
  ).filter((p) => p[amountField].greaterThan(0));
548
- applicableProducts = filterByMaxPassesPerItem(applicableProducts, product_id, maxPassesPerItem);
611
+ applicableProducts = filterByMaxPassesPerItemRecalc(applicableProducts, product_id, maxPassesPerItem);
549
612
  if (applicableProducts.length === 0) {
550
613
  isAvailable = false;
551
614
  reasonCode = "not_meet_the_required_conditions";
@@ -578,7 +641,7 @@ function recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, pr
578
641
  }
579
642
  } else {
580
643
  const maxProduct = applicableProducts.reduce(
581
- (max, p) => p[amountField].greaterThan(max[amountField]) ? p : max
644
+ (max, p) => p[unitPriceField].greaterThan(max[unitPriceField]) ? p : max
582
645
  );
583
646
  if (maxPassesPerItem > 0) {
584
647
  calculatedMaxAmount = import_decimal.default.min(
@@ -631,7 +694,7 @@ var getProductDiscountDifference = (product) => {
631
694
  return new import_decimal.default(((_a = product == null ? void 0 : product.metadata) == null ? void 0 : _a.product_discount_difference) || 0).toNumber();
632
695
  };
633
696
  var getMainProductPrice = (product, isDeductTaxAndFee) => {
634
- var _a, _b, _c;
697
+ var _a, _b, _c, _d;
635
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);
636
699
  for (let bundleItem of (product == null ? void 0 : product.product_bundle) || []) {
637
700
  if (getBundleItemIsMarkupOrDiscountPrice(bundleItem)) {
@@ -639,11 +702,11 @@ var getMainProductPrice = (product, isDeductTaxAndFee) => {
639
702
  mainProductPrice = mainProductPrice.add(bundleItemPrice.times(bundleItem.num));
640
703
  }
641
704
  }
642
- 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);
643
706
  if (product.is_price_include_tax === 1) {
644
707
  taxFee = new import_decimal.default(0);
645
708
  }
646
- 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);
647
710
  const taxAndFeeTotal = taxFee.add(surchargeFee);
648
711
  if (isDeductTaxAndFee) {
649
712
  mainProductPrice = mainProductPrice.add(taxAndFeeTotal);
@@ -682,8 +745,9 @@ var getBundleItemPrice = (bundleItem, parentQuantity, isDeductTaxAndFee) => {
682
745
  };
683
746
  var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
684
747
  const expandedProducts = [];
685
- products.forEach((product) => {
748
+ products.forEach((product, indexInOrder) => {
686
749
  const productQuantity = getProductQuantity(product);
750
+ const parentLineKey = resolveWalletPassLineKey(product, indexInOrder);
687
751
  const unitPriceWithTax = getMainProductPrice(product, true);
688
752
  const unitPricePure = getMainProductPrice(product, false);
689
753
  const roundingRemainderWithTax = getTaxAndFeeRoundingRemainder(product, true);
@@ -692,6 +756,8 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
692
756
  ...product,
693
757
  is_bundle_item: false,
694
758
  parent_product_id: null,
759
+ _walletPassLineKey: parentLineKey,
760
+ _orderLineQuantity: productQuantity,
695
761
  // 单价(用于按 quantity 计算抵扣)
696
762
  unitPriceWithTax: new import_decimal.default(unitPriceWithTax),
697
763
  unitPricePure: new import_decimal.default(unitPricePure),
@@ -706,6 +772,7 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
706
772
  product.product_bundle.forEach((bundleItem) => {
707
773
  if (getBundleItemIsOriginalPrice(bundleItem)) {
708
774
  const bundleQuantity = bundleItem.num * productQuantity;
775
+ const bundleLineKey = `${parentLineKey}#bundle:${bundleItem.bundle_id}:${bundleItem.bundle_product_id}`;
709
776
  const bundleUnitPriceWithTax = new import_decimal.default(getBundleItemPrice(bundleItem, 1, true)).dividedBy(bundleItem.num);
710
777
  const bundleUnitPricePure = new import_decimal.default(getBundleItemPrice(bundleItem, 1, false)).dividedBy(bundleItem.num);
711
778
  const bundleRoundingRemainder = getBundleItemTaxAndFeeRoundingRemainder(bundleItem, true);
@@ -718,6 +785,8 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
718
785
  parent_product_id: product.product_id,
719
786
  quantity: bundleQuantity,
720
787
  // 子商品数量 * 主商品数量
788
+ _walletPassLineKey: bundleLineKey,
789
+ _orderLineQuantity: bundleQuantity,
721
790
  // 单价(用于按 quantity 计算抵扣)
722
791
  unitPriceWithTax: bundleUnitPriceWithTax,
723
792
  unitPricePure: bundleUnitPricePure,
@@ -734,9 +803,6 @@ var expandProductsWithBundleItems = (products, deductTaxAndFee) => {
734
803
  });
735
804
  return expandedProducts;
736
805
  };
737
- var getProductQuantity = (product) => {
738
- return product.quantity || product.product_quantity || 1;
739
- };
740
806
  var getBundleItemIsOriginalPrice = (item) => {
741
807
  return (item == null ? void 0 : item.price_type) === "markup" && (item == null ? void 0 : item.price_type_ext) === "product_price";
742
808
  };
@@ -764,5 +830,6 @@ var getBundleItemIsMarkupOrDiscountPrice = (item) => {
764
830
  getProductQuantity,
765
831
  getTaxAndFeeRoundingRemainder,
766
832
  processVouchers,
767
- recalculateVouchers
833
+ recalculateVouchers,
834
+ resolveWalletPassLineKey
768
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
  */