@pisell/pisellos 2.1.52 → 2.1.54

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 (101) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +3 -0
  6. package/dist/model/strategy/adapter/index.js +4 -0
  7. package/dist/model/strategy/adapter/type.d.ts +28 -0
  8. package/dist/model/strategy/adapter/type.js +1 -0
  9. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  10. package/dist/model/strategy/adapter/walletPass/evaluator.js +496 -0
  11. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  12. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  13. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  14. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  15. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  16. package/dist/model/strategy/adapter/walletPass/locales.js +23 -0
  17. package/dist/model/strategy/adapter/walletPass/type.d.ts +163 -0
  18. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  19. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  20. package/dist/model/strategy/adapter/walletPass/utils.js +965 -0
  21. package/dist/model/strategy/index.d.ts +94 -0
  22. package/dist/model/strategy/index.js +551 -0
  23. package/dist/model/strategy/strategy-example.d.ts +5 -0
  24. package/dist/model/strategy/strategy-example.js +331 -0
  25. package/dist/model/strategy/type.d.ts +228 -0
  26. package/dist/model/strategy/type.js +94 -0
  27. package/dist/modules/Cart/types.d.ts +2 -0
  28. package/dist/modules/Cart/utils/cartProduct.js +11 -0
  29. package/dist/modules/Discount/index.d.ts +1 -0
  30. package/dist/modules/Discount/index.js +1 -1
  31. package/dist/modules/Discount/types.d.ts +15 -0
  32. package/dist/modules/Payment/index.d.ts +2 -1
  33. package/dist/modules/Payment/index.js +10 -7
  34. package/dist/modules/Payment/utils.js +3 -0
  35. package/dist/modules/Payment/walletpass.d.ts +23 -0
  36. package/dist/modules/Payment/walletpass.js +191 -95
  37. package/dist/modules/Rules/index.d.ts +15 -3
  38. package/dist/modules/Rules/index.js +194 -28
  39. package/dist/modules/Rules/types.d.ts +5 -0
  40. package/dist/modules/Summary/types.d.ts +2 -0
  41. package/dist/modules/Summary/utils.d.ts +6 -0
  42. package/dist/modules/Summary/utils.js +21 -0
  43. package/dist/plugins/window.d.ts +2 -0
  44. package/dist/solution/BookingByStep/index.d.ts +1 -0
  45. package/dist/solution/BookingByStep/utils/capacity.js +1 -2
  46. package/dist/solution/Checkout/index.js +2 -0
  47. package/dist/solution/ShopDiscount/index.d.ts +4 -0
  48. package/dist/solution/ShopDiscount/index.js +26 -5
  49. package/dist/solution/ShopDiscount/types.d.ts +6 -0
  50. package/dist/solution/ShopDiscount/utils.js +26 -11
  51. package/lib/index.d.ts +1 -0
  52. package/lib/index.js +3 -1
  53. package/lib/model/index.d.ts +1 -0
  54. package/lib/model/index.js +23 -0
  55. package/lib/model/strategy/adapter/index.d.ts +3 -0
  56. package/lib/model/strategy/adapter/index.js +45 -0
  57. package/lib/model/strategy/adapter/type.d.ts +28 -0
  58. package/lib/model/strategy/adapter/type.js +17 -0
  59. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  60. package/lib/model/strategy/adapter/walletPass/evaluator.js +420 -0
  61. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  62. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  63. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  64. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  65. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  66. package/lib/model/strategy/adapter/walletPass/locales.js +51 -0
  67. package/lib/model/strategy/adapter/walletPass/type.d.ts +163 -0
  68. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  69. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  70. package/lib/model/strategy/adapter/walletPass/utils.js +660 -0
  71. package/lib/model/strategy/index.d.ts +94 -0
  72. package/lib/model/strategy/index.js +413 -0
  73. package/lib/model/strategy/strategy-example.d.ts +5 -0
  74. package/lib/model/strategy/strategy-example.js +318 -0
  75. package/lib/model/strategy/type.d.ts +228 -0
  76. package/lib/model/strategy/type.js +44 -0
  77. package/lib/modules/Cart/types.d.ts +2 -0
  78. package/lib/modules/Cart/utils/cartProduct.js +9 -0
  79. package/lib/modules/Discount/index.d.ts +1 -0
  80. package/lib/modules/Discount/index.js +1 -1
  81. package/lib/modules/Discount/types.d.ts +15 -0
  82. package/lib/modules/Payment/index.d.ts +2 -1
  83. package/lib/modules/Payment/index.js +1 -0
  84. package/lib/modules/Payment/utils.js +3 -0
  85. package/lib/modules/Payment/walletpass.d.ts +23 -0
  86. package/lib/modules/Payment/walletpass.js +94 -17
  87. package/lib/modules/Rules/index.d.ts +15 -3
  88. package/lib/modules/Rules/index.js +409 -195
  89. package/lib/modules/Rules/types.d.ts +5 -0
  90. package/lib/modules/Summary/types.d.ts +2 -0
  91. package/lib/modules/Summary/utils.d.ts +6 -0
  92. package/lib/modules/Summary/utils.js +15 -0
  93. package/lib/plugins/window.d.ts +2 -0
  94. package/lib/solution/BookingByStep/index.d.ts +1 -0
  95. package/lib/solution/BookingByStep/utils/capacity.js +1 -2
  96. package/lib/solution/Checkout/index.js +2 -0
  97. package/lib/solution/ShopDiscount/index.d.ts +4 -0
  98. package/lib/solution/ShopDiscount/index.js +18 -4
  99. package/lib/solution/ShopDiscount/types.d.ts +6 -0
  100. package/lib/solution/ShopDiscount/utils.js +10 -6
  101. package/package.json +1 -1
@@ -49,6 +49,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
49
49
  this.core = core;
50
50
  this.hooks = options == null ? void 0 : options.hooks;
51
51
  this.store = options == null ? void 0 : options.store;
52
+ this.window = core.getPlugin("window");
52
53
  }
53
54
  async setRulesList(rulesList) {
54
55
  this.store.rulesList = rulesList;
@@ -57,11 +58,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
57
58
  getRulesList() {
58
59
  return this.store.rulesList;
59
60
  }
61
+ getWalletPassEvaluator() {
62
+ var _a, _b;
63
+ return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
64
+ }
65
+ // 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
66
+ checkHolderMatch(discount, product, holders) {
67
+ var _a;
68
+ if (((_a = discount.holder) == null ? void 0 : _a.holder_type) !== "form")
69
+ return true;
70
+ const orderHolderId = Array.isArray(holders) && holders.length > 0 ? holders[0].form_record_id : void 0;
71
+ const productHolderId = Array.isArray(product.holder_id) ? product.holder_id[0] : product.holder_id;
72
+ if (!product.isNeedHolder)
73
+ return true;
74
+ if (!orderHolderId && !productHolderId)
75
+ return false;
76
+ return (productHolderId || orderHolderId) === discount.holder.holder_id;
77
+ }
60
78
  // 判断discountList 是否可以对当前productList生效
61
79
  isDiscountListAvailable({
62
80
  oldDiscountList,
63
81
  newDiscountList,
64
- productList
82
+ productList,
83
+ holders,
84
+ orderTotalAmount
65
85
  }) {
66
86
  if (!newDiscountList || newDiscountList.length === 0) {
67
87
  return {
@@ -81,14 +101,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
81
101
  productList
82
102
  };
83
103
  }
84
- const filteredOldDiscountList = oldDiscountList.filter((discount) => !discount.isEditMode && discount.tag !== "good_pass");
85
- const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
86
- ...filteredOldDiscountList,
87
- ...newDiscountList
88
- ]), "product_id");
104
+ const filteredOldDiscountList = oldDiscountList.filter(
105
+ (discount) => !discount.isEditMode && discount.tag !== "good_pass"
106
+ );
107
+ const mergedDiscountList = (0, import_utils.uniqueById)(
108
+ (0, import_utils.uniqueById)([...filteredOldDiscountList, ...newDiscountList]),
109
+ "product_id"
110
+ );
89
111
  const result = this.calcDiscount({
90
112
  discountList: mergedDiscountList,
91
- productList: [...productList]
113
+ productList: [...productList],
114
+ holders,
115
+ orderTotalAmount
92
116
  }, {
93
117
  scan: true
94
118
  });
@@ -120,7 +144,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
120
144
  }
121
145
  calcDiscount({
122
146
  discountList,
123
- productList
147
+ productList,
148
+ holders,
149
+ orderTotalAmount
124
150
  }, options) {
125
151
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
126
152
  const editModeDiscount = [];
@@ -240,7 +266,50 @@ var RulesModule = class extends import_BaseModule.BaseModule {
240
266
  }
241
267
  return priceB.minus(priceA).toNumber();
242
268
  });
269
+ const evaluator = this.getWalletPassEvaluator();
270
+ if (evaluator) {
271
+ addModeDiscount.forEach((discount) => {
272
+ var _a, _b;
273
+ const discountType = discount.tag || discount.type;
274
+ if (["good_pass", "discount_card", "product_discount_card"].includes(
275
+ discountType
276
+ )) {
277
+ const voucher = {
278
+ id: discount.id,
279
+ amount: Number(discount.par_value || 0),
280
+ balance: Number(discount.balance || 0),
281
+ type: discountType,
282
+ product_id: discount.product_id,
283
+ unified_available_status: 1,
284
+ available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
285
+ available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
286
+ };
287
+ const productsForEvaluate = sortedFlattenedList.map((item) => ({
288
+ product_id: item.id,
289
+ price: item.price || 0,
290
+ quantity: item.quantity || item.num || 1,
291
+ selling_price: item.price || 0
292
+ }));
293
+ const result = evaluator.checkVoucherAvailability({
294
+ orderTotalAmount,
295
+ products: productsForEvaluate,
296
+ vouchers: [voucher]
297
+ });
298
+ if (result.isAvailable) {
299
+ discount.config = {
300
+ ...result.config,
301
+ isAvailable: true
302
+ };
303
+ } else {
304
+ discount.config = {
305
+ isAvailable: false
306
+ };
307
+ }
308
+ }
309
+ });
310
+ }
243
311
  const usedDiscounts = /* @__PURE__ */ new Map();
312
+ const usedProductIdCounts = /* @__PURE__ */ new Map();
244
313
  const discountApplicability = /* @__PURE__ */ new Map();
245
314
  const discountApplicableProducts = /* @__PURE__ */ new Map();
246
315
  addModeDiscount.forEach((discount) => {
@@ -269,15 +338,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
269
338
  originProduct = flatItem.originProduct;
270
339
  }
271
340
  addModeDiscount.forEach((discount) => {
272
- var _a, _b, _c, _d, _e, _f;
341
+ var _a, _b, _c, _d, _e, _f, _g;
273
342
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
343
+ const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
344
+ const isHolderMatch = this.checkHolderMatch(
345
+ discount,
346
+ {
347
+ isNeedHolder: _tempVar == null ? void 0 : _tempVar.isNeedHolder,
348
+ holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
349
+ },
350
+ holders
351
+ );
274
352
  let timeLimit = true;
275
353
  timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
276
- const isLimitedProduct = limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id);
277
- const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every((discount2) => discount2.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount2.tag || discount2.type)))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
354
+ const isLimitedProduct = (limitedData.type === "product_all" && limitedData.filter !== 1 || limitedData.type === "product_all" && limitedData.filter === 1 && !limitedData.exclude_product_ids.includes(product.id) || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
355
+ const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a = product == null ? void 0 : product.discount_list) == null ? void 0 : _a.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every(
356
+ (discount2) => discount2.id && [
357
+ "good_pass",
358
+ "discount_card",
359
+ "product_discount_card"
360
+ ].includes(discount2.tag || discount2.type)
361
+ ))) : !((flatItem == null ? void 0 : flatItem.booking_id) && ((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.metadata) == null ? void 0 : _d.custom_product_bundle_map_id));
278
362
  const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
279
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
280
- (_e = discountApplicability.get(discount.id)) == null ? void 0 : _e.push(product.id);
363
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_e = discount.config) == null ? void 0 : _e.isAvailable)) {
364
+ (_f = discountApplicability.get(discount.id)) == null ? void 0 : _f.push(product.id);
281
365
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
282
366
  const discountType = discount.tag || discount.type;
283
367
  const isGoodPass = discountType === "good_pass";
@@ -287,13 +371,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
287
371
  type: discountType,
288
372
  tag: discountType,
289
373
  discount: {
290
- discount_card_type: (_f = discount == null ? void 0 : discount.metadata) == null ? void 0 : _f.discount_card_type,
374
+ discount_card_type: (_g = discount == null ? void 0 : discount.metadata) == null ? void 0 : _g.discount_card_type,
291
375
  fixed_amount: product.price,
292
376
  resource_id: discount.id,
293
377
  title: discount.format_title,
294
378
  original_amount: product.price || product.origin_total,
295
379
  pre_value: discount.par_value,
296
- product_id: originProduct.id
380
+ product_id: originProduct.id,
381
+ discount_product_id: discount.product_id
297
382
  },
298
383
  metadata: {
299
384
  num
@@ -326,25 +411,39 @@ var RulesModule = class extends import_BaseModule.BaseModule {
326
411
  };
327
412
  originProduct = flatItem.originProduct;
328
413
  }
329
- if ((product == null ? void 0 : product.booking_id) && ((_d = product.discount_list) == null ? void 0 : _d.length) && ((_e = product == null ? void 0 : product.discount_list) == null ? void 0 : _e.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
414
+ if ((product == null ? void 0 : product.booking_id) && ((_d = product.discount_list) == null ? void 0 : _d.length) && ((_e = product == null ? void 0 : product.discount_list) == null ? void 0 : _e.every(
415
+ (discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
416
+ discount.tag || discount.type
417
+ )
418
+ ))) {
330
419
  if (flatItem.type === "main") {
331
420
  processedProductsMap.set(product._id, [originProduct]);
332
421
  } else {
333
- processedFlatItemsMap.set(flatItem._id, [{
334
- ...flatItem,
335
- processed: true
336
- }]);
422
+ processedFlatItemsMap.set(flatItem._id, [
423
+ {
424
+ ...flatItem,
425
+ processed: true
426
+ }
427
+ ]);
337
428
  }
338
429
  return;
339
430
  }
340
431
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
341
- var _a2, _b2;
342
- if ((Number(product.price) <= 0 || !product.price) && !((_a2 = product.discount_list) == null ? void 0 : _a2.find((n) => {
432
+ var _a2, _b2, _c2, _d2;
433
+ const discountType = discount.tag || discount.type;
434
+ if (["good_pass", "discount_card", "product_discount_card"].includes(
435
+ discountType
436
+ )) {
437
+ if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
438
+ return false;
439
+ }
440
+ }
441
+ if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
343
442
  var _a3;
344
443
  return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
345
444
  })) && (discount.tag || discount.type) === "good_pass")
346
445
  return false;
347
- if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
446
+ if ((Number(product.price) <= 0 || !product.price) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
348
447
  var _a3;
349
448
  return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
350
449
  })) && (discount.tag || discount.type) !== "good_pass")
@@ -352,13 +451,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
352
451
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
353
452
  if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
354
453
  return false;
454
+ if ((discount.tag || discount.type) === "good_pass") {
455
+ const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
456
+ if (maxUsagePerOrder && maxUsagePerOrder > 0) {
457
+ const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
458
+ if (currentUsedCount >= maxUsagePerOrder) {
459
+ return false;
460
+ }
461
+ }
462
+ }
355
463
  const limitedData = discount.limited_relation_product_data;
464
+ const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
465
+ const isHolderMatch = this.checkHolderMatch(
466
+ discount,
467
+ {
468
+ isNeedHolder: _tempVar == null ? void 0 : _tempVar.isNeedHolder,
469
+ holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
470
+ },
471
+ holders
472
+ );
473
+ if (!isHolderMatch)
474
+ return false;
356
475
  let timeLimit = true;
357
476
  timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
358
477
  if (!timeLimit) {
359
478
  return false;
360
479
  }
361
480
  if (limitedData.type === "product_all") {
481
+ if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
482
+ return false;
483
+ }
362
484
  if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
363
485
  return false;
364
486
  }
@@ -371,66 +493,96 @@ var RulesModule = class extends import_BaseModule.BaseModule {
371
493
  }
372
494
  return false;
373
495
  });
374
- const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
496
+ const selectedDiscountCard = applicableDiscounts.find(
497
+ (n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
498
+ );
375
499
  const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
376
500
  let isManualDiscount = false;
377
501
  if (flatItem.type === "main") {
378
- isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every((item) => {
379
- var _a2;
380
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
381
- }) && (!((_f = product.discount_list) == null ? void 0 : _f.length) || ((_h = (_g = product == null ? void 0 : product.discount_list) == null ? void 0 : _g.every) == null ? void 0 : _h.call(_g, (item) => item.type === "product")));
502
+ isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
503
+ (item) => {
504
+ var _a2;
505
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
506
+ }
507
+ ) && (!((_f = product.discount_list) == null ? void 0 : _f.length) || ((_h = (_g = product == null ? void 0 : product.discount_list) == null ? void 0 : _g.every) == null ? void 0 : _h.call(
508
+ _g,
509
+ (item) => item.type === "product"
510
+ )));
382
511
  } else {
383
512
  const parentProduct = flatItem.parentProduct;
384
513
  if (parentProduct) {
385
- isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every((item) => {
386
- var _a2;
387
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
388
- }) && (!((_i = parentProduct.discount_list) == null ? void 0 : _i.length) || ((_k = (_j = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _j.every) == null ? void 0 : _k.call(_j, (item) => item.type === "product")));
514
+ isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
515
+ (item) => {
516
+ var _a2;
517
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
518
+ }
519
+ ) && (!((_i = parentProduct.discount_list) == null ? void 0 : _i.length) || ((_k = (_j = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _j.every) == null ? void 0 : _k.call(
520
+ _j,
521
+ (item) => item.type === "product"
522
+ )));
389
523
  }
390
524
  }
391
525
  if (options == null ? void 0 : options.discountId) {
392
- if (flatItem.type === "main" && ((_l = product.discount_list) == null ? void 0 : _l.some((item) => {
393
- var _a2;
394
- return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
395
- }))) {
526
+ if (flatItem.type === "main" && ((_l = product.discount_list) == null ? void 0 : _l.some(
527
+ (item) => {
528
+ var _a2;
529
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
530
+ }
531
+ ))) {
396
532
  isManualDiscount = false;
397
533
  }
398
534
  if (flatItem.type === "bundle") {
399
- if (((_m = product.discount_list) == null ? void 0 : _m.some((item) => {
400
- var _a2;
401
- return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
402
- })) || ((_o = (_n = flatItem.parentProduct) == null ? void 0 : _n.discount_list) == null ? void 0 : _o.some((item) => {
403
- var _a2;
404
- return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
405
- }))) {
535
+ if (((_m = product.discount_list) == null ? void 0 : _m.some(
536
+ (item) => {
537
+ var _a2;
538
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
539
+ }
540
+ )) || ((_o = (_n = flatItem.parentProduct) == null ? void 0 : _n.discount_list) == null ? void 0 : _o.some(
541
+ (item) => {
542
+ var _a2;
543
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
544
+ }
545
+ ))) {
406
546
  isManualDiscount = false;
407
547
  }
408
548
  }
409
549
  }
410
550
  if (options == null ? void 0 : options.selectedList) {
411
- if (flatItem.type === "main" && ((_p = product.discount_list) == null ? void 0 : _p.some((item) => {
412
- var _a2;
413
- return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
414
- var _a3;
415
- return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
416
- });
417
- }))) {
551
+ if (flatItem.type === "main" && ((_p = product.discount_list) == null ? void 0 : _p.some(
552
+ (item) => {
553
+ var _a2;
554
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
555
+ (n) => {
556
+ var _a3;
557
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
558
+ }
559
+ );
560
+ }
561
+ ))) {
418
562
  isManualDiscount = false;
419
563
  }
420
564
  if (flatItem.type === "bundle") {
421
- if (((_q = product.discount_list) == null ? void 0 : _q.some((item) => {
422
- var _a2;
423
- return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
424
- var _a3;
425
- return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
426
- });
427
- })) || ((_s = (_r = flatItem.parentProduct) == null ? void 0 : _r.discount_list) == null ? void 0 : _s.some((item) => {
428
- var _a2;
429
- return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
430
- var _a3;
431
- return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
432
- });
433
- }))) {
565
+ if (((_q = product.discount_list) == null ? void 0 : _q.some(
566
+ (item) => {
567
+ var _a2;
568
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
569
+ (n) => {
570
+ var _a3;
571
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
572
+ }
573
+ );
574
+ }
575
+ )) || ((_s = (_r = flatItem.parentProduct) == null ? void 0 : _r.discount_list) == null ? void 0 : _s.some(
576
+ (item) => {
577
+ var _a2;
578
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some(
579
+ (n) => {
580
+ var _a3;
581
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
582
+ }
583
+ );
584
+ }
585
+ ))) {
434
586
  isManualDiscount = false;
435
587
  }
436
588
  }
@@ -438,9 +590,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
438
590
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
439
591
  if (flatItem.type === "main") {
440
592
  if (product.isClient) {
441
- processedProductsMap.set(
442
- product._id,
443
- [this.hooks.setProduct(originProduct, {
593
+ processedProductsMap.set(product._id, [
594
+ this.hooks.setProduct(originProduct, {
444
595
  ...isManualDiscount ? {} : {
445
596
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
446
597
  product: {
@@ -461,12 +612,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
461
612
  price: product.price
462
613
  },
463
614
  discount_list: []
464
- })]
465
- );
615
+ })
616
+ ]);
466
617
  } else {
467
- processedProductsMap.set(
468
- product._id,
469
- [this.hooks.setProduct(originProduct, {
618
+ processedProductsMap.set(product._id, [
619
+ this.hooks.setProduct(originProduct, {
470
620
  ...isManualDiscount ? {
471
621
  price: product.price,
472
622
  main_product_selling_price: product.price
@@ -477,8 +627,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
477
627
  main_product_selling_price: product.price
478
628
  },
479
629
  discount_list: []
480
- })]
481
- );
630
+ })
631
+ ]);
482
632
  }
483
633
  } else {
484
634
  processedFlatItemsMap.set(flatItem._id, [{
@@ -495,20 +645,36 @@ var RulesModule = class extends import_BaseModule.BaseModule {
495
645
  }
496
646
  const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
497
647
  const totalQuantity = product.quantity || product.num || 1;
498
- const availableGoodPassCount = applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length;
499
- const splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
648
+ const availableGoodPassCount = applicableDiscounts.filter(
649
+ (item) => (item.tag || item.type) === "good_pass"
650
+ ).length;
651
+ let maxUsageLimit = availableGoodPassCount;
652
+ if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
653
+ maxUsageLimit = Math.min(
654
+ availableGoodPassCount,
655
+ selectedDiscount.config.maxUsagePerOrder
656
+ );
657
+ }
658
+ const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
500
659
  const arr = [];
501
660
  if (flatItem.type === "main") {
502
661
  if (splitCount < totalQuantity && isNeedSplit) {
503
- arr.push(this.hooks.setProduct(originProduct, {
504
- discount_list: [],
505
- quantity: totalQuantity - splitCount,
506
- _id: product._id.split("___")[0]
507
- }));
662
+ arr.push(
663
+ this.hooks.setProduct(originProduct, {
664
+ discount_list: [],
665
+ quantity: totalQuantity - splitCount,
666
+ _id: product._id.split("___")[0],
667
+ total: product.origin_total || product.total
668
+ })
669
+ );
508
670
  }
509
671
  for (let i = 0; i < splitCount; i++) {
510
672
  const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
511
673
  usedDiscounts.set(selectedDiscount2.id, true);
674
+ if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
675
+ const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
676
+ usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
677
+ }
512
678
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
513
679
  let productOriginTotal = product.origin_total || product.total || 0;
514
680
  if (((_t = product.discount_list) == null ? void 0 : _t.length) && product.origin_total) {
@@ -517,24 +683,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
517
683
  if (Number(((_u = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _u.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
518
684
  productOriginTotal = product.total;
519
685
  }
520
- const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
521
- const discountType = selectedDiscount2.tag || selectedDiscount2.type;
686
+ const targetProductTotal = (0, import_utils.getDiscountAmount)(
687
+ selectedDiscount2,
688
+ product.price,
689
+ product.price
690
+ );
691
+ const discountType = selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag;
692
+ const actualDiscountAmount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
522
693
  const isGoodPass = discountType === "good_pass";
523
- const amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
524
694
  const discountDetail = {
525
- amount,
526
- type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
695
+ amount: actualDiscountAmount,
696
+ type: discountType,
527
697
  discount: {
528
698
  discount_card_type: (_v = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _v.discount_card_type,
529
- fixed_amount: amount,
699
+ fixed_amount: actualDiscountAmount,
530
700
  resource_id: selectedDiscount2.id,
531
701
  title: selectedDiscount2.format_title,
532
702
  original_amount: product.price,
533
703
  product_id: originProduct.id,
534
- percent: selectedDiscount2.par_value
704
+ percent: selectedDiscount2.par_value,
705
+ discount_product_id: selectedDiscount2.product_id
535
706
  },
536
707
  // 前端使用的num数量,为了计算优惠金额
537
708
  _num: isGoodPass ? 1 : product.num,
709
+ config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
538
710
  metadata: {
539
711
  num: 1
540
712
  }
@@ -550,7 +722,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
550
722
  }, new import_decimal.default(total)).toNumber();
551
723
  }
552
724
  if (product.isClient) {
553
- debugger;
554
725
  arr.push(this.hooks.setProduct(originProduct, {
555
726
  discount_list: [discountDetail],
556
727
  price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
@@ -587,23 +758,35 @@ var RulesModule = class extends import_BaseModule.BaseModule {
587
758
  for (let i = 0; i < discountNum; i++) {
588
759
  const selectedDiscount2 = applicableDiscounts[i];
589
760
  usedDiscounts.set(selectedDiscount2.id, true);
761
+ if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
762
+ const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
763
+ usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
764
+ }
590
765
  const uniqueId = `${flatItem._id}_split_${i}`;
766
+ const discountedPrice = (0, import_utils.getDiscountAmount)(
767
+ selectedDiscount2,
768
+ product.origin_total,
769
+ product.origin_total
770
+ );
771
+ const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
591
772
  const discountDetail = {
592
- amount: product.origin_total,
773
+ amount: bundleDiscountAmount,
593
774
  type: "good_pass",
594
775
  discount: {
595
776
  fixed_amount: product.origin_total,
596
777
  resource_id: selectedDiscount2.id,
597
778
  title: selectedDiscount2.format_title,
598
779
  original_amount: product.origin_total,
599
- product_id: product.id
780
+ product_id: product.id,
781
+ discount_product_id: selectedDiscount2.product_id
600
782
  },
601
783
  metadata: {
602
784
  // 🔥 使用拆分后的唯一 _id
603
785
  custom_product_bundle_map_id: uniqueId,
604
786
  num: 1
605
787
  },
606
- _num: 1
788
+ _num: 1,
789
+ config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config
607
790
  };
608
791
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
609
792
  appliedProducts.push(discountDetail);
@@ -614,9 +797,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
614
797
  _id: uniqueId,
615
798
  num: 1,
616
799
  quantity: 1,
617
- price: 0,
618
- // 商品券价格为0
619
- total: 0,
800
+ price: discountedPrice,
801
+ // 折扣后的价格
802
+ total: discountedPrice,
620
803
  discount_list: [discountDetail],
621
804
  processed: true,
622
805
  _discountId: selectedDiscount2.id
@@ -636,30 +819,37 @@ var RulesModule = class extends import_BaseModule.BaseModule {
636
819
  } else {
637
820
  const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
638
821
  usedDiscounts.set(selectedDiscount2.id, true);
822
+ if ((selectedDiscount2.tag || selectedDiscount2.type) === "good_pass") {
823
+ const currentCount = usedProductIdCounts.get(selectedDiscount2.product_id) || 0;
824
+ usedProductIdCounts.set(selectedDiscount2.product_id, currentCount + 1);
825
+ }
639
826
  const productOriginTotal = product.original_price || product.price || 0;
640
827
  const targetProductTotal = (0, import_utils.getDiscountAmount)(
641
828
  selectedDiscount2,
642
829
  productOriginTotal,
643
830
  productOriginTotal
644
831
  );
832
+ const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
645
833
  const uniqueId = flatItem._id;
646
834
  const discountDetail = {
647
- amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber() * (product.num || 1),
835
+ amount: bundleActualDiscountAmount * (product.num || 1),
648
836
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
649
837
  discount: {
650
838
  discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
651
- fixed_amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber(),
839
+ fixed_amount: bundleActualDiscountAmount,
652
840
  resource_id: selectedDiscount2.id,
653
841
  title: selectedDiscount2.format_title,
654
842
  original_amount: product.original_price,
655
843
  product_id: product.id,
656
- percent: selectedDiscount2.par_value
844
+ percent: selectedDiscount2.par_value,
845
+ discount_product_id: selectedDiscount2.product_id
657
846
  },
658
847
  metadata: {
659
848
  // 🔥 使用唯一的 _id
660
849
  custom_product_bundle_map_id: uniqueId,
661
850
  num: product.num || 1
662
851
  },
852
+ config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
663
853
  _num: (product.num || 1) * (((_x = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _x.num) || 1)
664
854
  };
665
855
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
@@ -717,7 +907,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
717
907
  return;
718
908
  }
719
909
  const hasBundle = product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0;
720
- debugger;
721
910
  if (!hasBundle) {
722
911
  result.push(...mainProductArr);
723
912
  } else {
@@ -750,59 +939,65 @@ var RulesModule = class extends import_BaseModule.BaseModule {
750
939
  const mainProduct = mainProductArr[0];
751
940
  const mainProductData = this.hooks.getProduct(mainProduct);
752
941
  const newBundleWithDiscount = [];
753
- (product.bundle || []).forEach((bundleItem, bundleIndex) => {
754
- const processedItems = bundleProcessingInfo.get(bundleIndex) || [bundleItem];
755
- if (processedItems.length > 1) {
756
- processedItems.forEach((item) => {
757
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
758
- var _a;
759
- return {
760
- ...discount,
761
- metadata: {
762
- num: item.num,
763
- custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
764
- }
765
- // num: item.num, // 使用拆分后的 num
766
- };
767
- });
768
- newBundleWithDiscount.push({
769
- ...bundleItem,
770
- _id: item._id,
771
- product_id: bundleItem.product_id,
772
- price: item.price,
773
- num: item.num,
774
- discount_list: updatedDiscountList2
775
- });
776
- });
777
- } else {
778
- const item = processedItems[0];
779
- if (item.processed) {
780
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
781
- var _a;
782
- return {
783
- ...discount,
784
- metadata: {
785
- num: item.num,
786
- custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
787
- }
788
- // num: item.num, // 使用当前的 num
789
- };
790
- });
791
- newBundleWithDiscount.push({
792
- ...bundleItem,
793
- _id: item._id,
794
- product_id: bundleItem.product_id,
795
- price: item.price,
796
- num: item.num,
797
- discount_list: updatedDiscountList2
942
+ (product.bundle || []).forEach(
943
+ (bundleItem, bundleIndex) => {
944
+ const processedItems = bundleProcessingInfo.get(
945
+ bundleIndex
946
+ ) || [bundleItem];
947
+ if (processedItems.length > 1) {
948
+ processedItems.forEach((item) => {
949
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
950
+ var _a;
951
+ return {
952
+ ...discount,
953
+ metadata: {
954
+ num: item.num,
955
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
956
+ }
957
+ // num: item.num, // 使用拆分后的 num
958
+ };
959
+ });
960
+ newBundleWithDiscount.push({
961
+ ...bundleItem,
962
+ _id: item._id,
963
+ product_id: bundleItem.product_id,
964
+ price: item.price,
965
+ num: item.num,
966
+ discount_list: updatedDiscountList2
967
+ });
798
968
  });
799
969
  } else {
800
- newBundleWithDiscount.push(item);
970
+ const item = processedItems[0];
971
+ if (item.processed) {
972
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
973
+ var _a;
974
+ return {
975
+ ...discount,
976
+ metadata: {
977
+ num: item.num,
978
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
979
+ }
980
+ // num: item.num, // 使用当前的 num
981
+ };
982
+ });
983
+ newBundleWithDiscount.push({
984
+ ...bundleItem,
985
+ _id: item._id,
986
+ product_id: bundleItem.product_id,
987
+ price: item.price,
988
+ num: item.num,
989
+ discount_list: updatedDiscountList2
990
+ });
991
+ } else {
992
+ newBundleWithDiscount.push(item);
993
+ }
801
994
  }
802
995
  }
803
- });
996
+ );
804
997
  let newTotalWithDiscount = Number(mainProductData.price || 0);
805
- let newOriginTotalWithDiscount = Number(mainProductData.original_price || mainProductData.price || 0);
998
+ let newOriginTotalWithDiscount = Number(
999
+ mainProductData.original_price || mainProductData.price || 0
1000
+ );
806
1001
  const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
807
1002
  var _a, _b;
808
1003
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -817,10 +1012,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
817
1012
  }
818
1013
  };
819
1014
  });
820
- const mainDiscountList = updatedMainDiscountList.filter((item) => {
821
- var _a;
822
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
823
- });
1015
+ const mainDiscountList = updatedMainDiscountList.filter(
1016
+ (item) => {
1017
+ var _a;
1018
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1019
+ }
1020
+ );
824
1021
  if (mainDiscountList && mainDiscountList.length > 0) {
825
1022
  const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
826
1023
  newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
@@ -856,14 +1053,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
856
1053
  );
857
1054
  if (mainProductQuantity > 1) {
858
1055
  const newBundleOriginal = [];
859
- (product.bundle || []).forEach((bundleItem, bundleIndex) => {
860
- newBundleOriginal.push({
861
- ...bundleItem,
862
- discount_list: []
863
- });
864
- });
1056
+ (product.bundle || []).forEach(
1057
+ (bundleItem, bundleIndex) => {
1058
+ newBundleOriginal.push({
1059
+ ...bundleItem,
1060
+ discount_list: []
1061
+ });
1062
+ }
1063
+ );
865
1064
  let newTotalOriginal = Number(mainProductData.price || 0);
866
- let newOriginTotalOriginal = Number(mainProductData.original_price || mainProductData.price || 0);
1065
+ let newOriginTotalOriginal = Number(
1066
+ mainProductData.original_price || mainProductData.price || 0
1067
+ );
867
1068
  const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
868
1069
  var _a, _b;
869
1070
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -878,12 +1079,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
878
1079
  // num: mainProductQuantity - 1,
879
1080
  };
880
1081
  });
881
- const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter((item) => {
882
- var _a;
883
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
884
- });
1082
+ const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
1083
+ (item) => {
1084
+ var _a;
1085
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1086
+ }
1087
+ );
885
1088
  if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
886
- const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountListOriginal);
1089
+ const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
1090
+ mainDiscountListOriginal
1091
+ );
887
1092
  newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
888
1093
  newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
889
1094
  }
@@ -918,47 +1123,56 @@ var RulesModule = class extends import_BaseModule.BaseModule {
918
1123
  const mainProductData = this.hooks.getProduct(mainProduct);
919
1124
  const newBundle = [];
920
1125
  if (product.bundle && Array.isArray(product.bundle)) {
921
- product.bundle.forEach((bundleItem, bundleIndex) => {
922
- const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
923
- const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
924
- if (!processedBundleItems || processedBundleItems.length === 0) {
925
- newBundle.push(bundleItem);
926
- } else {
927
- processedBundleItems.forEach((item) => {
928
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
929
- var _a2;
930
- return {
931
- ...discount,
932
- metadata: {
933
- num: item.num,
934
- custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
935
- }
936
- // num: item.num, // 使用拆分后的 num
937
- };
938
- });
939
- newBundle.push({
940
- ...bundleItem,
941
- _id: item._id,
942
- product_id: bundleItem.product_id,
943
- price: item.price,
944
- num: item.num,
945
- discount_list: updatedDiscountList2
1126
+ product.bundle.forEach(
1127
+ (bundleItem, bundleIndex) => {
1128
+ const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
1129
+ const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
1130
+ if (!processedBundleItems || processedBundleItems.length === 0) {
1131
+ newBundle.push(bundleItem);
1132
+ } else {
1133
+ processedBundleItems.forEach((item) => {
1134
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1135
+ var _a2;
1136
+ return {
1137
+ ...discount,
1138
+ metadata: {
1139
+ num: item.num,
1140
+ custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
1141
+ }
1142
+ // num: item.num, // 使用拆分后的 num
1143
+ };
1144
+ });
1145
+ newBundle.push({
1146
+ ...bundleItem,
1147
+ _id: item._id,
1148
+ product_id: bundleItem.product_id,
1149
+ price: item.price,
1150
+ num: item.num,
1151
+ discount_list: updatedDiscountList2
1152
+ });
946
1153
  });
947
- });
1154
+ }
948
1155
  }
949
- });
1156
+ );
950
1157
  }
951
1158
  let newTotal = Number(mainProductData.price || 0);
952
- let newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
953
- const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(_b, (item) => item.type === "product")));
1159
+ let newOriginTotal = Number(
1160
+ mainProductData.original_price || mainProductData.price || 0
1161
+ );
1162
+ const isManualDiscount = typeof mainProductData.isManualDiscount === "boolean" ? mainProductData.isManualDiscount : mainProductData.total != mainProductData.origin_total && (!((_a = mainProductData.discount_list) == null ? void 0 : _a.length) || ((_c = (_b = mainProductData == null ? void 0 : mainProductData.discount_list) == null ? void 0 : _b.every) == null ? void 0 : _c.call(
1163
+ _b,
1164
+ (item) => item.type === "product"
1165
+ )));
954
1166
  if (isManualDiscount) {
955
1167
  newTotal = mainProductData.total ?? newTotal;
956
1168
  newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
957
1169
  } else {
958
- const mainDiscountList = mainProductData.discount_list.filter((item) => {
959
- var _a2;
960
- return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
961
- });
1170
+ const mainDiscountList = mainProductData.discount_list.filter(
1171
+ (item) => {
1172
+ var _a2;
1173
+ return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
1174
+ }
1175
+ );
962
1176
  if (mainDiscountList && mainDiscountList.length > 0) {
963
1177
  const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
964
1178
  newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;