@pisell/pisellos 2.1.54 → 2.1.58

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 (100) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/modules/Cart/types.d.ts +0 -2
  4. package/dist/modules/Cart/utils/cartProduct.js +0 -11
  5. package/dist/modules/Discount/types.d.ts +0 -15
  6. package/dist/modules/Payment/index.d.ts +1 -2
  7. package/dist/modules/Payment/index.js +7 -10
  8. package/dist/modules/Payment/utils.js +0 -3
  9. package/dist/modules/Payment/walletpass.d.ts +0 -23
  10. package/dist/modules/Payment/walletpass.js +95 -191
  11. package/dist/modules/Product/index.d.ts +1 -1
  12. package/dist/modules/Rules/index.d.ts +5 -8
  13. package/dist/modules/Rules/index.js +31 -154
  14. package/dist/modules/Rules/types.d.ts +1 -1
  15. package/dist/modules/Summary/types.d.ts +0 -2
  16. package/dist/modules/Summary/utils.d.ts +0 -6
  17. package/dist/modules/Summary/utils.js +0 -21
  18. package/dist/plugins/window.d.ts +0 -2
  19. package/dist/solution/BookingByStep/index.d.ts +0 -1
  20. package/dist/solution/BookingTicket/index.d.ts +1 -1
  21. package/dist/solution/Checkout/index.js +0 -2
  22. package/dist/solution/ShopDiscount/index.d.ts +4 -1
  23. package/dist/solution/ShopDiscount/index.js +11 -12
  24. package/dist/solution/ShopDiscount/types.d.ts +4 -1
  25. package/dist/solution/ShopDiscount/utils.js +11 -26
  26. package/lib/index.d.ts +0 -1
  27. package/lib/index.js +1 -3
  28. package/lib/modules/Cart/types.d.ts +0 -2
  29. package/lib/modules/Cart/utils/cartProduct.js +0 -9
  30. package/lib/modules/Discount/types.d.ts +0 -15
  31. package/lib/modules/Payment/index.d.ts +1 -2
  32. package/lib/modules/Payment/index.js +0 -1
  33. package/lib/modules/Payment/utils.js +0 -3
  34. package/lib/modules/Payment/walletpass.d.ts +0 -23
  35. package/lib/modules/Payment/walletpass.js +17 -94
  36. package/lib/modules/Product/index.d.ts +1 -1
  37. package/lib/modules/Rules/index.d.ts +5 -8
  38. package/lib/modules/Rules/index.js +197 -372
  39. package/lib/modules/Rules/types.d.ts +1 -1
  40. package/lib/modules/Summary/types.d.ts +0 -2
  41. package/lib/modules/Summary/utils.d.ts +0 -6
  42. package/lib/modules/Summary/utils.js +0 -15
  43. package/lib/plugins/window.d.ts +0 -2
  44. package/lib/solution/BookingByStep/index.d.ts +0 -1
  45. package/lib/solution/BookingTicket/index.d.ts +1 -1
  46. package/lib/solution/BookingTicket/index.js +6 -0
  47. package/lib/solution/Checkout/index.js +0 -2
  48. package/lib/solution/ShopDiscount/index.d.ts +4 -1
  49. package/lib/solution/ShopDiscount/index.js +9 -8
  50. package/lib/solution/ShopDiscount/types.d.ts +4 -1
  51. package/lib/solution/ShopDiscount/utils.js +6 -10
  52. package/package.json +1 -1
  53. package/dist/model/index.d.ts +0 -1
  54. package/dist/model/index.js +0 -1
  55. package/dist/model/strategy/adapter/index.d.ts +0 -3
  56. package/dist/model/strategy/adapter/index.js +0 -4
  57. package/dist/model/strategy/adapter/type.d.ts +0 -28
  58. package/dist/model/strategy/adapter/type.js +0 -1
  59. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  60. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -496
  61. package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
  62. package/dist/model/strategy/adapter/walletPass/example.js +0 -258
  63. package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
  64. package/dist/model/strategy/adapter/walletPass/index.js +0 -182
  65. package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  66. package/dist/model/strategy/adapter/walletPass/locales.js +0 -23
  67. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -163
  68. package/dist/model/strategy/adapter/walletPass/type.js +0 -1
  69. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  70. package/dist/model/strategy/adapter/walletPass/utils.js +0 -965
  71. package/dist/model/strategy/index.d.ts +0 -94
  72. package/dist/model/strategy/index.js +0 -551
  73. package/dist/model/strategy/strategy-example.d.ts +0 -5
  74. package/dist/model/strategy/strategy-example.js +0 -331
  75. package/dist/model/strategy/type.d.ts +0 -228
  76. package/dist/model/strategy/type.js +0 -94
  77. package/lib/model/index.d.ts +0 -1
  78. package/lib/model/index.js +0 -23
  79. package/lib/model/strategy/adapter/index.d.ts +0 -3
  80. package/lib/model/strategy/adapter/index.js +0 -45
  81. package/lib/model/strategy/adapter/type.d.ts +0 -28
  82. package/lib/model/strategy/adapter/type.js +0 -17
  83. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  84. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -420
  85. package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
  86. package/lib/model/strategy/adapter/walletPass/example.js +0 -207
  87. package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
  88. package/lib/model/strategy/adapter/walletPass/index.js +0 -142
  89. package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  90. package/lib/model/strategy/adapter/walletPass/locales.js +0 -51
  91. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -163
  92. package/lib/model/strategy/adapter/walletPass/type.js +0 -17
  93. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  94. package/lib/model/strategy/adapter/walletPass/utils.js +0 -660
  95. package/lib/model/strategy/index.d.ts +0 -94
  96. package/lib/model/strategy/index.js +0 -413
  97. package/lib/model/strategy/strategy-example.d.ts +0 -5
  98. package/lib/model/strategy/strategy-example.js +0 -318
  99. package/lib/model/strategy/type.d.ts +0 -228
  100. package/lib/model/strategy/type.js +0 -44
@@ -49,7 +49,6 @@ 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");
53
52
  }
54
53
  async setRulesList(rulesList) {
55
54
  this.store.rulesList = rulesList;
@@ -58,10 +57,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
58
57
  getRulesList() {
59
58
  return this.store.rulesList;
60
59
  }
61
- getWalletPassEvaluator() {
62
- var _a, _b;
63
- return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
64
- }
65
60
  // 商品不需要holder,则不需要判断,直接返回true,商品需要holder但是还没填写,那么暂时不使用带有holder的券,直到填写才去匹配
66
61
  checkHolderMatch(discount, product, holders) {
67
62
  var _a;
@@ -81,7 +76,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
81
76
  newDiscountList,
82
77
  productList,
83
78
  holders,
84
- orderTotalAmount
79
+ isFormSubject
85
80
  }) {
86
81
  if (!newDiscountList || newDiscountList.length === 0) {
87
82
  return {
@@ -101,18 +96,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
101
96
  productList
102
97
  };
103
98
  }
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
- );
99
+ const filteredOldDiscountList = oldDiscountList.filter((discount) => !discount.isEditMode && discount.tag !== "good_pass");
100
+ const mergedDiscountList = (0, import_utils.uniqueById)((0, import_utils.uniqueById)([
101
+ ...filteredOldDiscountList,
102
+ ...newDiscountList
103
+ ]), "product_id");
111
104
  const result = this.calcDiscount({
112
105
  discountList: mergedDiscountList,
113
106
  productList: [...productList],
114
107
  holders,
115
- orderTotalAmount
108
+ isFormSubject
116
109
  }, {
117
110
  scan: true
118
111
  });
@@ -146,7 +139,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
146
139
  discountList,
147
140
  productList,
148
141
  holders,
149
- orderTotalAmount
142
+ isFormSubject
150
143
  }, options) {
151
144
  const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
152
145
  const editModeDiscount = [];
@@ -266,50 +259,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
266
259
  }
267
260
  return priceB.minus(priceA).toNumber();
268
261
  });
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
- }
311
262
  const usedDiscounts = /* @__PURE__ */ new Map();
312
- const usedProductIdCounts = /* @__PURE__ */ new Map();
313
263
  const discountApplicability = /* @__PURE__ */ new Map();
314
264
  const discountApplicableProducts = /* @__PURE__ */ new Map();
315
265
  addModeDiscount.forEach((discount) => {
@@ -338,30 +288,24 @@ var RulesModule = class extends import_BaseModule.BaseModule {
338
288
  originProduct = flatItem.originProduct;
339
289
  }
340
290
  addModeDiscount.forEach((discount) => {
341
- var _a, _b, _c, _d, _e, _f, _g;
291
+ var _a, _b, _c, _d, _e, _f;
342
292
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
343
293
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
344
294
  const isHolderMatch = this.checkHolderMatch(
345
295
  discount,
346
296
  {
347
- isNeedHolder: _tempVar == null ? void 0 : _tempVar.isNeedHolder,
297
+ isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
348
298
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
349
299
  },
350
300
  holders
351
301
  );
352
302
  let timeLimit = true;
353
303
  timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
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));
304
+ const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
305
+ 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));
362
306
  const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
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);
307
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
308
+ (_e = discountApplicability.get(discount.id)) == null ? void 0 : _e.push(product.id);
365
309
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
366
310
  const discountType = discount.tag || discount.type;
367
311
  const isGoodPass = discountType === "good_pass";
@@ -371,14 +315,13 @@ var RulesModule = class extends import_BaseModule.BaseModule {
371
315
  type: discountType,
372
316
  tag: discountType,
373
317
  discount: {
374
- discount_card_type: (_g = discount == null ? void 0 : discount.metadata) == null ? void 0 : _g.discount_card_type,
318
+ discount_card_type: (_f = discount == null ? void 0 : discount.metadata) == null ? void 0 : _f.discount_card_type,
375
319
  fixed_amount: product.price,
376
320
  resource_id: discount.id,
377
321
  title: discount.format_title,
378
322
  original_amount: product.price || product.origin_total,
379
323
  pre_value: discount.par_value,
380
- product_id: originProduct.id,
381
- discount_product_id: discount.product_id
324
+ product_id: originProduct.id
382
325
  },
383
326
  metadata: {
384
327
  num
@@ -411,39 +354,25 @@ var RulesModule = class extends import_BaseModule.BaseModule {
411
354
  };
412
355
  originProduct = flatItem.originProduct;
413
356
  }
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
- ))) {
357
+ 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)))) {
419
358
  if (flatItem.type === "main") {
420
359
  processedProductsMap.set(product._id, [originProduct]);
421
360
  } else {
422
- processedFlatItemsMap.set(flatItem._id, [
423
- {
424
- ...flatItem,
425
- processed: true
426
- }
427
- ]);
361
+ processedFlatItemsMap.set(flatItem._id, [{
362
+ ...flatItem,
363
+ processed: true
364
+ }]);
428
365
  }
429
366
  return;
430
367
  }
431
368
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
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) => {
369
+ var _a2, _b2;
370
+ if ((Number(product.price) <= 0 || !product.price) && !((_a2 = product.discount_list) == null ? void 0 : _a2.find((n) => {
442
371
  var _a3;
443
372
  return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
444
373
  })) && (discount.tag || discount.type) === "good_pass")
445
374
  return false;
446
- if ((Number(product.price) <= 0 || !product.price) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
375
+ if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
447
376
  var _a3;
448
377
  return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
449
378
  })) && (discount.tag || discount.type) !== "good_pass")
@@ -451,21 +380,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
451
380
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
452
381
  if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
453
382
  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
- }
463
383
  const limitedData = discount.limited_relation_product_data;
464
384
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
465
385
  const isHolderMatch = this.checkHolderMatch(
466
386
  discount,
467
387
  {
468
- isNeedHolder: _tempVar == null ? void 0 : _tempVar.isNeedHolder,
388
+ isNeedHolder: isFormSubject && !(_tempVar == null ? void 0 : _tempVar.isNormalProduct),
469
389
  holder_id: (_tempVar == null ? void 0 : _tempVar.holder_id) || product.holder_id
470
390
  },
471
391
  holders
@@ -478,9 +398,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
478
398
  return false;
479
399
  }
480
400
  if (limitedData.type === "product_all") {
481
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
482
- return false;
483
- }
484
401
  if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
485
402
  return false;
486
403
  }
@@ -493,96 +410,66 @@ var RulesModule = class extends import_BaseModule.BaseModule {
493
410
  }
494
411
  return false;
495
412
  });
496
- const selectedDiscountCard = applicableDiscounts.find(
497
- (n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
498
- );
413
+ const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
499
414
  const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
500
415
  let isManualDiscount = false;
501
416
  if (flatItem.type === "main") {
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
- )));
417
+ isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every((item) => {
418
+ var _a2;
419
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
420
+ }) && (!((_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")));
511
421
  } else {
512
422
  const parentProduct = flatItem.parentProduct;
513
423
  if (parentProduct) {
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
- )));
424
+ isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every((item) => {
425
+ var _a2;
426
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
427
+ }) && (!((_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")));
523
428
  }
524
429
  }
525
430
  if (options == null ? void 0 : options.discountId) {
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
- ))) {
431
+ if (flatItem.type === "main" && ((_l = product.discount_list) == null ? void 0 : _l.some((item) => {
432
+ var _a2;
433
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
434
+ }))) {
532
435
  isManualDiscount = false;
533
436
  }
534
437
  if (flatItem.type === "bundle") {
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
- ))) {
438
+ if (((_m = product.discount_list) == null ? void 0 : _m.some((item) => {
439
+ var _a2;
440
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
441
+ })) || ((_o = (_n = flatItem.parentProduct) == null ? void 0 : _n.discount_list) == null ? void 0 : _o.some((item) => {
442
+ var _a2;
443
+ return ((_a2 = item.discount) == null ? void 0 : _a2.resource_id) === options.discountId;
444
+ }))) {
546
445
  isManualDiscount = false;
547
446
  }
548
447
  }
549
448
  }
550
449
  if (options == null ? void 0 : options.selectedList) {
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
- ))) {
450
+ if (flatItem.type === "main" && ((_p = product.discount_list) == null ? void 0 : _p.some((item) => {
451
+ var _a2;
452
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
453
+ var _a3;
454
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
455
+ });
456
+ }))) {
562
457
  isManualDiscount = false;
563
458
  }
564
459
  if (flatItem.type === "bundle") {
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
- ))) {
460
+ if (((_q = product.discount_list) == null ? void 0 : _q.some((item) => {
461
+ var _a2;
462
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
463
+ var _a3;
464
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
465
+ });
466
+ })) || ((_s = (_r = flatItem.parentProduct) == null ? void 0 : _r.discount_list) == null ? void 0 : _s.some((item) => {
467
+ var _a2;
468
+ return (_a2 = options == null ? void 0 : options.selectedList) == null ? void 0 : _a2.some((n) => {
469
+ var _a3;
470
+ return n.discountId === ((_a3 = item.discount) == null ? void 0 : _a3.resource_id);
471
+ });
472
+ }))) {
586
473
  isManualDiscount = false;
587
474
  }
588
475
  }
@@ -590,8 +477,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
590
477
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
591
478
  if (flatItem.type === "main") {
592
479
  if (product.isClient) {
593
- processedProductsMap.set(product._id, [
594
- this.hooks.setProduct(originProduct, {
480
+ processedProductsMap.set(
481
+ product._id,
482
+ [this.hooks.setProduct(originProduct, {
595
483
  ...isManualDiscount ? {} : {
596
484
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
597
485
  product: {
@@ -612,11 +500,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
612
500
  price: product.price
613
501
  },
614
502
  discount_list: []
615
- })
616
- ]);
503
+ })]
504
+ );
617
505
  } else {
618
- processedProductsMap.set(product._id, [
619
- this.hooks.setProduct(originProduct, {
506
+ processedProductsMap.set(
507
+ product._id,
508
+ [this.hooks.setProduct(originProduct, {
620
509
  ...isManualDiscount ? {
621
510
  price: product.price,
622
511
  main_product_selling_price: product.price
@@ -627,8 +516,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
627
516
  main_product_selling_price: product.price
628
517
  },
629
518
  discount_list: []
630
- })
631
- ]);
519
+ })]
520
+ );
632
521
  }
633
522
  } else {
634
523
  processedFlatItemsMap.set(flatItem._id, [{
@@ -645,36 +534,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
645
534
  }
646
535
  const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
647
536
  const totalQuantity = product.quantity || product.num || 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;
537
+ const availableGoodPassCount = applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length;
538
+ const splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
659
539
  const arr = [];
660
540
  if (flatItem.type === "main") {
661
541
  if (splitCount < totalQuantity && isNeedSplit) {
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
- );
542
+ arr.push(this.hooks.setProduct(originProduct, {
543
+ discount_list: [],
544
+ quantity: totalQuantity - splitCount,
545
+ _id: product._id.split("___")[0]
546
+ }));
670
547
  }
671
548
  for (let i = 0; i < splitCount; i++) {
672
549
  const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
673
550
  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
- }
678
551
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
679
552
  let productOriginTotal = product.origin_total || product.total || 0;
680
553
  if (((_t = product.discount_list) == null ? void 0 : _t.length) && product.origin_total) {
@@ -683,30 +556,24 @@ var RulesModule = class extends import_BaseModule.BaseModule {
683
556
  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) {
684
557
  productOriginTotal = product.total;
685
558
  }
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();
559
+ const targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
560
+ const discountType = selectedDiscount2.tag || selectedDiscount2.type;
693
561
  const isGoodPass = discountType === "good_pass";
562
+ const amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
694
563
  const discountDetail = {
695
- amount: actualDiscountAmount,
696
- type: discountType,
564
+ amount,
565
+ type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
697
566
  discount: {
698
567
  discount_card_type: (_v = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _v.discount_card_type,
699
- fixed_amount: actualDiscountAmount,
568
+ fixed_amount: amount,
700
569
  resource_id: selectedDiscount2.id,
701
570
  title: selectedDiscount2.format_title,
702
571
  original_amount: product.price,
703
572
  product_id: originProduct.id,
704
- percent: selectedDiscount2.par_value,
705
- discount_product_id: selectedDiscount2.product_id
573
+ percent: selectedDiscount2.par_value
706
574
  },
707
575
  // 前端使用的num数量,为了计算优惠金额
708
576
  _num: isGoodPass ? 1 : product.num,
709
- config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
710
577
  metadata: {
711
578
  num: 1
712
579
  }
@@ -722,6 +589,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
722
589
  }, new import_decimal.default(total)).toNumber();
723
590
  }
724
591
  if (product.isClient) {
592
+ debugger;
725
593
  arr.push(this.hooks.setProduct(originProduct, {
726
594
  discount_list: [discountDetail],
727
595
  price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
@@ -758,35 +626,23 @@ var RulesModule = class extends import_BaseModule.BaseModule {
758
626
  for (let i = 0; i < discountNum; i++) {
759
627
  const selectedDiscount2 = applicableDiscounts[i];
760
628
  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
- }
765
629
  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();
772
630
  const discountDetail = {
773
- amount: bundleDiscountAmount,
631
+ amount: product.origin_total,
774
632
  type: "good_pass",
775
633
  discount: {
776
634
  fixed_amount: product.origin_total,
777
635
  resource_id: selectedDiscount2.id,
778
636
  title: selectedDiscount2.format_title,
779
637
  original_amount: product.origin_total,
780
- product_id: product.id,
781
- discount_product_id: selectedDiscount2.product_id
638
+ product_id: product.id
782
639
  },
783
640
  metadata: {
784
641
  // 🔥 使用拆分后的唯一 _id
785
642
  custom_product_bundle_map_id: uniqueId,
786
643
  num: 1
787
644
  },
788
- _num: 1,
789
- config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config
645
+ _num: 1
790
646
  };
791
647
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
792
648
  appliedProducts.push(discountDetail);
@@ -797,9 +653,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
797
653
  _id: uniqueId,
798
654
  num: 1,
799
655
  quantity: 1,
800
- price: discountedPrice,
801
- // 折扣后的价格
802
- total: discountedPrice,
656
+ price: 0,
657
+ // 商品券价格为0
658
+ total: 0,
803
659
  discount_list: [discountDetail],
804
660
  processed: true,
805
661
  _discountId: selectedDiscount2.id
@@ -819,37 +675,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
819
675
  } else {
820
676
  const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
821
677
  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
- }
826
678
  const productOriginTotal = product.original_price || product.price || 0;
827
679
  const targetProductTotal = (0, import_utils.getDiscountAmount)(
828
680
  selectedDiscount2,
829
681
  productOriginTotal,
830
682
  productOriginTotal
831
683
  );
832
- const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
833
684
  const uniqueId = flatItem._id;
834
685
  const discountDetail = {
835
- amount: bundleActualDiscountAmount * (product.num || 1),
686
+ amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber() * (product.num || 1),
836
687
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
837
688
  discount: {
838
689
  discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
839
- fixed_amount: bundleActualDiscountAmount,
690
+ fixed_amount: new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber(),
840
691
  resource_id: selectedDiscount2.id,
841
692
  title: selectedDiscount2.format_title,
842
693
  original_amount: product.original_price,
843
694
  product_id: product.id,
844
- percent: selectedDiscount2.par_value,
845
- discount_product_id: selectedDiscount2.product_id
695
+ percent: selectedDiscount2.par_value
846
696
  },
847
697
  metadata: {
848
698
  // 🔥 使用唯一的 _id
849
699
  custom_product_bundle_map_id: uniqueId,
850
700
  num: product.num || 1
851
701
  },
852
- config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
853
702
  _num: (product.num || 1) * (((_x = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _x.num) || 1)
854
703
  };
855
704
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
@@ -907,6 +756,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
907
756
  return;
908
757
  }
909
758
  const hasBundle = product.bundle && Array.isArray(product.bundle) && product.bundle.length > 0;
759
+ debugger;
910
760
  if (!hasBundle) {
911
761
  result.push(...mainProductArr);
912
762
  } else {
@@ -939,65 +789,59 @@ var RulesModule = class extends import_BaseModule.BaseModule {
939
789
  const mainProduct = mainProductArr[0];
940
790
  const mainProductData = this.hooks.getProduct(mainProduct);
941
791
  const newBundleWithDiscount = [];
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
- });
792
+ (product.bundle || []).forEach((bundleItem, bundleIndex) => {
793
+ const processedItems = bundleProcessingInfo.get(bundleIndex) || [bundleItem];
794
+ if (processedItems.length > 1) {
795
+ processedItems.forEach((item) => {
796
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
797
+ var _a;
798
+ return {
799
+ ...discount,
800
+ metadata: {
801
+ num: item.num,
802
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
803
+ }
804
+ // num: item.num, // 使用拆分后的 num
805
+ };
806
+ });
807
+ newBundleWithDiscount.push({
808
+ ...bundleItem,
809
+ _id: item._id,
810
+ product_id: bundleItem.product_id,
811
+ price: item.price,
812
+ num: item.num,
813
+ discount_list: updatedDiscountList2
814
+ });
815
+ });
816
+ } else {
817
+ const item = processedItems[0];
818
+ if (item.processed) {
819
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
820
+ var _a;
821
+ return {
822
+ ...discount,
823
+ metadata: {
824
+ num: item.num,
825
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
826
+ }
827
+ // num: item.num, // 使用当前的 num
828
+ };
829
+ });
830
+ newBundleWithDiscount.push({
831
+ ...bundleItem,
832
+ _id: item._id,
833
+ product_id: bundleItem.product_id,
834
+ price: item.price,
835
+ num: item.num,
836
+ discount_list: updatedDiscountList2
968
837
  });
969
838
  } else {
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
- }
839
+ newBundleWithDiscount.push(item);
994
840
  }
995
841
  }
996
- );
842
+ });
997
843
  let newTotalWithDiscount = Number(mainProductData.price || 0);
998
- let newOriginTotalWithDiscount = Number(
999
- mainProductData.original_price || mainProductData.price || 0
1000
- );
844
+ let newOriginTotalWithDiscount = Number(mainProductData.original_price || mainProductData.price || 0);
1001
845
  const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
1002
846
  var _a, _b;
1003
847
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -1012,12 +856,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1012
856
  }
1013
857
  };
1014
858
  });
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
- );
859
+ const mainDiscountList = updatedMainDiscountList.filter((item) => {
860
+ var _a;
861
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
862
+ });
1021
863
  if (mainDiscountList && mainDiscountList.length > 0) {
1022
864
  const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
1023
865
  newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
@@ -1053,18 +895,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1053
895
  );
1054
896
  if (mainProductQuantity > 1) {
1055
897
  const newBundleOriginal = [];
1056
- (product.bundle || []).forEach(
1057
- (bundleItem, bundleIndex) => {
1058
- newBundleOriginal.push({
1059
- ...bundleItem,
1060
- discount_list: []
1061
- });
1062
- }
1063
- );
898
+ (product.bundle || []).forEach((bundleItem, bundleIndex) => {
899
+ newBundleOriginal.push({
900
+ ...bundleItem,
901
+ discount_list: []
902
+ });
903
+ });
1064
904
  let newTotalOriginal = Number(mainProductData.price || 0);
1065
- let newOriginTotalOriginal = Number(
1066
- mainProductData.original_price || mainProductData.price || 0
1067
- );
905
+ let newOriginTotalOriginal = Number(mainProductData.original_price || mainProductData.price || 0);
1068
906
  const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
1069
907
  var _a, _b;
1070
908
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -1079,16 +917,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1079
917
  // num: mainProductQuantity - 1,
1080
918
  };
1081
919
  });
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
- );
920
+ const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter((item) => {
921
+ var _a;
922
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
923
+ });
1088
924
  if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
1089
- const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
1090
- mainDiscountListOriginal
1091
- );
925
+ const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountListOriginal);
1092
926
  newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
1093
927
  newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
1094
928
  }
@@ -1123,56 +957,47 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1123
957
  const mainProductData = this.hooks.getProduct(mainProduct);
1124
958
  const newBundle = [];
1125
959
  if (product.bundle && Array.isArray(product.bundle)) {
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
- });
960
+ product.bundle.forEach((bundleItem, bundleIndex) => {
961
+ const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
962
+ const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
963
+ if (!processedBundleItems || processedBundleItems.length === 0) {
964
+ newBundle.push(bundleItem);
965
+ } else {
966
+ processedBundleItems.forEach((item) => {
967
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
968
+ var _a2;
969
+ return {
970
+ ...discount,
971
+ metadata: {
972
+ num: item.num,
973
+ custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
974
+ }
975
+ // num: item.num, // 使用拆分后的 num
976
+ };
1153
977
  });
1154
- }
978
+ newBundle.push({
979
+ ...bundleItem,
980
+ _id: item._id,
981
+ product_id: bundleItem.product_id,
982
+ price: item.price,
983
+ num: item.num,
984
+ discount_list: updatedDiscountList2
985
+ });
986
+ });
1155
987
  }
1156
- );
988
+ });
1157
989
  }
1158
990
  let newTotal = Number(mainProductData.price || 0);
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
- )));
991
+ let newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
992
+ 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")));
1166
993
  if (isManualDiscount) {
1167
994
  newTotal = mainProductData.total ?? newTotal;
1168
995
  newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
1169
996
  } else {
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
- );
997
+ const mainDiscountList = mainProductData.discount_list.filter((item) => {
998
+ var _a2;
999
+ return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
1000
+ });
1176
1001
  if (mainDiscountList && mainDiscountList.length > 0) {
1177
1002
  const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
1178
1003
  newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;