@pisell/pisellos 2.1.107 → 2.1.109

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.
@@ -95,7 +95,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
95
95
  if (productList.every((item) => {
96
96
  var _a;
97
97
  const product = this.hooks.getProduct(item);
98
- return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || (newDiscountList[0].tag === "good_pass" ? product.price == 0 : product.total == 0));
98
+ return product.booking_id && (((_a = product.discount_list) == null ? void 0 : _a.length) || product.total == 0);
99
99
  })) {
100
100
  return {
101
101
  isAvailable: false,
@@ -193,7 +193,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
193
193
  isFormSubject,
194
194
  orderTotalAmount
195
195
  }, options) {
196
- const isEditModeAddNewProduct = productList.find((n) => n.booking_id) && productList.find((n) => !n.booking_id);
197
196
  const editModeDiscount = [];
198
197
  const addModeDiscount = [];
199
198
  discountList.forEach((discount) => {
@@ -346,6 +345,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
346
345
  return compareByExpireTime(a, b);
347
346
  });
348
347
  const flattenedList = flattenProductsWithBundle(productList);
348
+ const isEditModeAddNewProduct = flattenedList.find((n) => n.booking_id) && flattenedList.find((n) => !n.booking_id);
349
349
  const sortedFlattenedList = flattenedList.sort((a, b) => {
350
350
  var _a, _b;
351
351
  const priceA = new import_decimal.default(
@@ -388,12 +388,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
388
388
  available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
389
389
  available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
390
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
- }));
391
+ const productsForEvaluate = sortedFlattenedList.map((item) => {
392
+ var _a2;
393
+ return {
394
+ product_id: item.id,
395
+ price: item.price || 0,
396
+ quantity: item.quantity || item.num || 1,
397
+ selling_price: item.price || 0,
398
+ product_options: item.type === "main" ? (_a2 = item.product) == null ? void 0 : _a2.options : void 0
399
+ };
400
+ });
397
401
  const result = evaluator.checkVoucherAvailability({
398
402
  orderTotalAmount,
399
403
  products: productsForEvaluate,
@@ -562,6 +566,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
562
566
  originProduct = flatItem.originProduct;
563
567
  } else {
564
568
  product = {
569
+ startDate: (_a = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _a.startDate,
565
570
  _id: flatItem._id,
566
571
  id: flatItem.id,
567
572
  price: flatItem.price,
@@ -570,8 +575,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
570
575
  total: flatItem.total,
571
576
  origin_total: flatItem.origin_total,
572
577
  booking_id: flatItem.booking_id,
573
- discount_list: flatItem.discount_list || [],
574
- startDate: (_a = flatItem.parentProduct) == null ? void 0 : _a.startDate
578
+ discount_list: flatItem.discount_list || []
575
579
  };
576
580
  originProduct = flatItem.originProduct;
577
581
  }
@@ -630,25 +634,69 @@ var RulesModule = class extends import_BaseModule.BaseModule {
630
634
  });
631
635
  });
632
636
  const processedFlatItemsMap = /* @__PURE__ */ new Map();
637
+ const applyDiscountToOptions = (options2, discount) => {
638
+ if (!(options2 == null ? void 0 : options2.length))
639
+ return { discountedOptions: options2, optionDiscountAmount: 0 };
640
+ let optionDiscountAmount = 0;
641
+ const discountedOptions = options2.map((option) => {
642
+ const rawUnit = option._original_price ?? option._original_add_price ?? option.price ?? option.add_price;
643
+ const baseUnitNum = Number(rawUnit ?? 0);
644
+ if (baseUnitNum <= 0)
645
+ return option;
646
+ const discountedPrice = (0, import_utils.getDiscountAmount)(discount, baseUnitNum, baseUnitNum);
647
+ const optQty = Number(option.num ?? option.quantity ?? 1);
648
+ optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(baseUnitNum).minus(discountedPrice).mul(optQty)).toNumber();
649
+ const { _original_add_price, ...rest } = option;
650
+ const tmpl = rest.price ?? rest.add_price;
651
+ const nextPrice = typeof tmpl === "string" ? String(discountedPrice) : discountedPrice;
652
+ return {
653
+ ...rest,
654
+ _original_price: option._original_price ?? (_original_add_price !== void 0 ? _original_add_price : rawUnit),
655
+ price: nextPrice
656
+ };
657
+ });
658
+ return { discountedOptions, optionDiscountAmount };
659
+ };
660
+ const restoreOptionPrices = (options2) => {
661
+ if (!(options2 == null ? void 0 : options2.length))
662
+ return options2;
663
+ return options2.map((option) => {
664
+ const orig = option._original_price !== void 0 ? option._original_price : option._original_add_price;
665
+ if (orig !== void 0) {
666
+ const { _original_price, _original_add_price, ...rest } = option;
667
+ return { ...rest, price: orig };
668
+ }
669
+ return option;
670
+ });
671
+ };
672
+ const getOptionTotal = (options2) => {
673
+ if (!(options2 == null ? void 0 : options2.length))
674
+ return 0;
675
+ return options2.reduce((sum, opt) => {
676
+ const unit = Number(opt.price ?? opt.add_price ?? 0);
677
+ const n = Number(opt.num ?? opt.quantity ?? 1);
678
+ return new import_decimal.default(sum).plus(new import_decimal.default(unit).mul(n)).toNumber();
679
+ }, 0);
680
+ };
633
681
  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;
682
+ 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, _K, _L, _M;
635
683
  let product, originProduct;
636
684
  if (flatItem.type === "main") {
637
685
  product = flatItem.product;
638
686
  originProduct = flatItem.originProduct;
639
687
  } else {
640
688
  product = {
689
+ startDate: (_a = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _a.startDate,
641
690
  _id: flatItem._id,
642
691
  id: flatItem.id,
643
692
  price: flatItem.price,
644
693
  quantity: flatItem.quantity,
645
694
  num: flatItem.num,
646
695
  total: flatItem.total,
647
- original_price: (_a = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _a.original_price,
648
- origin_total: (_b = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _b.original_price,
696
+ original_price: (_b = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _b.original_price,
697
+ origin_total: (_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.original_price,
649
698
  booking_id: flatItem.booking_id,
650
- discount_list: ((_c = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _c.discount_list) || [],
651
- startDate: (_d = flatItem.parentProduct) == null ? void 0 : _d.startDate
699
+ discount_list: ((_d = flatItem == null ? void 0 : flatItem.bundleItem) == null ? void 0 : _d.discount_list) || []
652
700
  };
653
701
  originProduct = flatItem.originProduct;
654
702
  }
@@ -709,11 +757,6 @@ var RulesModule = class extends import_BaseModule.BaseModule {
709
757
  }
710
758
  }
711
759
  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
760
  const _tempVar = (flatItem == null ? void 0 : flatItem.type) === "bundle" ? flatItem == null ? void 0 : flatItem.parentProduct : flatItem == null ? void 0 : flatItem.product;
718
761
  const isHolderMatch = this.checkHolderMatch(
719
762
  discount,
@@ -725,6 +768,11 @@ var RulesModule = class extends import_BaseModule.BaseModule {
725
768
  );
726
769
  if (!isHolderMatch)
727
770
  return false;
771
+ let timeLimit = true;
772
+ timeLimit = !!(0, import_utils.filterDiscountListByBookingTime)([discount], (product.startDate || (0, import_dayjs.default)()).format("YYYY-MM-DD HH:mm:ss")).length;
773
+ if (!timeLimit) {
774
+ return false;
775
+ }
728
776
  if (limitedData.type === "product_all") {
729
777
  if (limitedData.filter === 1 && limitedData.exclude_product_ids.includes(product.id)) {
730
778
  return false;
@@ -747,17 +795,30 @@ var RulesModule = class extends import_BaseModule.BaseModule {
747
795
  const selectedDiscount = selectedDiscountCard || applicableDiscounts[0];
748
796
  let isManualDiscount = false;
749
797
  if (flatItem.type === "main") {
750
- isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every((item) => {
751
- var _a2;
752
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
753
- }) && (!((_g = product.discount_list) == null ? void 0 : _g.length) || ((_i = (_h = product == null ? void 0 : product.discount_list) == null ? void 0 : _h.every) == null ? void 0 : _i.call(_h, (item) => item.type === "product")));
798
+ isManualDiscount = typeof product.isManualDiscount === "boolean" ? product.isManualDiscount : product.total != product.origin_total && (product.bundle || []).every(
799
+ (item) => {
800
+ var _a2;
801
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
802
+ }
803
+ ) && (!((_g = product.discount_list) == null ? void 0 : _g.length) || ((_i = (_h = product == null ? void 0 : product.discount_list) == null ? void 0 : _h.every) == null ? void 0 : _i.call(
804
+ _h,
805
+ (item) => item.type === "product"
806
+ )));
807
+ if (product.inPromotion) {
808
+ isManualDiscount = false;
809
+ }
754
810
  } else {
755
811
  const parentProduct = flatItem.parentProduct;
756
812
  if (parentProduct) {
757
- isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every((item) => {
758
- var _a2;
759
- return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
760
- }) && (!((_j = parentProduct.discount_list) == null ? void 0 : _j.length) || ((_l = (_k = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _k.every) == null ? void 0 : _l.call(_k, (item) => item.type === "product")));
813
+ isManualDiscount = typeof parentProduct.isManualDiscount === "boolean" ? parentProduct.isManualDiscount : parentProduct.total != parentProduct.origin_total && (parentProduct.bundle || []).every(
814
+ (item) => {
815
+ var _a2;
816
+ return !((_a2 = item.discount_list || []) == null ? void 0 : _a2.length);
817
+ }
818
+ ) && (!((_j = parentProduct.discount_list) == null ? void 0 : _j.length) || ((_l = (_k = parentProduct == null ? void 0 : parentProduct.discount_list) == null ? void 0 : _k.every) == null ? void 0 : _l.call(
819
+ _k,
820
+ (item) => item.type === "product"
821
+ )));
761
822
  }
762
823
  }
763
824
  if (options == null ? void 0 : options.discountId) {
@@ -809,34 +870,33 @@ var RulesModule = class extends import_BaseModule.BaseModule {
809
870
  }
810
871
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
811
872
  if (flatItem.type === "main") {
873
+ const restoredOptions = restoreOptionPrices(product.options);
812
874
  if (product.isClient) {
813
- processedProductsMap.set(
814
- 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
- ]
839
- );
875
+ processedProductsMap.set(product._id, [
876
+ this.hooks.setProduct(originProduct, {
877
+ ...isManualDiscount ? {} : {
878
+ origin_total: (0, import_utils2.getProductOriginTotalPrice)({
879
+ product: {
880
+ original_price: product.original_price
881
+ },
882
+ bundle: product.bundle,
883
+ options: restoredOptions
884
+ }),
885
+ variant: originProduct._productInit.variant,
886
+ original_price: originProduct._productInit.original_price,
887
+ total: (0, import_utils2.getProductTotalPrice)({
888
+ product: {
889
+ price: product.price
890
+ },
891
+ bundle: product.bundle,
892
+ options: restoredOptions
893
+ }),
894
+ price: product.price,
895
+ options: restoredOptions
896
+ },
897
+ discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
898
+ })
899
+ ]);
840
900
  } else {
841
901
  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;
842
902
  let main_product_selling_price = product.price ?? product.main_product_selling_price;
@@ -846,17 +906,20 @@ var RulesModule = class extends import_BaseModule.BaseModule {
846
906
  }
847
907
  processedProductsMap.set(
848
908
  product._id,
849
- [this.hooks.setProduct(originProduct, {
850
- ...isManualDiscount ? {
851
- price: product.price
852
- } : {
853
- _id: product._id.split("___")[0] + "___" + index,
854
- total,
855
- price: product.price,
856
- main_product_selling_price
857
- },
858
- discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
859
- })]
909
+ [
910
+ this.hooks.setProduct(originProduct, {
911
+ ...isManualDiscount ? {
912
+ price: product.price
913
+ } : {
914
+ _id: product._id.split("___")[0] + "___" + index,
915
+ total,
916
+ price: product.price,
917
+ main_product_selling_price,
918
+ options: restoredOptions
919
+ },
920
+ discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
921
+ })
922
+ ]
860
923
  );
861
924
  }
862
925
  } else {
@@ -900,12 +963,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
900
963
  const arr = [];
901
964
  if (flatItem.type === "main") {
902
965
  if (splitCount < totalQuantity && isNeedSplit) {
903
- arr.push(this.hooks.setProduct(originProduct, {
904
- discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
905
- quantity: totalQuantity - splitCount,
906
- _id: product._id.split("___")[0],
907
- total: product.origin_total || product.total
908
- }));
966
+ let total = product.origin_total ?? product.total;
967
+ if ((product.discount_list || []).some((item) => item.type === "promotion")) {
968
+ total = product.total ?? product.origin_total;
969
+ }
970
+ arr.push(
971
+ this.hooks.setProduct(originProduct, {
972
+ discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
973
+ quantity: totalQuantity - splitCount,
974
+ _id: product._id.split("___")[0],
975
+ total
976
+ })
977
+ );
909
978
  }
910
979
  for (let i = 0; i < splitCount; i++) {
911
980
  const currentSelectedDiscount = isGoodPass ? selectedDiscountCard || applicableDiscounts[i] : selectedDiscountCard || applicableDiscounts[0];
@@ -930,29 +999,49 @@ var RulesModule = class extends import_BaseModule.BaseModule {
930
999
  const isOrderLevel = (0, import_utils.isOrderLevelFixedAmountDiscount)(selectedDiscount);
931
1000
  const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount.id) : null;
932
1001
  const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
933
- let targetProductTotal;
1002
+ const isDeductOptionPrice = !!((_y = selectedDiscount.config) == null ? void 0 : _y.deductOptionPrice);
1003
+ let mainProductSellingPrice;
934
1004
  let amount;
935
1005
  let productDiscountDifference;
1006
+ let discountedOptions = product.options;
1007
+ let optionDiscountAmount = 0;
936
1008
  if (isOrderLevel && productAllocation) {
937
1009
  amount = productAllocation.discountAmount;
938
1010
  productDiscountDifference = productAllocation.difference;
939
- targetProductTotal = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
1011
+ mainProductSellingPrice = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
940
1012
  } else {
941
- targetProductTotal = (0, import_utils.getDiscountAmount)(currentSelectedDiscount, product.price, product.price);
942
- amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
1013
+ mainProductSellingPrice = (0, import_utils.getDiscountAmount)(
1014
+ currentSelectedDiscount,
1015
+ product.price,
1016
+ product.price
1017
+ );
1018
+ amount = new import_decimal.default(product.price).minus(new import_decimal.default(mainProductSellingPrice)).toNumber();
1019
+ }
1020
+ if (isDeductOptionPrice && ((_z = product.options) == null ? void 0 : _z.length)) {
1021
+ const optionResult = applyDiscountToOptions(
1022
+ product.options,
1023
+ currentSelectedDiscount
1024
+ );
1025
+ discountedOptions = optionResult.discountedOptions;
1026
+ optionDiscountAmount = optionResult.optionDiscountAmount;
943
1027
  }
1028
+ const optionsForLineTotal = isDeductOptionPrice && ((_A = product.options) == null ? void 0 : _A.length) ? discountedOptions : product.options;
1029
+ const optionsLineTotal = getOptionTotal(optionsForLineTotal || []);
1030
+ const total = new import_decimal.default(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
1031
+ const mainProductDiscountAmount = amount;
1032
+ const lineDiscountAmount = new import_decimal.default(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
944
1033
  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();
1034
+ const discountType2 = selectedDiscount.tag || selectedDiscount.type;
946
1035
  const currentIsGoodPass = currentDiscountType === "good_pass";
947
1036
  const discountDetail = {
948
- amount: actualDiscountAmount,
949
- type: currentDiscountType,
1037
+ amount: lineDiscountAmount,
1038
+ type: selectedDiscount.tag === "product_discount_card" ? "discount_card" : discountType2,
950
1039
  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,
1040
+ discount_card_type: (_B = selectedDiscount == null ? void 0 : selectedDiscount.metadata) == null ? void 0 : _B.discount_card_type,
1041
+ fixed_amount: lineDiscountAmount,
1042
+ discount_calculation_mode: (_C = selectedDiscount == null ? void 0 : selectedDiscount.metadata) == null ? void 0 : _C.discount_calculation_mode,
1043
+ resource_id: selectedDiscount.id,
1044
+ title: selectedDiscount.format_title,
956
1045
  original_amount: product.price,
957
1046
  product_id: originProduct.id,
958
1047
  percent: currentSelectedDiscount.par_value,
@@ -965,35 +1054,32 @@ var RulesModule = class extends import_BaseModule.BaseModule {
965
1054
  num: 1,
966
1055
  discount_rule_uncheck_flag: selectedDiscount == null ? void 0 : selectedDiscount.discount_rule_uncheck_flag,
967
1056
  // 🔥 order_level 分摊差值
968
- ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
1057
+ ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference },
1058
+ /** 仅主商品上的优惠金额(不含 option) */
1059
+ mainProductDiscountAmount,
1060
+ optionDiscountAmount
969
1061
  }
970
1062
  };
971
1063
  appliedProducts.push(discountDetail);
972
1064
  appliedDiscountProducts.set(currentSelectedDiscount.id, appliedProducts);
973
- let total = targetProductTotal;
974
- if (product.options) {
975
- total = product.options.reduce((accumulator, currentValue) => {
976
- const currentPrice = new import_decimal.default(currentValue.price || 0);
977
- const currentNum = new import_decimal.default(currentValue.num || 0);
978
- return accumulator.add(currentPrice.mul(currentNum));
979
- }, new import_decimal.default(total)).toNumber();
980
- }
981
1065
  if (product.isClient) {
982
1066
  arr.push(
983
1067
  this.hooks.setProduct(originProduct, {
984
1068
  discount_list: [discountDetail],
985
- price: currentIsGoodPass ? product.price - discountDetail.amount : product.price,
1069
+ // good_pass:主商品价以折后价为准;勿用 product.price - amount(amount option 优惠时会算错)
1070
+ price: currentIsGoodPass ? mainProductSellingPrice : product.price,
986
1071
  quantity: isNeedSplit ? 1 : product.quantity,
987
1072
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
988
1073
  product: {
989
1074
  original_price: product.original_price
990
1075
  },
991
1076
  bundle: product.bundle,
992
- options: product.options
1077
+ options: restoreOptionPrices(product.options)
993
1078
  }),
994
1079
  variant: originProduct._productInit.variant,
995
1080
  original_price: new import_decimal.default(product.price || 0).toNumber(),
996
- total: targetProductTotal
1081
+ total,
1082
+ options: discountedOptions
997
1083
  })
998
1084
  );
999
1085
  } else {
@@ -1003,9 +1089,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1003
1089
  _id: product._id.split("___")[0] + "___" + currentSelectedDiscount.id + "_" + i + "_" + index,
1004
1090
  price: currentIsGoodPass ? 0 : product.price,
1005
1091
  quantity: isNeedSplit ? 1 : product.quantity,
1006
- total: targetProductTotal,
1092
+ total,
1007
1093
  origin_total: productOriginTotal,
1008
- main_product_selling_price: targetProductTotal
1094
+ main_product_selling_price: mainProductSellingPrice,
1095
+ options: discountedOptions
1009
1096
  })
1010
1097
  );
1011
1098
  }
@@ -1040,8 +1127,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1040
1127
  amount: bundleDiscountAmount,
1041
1128
  type: bundleDiscountType,
1042
1129
  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,
1130
+ discount_card_type: (_D = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _D.discount_card_type,
1131
+ discount_calculation_mode: (_E = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _E.discount_calculation_mode,
1045
1132
  fixed_amount: bundleDiscountAmount,
1046
1133
  resource_id: currentBundleDiscount.id,
1047
1134
  title: currentBundleDiscount.format_title,
@@ -1149,7 +1236,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1149
1236
  const nextDiscType = nextSelectedDiscount.tag || nextSelectedDiscount.type;
1150
1237
  const nextIsGoodPass = nextDiscType === "good_pass";
1151
1238
  const nextIsDiscountCard = ["discount_card", "product_discount_card"].includes(nextDiscType);
1152
- const nextApplicableProductLimit = ((_C = nextSelectedDiscount.config) == null ? void 0 : _C.applicableProductLimit) || 0;
1239
+ const nextApplicableProductLimit = ((_F = nextSelectedDiscount.config) == null ? void 0 : _F.applicableProductLimit) || 0;
1153
1240
  const nextIsNeedSplit = nextIsGoodPass || nextIsDiscountCard && nextApplicableProductLimit > 0;
1154
1241
  if (!nextIsNeedSplit) {
1155
1242
  const nextBundleDiscount = nextSelectedDiscountCard || nextApplicableDiscounts[0];
@@ -1172,7 +1259,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1172
1259
  amount: nextDiscountAmount * remainingNum,
1173
1260
  type: nextBundleDiscType,
1174
1261
  discount: {
1175
- discount_card_type: (_D = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _D.discount_card_type,
1262
+ discount_card_type: (_G = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _G.discount_card_type,
1176
1263
  fixed_amount: nextDiscountAmount,
1177
1264
  resource_id: nextBundleDiscount.id,
1178
1265
  title: nextBundleDiscount.format_title,
@@ -1186,7 +1273,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1186
1273
  num: remainingNum
1187
1274
  },
1188
1275
  config: nextBundleDiscount == null ? void 0 : nextBundleDiscount.config,
1189
- _num: remainingNum * (((_E = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _E.num) || 1)
1276
+ _num: remainingNum * (((_H = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _H.num) || 1)
1190
1277
  };
1191
1278
  const nextAppliedProducts = appliedDiscountProducts.get(nextBundleDiscount.id) || [];
1192
1279
  nextAppliedProducts.push(nextDiscountDetail);
@@ -1210,7 +1297,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1210
1297
  (item) => (item.tag || item.type) === "good_pass"
1211
1298
  ).length;
1212
1299
  nextMaxUsageLimit = nextGoodPassCount;
1213
- if ((_F = nextSelectedDiscount.config) == null ? void 0 : _F.maxUsagePerOrder) {
1300
+ if ((_I = nextSelectedDiscount.config) == null ? void 0 : _I.maxUsagePerOrder) {
1214
1301
  const usedCount = usedProductIdCounts.get(nextSelectedDiscount.product_id) || 0;
1215
1302
  nextMaxUsageLimit = Math.min(
1216
1303
  nextGoodPassCount,
@@ -1259,7 +1346,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1259
1346
  amount: nextBundleDiscAmount,
1260
1347
  type: nextBundleDiscTypeStr,
1261
1348
  discount: {
1262
- discount_card_type: (_G = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _G.discount_card_type,
1349
+ discount_card_type: (_J = nextBundleDiscount == null ? void 0 : nextBundleDiscount.metadata) == null ? void 0 : _J.discount_card_type,
1263
1350
  fixed_amount: nextBundleDiscAmount,
1264
1351
  resource_id: nextBundleDiscount.id,
1265
1352
  title: nextBundleDiscount.format_title,
@@ -1331,9 +1418,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1331
1418
  amount: bundleActualDiscountAmount * (product.num || 1),
1332
1419
  type: currentBundleDiscount.tag === "product_discount_card" ? "discount_card" : currentBundleDiscount.tag,
1333
1420
  discount: {
1334
- discount_card_type: (_H = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _H.discount_card_type,
1421
+ discount_card_type: (_K = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _K.discount_card_type,
1335
1422
  fixed_amount: bundleActualDiscountAmount,
1336
- discount_calculation_mode: (_I = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _I.discount_calculation_mode,
1423
+ discount_calculation_mode: (_L = currentBundleDiscount == null ? void 0 : currentBundleDiscount.metadata) == null ? void 0 : _L.discount_calculation_mode,
1337
1424
  resource_id: currentBundleDiscount.id,
1338
1425
  title: currentBundleDiscount.format_title,
1339
1426
  original_amount: product.original_price,
@@ -1350,7 +1437,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1350
1437
  ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
1351
1438
  },
1352
1439
  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)
1440
+ _num: (product.num || 1) * (((_M = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _M.num) || 1)
1354
1441
  };
1355
1442
  const appliedProducts = appliedDiscountProducts.get(currentBundleDiscount.id) || [];
1356
1443
  appliedProducts.push(discountDetail);
@@ -1373,6 +1460,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1373
1460
  const mainProductArr = processedProductsMap2.get(product._id);
1374
1461
  if (!mainProductArr || mainProductArr.length === 0) {
1375
1462
  const getDefaultProduct = () => {
1463
+ const restoredOptions = restoreOptionPrices(product.options);
1376
1464
  if (product.isClient) {
1377
1465
  return this.hooks.setProduct(originProduct, {
1378
1466
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
@@ -1382,7 +1470,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1382
1470
  original_price: product.original_price
1383
1471
  },
1384
1472
  bundle: product.bundle,
1385
- options: product.options
1473
+ options: restoredOptions
1386
1474
  }),
1387
1475
  variant: originProduct._productInit.variant,
1388
1476
  original_price: originProduct._productInit.original_price,
@@ -1391,15 +1479,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1391
1479
  price: product.price
1392
1480
  },
1393
1481
  bundle: product.bundle,
1394
- options: product.options
1395
- })
1482
+ options: restoredOptions
1483
+ }),
1484
+ options: restoredOptions
1396
1485
  });
1397
1486
  } else {
1398
1487
  return this.hooks.setProduct(originProduct, {
1399
1488
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
1400
1489
  total: product.total,
1401
1490
  origin_total: product.origin_total,
1402
- price: product.price
1491
+ price: product.price,
1492
+ options: restoreOptionPrices(product.options)
1403
1493
  });
1404
1494
  }
1405
1495
  };
@@ -1446,20 +1536,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1446
1536
  ) || [bundleItem];
1447
1537
  if (processedItems.length > 1) {
1448
1538
  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
- };
1461
- }
1462
- );
1539
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1540
+ var _a;
1541
+ return {
1542
+ ...discount,
1543
+ metadata: {
1544
+ ...discount.metadata,
1545
+ num: item.num,
1546
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1547
+ }
1548
+ // num: item.num, // 使用拆分后的 num
1549
+ };
1550
+ });
1463
1551
  newBundleWithDiscount.push({
1464
1552
  ...bundleItem,
1465
1553
  _id: item._id,
@@ -1473,20 +1561,18 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1473
1561
  } else {
1474
1562
  const item = processedItems[0];
1475
1563
  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
- };
1488
- }
1489
- );
1564
+ const updatedDiscountList2 = (item.discount_list || []).map((discount) => {
1565
+ var _a;
1566
+ return {
1567
+ ...discount,
1568
+ metadata: {
1569
+ ...discount.metadata,
1570
+ num: item.num,
1571
+ custom_product_bundle_map_id: (_a = item.metadata) == null ? void 0 : _a.custom_product_bundle_map_id
1572
+ }
1573
+ // num: item.num, // 使用当前的 num
1574
+ };
1575
+ });
1490
1576
  newBundleWithDiscount.push({
1491
1577
  ...bundleItem,
1492
1578
  _id: item._id,
@@ -1664,7 +1750,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1664
1750
  price: item.price,
1665
1751
  num: item.num,
1666
1752
  quantity: item.num,
1667
- discount_list: updatedDiscountList2
1753
+ discount_list: updatedDiscountList2,
1754
+ bundle_selling_price: bundleItem.bundle_selling_price !== void 0 ? item.price : void 0
1668
1755
  });
1669
1756
  });
1670
1757
  }
@@ -67,6 +67,7 @@ export interface RulesParamsHooks {
67
67
  quantity?: number;
68
68
  bundle?: any[];
69
69
  main_product_selling_price?: string | number;
70
+ options?: any[];
70
71
  }) => Record<string, any>;
71
72
  }
72
73
  export {};
@@ -311,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
311
311
  date: string;
312
312
  status: string;
313
313
  week: string;
314
- weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
315
315
  }[]>;
316
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
317
317
  private getScheduleDataByIds;