@pisell/pisellos 2.1.93 → 2.1.94

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 -16
  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/Rules/index.d.ts +5 -9
  12. package/dist/modules/Rules/index.js +125 -539
  13. package/dist/modules/Rules/types.d.ts +0 -1
  14. package/dist/modules/Summary/types.d.ts +0 -2
  15. package/dist/modules/Summary/utils.d.ts +0 -6
  16. package/dist/modules/Summary/utils.js +0 -21
  17. package/dist/plugins/window.d.ts +0 -2
  18. package/dist/solution/BookingByStep/index.d.ts +1 -2
  19. package/dist/solution/BookingByStep/index.js +5 -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 +0 -1
  23. package/dist/solution/ShopDiscount/index.js +7 -23
  24. package/dist/solution/ShopDiscount/types.d.ts +0 -1
  25. package/dist/solution/ShopDiscount/types.js +1 -2
  26. package/dist/solution/ShopDiscount/utils.js +12 -26
  27. package/lib/index.d.ts +0 -1
  28. package/lib/index.js +1 -3
  29. package/lib/modules/Cart/types.d.ts +0 -2
  30. package/lib/modules/Cart/utils/cartProduct.js +0 -9
  31. package/lib/modules/Discount/types.d.ts +0 -16
  32. package/lib/modules/Payment/index.d.ts +1 -2
  33. package/lib/modules/Payment/index.js +0 -1
  34. package/lib/modules/Payment/utils.js +0 -3
  35. package/lib/modules/Payment/walletpass.d.ts +0 -23
  36. package/lib/modules/Payment/walletpass.js +17 -94
  37. package/lib/modules/Rules/index.d.ts +5 -9
  38. package/lib/modules/Rules/index.js +259 -665
  39. package/lib/modules/Rules/types.d.ts +0 -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 +1 -2
  45. package/lib/solution/BookingByStep/index.js +3 -1
  46. package/lib/solution/BookingTicket/index.d.ts +1 -1
  47. package/lib/solution/Checkout/index.js +0 -2
  48. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  49. package/lib/solution/ShopDiscount/index.js +8 -22
  50. package/lib/solution/ShopDiscount/types.d.ts +0 -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 -497
  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 -165
  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 -421
  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 -165
  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
@@ -50,7 +50,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
50
50
  this.core = core;
51
51
  this.hooks = options == null ? void 0 : options.hooks;
52
52
  this.store = options == null ? void 0 : options.store;
53
- this.window = core.getPlugin("window");
54
53
  }
55
54
  async setRulesList(rulesList) {
56
55
  this.store.rulesList = rulesList;
@@ -72,16 +71,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
72
71
  return false;
73
72
  return (productHolderId || orderHolderId) === discount.holder.holder_id;
74
73
  }
75
- getWalletPassEvaluator() {
76
- var _a, _b;
77
- return (_b = (_a = this.window).getWalletPassEvaluator) == null ? void 0 : _b.call(_a);
78
- }
79
74
  // 判断discountList 是否可以对当前productList生效
80
75
  isDiscountListAvailable({
81
76
  oldDiscountList,
82
77
  newDiscountList,
83
78
  productList,
84
- orderTotalAmount,
85
79
  holders,
86
80
  isFormSubject
87
81
  }) {
@@ -114,7 +108,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
114
108
  const result = this.calcDiscount({
115
109
  discountList: mergedDiscountList,
116
110
  productList: [...productList],
117
- orderTotalAmount,
118
111
  holders,
119
112
  isFormSubject
120
113
  }, {
@@ -187,10 +180,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
187
180
  discountList,
188
181
  productList,
189
182
  holders,
190
- isFormSubject,
191
- orderTotalAmount
183
+ isFormSubject
192
184
  }, options) {
193
- const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
194
185
  const editModeDiscount = [];
195
186
  const addModeDiscount = [];
196
187
  discountList.forEach((discount) => {
@@ -343,6 +334,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
343
334
  return compareByExpireTime(a, b);
344
335
  });
345
336
  const flattenedList = flattenProductsWithBundle(productList);
337
+ const isEditModeAddNewProduct = flattenedList.find((n) => n.booking_id) && flattenedList.find((n) => !n.booking_id);
346
338
  const sortedFlattenedList = flattenedList.sort((a, b) => {
347
339
  var _a, _b;
348
340
  const priceA = new import_decimal.default(
@@ -367,59 +359,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
367
359
  }
368
360
  return priceB.minus(priceA).toNumber();
369
361
  });
370
- const evaluator = this.getWalletPassEvaluator();
371
- if (evaluator) {
372
- addModeDiscount.forEach((discount) => {
373
- var _a, _b;
374
- const discountType = discount.tag || discount.type;
375
- if (["good_pass", "discount_card", "product_discount_card"].includes(
376
- discountType
377
- )) {
378
- const voucher = {
379
- id: discount.id,
380
- amount: Number(discount.par_value || 0),
381
- balance: Number(discount.balance || 0),
382
- type: discountType,
383
- product_id: discount.product_id,
384
- unified_available_status: 1,
385
- available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
386
- available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
387
- };
388
- const productsForEvaluate = sortedFlattenedList.map((item) => ({
389
- product_id: item.id,
390
- price: item.price || 0,
391
- quantity: item.quantity || item.num || 1,
392
- selling_price: item.price || 0
393
- }));
394
- const result = evaluator.checkVoucherAvailability({
395
- orderTotalAmount,
396
- products: productsForEvaluate,
397
- vouchers: [voucher]
398
- });
399
- if (result.isAvailable) {
400
- discount.config = {
401
- ...result.config,
402
- isAvailable: true
403
- };
404
- } else {
405
- discount.config = {
406
- isAvailable: false
407
- };
408
- }
409
- }
410
- });
411
- }
412
362
  const usedDiscounts = /* @__PURE__ */ new Map();
413
- const usedProductIdCounts = /* @__PURE__ */ new Map();
414
- const usedDiscountCardLimitCounts = /* @__PURE__ */ new Map();
415
- editModeDiscount.forEach((discount) => {
416
- var _a;
417
- const discountType = discount.tag || discount.type;
418
- if (["discount_card", "product_discount_card"].includes(discountType)) {
419
- const currentCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
420
- usedDiscountCardLimitCounts.set(discount.id, currentCount + (((_a = discount.metadata) == null ? void 0 : _a.num) || 1));
421
- }
422
- });
423
363
  const discountApplicability = /* @__PURE__ */ new Map();
424
364
  const discountApplicableProducts = /* @__PURE__ */ new Map();
425
365
  addModeDiscount.forEach((discount) => {
@@ -573,7 +513,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
573
513
  originProduct = flatItem.originProduct;
574
514
  }
575
515
  addModeDiscount.forEach((discount) => {
576
- var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
516
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i;
577
517
  const limitedData = discount == null ? void 0 : discount.limited_relation_product_data;
578
518
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
579
519
  const isHolderMatch = this.checkHolderMatch(
@@ -586,7 +526,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
586
526
  );
587
527
  let timeLimit = true;
588
528
  timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], ((product == null ? void 0 : product.startDate) || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
589
- 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;
529
+ const isLimitedProduct = (limitedData.type === "product_all" || limitedData.product_ids && limitedData.product_ids.includes(product.id)) && isHolderMatch;
590
530
  const isAvailableProduct = flatItem.type === "main" ? !((product == null ? void 0 : product.booking_id) && ((_a2 = product == null ? void 0 : product.discount_list) == null ? void 0 : _a2.length) && ((_b = product == null ? void 0 : product.discount_list) == null ? void 0 : _b.every(
591
531
  (discount2) => discount2.id && [
592
532
  "good_pass",
@@ -595,8 +535,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
595
535
  ].includes(discount2.tag || discount2.type)
596
536
  ))) : !((flatItem == null ? void 0 : flatItem.booking_id) && !!((_d = (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) == null ? void 0 : _d.length) && ((_f = (_e = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _e.discount_list) == null ? void 0 : _f.every((discount2) => discount2.id)));
597
537
  const isBundleAvailable = this.checkPackageSubItemUsageRules(discount, flatItem);
598
- if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable && ((_g = discount.config) == null ? void 0 : _g.isAvailable)) {
599
- (_h = discountApplicability.get(discount.id)) == null ? void 0 : _h.push(product.id);
538
+ if (isAvailableProduct && isLimitedProduct && timeLimit && isBundleAvailable) {
539
+ (_g = discountApplicability.get(discount.id)) == null ? void 0 : _g.push(product.id);
600
540
  const applicableProducts = discountApplicableProducts.get(discount.id) || [];
601
541
  const discountType = discount.tag || discount.type;
602
542
  const isGoodPass = discountType === "good_pass";
@@ -606,15 +546,14 @@ var RulesModule = class extends import_BaseModule.BaseModule {
606
546
  type: discountType,
607
547
  tag: discountType,
608
548
  discount: {
609
- discount_card_type: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_card_type,
549
+ discount_card_type: (_h = discount == null ? void 0 : discount.metadata) == null ? void 0 : _h.discount_card_type,
610
550
  fixed_amount: product.price,
611
- discount_calculation_mode: (_j = discount == null ? void 0 : discount.metadata) == null ? void 0 : _j.discount_calculation_mode,
551
+ discount_calculation_mode: (_i = discount == null ? void 0 : discount.metadata) == null ? void 0 : _i.discount_calculation_mode,
612
552
  resource_id: discount.id,
613
553
  title: discount.format_title,
614
554
  original_amount: product.price || product.origin_total,
615
555
  pre_value: discount.par_value,
616
- product_id: originProduct.id,
617
- discount_product_id: discount.product_id
556
+ product_id: originProduct.id
618
557
  },
619
558
  metadata: {
620
559
  num,
@@ -628,7 +567,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
628
567
  });
629
568
  const processedFlatItemsMap = /* @__PURE__ */ new Map();
630
569
  sortedFlattenedList.forEach((flatItem, index) => {
631
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F, _G, _H, _I;
570
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B;
632
571
  let product, originProduct;
633
572
  if (flatItem.type === "main") {
634
573
  product = flatItem.product;
@@ -649,36 +588,22 @@ var RulesModule = class extends import_BaseModule.BaseModule {
649
588
  };
650
589
  originProduct = flatItem.originProduct;
651
590
  }
652
- if ((product == null ? void 0 : product.booking_id) && ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every(
653
- (discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(
654
- discount.tag || discount.type
655
- )
656
- ))) {
591
+ if ((product == null ? void 0 : product.booking_id) && ((_e = product.discount_list) == null ? void 0 : _e.length) && ((_f = product == null ? void 0 : product.discount_list) == null ? void 0 : _f.every((discount) => discount.id && ["good_pass", "discount_card", "product_discount_card"].includes(discount.tag || discount.type)))) {
657
592
  if (flatItem.type === "main") {
658
593
  processedProductsMap.set(product._id, [originProduct]);
659
594
  } else {
660
- processedFlatItemsMap.set(flatItem._id, [
661
- {
662
- ...flatItem,
663
- processed: true
664
- }
665
- ]);
595
+ processedFlatItemsMap.set(flatItem._id, [{
596
+ ...flatItem,
597
+ processed: true
598
+ }]);
666
599
  }
667
600
  return;
668
601
  }
669
602
  const applicableDiscounts = sortedDiscountList.filter((discount) => {
670
- var _a2, _b2, _c2, _d2, _e2;
671
- const discountType2 = discount.tag || discount.type;
672
- if (["good_pass", "discount_card", "product_discount_card"].includes(
673
- discountType2
674
- )) {
675
- if (discount.config === void 0 || !((_a2 = discount == null ? void 0 : discount.config) == null ? void 0 : _a2.isAvailable)) {
676
- return false;
677
- }
678
- }
679
- if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.length) && (discount.tag || discount.type) === "good_pass")
603
+ var _a2, _b2;
604
+ if ((Number(product.price) <= 0 || !product.price) && !((_a2 = product.discount_list) == null ? void 0 : _a2.length) && (discount.tag || discount.type) === "good_pass")
680
605
  return false;
681
- if ((Number(product.price) <= 0 || !product.price) && !((_c2 = product.discount_list) == null ? void 0 : _c2.find((n) => {
606
+ if ((Number(product.price) <= 0 || !product.price) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find((n) => {
682
607
  var _a3;
683
608
  return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === discount.id;
684
609
  })) && (discount.tag || discount.type) !== "good_pass")
@@ -686,31 +611,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
686
611
  const targetUsedDiscounts = usedDiscounts.get(discount.id);
687
612
  if (targetUsedDiscounts && (discount.tag || discount.type) === "good_pass")
688
613
  return false;
689
- if ((discount.tag || discount.type) === "good_pass") {
690
- const maxUsagePerOrder = (_d2 = discount.config) == null ? void 0 : _d2.maxUsagePerOrder;
691
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
692
- const currentUsedCount = usedProductIdCounts.get(discount.product_id) || 0;
693
- if (currentUsedCount >= maxUsagePerOrder) {
694
- return false;
695
- }
696
- }
697
- }
698
- const discountTypeForLimit = discount.tag || discount.type;
699
- if (["discount_card", "product_discount_card"].includes(discountTypeForLimit)) {
700
- const applicableProductLimitConfig = ((_e2 = discount.config) == null ? void 0 : _e2.applicableProductLimit) || 0;
701
- if (applicableProductLimitConfig > 0) {
702
- const currentUsedLimitCount = usedDiscountCardLimitCounts.get(discount.id) || 0;
703
- if (currentUsedLimitCount >= applicableProductLimitConfig) {
704
- return false;
705
- }
706
- }
707
- }
708
614
  const limitedData = discount.limited_relation_product_data;
709
- let timeLimit = true;
710
- timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
711
- if (!timeLimit) {
712
- return false;
713
- }
714
615
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
715
616
  const isHolderMatch = this.checkHolderMatch(
716
617
  discount,
@@ -722,10 +623,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
722
623
  );
723
624
  if (!isHolderMatch)
724
625
  return false;
626
+ let timeLimit = true;
627
+ timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
628
+ if (!timeLimit) {
629
+ return false;
630
+ }
725
631
  if (limitedData.type === "product_all") {
726
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
727
- return false;
728
- }
729
632
  if (!this.checkPackageSubItemUsageRules(discount, flatItem)) {
730
633
  return false;
731
634
  }
@@ -738,9 +641,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
738
641
  }
739
642
  return false;
740
643
  });
741
- const selectedDiscountCard = applicableDiscounts.find(
742
- (n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
743
- );
644
+ const selectedDiscountCard = applicableDiscounts.find((n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass");
744
645
  const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
745
646
  let isManualDiscount = false;
746
647
  if (flatItem.type === "main") {
@@ -807,8 +708,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
807
708
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
808
709
  if (flatItem.type === "main") {
809
710
  if (product.isClient) {
810
- processedProductsMap.set(product._id, [
811
- this.hooks.setProduct(originProduct, {
711
+ processedProductsMap.set(
712
+ product._id,
713
+ [this.hooks.setProduct(originProduct, {
812
714
  ...isManualDiscount ? {} : {
813
715
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
814
716
  product: {
@@ -829,11 +731,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
829
731
  price: product.price
830
732
  },
831
733
  discount_list: []
832
- })
833
- ]);
734
+ })]
735
+ );
834
736
  } else {
835
- processedProductsMap.set(product._id, [
836
- this.hooks.setProduct(originProduct, {
737
+ processedProductsMap.set(
738
+ product._id,
739
+ [this.hooks.setProduct(originProduct, {
837
740
  ...isManualDiscount ? {
838
741
  price: product.price,
839
742
  main_product_selling_price: product.price
@@ -844,83 +747,48 @@ var RulesModule = class extends import_BaseModule.BaseModule {
844
747
  main_product_selling_price: product.price
845
748
  },
846
749
  discount_list: []
847
- })
848
- ]);
750
+ })]
751
+ );
849
752
  }
850
753
  } else {
851
- processedFlatItemsMap.set(flatItem._id, [
852
- {
853
- ...flatItem,
854
- discount_list: [],
855
- price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
856
- processed: true
857
- }
858
- ]);
754
+ processedFlatItemsMap.set(flatItem._id, [{
755
+ ...flatItem,
756
+ discount_list: [],
757
+ price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
758
+ processed: true
759
+ }]);
859
760
  }
860
761
  return;
861
762
  }
862
763
  if (applicableDiscounts.length && product.booking_id && typeof selectedDiscount.isManualSelect === "undefined" && !(options == null ? void 0 : options.scan) && !isEditModeAddNewProduct) {
863
764
  return;
864
765
  }
865
- const discountType = selectedDiscount.tag || selectedDiscount.type;
866
- const isGoodPass = discountType === "good_pass";
867
- const isDiscountCard = ["discount_card", "product_discount_card"].includes(discountType);
868
- const applicableProductLimit = ((_u = selectedDiscount.config) == null ? void 0 : _u.applicableProductLimit) || 0;
869
- const isNeedSplit = isGoodPass || isDiscountCard && applicableProductLimit > 0;
766
+ const isNeedSplit = (selectedDiscount.tag || selectedDiscount.type) === "good_pass";
870
767
  const totalQuantity = product.quantity || product.num || 1;
871
- const availableGoodPassCount = applicableDiscounts.filter(
872
- (item) => (item.tag || item.type) === "good_pass"
873
- ).length;
874
- let maxUsageLimit;
875
- if (isGoodPass) {
876
- maxUsageLimit = availableGoodPassCount;
877
- if (selectedDiscount.config && selectedDiscount.config.maxUsagePerOrder) {
878
- maxUsageLimit = Math.min(
879
- availableGoodPassCount,
880
- selectedDiscount.config.maxUsagePerOrder
881
- );
882
- }
883
- } else if (isDiscountCard && applicableProductLimit > 0) {
884
- const usedLimitCount = usedDiscountCardLimitCounts.get(selectedDiscount.id) || 0;
885
- maxUsageLimit = Math.max(0, applicableProductLimit - usedLimitCount);
886
- } else {
887
- maxUsageLimit = 1;
888
- }
889
- const splitCount = isNeedSplit ? Math.min(product.quantity || product.num || 1, maxUsageLimit) : 1;
768
+ const availableGoodPassCount = applicableDiscounts.filter((item) => (item.tag || item.type) === "good_pass").length;
769
+ const splitCount = isNeedSplit ? Math.min(totalQuantity, availableGoodPassCount) : 1;
890
770
  const arr = [];
891
771
  if (flatItem.type === "main") {
892
772
  if (splitCount < totalQuantity && isNeedSplit) {
893
- arr.push(
894
- this.hooks.setProduct(originProduct, {
895
- discount_list: [],
896
- quantity: totalQuantity - splitCount,
897
- _id: product._id.split("___")[0],
898
- total: product.origin_total || product.total
899
- })
900
- );
773
+ arr.push(this.hooks.setProduct(originProduct, {
774
+ discount_list: [],
775
+ quantity: totalQuantity - splitCount,
776
+ _id: product._id.split("___")[0]
777
+ }));
901
778
  }
902
779
  for (let i = 0; i < splitCount; i++) {
903
- const currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
904
- usedDiscounts.set(currentSelectedDiscount.id, true);
905
- if ((currentSelectedDiscount.tag || currentSelectedDiscount.type) === "good_pass") {
906
- const currentCount = usedProductIdCounts.get(currentSelectedDiscount.product_id) || 0;
907
- usedProductIdCounts.set(currentSelectedDiscount.product_id, currentCount + 1);
908
- }
909
- const currentDiscountTypeForCount = currentSelectedDiscount.tag || currentSelectedDiscount.type;
910
- if (["discount_card", "product_discount_card"].includes(currentDiscountTypeForCount)) {
911
- const currentLimitCount = usedDiscountCardLimitCounts.get(currentSelectedDiscount.id) || 0;
912
- usedDiscountCardLimitCounts.set(currentSelectedDiscount.id, currentLimitCount + 1);
913
- }
914
- const appliedProducts = appliedDiscountProducts.get(currentSelectedDiscount.id) || [];
780
+ const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[i];
781
+ usedDiscounts.set(selectedDiscount2.id, true);
782
+ const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
915
783
  let productOriginTotal = product.origin_total || product.total || 0;
916
- if (((_v = product.discount_list) == null ? void 0 : _v.length) && product.origin_total) {
784
+ if (((_u = product.discount_list) == null ? void 0 : _u.length) && product.origin_total) {
917
785
  productOriginTotal = product.origin_total;
918
786
  }
919
- if (Number(((_w = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _w.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
787
+ if (Number(((_v = originProduct == null ? void 0 : originProduct._productInit) == null ? void 0 : _v.original_price) || 0) > 0 && product.origin_total && product.total && product.origin_total !== product.total) {
920
788
  productOriginTotal = product.total;
921
789
  }
922
- const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount);
923
- const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
790
+ const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
791
+ const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
924
792
  const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
925
793
  let targetProductTotal;
926
794
  let amount;
@@ -930,38 +798,35 @@ var RulesModule = class extends import_BaseModule.BaseModule {
930
798
  productDiscountDifference = productAllocation.difference;
931
799
  targetProductTotal = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
932
800
  } else {
933
- targetProductTotal = (0, import_utils.getDiscountAmount)(currentSelectedDiscount, product.price, product.price);
801
+ targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
934
802
  amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
935
803
  }
936
- const currentDiscountType = currentSelectedDiscount.tag === "product_discount_card" ? "discount_card" : currentSelectedDiscount.tag;
937
- const actualDiscountAmount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
938
- const currentIsGoodPass = currentDiscountType === "good_pass";
804
+ const discountType = selectedDiscount2.tag || selectedDiscount2.type;
805
+ const isGoodPass = discountType === "good_pass";
939
806
  const discountDetail = {
940
- amount: actualDiscountAmount,
941
- type: currentDiscountType,
807
+ amount,
808
+ type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
942
809
  discount: {
943
- discount_card_type: (_x = currentSelectedDiscount == null ? void 0 : currentSelectedDiscount.metadata) == null ? void 0 : _x.discount_card_type,
944
- fixed_amount: actualDiscountAmount,
945
- discount_calculation_mode: (_y = currentSelectedDiscount == null ? void 0 : currentSelectedDiscount.metadata) == null ? void 0 : _y.discount_calculation_mode,
946
- resource_id: currentSelectedDiscount.id,
947
- title: currentSelectedDiscount.format_title,
810
+ discount_card_type: (_w = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _w.discount_card_type,
811
+ fixed_amount: amount,
812
+ discount_calculation_mode: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_calculation_mode,
813
+ resource_id: selectedDiscount2.id,
814
+ title: selectedDiscount2.format_title,
948
815
  original_amount: product.price,
949
816
  product_id: originProduct.id,
950
- percent: currentSelectedDiscount.par_value,
951
- discount_product_id: currentSelectedDiscount.product_id
817
+ percent: selectedDiscount2.par_value
952
818
  },
953
- // 前端使用的num数量,为了计算优惠金额(拆分时为1)
954
- _num: isNeedSplit ? 1 : product.num,
955
- config: currentSelectedDiscount == null ? void 0 : currentSelectedDiscount.config,
819
+ // 前端使用的num数量,为了计算优惠金额
820
+ _num: isGoodPass ? 1 : product.num,
956
821
  metadata: {
957
822
  num: 1,
958
- discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
823
+ discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
959
824
  // 🔥 order_level 分摊差值
960
825
  ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
961
826
  }
962
827
  };
963
828
  appliedProducts.push(discountDetail);
964
- appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
829
+ appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
965
830
  let total = targetProductTotal;
966
831
  if (product.options) {
967
832
  total = product.options.reduce((accumulator, currentValue) => {
@@ -971,35 +836,32 @@ var RulesModule = class extends import_BaseModule.BaseModule {
971
836
  }, new import_decimal.default(total)).toNumber();
972
837
  }
973
838
  if (product.isClient) {
974
- arr.push(
975
- this.hooks.setProduct(originProduct, {
976
- discount_list: [discountDetail],
977
- price: currentIsGoodPass ? product.price - discountDetail.amount : product.price,
978
- quantity: isNeedSplit ? 1 : product.quantity,
979
- origin_total: (0, import_utils2.getProductOriginTotalPrice)({
980
- product: {
981
- original_price: product.original_price
982
- },
983
- bundle: product.bundle,
984
- options: product.options
985
- }),
986
- variant: originProduct._productInit.variant,
987
- original_price: new import_decimal.default(product.price || 0).toNumber(),
988
- total: targetProductTotal
989
- })
990
- );
839
+ debugger;
840
+ arr.push(this.hooks.setProduct(originProduct, {
841
+ discount_list: [discountDetail],
842
+ price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
843
+ quantity: isNeedSplit ? 1 : product.quantity,
844
+ origin_total: (0, import_utils2.getProductOriginTotalPrice)({
845
+ product: {
846
+ original_price: product.original_price
847
+ },
848
+ bundle: product.bundle,
849
+ options: product.options
850
+ }),
851
+ variant: originProduct._productInit.variant,
852
+ original_price: new import_decimal.default(product.price || 0).toNumber(),
853
+ total
854
+ }));
991
855
  } else {
992
- arr.push(
993
- this.hooks.setProduct(originProduct, {
994
- discount_list: [discountDetail],
995
- _id: product._id.split("___")[0] + "___" + currentSelectedDiscount.id + "_" + i + "_" + index,
996
- price: currentIsGoodPass ? 0 : product.price,
997
- quantity: isNeedSplit ? 1 : product.quantity,
998
- total: targetProductTotal,
999
- origin_total: productOriginTotal,
1000
- main_product_selling_price: targetProductTotal
1001
- })
1002
- );
856
+ arr.push(this.hooks.setProduct(originProduct, {
857
+ discount_list: [discountDetail],
858
+ _id: product._id.split("___")[0] + "___" + selectedDiscount2.id + index,
859
+ price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
860
+ quantity: isNeedSplit ? 1 : product.quantity,
861
+ total,
862
+ origin_total: productOriginTotal,
863
+ main_product_selling_price: targetProductTotal
864
+ }));
1003
865
  }
1004
866
  }
1005
867
  processedProductsMap.set(product._id, arr);
@@ -1009,298 +871,62 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1009
871
  const discountNum = splitCount;
1010
872
  const normalNum = totalQuantity - discountNum;
1011
873
  for (let i = 0; i < discountNum; i++) {
1012
- const currentBundleDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
1013
- usedDiscounts.set(currentBundleDiscount.id, true);
1014
- if ((currentBundleDiscount.tag || currentBundleDiscount.type) === "good_pass") {
1015
- const currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
1016
- usedProductIdCounts.set(currentBundleDiscount.product_id, currentCount + 1);
1017
- }
1018
- const bundleDiscountTypeForCount = currentBundleDiscount.tag || currentBundleDiscount.type;
1019
- if (["discount_card", "product_discount_card"].includes(bundleDiscountTypeForCount)) {
1020
- const currentBundleLimitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
1021
- usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentBundleLimitCount + 1);
1022
- }
874
+ const selectedDiscount2 = applicableDiscounts[i];
875
+ usedDiscounts.set(selectedDiscount2.id, true);
1023
876
  const uniqueId = `${flatItem._id}_split_${i}`;
1024
- const discountedPrice = (0, import_utils.getDiscountAmount)(
1025
- currentBundleDiscount,
1026
- product.origin_total,
1027
- product.origin_total
1028
- );
1029
- const bundleDiscountAmount = new import_decimal.default(product.origin_total || 0).minus(discountedPrice).toNumber();
1030
- const bundleDiscountType = currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag;
1031
877
  const discountDetail = {
1032
- amount: bundleDiscountAmount,
1033
- type: bundleDiscountType,
878
+ amount: product.origin_total,
879
+ type: "good_pass",
1034
880
  discount: {
1035
- discount_card_type: (_z = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _z.discount_card_type,
1036
- discount_calculation_mode: (_A = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _A.discount_calculation_mode,
1037
- fixed_amount: bundleDiscountAmount,
1038
- resource_id: currentBundleDiscount.id,
1039
- title: currentBundleDiscount.format_title,
881
+ fixed_amount: product.origin_total,
882
+ discount_calculation_mode: (_y = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _y.discount_calculation_mode,
883
+ resource_id: selectedDiscount2.id,
884
+ title: selectedDiscount2.format_title,
1040
885
  original_amount: product.origin_total,
1041
- product_id: product.id,
1042
- percent: currentBundleDiscount.par_value,
1043
- discount_product_id: currentBundleDiscount.product_id
886
+ product_id: product.id
1044
887
  },
1045
888
  metadata: {
1046
889
  // 🔥 使用拆分后的唯一 _id
1047
890
  custom_product_bundle_map_id: uniqueId,
1048
- discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
891
+ discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
1049
892
  num: 1
1050
893
  },
1051
- _num: 1,
1052
- config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config
894
+ _num: 1
1053
895
  };
1054
- const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
896
+ const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
1055
897
  appliedProducts.push(discountDetail);
1056
- appliedDiscountProducts.set(currentBundleDiscount.id, appliedProducts);
898
+ appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
1057
899
  processedItems.push({
1058
900
  ...flatItem,
1059
901
  // 🔥 使用唯一的 _id
1060
902
  _id: uniqueId,
1061
903
  num: 1,
1062
904
  quantity: 1,
1063
- price: discountedPrice,
1064
- // 折扣后的价格
1065
- total: discountedPrice,
905
+ price: 0,
906
+ // 商品券价格为0
907
+ total: 0,
1066
908
  discount_list: [discountDetail],
1067
909
  processed: true,
1068
- _discountId: currentBundleDiscount.id
910
+ _discountId: selectedDiscount2.id
1069
911
  });
1070
912
  }
1071
- let remainingNum = normalNum;
1072
- let continueSplitIndex = discountNum;
1073
- while (remainingNum > 0) {
1074
- const nextApplicableDiscounts = sortedDiscountList.filter((nextDiscount) => {
1075
- var _a2, _b2, _c2, _d2;
1076
- const nextDiscountType = nextDiscount.tag || nextDiscount.type;
1077
- if (["good_pass", "discount_card", "product_discount_card"].includes(nextDiscountType)) {
1078
- if (nextDiscount.config === void 0 || !((_a2 = nextDiscount == null ? void 0 : nextDiscount.config) == null ? void 0 : _a2.isAvailable)) {
1079
- return false;
1080
- }
1081
- }
1082
- if ((Number(product.total) <= 0 || !product.total) && !((_b2 = product.discount_list) == null ? void 0 : _b2.find(
1083
- (n) => {
1084
- var _a3;
1085
- return ((_a3 = n.discount) == null ? void 0 : _a3.resource_id) === nextDiscount.id;
1086
- }
1087
- )) && nextDiscountType !== "good_pass")
1088
- return false;
1089
- if (usedDiscounts.get(nextDiscount.id) && nextDiscountType === "good_pass")
1090
- return false;
1091
- if (nextDiscountType === "good_pass") {
1092
- const maxUsagePerOrder = (_c2 = nextDiscount.config) == null ? void 0 : _c2.maxUsagePerOrder;
1093
- if (maxUsagePerOrder && maxUsagePerOrder > 0) {
1094
- const currentUsedCount = usedProductIdCounts.get(nextDiscount.product_id) || 0;
1095
- if (currentUsedCount >= maxUsagePerOrder) {
1096
- return false;
1097
- }
1098
- }
1099
- }
1100
- if (["discount_card", "product_discount_card"].includes(nextDiscountType)) {
1101
- const limitConfig = ((_d2 = nextDiscount.config) == null ? void 0 : _d2.applicableProductLimit) || 0;
1102
- if (limitConfig > 0) {
1103
- const currentUsedLimitCount = usedDiscountCardLimitCounts.get(nextDiscount.id) || 0;
1104
- if (currentUsedLimitCount >= limitConfig) {
1105
- return false;
1106
- }
1107
- }
1108
- }
1109
- const limitedData = nextDiscount.limited_relation_product_data;
1110
- if (limitedData.type === "product_all") {
1111
- if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
1112
- return false;
1113
- }
1114
- if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1115
- return false;
1116
- }
1117
- return true;
1118
- } else if (limitedData.product_ids && limitedData.product_ids.includes(product.id)) {
1119
- if (!this.checkPackageSubItemUsageRules(nextDiscount, flatItem)) {
1120
- return false;
1121
- }
1122
- return true;
1123
- }
1124
- return false;
913
+ if (normalNum > 0) {
914
+ processedItems.push({
915
+ ...flatItem,
916
+ // 🔥 为剩余商品生成唯一的 _id
917
+ _id: `${flatItem._id}_split_rest`,
918
+ num: normalNum,
919
+ quantity: normalNum,
920
+ discount_list: [],
921
+ processed: true
1125
922
  });
1126
- if (nextApplicableDiscounts.length === 0) {
1127
- processedItems.push({
1128
- ...flatItem,
1129
- _id: `${flatItem._id}_split_rest`,
1130
- num: remainingNum,
1131
- quantity: remainingNum,
1132
- discount_list: [],
1133
- processed: true
1134
- });
1135
- break;
1136
- }
1137
- const nextSelectedDiscountCard = nextApplicableDiscounts.find(
1138
- (n) => n.isScan && n.isSelected && (n.tag || n.type) !== "good_pass"
1139
- );
1140
- const nextSelectedDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1141
- const nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
1142
- const nextIsGoodPass = nextDiscType === "good_pass";
1143
- const nextIsDiscountCard = ["discount_card", "product_discount_card"].includes(nextDiscType);
1144
- const nextApplicableProductLimit = ((_B = nextSelectedDiscount.config) == null ? void 0 : _B.applicableProductLimit) || 0;
1145
- const nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
1146
- if (!nextIsNeedSplit) {
1147
- const nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
1148
- usedDiscounts.set(nextBundleDiscount.id, true);
1149
- if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
1150
- const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1151
- usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1152
- }
1153
- const nextNoSplitType = nextBundleDiscount.tag || nextBundleDiscount.type;
1154
- if (["discount_card", "product_discount_card"].includes(nextNoSplitType)) {
1155
- const curCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1156
- usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curCount + remainingNum);
1157
- }
1158
- const nextOriginTotal = product.original_price || product.price || 0;
1159
- const nextTargetTotal = (0, import_utils.getDiscountAmount)(nextBundleDiscount, nextOriginTotal, nextOriginTotal);
1160
- const nextDiscountAmount = new import_decimal.default(nextOriginTotal).minus(nextTargetTotal).toNumber();
1161
- const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
1162
- const nextBundleDiscType = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
1163
- const nextDiscountDetail = {
1164
- amount: nextDiscountAmount * remainingNum,
1165
- type: nextBundleDiscType,
1166
- discount: {
1167
- discount_card_type: (_C = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _C.discount_card_type,
1168
- fixed_amount: nextDiscountAmount,
1169
- resource_id: nextBundleDiscount.id,
1170
- title: nextBundleDiscount.format_title,
1171
- original_amount: product.original_price,
1172
- product_id: product.id,
1173
- percent: nextBundleDiscount.par_value,
1174
- discount_product_id: nextBundleDiscount.product_id
1175
- },
1176
- metadata: {
1177
- custom_product_bundle_map_id: nextUniqueId,
1178
- num: remainingNum
1179
- },
1180
- config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config,
1181
- _num: remainingNum * (((_D = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _D.num) || 1)
1182
- };
1183
- const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1184
- nextAppliedProducts.push(nextDiscountDetail);
1185
- appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1186
- processedItems.push({
1187
- ...flatItem,
1188
- _id: nextUniqueId,
1189
- num: remainingNum,
1190
- quantity: remainingNum,
1191
- total: nextTargetTotal,
1192
- price: new import_decimal.default(nextOriginTotal || 0).minus(nextDiscountDetail.discount.fixed_amount).toNumber(),
1193
- discount_list: [nextDiscountDetail],
1194
- processed: true
1195
- });
1196
- remainingNum = 0;
1197
- break;
1198
- }
1199
- let nextMaxUsageLimit;
1200
- if (nextIsGoodPass) {
1201
- const nextGoodPassCount = nextApplicableDiscounts.filter(
1202
- (item) => (item.tag || item.type) === "good_pass"
1203
- ).length;
1204
- nextMaxUsageLimit = nextGoodPassCount;
1205
- if ((_E = nextSelectedDiscount.config) == null ? void 0 : _E.maxUsagePerOrder) {
1206
- const usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
1207
- nextMaxUsageLimit = Math.min(
1208
- nextGoodPassCount,
1209
- Math.max(0, nextSelectedDiscount.config.maxUsagePerOrder - usedCount)
1210
- );
1211
- }
1212
- } else if (nextIsDiscountCard && nextApplicableProductLimit > 0) {
1213
- const usedLimitCount = usedDiscountCardLimitCounts.get(nextSelectedDiscount.id) || 0;
1214
- nextMaxUsageLimit = Math.max(0, nextApplicableProductLimit - usedLimitCount);
1215
- } else {
1216
- nextMaxUsageLimit = 1;
1217
- }
1218
- const nextSplitCount = Math.min(remainingNum, nextMaxUsageLimit);
1219
- if (nextSplitCount === 0) {
1220
- processedItems.push({
1221
- ...flatItem,
1222
- _id: `${flatItem._id}_split_rest`,
1223
- num: remainingNum,
1224
- quantity: remainingNum,
1225
- discount_list: [],
1226
- processed: true
1227
- });
1228
- break;
1229
- }
1230
- for (let j = 0; j < nextSplitCount; j++) {
1231
- const nextBundleDiscount = nextIsGoodPass ? nextSelectedDiscountCard || nextApplicableDiscounts[j] : nextSelectedDiscountCard || nextApplicableDiscounts[0];
1232
- usedDiscounts.set(nextBundleDiscount.id, true);
1233
- if ((nextBundleDiscount.tag || nextBundleDiscount.type) === "good_pass") {
1234
- const curCount = usedProductIdCounts.get(nextBundleDiscount.product_id) || 0;
1235
- usedProductIdCounts.set(nextBundleDiscount.product_id, curCount + 1);
1236
- }
1237
- const nextBundleDiscTypeForCount = nextBundleDiscount.tag || nextBundleDiscount.type;
1238
- if (["discount_card", "product_discount_card"].includes(nextBundleDiscTypeForCount)) {
1239
- const curLimitCount = usedDiscountCardLimitCounts.get(nextBundleDiscount.id) || 0;
1240
- usedDiscountCardLimitCounts.set(nextBundleDiscount.id, curLimitCount + 1);
1241
- }
1242
- const nextUniqueId = `${flatItem._id}_split_${continueSplitIndex}`;
1243
- const nextDiscountedPrice = (0, import_utils.getDiscountAmount)(
1244
- nextBundleDiscount,
1245
- product.origin_total,
1246
- product.origin_total
1247
- );
1248
- const nextBundleDiscAmount = new import_decimal.default(product.origin_total || 0).minus(nextDiscountedPrice).toNumber();
1249
- const nextBundleDiscTypeStr = nextBundleDiscount.tag === "product_discount_card" ? "discount_card" : nextBundleDiscount.tag;
1250
- const nextDiscountDetail = {
1251
- amount: nextBundleDiscAmount,
1252
- type: nextBundleDiscTypeStr,
1253
- discount: {
1254
- discount_card_type: (_F = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _F.discount_card_type,
1255
- fixed_amount: nextBundleDiscAmount,
1256
- resource_id: nextBundleDiscount.id,
1257
- title: nextBundleDiscount.format_title,
1258
- original_amount: product.origin_total,
1259
- product_id: product.id,
1260
- percent: nextBundleDiscount.par_value,
1261
- discount_product_id: nextBundleDiscount.product_id
1262
- },
1263
- metadata: {
1264
- custom_product_bundle_map_id: nextUniqueId,
1265
- num: 1
1266
- },
1267
- _num: 1,
1268
- config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config
1269
- };
1270
- const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1271
- nextAppliedProducts.push(nextDiscountDetail);
1272
- appliedDiscountProducts.set(nextBundleDiscount.id, nextAppliedProducts);
1273
- processedItems.push({
1274
- ...flatItem,
1275
- _id: nextUniqueId,
1276
- num: 1,
1277
- quantity: 1,
1278
- price: nextDiscountedPrice,
1279
- total: nextDiscountedPrice,
1280
- discount_list: [nextDiscountDetail],
1281
- processed: true,
1282
- _discountId: nextBundleDiscount.id
1283
- });
1284
- continueSplitIndex++;
1285
- }
1286
- remainingNum -= nextSplitCount;
1287
923
  }
1288
924
  } else {
1289
- const currentBundleDiscount = selectedDiscountCard || applicableDiscounts[0];
1290
- usedDiscounts.set(currentBundleDiscount.id, true);
1291
- if ((currentBundleDiscount.tag || currentBundleDiscount.type) === "good_pass") {
1292
- const currentCount = usedProductIdCounts.get(currentBundleDiscount.product_id) || 0;
1293
- usedProductIdCounts.set(currentBundleDiscount.product_id, currentCount + 1);
1294
- }
1295
- const noSplitDiscountType = currentBundleDiscount.tag || currentBundleDiscount.type;
1296
- if (["discount_card", "product_discount_card"].includes(noSplitDiscountType)) {
1297
- const bundleQuantity = product.num || 1;
1298
- const currentNoSplitCount = usedDiscountCardLimitCounts.get(currentBundleDiscount.id) || 0;
1299
- usedDiscountCardLimitCounts.set(currentBundleDiscount.id, currentNoSplitCount + bundleQuantity);
1300
- }
925
+ const selectedDiscount2 = selectedDiscountCard || applicableDiscounts[0];
926
+ usedDiscounts.set(selectedDiscount2.id, true);
1301
927
  const productOriginTotal = product.original_price || product.price || 0;
1302
- const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount);
1303
- const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
928
+ const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
929
+ const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
1304
930
  const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
1305
931
  let targetProductTotal;
1306
932
  let fixedAmountPerItem;
@@ -1311,42 +937,40 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1311
937
  targetProductTotal = Math.max(new import_decimal.default(productOriginTotal).minus(fixedAmountPerItem).toNumber(), 0);
1312
938
  } else {
1313
939
  targetProductTotal = (0, import_utils.getDiscountAmount)(
1314
- currentBundleDiscount,
940
+ selectedDiscount2,
1315
941
  productOriginTotal,
1316
942
  productOriginTotal
1317
943
  );
1318
944
  fixedAmountPerItem = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
1319
945
  }
1320
- const bundleActualDiscountAmount = new import_decimal.default(productOriginTotal).minus(targetProductTotal).toNumber();
946
+ debugger;
1321
947
  const uniqueId = flatItem._id;
1322
948
  const discountDetail = {
1323
- amount: bundleActualDiscountAmount * (product.num || 1),
1324
- type: currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag,
949
+ amount: fixedAmountPerItem * (product.num || 1),
950
+ type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
1325
951
  discount: {
1326
- discount_card_type: (_G = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _G.discount_card_type,
1327
- fixed_amount: bundleActualDiscountAmount,
1328
- discount_calculation_mode: (_H = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _H.discount_calculation_mode,
1329
- resource_id: currentBundleDiscount.id,
1330
- title: currentBundleDiscount.format_title,
952
+ discount_card_type: (_z = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _z.discount_card_type,
953
+ fixed_amount: fixedAmountPerItem,
954
+ discount_calculation_mode: (_A = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _A.discount_calculation_mode,
955
+ resource_id: selectedDiscount2.id,
956
+ title: selectedDiscount2.format_title,
1331
957
  original_amount: product.original_price,
1332
958
  product_id: product.id,
1333
- percent: currentBundleDiscount.par_value,
1334
- discount_product_id: currentBundleDiscount.product_id
959
+ percent: selectedDiscount2.par_value
1335
960
  },
1336
961
  metadata: {
1337
962
  // 🔥 使用唯一的 _id
1338
963
  custom_product_bundle_map_id: uniqueId,
1339
- discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
964
+ discount_rule_uncheck_flag: selectedDiscount2 == null ? void 0 : selectedDiscount2.discount_rule_uncheck_flag,
1340
965
  num: product.num || 1,
1341
966
  // 🔥 order_level 分摊差值
1342
967
  ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
1343
968
  },
1344
- config: currentBundleDiscount == null ? void 0 : currentBundleDiscount.config,
1345
- _num: (product.num || 1) * (((_I = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _I.num) || 1)
969
+ _num: (product.num || 1) * (((_B = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _B.num) || 1)
1346
970
  };
1347
- const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
971
+ const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
1348
972
  appliedProducts.push(discountDetail);
1349
- appliedDiscountProducts.set(currentBundleDiscount.id, appliedProducts);
973
+ appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
1350
974
  processedItems.push({
1351
975
  ...flatItem,
1352
976
  total: targetProductTotal,
@@ -1431,96 +1055,80 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1431
1055
  const mainProduct = mainProductArr[0];
1432
1056
  const mainProductData = this.hooks.getProduct(mainProduct);
1433
1057
  const newBundleWithDiscount = [];
1434
- (product.bundle || []).forEach(
1435
- (bundleItem, bundleIndex) => {
1436
- const processedItems = bundleProcessingInfo.get(
1437
- bundleIndex
1438
- ) || [bundleItem];
1439
- if (processedItems.length > 1) {
1440
- processedItems.forEach((item) => {
1441
- const updatedDiscountList2 = (item.discount_list || []).map(
1442
- (discount) => {
1443
- var _a;
1444
- return {
1445
- ...discount,
1446
- metadata: {
1447
- ...discount.metadata,
1448
- num: item.num,
1449
- custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1450
- }
1451
- // num: item.num, // 使用拆分后的 num
1452
- };
1058
+ (product.bundle || []).forEach((bundleItem, bundleIndex) => {
1059
+ const processedItems = bundleProcessingInfo.get(bundleIndex) || [bundleItem];
1060
+ if (processedItems.length > 1) {
1061
+ processedItems.forEach((item) => {
1062
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1063
+ var _a;
1064
+ return {
1065
+ ...discount,
1066
+ metadata: {
1067
+ ...discount.metadata,
1068
+ num: item.num,
1069
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1453
1070
  }
1454
- );
1455
- newBundleWithDiscount.push({
1456
- ...bundleItem,
1457
- _id: item._id,
1458
- product_id: bundleItem.product_id,
1459
- price: item.price,
1460
- num: item.num,
1461
- quantity: item.num,
1462
- discount_list: updatedDiscountList2
1463
- });
1071
+ // num: item.num, // 使用拆分后的 num
1072
+ };
1464
1073
  });
1465
- } else {
1466
- const item = processedItems[0];
1467
- if (item.processed) {
1468
- const updatedDiscountList2 = (item.discount_list || []).map(
1469
- (discount) => {
1470
- var _a;
1471
- return {
1472
- ...discount,
1473
- metadata: {
1474
- ...discount.metadata,
1475
- num: item.num,
1476
- custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1477
- }
1478
- // num: item.num, // 使用当前的 num
1479
- };
1074
+ newBundleWithDiscount.push({
1075
+ ...bundleItem,
1076
+ _id: item._id,
1077
+ product_id: bundleItem.product_id,
1078
+ price: item.price,
1079
+ num: item.num,
1080
+ discount_list: updatedDiscountList2
1081
+ });
1082
+ });
1083
+ } else {
1084
+ const item = processedItems[0];
1085
+ if (item.processed) {
1086
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1087
+ var _a;
1088
+ return {
1089
+ ...discount,
1090
+ metadata: {
1091
+ ...discount.metadata,
1092
+ num: item.num,
1093
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1480
1094
  }
1481
- );
1482
- newBundleWithDiscount.push({
1483
- ...bundleItem,
1484
- _id: item._id,
1485
- product_id: bundleItem.product_id,
1486
- price: item.price,
1487
- num: item.num,
1488
- quantity: item.num,
1489
- discount_list: updatedDiscountList2
1490
- });
1491
- } else {
1492
- newBundleWithDiscount.push(item);
1493
- }
1095
+ // num: item.num, // 使用当前的 num
1096
+ };
1097
+ });
1098
+ newBundleWithDiscount.push({
1099
+ ...bundleItem,
1100
+ _id: item._id,
1101
+ product_id: bundleItem.product_id,
1102
+ price: item.price,
1103
+ num: item.num,
1104
+ discount_list: updatedDiscountList2
1105
+ });
1106
+ } else {
1107
+ newBundleWithDiscount.push(item);
1494
1108
  }
1495
1109
  }
1496
- );
1110
+ });
1497
1111
  let newTotalWithDiscount = Number(mainProductData.price || 0);
1498
- let newOriginTotalWithDiscount = Number(
1499
- mainProductData.original_price || mainProductData.price || 0
1500
- );
1501
- const updatedMainDiscountList = mainProductData.discount_list.map(
1502
- (discount) => {
1503
- var _a, _b;
1504
- if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
1505
- return discount;
1506
- }
1507
- return {
1508
- ...discount,
1509
- // num: 1,
1510
- metadata: {
1511
- ...discount.metadata,
1512
- custom_product_bundle_map_id: (_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.custom_product_bundle_map_id,
1513
- num: 1
1514
- }
1515
- };
1112
+ let newOriginTotalWithDiscount = Number(mainProductData.original_price || mainProductData.price || 0);
1113
+ const updatedMainDiscountList = mainProductData.discount_list.map((discount) => {
1114
+ var _a, _b;
1115
+ if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
1116
+ return discount;
1516
1117
  }
1517
- );
1518
- const mainDiscountList = updatedMainDiscountList.filter(
1519
- (item) => {
1520
- var _a;
1521
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1522
- }
1523
- );
1118
+ return {
1119
+ ...discount,
1120
+ // num: 1,
1121
+ metadata: {
1122
+ ...discount.metadata,
1123
+ custom_product_bundle_map_id: (_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.custom_product_bundle_map_id,
1124
+ num: 1
1125
+ }
1126
+ };
1127
+ });
1128
+ const mainDiscountList = updatedMainDiscountList.filter((item) => {
1129
+ var _a;
1130
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1131
+ });
1524
1132
  if (mainDiscountList && mainDiscountList.length > 0) {
1525
1133
  const allDiscountAmount = (0, import_utils.getDiscountListAmountTotal)(mainDiscountList);
1526
1134
  newTotalWithDiscount = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalWithDiscount;
@@ -1550,24 +1158,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1550
1158
  quantity: 1,
1551
1159
  discount_list: updatedMainDiscountList,
1552
1160
  bundle: newBundleWithDiscount,
1553
- total: newTotalWithDiscount,
1554
- origin_total: newOriginTotalWithDiscount
1161
+ total: new import_decimal.default(newTotalWithDiscount).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber(),
1162
+ origin_total: new import_decimal.default(newOriginTotalWithDiscount).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber()
1555
1163
  })
1556
1164
  );
1557
1165
  if (mainProductQuantity > 1) {
1558
1166
  const newBundleOriginal = [];
1559
- (product.bundle || []).forEach(
1560
- (bundleItem, bundleIndex) => {
1561
- newBundleOriginal.push({
1562
- ...bundleItem,
1563
- discount_list: []
1564
- });
1565
- }
1566
- );
1167
+ (product.bundle || []).forEach((bundleItem, bundleIndex) => {
1168
+ newBundleOriginal.push({
1169
+ ...bundleItem,
1170
+ discount_list: []
1171
+ });
1172
+ });
1567
1173
  let newTotalOriginal = Number(mainProductData.price || 0);
1568
- let newOriginTotalOriginal = Number(
1569
- mainProductData.original_price || mainProductData.price || 0
1570
- );
1174
+ let newOriginTotalOriginal = Number(mainProductData.original_price || mainProductData.price || 0);
1571
1175
  const updatedMainDiscountListOriginal = mainProductData.discount_list.map((discount) => {
1572
1176
  var _a, _b;
1573
1177
  if ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.custom_product_bundle_map_id) {
@@ -1583,16 +1187,12 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1583
1187
  // num: mainProductQuantity - 1,
1584
1188
  };
1585
1189
  });
1586
- const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter(
1587
- (item) => {
1588
- var _a;
1589
- return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1590
- }
1591
- );
1190
+ const mainDiscountListOriginal = updatedMainDiscountListOriginal.filter((item) => {
1191
+ var _a;
1192
+ return !((_a = item == null ? void 0 : item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id);
1193
+ });
1592
1194
  if (mainDiscountListOriginal && mainDiscountListOriginal.length > 0) {
1593
- const allDiscountAmount = (0, import_utils.getDiscountListAmount)(
1594
- mainDiscountListOriginal
1595
- );
1195
+ const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountListOriginal);
1596
1196
  newTotalOriginal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotalOriginal;
1597
1197
  newOriginTotalOriginal = mainProductData.origin_total ?? newOriginTotalOriginal;
1598
1198
  }
@@ -1629,58 +1229,48 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1629
1229
  const mainProductData = this.hooks.getProduct(mainProduct);
1630
1230
  const newBundle = [];
1631
1231
  if (product.bundle && Array.isArray(product.bundle)) {
1632
- product.bundle.forEach(
1633
- (bundleItem, bundleIndex) => {
1634
- const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
1635
- const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
1636
- if (!processedBundleItems || processedBundleItems.length === 0) {
1637
- newBundle.push(bundleItem);
1638
- } else {
1639
- processedBundleItems.forEach((item) => {
1640
- const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1641
- var _a2;
1642
- return {
1643
- ...discount,
1644
- metadata: {
1645
- ...discount.metadata,
1646
- num: item.num,
1647
- custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
1648
- }
1649
- // num: item.num, // 使用拆分后的 num
1650
- };
1651
- });
1652
- newBundle.push({
1653
- ...bundleItem,
1654
- _id: item._id,
1655
- product_id: bundleItem.product_id,
1656
- price: item.price,
1657
- num: item.num,
1658
- quantity: item.num,
1659
- discount_list: updatedDiscountList2
1660
- });
1232
+ product.bundle.forEach((bundleItem, bundleIndex) => {
1233
+ const bundleItemId = `${product._id}_bundle_${bundleIndex}`;
1234
+ const processedBundleItems = processedFlatItemsMap2.get(bundleItemId);
1235
+ if (!processedBundleItems || processedBundleItems.length === 0) {
1236
+ newBundle.push(bundleItem);
1237
+ } else {
1238
+ processedBundleItems.forEach((item) => {
1239
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1240
+ var _a2;
1241
+ return {
1242
+ ...discount,
1243
+ metadata: {
1244
+ ...discount.metadata,
1245
+ num: item.num,
1246
+ custom_product_bundle_map_id: (_a2 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id
1247
+ }
1248
+ // num: item.num, // 使用拆分后的 num
1249
+ };
1661
1250
  });
1662
- }
1251
+ newBundle.push({
1252
+ ...bundleItem,
1253
+ _id: item._id,
1254
+ product_id: bundleItem.product_id,
1255
+ price: item.price,
1256
+ num: item.num,
1257
+ discount_list: updatedDiscountList2
1258
+ });
1259
+ });
1663
1260
  }
1664
- );
1261
+ });
1665
1262
  }
1666
1263
  let newTotal = Number(mainProductData.price || 0);
1667
- let newOriginTotal = Number(
1668
- mainProductData.original_price || mainProductData.price || 0
1669
- );
1670
- 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(
1671
- _b,
1672
- (item) => item.type === "product"
1673
- )));
1264
+ let newOriginTotal = Number(mainProductData.original_price || mainProductData.price || 0);
1265
+ 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")));
1674
1266
  if (isManualDiscount) {
1675
1267
  newTotal = mainProductData.total ?? newTotal;
1676
1268
  newOriginTotal = mainProductData.origin_total ?? newOriginTotal;
1677
1269
  } else {
1678
- const mainDiscountList = mainProductData.discount_list.filter(
1679
- (item) => {
1680
- var _a2;
1681
- return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
1682
- }
1683
- );
1270
+ const mainDiscountList = mainProductData.discount_list.filter((item) => {
1271
+ var _a2;
1272
+ return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
1273
+ });
1684
1274
  if (mainDiscountList && mainDiscountList.length > 0) {
1685
1275
  const allDiscountAmount = (0, import_utils.getDiscountListAmount)(mainDiscountList);
1686
1276
  newTotal = new import_decimal.default(mainProductData.price || 0).minus(allDiscountAmount).toNumber() ?? newTotal;
@@ -1688,8 +1278,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1688
1278
  }
1689
1279
  if (newBundle.length > 0) {
1690
1280
  newBundle.forEach((item) => {
1691
- var _a2, _b2, _c2;
1692
1281
  newTotal += Number(item.price) * Number(item.num);
1282
+ });
1283
+ newBundle.forEach((item) => {
1284
+ var _a2, _b2, _c2;
1693
1285
  const originalPrice = ((_c2 = (_b2 = (_a2 = item.discount_list) == null ? void 0 : _a2[0]) == null ? void 0 : _b2.discount) == null ? void 0 : _c2.original_amount) || item.price;
1694
1286
  newOriginTotal += Number(originalPrice) * Number(item.num);
1695
1287
  });
@@ -1702,6 +1294,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1702
1294
  return accumulator.add(currentPrice.mul(currentNum));
1703
1295
  }, new import_decimal.default(newTotal)).toNumber();
1704
1296
  }
1297
+ newTotal = new import_decimal.default(newTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1298
+ newOriginTotal = new import_decimal.default(newOriginTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
1705
1299
  result.push(
1706
1300
  this.hooks.setProduct(mainProduct, {
1707
1301
  ...mainProductData,