@pisell/pisellos 0.0.338 → 0.0.340

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.
@@ -50,8 +50,9 @@ export interface RulesParamsHooks {
50
50
  origin_total?: number;
51
51
  price?: string | number;
52
52
  variant?: any[];
53
- original_price?: number;
53
+ original_price?: number | string;
54
54
  quantity?: number;
55
+ bundle?: any[];
55
56
  }) => Record<string, any>;
56
57
  }
57
58
  export {};
@@ -561,12 +561,13 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
561
561
  return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
562
562
  });
563
563
  if (index !== -1) {
564
+ var _discount$metadata;
564
565
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
565
566
  amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
566
- savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
567
+ savedAmount: new Decimal(discount.amount || 0).times((discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.num) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
567
568
  });
568
569
  } else {
569
- var _discount$discount2, _discount$discount3, _discount$discount4;
570
+ var _discount$metadata2, _discount$discount2, _discount$discount3, _discount$discount4;
570
571
  if (discount.type && !discount.tag) {
571
572
  discount.tag = discount.type;
572
573
  }
@@ -574,7 +575,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
574
575
  name: discount.name || discount.discount.title.auto,
575
576
  isEditMode: true,
576
577
  limited_relation_product_data: {},
577
- savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.num) || 1),
578
+ savedAmount: discount.amount * ((discount === null || discount === void 0 || (_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.num) || (product === null || product === void 0 ? void 0 : product.num) || 1),
578
579
  isAvailable: true,
579
580
  id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
580
581
  format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
@@ -595,6 +596,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
595
596
  var targetProduct = productList.find(function (n) {
596
597
  return n.id === id;
597
598
  });
599
+ if (!targetProduct) return false;
598
600
  var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
599
601
  // 如果 product.total 是小于等于0有可能是她已经用过商品券或者折扣卡导致的,或者本身就是负数价格,所以此时还需要判断 origin_total 是否小于等于0
600
602
  // 如果 product.vouchersApplicable是布尔值,并且是 false,也当做免费商品处理,此商品不可用优惠券或折扣卡
@@ -602,10 +604,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
602
604
  };
603
605
  var allUsedProductIds = newDiscountList.map(function (n) {
604
606
  var _n$appliedProductDeta;
605
- return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
607
+ return n.isSelected ? ((_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
606
608
  var _n$discount;
607
609
  return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
608
- }) : [];
610
+ })) || n.product_id : [];
609
611
  }).flat();
610
612
  newDiscountList.forEach(function (item) {
611
613
  var _item$applicableProdu;
@@ -12,6 +12,13 @@ export declare const isAllNormalProduct: (items: any[]) => boolean;
12
12
  * @returns
13
13
  */
14
14
  export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
15
+ export declare const getDiscountListAmountTotal: (discount: Discount[]) => any;
16
+ /**
17
+ * 获取折扣金额 计算每个折扣的金额
18
+ * @param discount
19
+ * @returns
20
+ */
21
+ export declare const getDiscountListAmount: (discount: Discount[]) => any;
15
22
  export interface ScheduleItem {
16
23
  id: number;
17
24
  name: string | {
@@ -37,7 +37,7 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
37
37
  var _discount$metadata;
38
38
  // 商品券
39
39
  if (discount.tag === 'good_pass') {
40
- return new Decimal(total).minus(new Decimal(price || 0)).toNumber();
40
+ return new Decimal(price).minus(new Decimal(price || 0)).toNumber();
41
41
  }
42
42
 
43
43
  // 判断是否是固定金额
@@ -45,11 +45,27 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
45
45
 
46
46
  // 固定金额 小于0时返回0
47
47
  if (isFixedAmount) {
48
- return Math.max(new Decimal(total).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
48
+ return Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
49
49
  }
50
50
 
51
51
  // 百分比:根据折扣卡金额计算
52
- return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
52
+ return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
53
+ };
54
+ export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
55
+ return discount.reduce(function (acc, cur) {
56
+ return new Decimal(acc).plus(new Decimal(cur.num || 1).mul(new Decimal(cur.amount || 0))).toNumber();
57
+ }, new Decimal(0));
58
+ };
59
+
60
+ /**
61
+ * 获取折扣金额 计算每个折扣的金额
62
+ * @param discount
63
+ * @returns
64
+ */
65
+ export var getDiscountListAmount = function getDiscountListAmount(discount) {
66
+ return discount.reduce(function (acc, cur) {
67
+ return new Decimal(acc).plus(new Decimal(cur.amount || 0)).toNumber();
68
+ }, new Decimal(0));
53
69
  };
54
70
 
55
71
  // 日程项接口定义
@@ -172,16 +172,6 @@ var formatProductToCartItemOrigin = (params) => {
172
172
  var getProductTotalPrice = (params) => {
173
173
  const { product, bundle, options, discounts } = params;
174
174
  let price = Number(product.price);
175
- if (bundle == null ? void 0 : bundle.length) {
176
- price = bundle.reduce((accumulator, currentValue) => {
177
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
178
- }, price);
179
- }
180
- if (options == null ? void 0 : options.length) {
181
- price = options.reduce((accumulator, currentValue) => {
182
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
183
- }, price);
184
- }
185
175
  if (discounts == null ? void 0 : discounts.length) {
186
176
  discounts.forEach((currentValue) => {
187
177
  var _a;
@@ -196,6 +186,16 @@ var getProductTotalPrice = (params) => {
196
186
  }
197
187
  });
198
188
  }
189
+ if (bundle == null ? void 0 : bundle.length) {
190
+ price = bundle.reduce((accumulator, currentValue) => {
191
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
192
+ }, price);
193
+ }
194
+ if (options == null ? void 0 : options.length) {
195
+ price = options.reduce((accumulator, currentValue) => {
196
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
197
+ }, price);
198
+ }
199
199
  return price;
200
200
  };
201
201
  var getProductOriginTotalPrice = (params) => {
@@ -254,9 +254,15 @@ var formatBundle = (bundle) => {
254
254
  price: item == null ? void 0 : item.price,
255
255
  total: item == null ? void 0 : item.price,
256
256
  price_type: item == null ? void 0 : item.price_type,
257
+ original_price: item == null ? void 0 : item.original_price,
258
+ original_total: item == null ? void 0 : item.original_total,
259
+ price_type_ext: item == null ? void 0 : item.price_type_ext,
257
260
  bundle_sum_price: item == null ? void 0 : item.bundle_sum_price,
258
261
  bundle_sum_type: item == null ? void 0 : item.bundle_sum_type,
259
- options: formatOptions(item == null ? void 0 : item.option)
262
+ options: formatOptions(item == null ? void 0 : item.option),
263
+ _bundle_product_id: item._bundle_product_id,
264
+ discount_list: item.discount_list,
265
+ originBundleItem: item.originBundleItem || item
260
266
  };
261
267
  });
262
268
  };
@@ -264,15 +270,24 @@ var formatBundleToOrigin = (bundle) => {
264
270
  if (!(bundle == null ? void 0 : bundle.length))
265
271
  return [];
266
272
  return bundle.map((d) => {
273
+ const getBundleValueByKey = (key) => {
274
+ var _a;
275
+ return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
276
+ };
267
277
  return {
268
- bundle_group_id: d.group_id,
278
+ bundle_group_id: getBundleValueByKey("group_id"),
269
279
  bundle_id: d.id,
270
- bundle_product_id: (d == null ? void 0 : d._bundle_product_id) || (d == null ? void 0 : d.product_id),
271
- bundle_variant_id: d.bundle_variant_id,
280
+ bundle_product_id: getBundleValueByKey("_bundle_product_id") || getBundleValueByKey("product_id"),
281
+ bundle_variant_id: getBundleValueByKey("bundle_variant_id"),
272
282
  num: d.num,
273
- extension_id: d.extension_id,
274
- extension_type: d.extension_type,
275
- option: formatOptionsToOrigin(d.option)
283
+ extension_id: getBundleValueByKey("extension_id"),
284
+ extension_type: getBundleValueByKey("extension_type"),
285
+ option: formatOptionsToOrigin(getBundleValueByKey("option")),
286
+ discount_list: d.discount_list,
287
+ "bundle_selling_price": d == null ? void 0 : d.price,
288
+ metadata: {
289
+ custom_product_bundle_map_id: d._id
290
+ }
276
291
  };
277
292
  });
278
293
  };
@@ -15,11 +15,19 @@ interface Formattitle {
15
15
  'zh-CN'?: any;
16
16
  'zh-HK'?: any;
17
17
  }
18
+ interface PackageSubItemUsageRules {
19
+ type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
+ custom_usage_rules: {
21
+ types: ("standalone_product" | "package_sub_item")[];
22
+ package_sub_item_rules: ("original_price" | "markup_price")[];
23
+ };
24
+ }
18
25
  interface Limitedrelationproductdata {
19
26
  id: number;
20
27
  type: 'product_all' | 'products' | 'product_collection';
21
28
  product_ids: number[];
22
29
  product_collection_id: number[];
30
+ package_sub_item_usage_rules?: PackageSubItemUsageRules;
23
31
  }
24
32
  interface ApplicableProductDetails {
25
33
  amount: string;
@@ -73,6 +81,7 @@ export interface Discount {
73
81
  metadata?: {
74
82
  discount_card_type?: 'fixed_amount' | 'percent';
75
83
  validity_type?: "custom_schedule_validity" | "fixed_validity";
84
+ custom_product_bundle_map_id?: string;
76
85
  };
77
86
  product: Product;
78
87
  type: "product" | 'good_pass';
@@ -102,6 +111,7 @@ export interface Discount {
102
111
  custom_schedule_snapshot?: {
103
112
  data: any[];
104
113
  };
114
+ num?: number;
105
115
  }
106
116
  export interface DiscountState {
107
117
  discountList: Discount[];
@@ -116,6 +116,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
116
116
  item._origin.duration = duration;
117
117
  item._origin.sub_type = durationType;
118
118
  }
119
+ const discountList = (0, import_utils.getAllDiscountList)(item);
120
+ item._origin.product.discount_list = discountList;
119
121
  if ((0, import_utils2.isNormalProduct)(item._origin)) {
120
122
  order.relation_products.push(item._origin.product);
121
123
  const relationForms = item._origin.relation_forms || [];
@@ -20,3 +20,4 @@ export declare const mergeRelationForms: (relationForms: {
20
20
  form_id: number;
21
21
  form_record_ids: number[];
22
22
  }[];
23
+ export declare const getAllDiscountList: (cartItem: CartItem) => any;
@@ -30,6 +30,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
32
  generateDuration: () => generateDuration,
33
+ getAllDiscountList: () => getAllDiscountList,
33
34
  mergeRelationForms: () => mergeRelationForms
34
35
  });
35
36
  module.exports = __toCommonJS(utils_exports);
@@ -55,8 +56,18 @@ var mergeRelationForms = (relationForms) => {
55
56
  }, {})
56
57
  ).filter((item) => item.form_record_ids.length > 0);
57
58
  };
59
+ var getAllDiscountList = (cartItem) => {
60
+ var _a, _b, _c, _d;
61
+ let discountList = ((_b = (_a = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _a.product) == null ? void 0 : _b.discount_list) || [];
62
+ (((_d = (_c = cartItem == null ? void 0 : cartItem._origin) == null ? void 0 : _c.product) == null ? void 0 : _d.product_bundle) || []).forEach((item) => {
63
+ discountList = [...discountList, ...item.discount_list];
64
+ item.discount_list = void 0;
65
+ });
66
+ return discountList;
67
+ };
58
68
  // Annotate the CommonJS export names for ESM import in node:
59
69
  0 && (module.exports = {
60
70
  generateDuration,
71
+ getAllDiscountList,
61
72
  mergeRelationForms
62
73
  });
@@ -49,5 +49,5 @@ export declare class Product extends BaseModule implements Module {
49
49
  getCategories(): ProductCategory[];
50
50
  setOtherParams(key: string, value: any): void;
51
51
  getOtherParams(): any;
52
- getProductType(): "duration" | "session" | "normal";
52
+ getProductType(): "normal" | "duration" | "session";
53
53
  }
@@ -30,6 +30,13 @@ export declare class RulesModule extends BaseModule implements Module, RulesModu
30
30
  selectedList?: SetDiscountSelectedParams[];
31
31
  scan?: boolean;
32
32
  }): DiscountResult;
33
+ /**
34
+ * 检查优惠是否符合 PackageSubItemUsageRules 配置
35
+ * @param discount 优惠券
36
+ * @param flatItem 扁平化后的商品项(可能是主商品或bundle子商品)
37
+ * @returns 是否可用
38
+ */
39
+ private checkPackageSubItemUsageRules;
33
40
  destroy(): Promise<void>;
34
41
  clear(): Promise<void>;
35
42
  }