@pisell/pisellos 2.1.104 → 2.1.105

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