@pisell/pisellos 2.2.101 → 2.2.103

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.
@@ -353,12 +353,16 @@ var RulesModule = class extends import_BaseModule.BaseModule {
353
353
  available_product_type: (_a = discount.limited_relation_product_data) == null ? void 0 : _a.type,
354
354
  available_product_ids: (_b = discount.limited_relation_product_data) == null ? void 0 : _b.product_ids
355
355
  };
356
- const productsForEvaluate = sortedFlattenedList.map((item) => ({
357
- product_id: item.id,
358
- price: item.price || 0,
359
- quantity: item.quantity || item.num || 1,
360
- selling_price: item.price || 0
361
- }));
356
+ const productsForEvaluate = sortedFlattenedList.map((item) => {
357
+ var _a2;
358
+ return {
359
+ product_id: item.id,
360
+ price: item.price || 0,
361
+ quantity: item.quantity || item.num || 1,
362
+ selling_price: item.price || 0,
363
+ product_options: item.type === "main" ? (_a2 = item.product) == null ? void 0 : _a2.options : void 0
364
+ };
365
+ });
362
366
  const result = evaluator.checkVoucherAvailability({
363
367
  orderTotalAmount,
364
368
  products: productsForEvaluate,
@@ -584,8 +588,47 @@ var RulesModule = class extends import_BaseModule.BaseModule {
584
588
  });
585
589
  });
586
590
  const processedFlatItemsMap = /* @__PURE__ */ new Map();
591
+ const applyDiscountToOptions = (options2, discount) => {
592
+ if (!(options2 == null ? void 0 : options2.length))
593
+ return { discountedOptions: options2, optionDiscountAmount: 0 };
594
+ let optionDiscountAmount = 0;
595
+ const discountedOptions = options2.map((option) => {
596
+ const addPrice = Number(option.add_price || 0);
597
+ if (addPrice <= 0)
598
+ return option;
599
+ const discountedPrice = (0, import_utils.getDiscountAmount)(discount, addPrice, addPrice);
600
+ const optQty = Number(option.num ?? option.quantity ?? 1);
601
+ optionDiscountAmount = new import_decimal.default(optionDiscountAmount).plus(new import_decimal.default(addPrice).minus(discountedPrice).mul(optQty)).toNumber();
602
+ return {
603
+ ...option,
604
+ _original_add_price: option._original_add_price ?? option.add_price,
605
+ add_price: discountedPrice
606
+ };
607
+ });
608
+ return { discountedOptions, optionDiscountAmount };
609
+ };
610
+ const restoreOptionPrices = (options2) => {
611
+ if (!(options2 == null ? void 0 : options2.length))
612
+ return options2;
613
+ return options2.map((option) => {
614
+ if (option._original_add_price !== void 0) {
615
+ const { _original_add_price, ...rest } = option;
616
+ return { ...rest, add_price: _original_add_price };
617
+ }
618
+ return option;
619
+ });
620
+ };
621
+ const getOptionTotal = (options2) => {
622
+ if (!(options2 == null ? void 0 : options2.length))
623
+ return 0;
624
+ return options2.reduce((sum, opt) => {
625
+ const unit = Number(opt.add_price ?? opt.price ?? 0);
626
+ const n = Number(opt.num ?? opt.quantity ?? 1);
627
+ return new import_decimal.default(sum).plus(new import_decimal.default(unit).mul(n)).toNumber();
628
+ }, 0);
629
+ };
587
630
  sortedFlattenedList.forEach((flatItem, index) => {
588
- 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;
631
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _A, _B, _C, _D, _E, _F;
589
632
  let product, originProduct;
590
633
  if (flatItem.type === "main") {
591
634
  product = flatItem.product;
@@ -784,6 +827,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
784
827
  }
785
828
  if (applicableDiscounts.length === 0 || isManualDiscount || (0, import_lodash_es.isBoolean)(product.vouchersApplicable) && !product.vouchersApplicable) {
786
829
  if (flatItem.type === "main") {
830
+ const restoredOptions = restoreOptionPrices(product.options);
787
831
  if (product.isClient) {
788
832
  processedProductsMap.set(product._id, [
789
833
  this.hooks.setProduct(originProduct, {
@@ -793,7 +837,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
793
837
  original_price: product.original_price
794
838
  },
795
839
  bundle: product.bundle,
796
- options: product.options
840
+ options: restoredOptions
797
841
  }),
798
842
  variant: originProduct._productInit.variant,
799
843
  original_price: originProduct._productInit.original_price,
@@ -802,9 +846,10 @@ var RulesModule = class extends import_BaseModule.BaseModule {
802
846
  price: product.price
803
847
  },
804
848
  bundle: product.bundle,
805
- options: product.options
849
+ options: restoredOptions
806
850
  }),
807
- price: product.price
851
+ price: product.price,
852
+ options: restoredOptions
808
853
  },
809
854
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
810
855
  })
@@ -825,7 +870,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
825
870
  _id: product._id.split("___")[0] + "___" + index,
826
871
  total,
827
872
  price: product.price,
828
- main_product_selling_price
873
+ main_product_selling_price,
874
+ options: restoredOptions
829
875
  },
830
876
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion")
831
877
  })
@@ -891,26 +937,46 @@ var RulesModule = class extends import_BaseModule.BaseModule {
891
937
  const isOrderLevel = (0, import_utils3.isOrderLevelFixedAmountDiscount)(selectedDiscount2);
892
938
  const orderLevelAllocation = isOrderLevel ? orderLevelDiscountAllocations.get(selectedDiscount2.id) : null;
893
939
  const productAllocation = orderLevelAllocation == null ? void 0 : orderLevelAllocation.get(flatItem._id);
894
- let targetProductTotal;
940
+ const isDeductOptionPrice = !!((_x = selectedDiscount2.config) == null ? void 0 : _x.deductOptionPrice);
941
+ let mainProductSellingPrice;
895
942
  let amount;
896
943
  let productDiscountDifference;
944
+ let discountedOptions = product.options;
945
+ let optionDiscountAmount = 0;
897
946
  if (isOrderLevel && productAllocation) {
898
947
  amount = productAllocation.discountAmount;
899
948
  productDiscountDifference = productAllocation.difference;
900
- targetProductTotal = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
949
+ mainProductSellingPrice = Math.max(new import_decimal.default(product.price).minus(amount).toNumber(), 0);
901
950
  } else {
902
- targetProductTotal = (0, import_utils.getDiscountAmount)(selectedDiscount2, product.price, product.price);
903
- amount = new import_decimal.default(product.price).minus(new import_decimal.default(targetProductTotal)).toNumber();
951
+ mainProductSellingPrice = (0, import_utils.getDiscountAmount)(
952
+ selectedDiscount2,
953
+ product.price,
954
+ product.price
955
+ );
956
+ amount = new import_decimal.default(product.price).minus(new import_decimal.default(mainProductSellingPrice)).toNumber();
957
+ }
958
+ if (isDeductOptionPrice && ((_y = product.options) == null ? void 0 : _y.length)) {
959
+ const optionResult = applyDiscountToOptions(
960
+ product.options,
961
+ selectedDiscount2
962
+ );
963
+ discountedOptions = optionResult.discountedOptions;
964
+ optionDiscountAmount = optionResult.optionDiscountAmount;
904
965
  }
966
+ const optionsForLineTotal = isDeductOptionPrice && ((_z = product.options) == null ? void 0 : _z.length) ? discountedOptions : product.options;
967
+ const optionsLineTotal = getOptionTotal(optionsForLineTotal || []);
968
+ const total = new import_decimal.default(mainProductSellingPrice).plus(optionsLineTotal).toNumber();
969
+ const mainProductDiscountAmount = amount;
970
+ const lineDiscountAmount = new import_decimal.default(mainProductDiscountAmount).plus(optionDiscountAmount).toNumber();
905
971
  const discountType = selectedDiscount2.tag || selectedDiscount2.type;
906
972
  const isGoodPass = discountType === "good_pass";
907
973
  const discountDetail = {
908
- amount,
974
+ amount: lineDiscountAmount,
909
975
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : discountType,
910
976
  discount: {
911
- discount_card_type: (_x = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _x.discount_card_type,
912
- fixed_amount: amount,
913
- discount_calculation_mode: (_y = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _y.discount_calculation_mode,
977
+ discount_card_type: (_A = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _A.discount_card_type,
978
+ fixed_amount: lineDiscountAmount,
979
+ discount_calculation_mode: (_B = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _B.discount_calculation_mode,
914
980
  resource_id: selectedDiscount2.id,
915
981
  title: selectedDiscount2.format_title,
916
982
  original_amount: product.price,
@@ -924,35 +990,32 @@ var RulesModule = class extends import_BaseModule.BaseModule {
924
990
  metadata: {
925
991
  num: 1,
926
992
  // 🔥 order_level 分摊差值
927
- ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
993
+ ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference },
994
+ /** 仅主商品上的优惠金额(不含 option) */
995
+ mainProductDiscountAmount,
996
+ optionDiscountAmount
928
997
  }
929
998
  };
930
999
  appliedProducts.push(discountDetail);
931
1000
  appliedDiscountProducts.set(selectedDiscount2.id, appliedProducts);
932
- let total = targetProductTotal;
933
- if (product.options) {
934
- total = product.options.reduce((accumulator, currentValue) => {
935
- const currentPrice = new import_decimal.default(currentValue.price || 0);
936
- const currentNum = new import_decimal.default(currentValue.num || 0);
937
- return accumulator.add(currentPrice.mul(currentNum));
938
- }, new import_decimal.default(total)).toNumber();
939
- }
940
1001
  if (product.isClient) {
941
1002
  arr.push(
942
1003
  this.hooks.setProduct(originProduct, {
943
1004
  discount_list: [discountDetail],
944
- price: selectedDiscount2.tag === "good_pass" ? 0 : product.price,
1005
+ // good_pass:主商品价以折后价为准;勿用 product.price - amount(amount option 优惠时会算错)
1006
+ price: isGoodPass ? mainProductSellingPrice : product.price,
945
1007
  quantity: isNeedSplit ? 1 : product.quantity,
946
1008
  origin_total: (0, import_utils2.getProductOriginTotalPrice)({
947
1009
  product: {
948
1010
  original_price: product.original_price
949
1011
  },
950
1012
  bundle: product.bundle,
951
- options: product.options
1013
+ options: restoreOptionPrices(product.options)
952
1014
  }),
953
1015
  variant: originProduct._productInit.variant,
954
1016
  original_price: new import_decimal.default(product.price || 0).toNumber(),
955
- total
1017
+ total,
1018
+ options: discountedOptions
956
1019
  })
957
1020
  );
958
1021
  } else {
@@ -964,7 +1027,8 @@ var RulesModule = class extends import_BaseModule.BaseModule {
964
1027
  quantity: isNeedSplit ? 1 : product.quantity,
965
1028
  total,
966
1029
  origin_total: productOriginTotal,
967
- main_product_selling_price: targetProductTotal
1030
+ main_product_selling_price: mainProductSellingPrice,
1031
+ options: discountedOptions
968
1032
  })
969
1033
  );
970
1034
  }
@@ -994,7 +1058,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
994
1058
  type: "good_pass",
995
1059
  discount: {
996
1060
  fixed_amount: product.origin_total,
997
- discount_calculation_mode: (_z = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _z.discount_calculation_mode,
1061
+ discount_calculation_mode: (_C = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _C.discount_calculation_mode,
998
1062
  resource_id: selectedDiscount2.id,
999
1063
  title: selectedDiscount2.format_title,
1000
1064
  original_amount: product.origin_total,
@@ -1068,9 +1132,9 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1068
1132
  amount: fixedAmountPerItem * (product.num || 1),
1069
1133
  type: selectedDiscount2.tag === "product_discount_card" ? "discount_card" : selectedDiscount2.tag,
1070
1134
  discount: {
1071
- discount_card_type: (_A = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _A.discount_card_type,
1135
+ discount_card_type: (_D = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _D.discount_card_type,
1072
1136
  fixed_amount: fixedAmountPerItem,
1073
- discount_calculation_mode: (_B = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _B.discount_calculation_mode,
1137
+ discount_calculation_mode: (_E = selectedDiscount2 == null ? void 0 : selectedDiscount2.metadata) == null ? void 0 : _E.discount_calculation_mode,
1074
1138
  resource_id: selectedDiscount2.id,
1075
1139
  title: selectedDiscount2.format_title,
1076
1140
  original_amount: product.original_price,
@@ -1086,7 +1150,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1086
1150
  ...productDiscountDifference !== void 0 && { product_discount_difference: productDiscountDifference }
1087
1151
  },
1088
1152
  config: selectedDiscount2 == null ? void 0 : selectedDiscount2.config,
1089
- _num: (product.num || 1) * (((_C = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _C.num) || 1)
1153
+ _num: (product.num || 1) * (((_F = flatItem == null ? void 0 : flatItem.parentProduct) == null ? void 0 : _F.num) || 1)
1090
1154
  };
1091
1155
  const appliedProducts = appliedDiscountProducts.get(selectedDiscount2.id) || [];
1092
1156
  appliedProducts.push(discountDetail);
@@ -1109,6 +1173,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1109
1173
  const mainProductArr = processedProductsMap2.get(product._id);
1110
1174
  if (!mainProductArr || mainProductArr.length === 0) {
1111
1175
  const getDefaultProduct = () => {
1176
+ const restoredOptions = restoreOptionPrices(product.options);
1112
1177
  if (product.isClient) {
1113
1178
  return this.hooks.setProduct(originProduct, {
1114
1179
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
@@ -1118,7 +1183,7 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1118
1183
  original_price: product.original_price
1119
1184
  },
1120
1185
  bundle: product.bundle,
1121
- options: product.options
1186
+ options: restoredOptions
1122
1187
  }),
1123
1188
  variant: originProduct._productInit.variant,
1124
1189
  original_price: originProduct._productInit.original_price,
@@ -1127,15 +1192,17 @@ var RulesModule = class extends import_BaseModule.BaseModule {
1127
1192
  price: product.price
1128
1193
  },
1129
1194
  bundle: product.bundle,
1130
- options: product.options
1131
- })
1195
+ options: restoredOptions
1196
+ }),
1197
+ options: restoredOptions
1132
1198
  });
1133
1199
  } else {
1134
1200
  return this.hooks.setProduct(originProduct, {
1135
1201
  discount_list: this.filterDiscountListByType(product.discount_list, "promotion"),
1136
1202
  total: product.total,
1137
1203
  origin_total: product.origin_total,
1138
- price: product.price
1204
+ price: product.price,
1205
+ options: restoreOptionPrices(product.options)
1139
1206
  });
1140
1207
  }
1141
1208
  };
@@ -61,6 +61,7 @@ export interface RulesParamsHooks {
61
61
  quantity?: number;
62
62
  bundle?: any[];
63
63
  main_product_selling_price?: string | number;
64
+ options?: any[];
64
65
  }) => Record<string, any>;
65
66
  }
66
67
  export {};
@@ -131,7 +131,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
131
131
  * 获取当前的客户搜索条件
132
132
  * @returns 当前搜索条件
133
133
  */
134
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
134
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
135
135
  /**
136
136
  * 获取客户列表状态(包含滚动加载相关状态)
137
137
  * @returns 客户状态
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.101",
4
+ "version": "2.2.103",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",