@pisell/pisellos 1.0.76 → 1.0.78

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 {};
@@ -3160,7 +3160,9 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
3160
3160
  var product = _ref13.product,
3161
3161
  date = _ref13.date,
3162
3162
  account = _ref13.account;
3163
- var cartItems = cloneDeep(this.store.cart.getItems());
3163
+ var cartItems = this.store.cart.getItems().filter(function (item) {
3164
+ return !isNormalProduct(item._productOrigin);
3165
+ });
3164
3166
 
3165
3167
  // 将 ProductData 转换为 CartItem 但不真正添加到购物车
3166
3168
  var currentCartItem = this.convertProductToCartItem({
@@ -495,12 +495,13 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
495
495
  return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
496
496
  });
497
497
  if (index !== -1) {
498
+ var _discount$metadata;
498
499
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
499
500
  amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
500
- 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()
501
+ 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()
501
502
  });
502
503
  } else {
503
- var _discount$discount2, _discount$discount3, _discount$discount4;
504
+ var _discount$metadata2, _discount$discount2, _discount$discount3, _discount$discount4;
504
505
  if (discount.type && !discount.tag) {
505
506
  discount.tag = discount.type;
506
507
  }
@@ -508,7 +509,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
508
509
  name: discount.name || discount.discount.title.auto,
509
510
  isEditMode: true,
510
511
  limited_relation_product_data: {},
511
- savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.num) || 1),
512
+ 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),
512
513
  isAvailable: true,
513
514
  id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
514
515
  format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
@@ -529,6 +530,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
529
530
  var targetProduct = productList.find(function (n) {
530
531
  return n.id === id;
531
532
  });
533
+ if (!targetProduct) return false;
532
534
  var product = (_this3$hooks2 = _this3.hooks) === null || _this3$hooks2 === void 0 ? void 0 : _this3$hooks2.getProduct(targetProduct);
533
535
  // 如果 product.total 是小于等于0有可能是她已经用过商品券或者折扣卡导致的,或者本身就是负数价格,所以此时还需要判断 origin_total 是否小于等于0
534
536
  // 如果 product.vouchersApplicable是布尔值,并且是 false,也当做免费商品处理,此商品不可用优惠券或折扣卡
@@ -536,10 +538,10 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
536
538
  };
537
539
  var allUsedProductIds = newDiscountList.map(function (n) {
538
540
  var _n$appliedProductDeta;
539
- return n.isSelected ? (_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
541
+ return n.isSelected ? ((_n$appliedProductDeta = n.appliedProductDetails) === null || _n$appliedProductDeta === void 0 ? void 0 : _n$appliedProductDeta.map(function (n) {
540
542
  var _n$discount;
541
543
  return (_n$discount = n.discount) === null || _n$discount === void 0 ? void 0 : _n$discount.product_id;
542
- }) : [];
544
+ })) || n.product_id : [];
543
545
  }).flat();
544
546
  newDiscountList.forEach(function (item) {
545
547
  var _item$applicableProdu;
@@ -10,3 +10,10 @@ export declare const uniqueById: <T>(arr: T[], key?: string) => T[];
10
10
  * @returns
11
11
  */
12
12
  export declare const getDiscountAmount: (discount: Discount, total: number, price: number) => number;
13
+ export declare const getDiscountListAmountTotal: (discount: Discount[]) => any;
14
+ /**
15
+ * 获取折扣金额 计算每个折扣的金额
16
+ * @param discount
17
+ * @returns
18
+ */
19
+ export declare const getDiscountListAmount: (discount: Discount[]) => any;
@@ -20,7 +20,7 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
20
20
  var _discount$metadata;
21
21
  // 商品券
22
22
  if (discount.tag === 'good_pass') {
23
- return new Decimal(total).minus(new Decimal(price || 0)).toNumber();
23
+ return new Decimal(price).minus(new Decimal(price || 0)).toNumber();
24
24
  }
25
25
 
26
26
  // 判断是否是固定金额
@@ -28,9 +28,25 @@ export var getDiscountAmount = function getDiscountAmount(discount, total, price
28
28
 
29
29
  // 固定金额 小于0时返回0
30
30
  if (isFixedAmount) {
31
- return Math.max(new Decimal(total).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
31
+ return Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
32
32
  }
33
33
 
34
34
  // 百分比:根据折扣卡金额计算
35
- return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(total)).toNumber();
35
+ return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
36
+ };
37
+ export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
38
+ return discount.reduce(function (acc, cur) {
39
+ return new Decimal(acc).plus(new Decimal(cur.num || 1).mul(new Decimal(cur.amount || 0))).toNumber();
40
+ }, new Decimal(0));
41
+ };
42
+
43
+ /**
44
+ * 获取折扣金额 计算每个折扣的金额
45
+ * @param discount
46
+ * @returns
47
+ */
48
+ export var getDiscountListAmount = function getDiscountListAmount(discount) {
49
+ return discount.reduce(function (acc, cur) {
50
+ return new Decimal(acc).plus(new Decimal(cur.amount || 0)).toNumber();
51
+ }, new Decimal(0));
36
52
  };
@@ -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,16 @@ 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
+ rules: ("original_price" | "markup_price")[];
21
+ }
18
22
  interface Limitedrelationproductdata {
19
23
  id: number;
20
24
  type: 'product_all' | 'products' | 'product_collection';
21
25
  product_ids: number[];
22
26
  product_collection_id: number[];
27
+ package_sub_item_usage_rules?: PackageSubItemUsageRules;
23
28
  }
24
29
  interface ApplicableProductDetails {
25
30
  amount: string;
@@ -72,6 +77,7 @@ export interface Discount {
72
77
  format_title: Formattitle;
73
78
  metadata?: {
74
79
  discount_card_type?: 'fixed_amount' | 'percent';
80
+ custom_product_bundle_map_id?: string;
75
81
  };
76
82
  product: Product;
77
83
  type: "product" | 'good_pass';
@@ -98,6 +104,7 @@ export interface Discount {
98
104
  week_order_behavior_count?: number;
99
105
  month_order_behavior_count?: number;
100
106
  customer_order_behavior_count?: number;
107
+ num?: number;
101
108
  }
102
109
  export interface DiscountState {
103
110
  discountList: Discount[];
@@ -115,6 +115,8 @@ var OrderModule = class extends import_BaseModule.BaseModule {
115
115
  item._origin.duration = duration;
116
116
  item._origin.sub_type = durationType;
117
117
  }
118
+ const discountList = (0, import_utils.getAllDiscountList)(item);
119
+ item._origin.product.discount_list = discountList;
118
120
  if ((0, import_utils2.isNormalProduct)(item._origin)) {
119
121
  order.relation_products.push(item._origin.product);
120
122
  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
  }