@pisell/pisellos 2.1.46 → 2.1.48

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.
@@ -174,6 +174,24 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
174
174
  discounts = params.discounts;
175
175
  // const num = params.num || 1;
176
176
  var price = Number(product.price);
177
+
178
+ // 如果商品有折扣,则计算折扣
179
+ if (discounts !== null && discounts !== void 0 && discounts.length) {
180
+ discounts.forEach(function (currentValue) {
181
+ var _currentValue$discoun;
182
+ // 不是商品券则代表折扣卡,计算打折后的价格
183
+ // 一个商品折扣卡只能存在于一张
184
+ // if (currentValue.type !== 'good_pass') {
185
+ price = getDiscountAmount({
186
+ tag: currentValue.type,
187
+ par_value: currentValue.discount.percent,
188
+ metadata: {
189
+ discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
190
+ }
191
+ }, price, price);
192
+ // }
193
+ });
194
+ }
177
195
  if (bundle !== null && bundle !== void 0 && bundle.length) {
178
196
  price = bundle.reduce(function (accumulator, currentValue) {
179
197
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
@@ -186,25 +204,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
186
204
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
187
205
  }, price);
188
206
  }
189
-
190
- // 如果商品有折扣,则计算折扣
191
- if (discounts !== null && discounts !== void 0 && discounts.length) {
192
- discounts.forEach(function (currentValue) {
193
- // 不是商品券则代表折扣卡,计算打折后的价格
194
- // 一个商品折扣卡只能存在于一张
195
- if (currentValue.type !== 'good_pass') {
196
- var _currentValue$discoun;
197
- price = getDiscountAmount({
198
- tag: currentValue.type,
199
- par_value: currentValue.discount.percent,
200
- metadata: {
201
- discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
202
- }
203
- }, price, price);
204
- }
205
- });
206
- }
207
- return price;
207
+ return Math.max(0, price);
208
208
  };
209
209
 
210
210
  /**
@@ -284,24 +284,39 @@ export var formatBundle = function formatBundle(bundle) {
284
284
  price: item === null || item === void 0 ? void 0 : item.price,
285
285
  total: item === null || item === void 0 ? void 0 : item.price,
286
286
  price_type: item === null || item === void 0 ? void 0 : item.price_type,
287
+ original_price: item === null || item === void 0 ? void 0 : item.original_price,
288
+ original_total: item === null || item === void 0 ? void 0 : item.original_total,
289
+ price_type_ext: item === null || item === void 0 ? void 0 : item.price_type_ext,
287
290
  bundle_sum_price: item === null || item === void 0 ? void 0 : item.bundle_sum_price,
288
291
  bundle_sum_type: item === null || item === void 0 ? void 0 : item.bundle_sum_type,
289
- options: formatOptions(item === null || item === void 0 ? void 0 : item.option)
292
+ options: formatOptions(item === null || item === void 0 ? void 0 : item.option),
293
+ _bundle_product_id: item._bundle_product_id,
294
+ discount_list: item.discount_list,
295
+ originBundleItem: item.originBundleItem || item
290
296
  };
291
297
  });
292
298
  };
293
299
  export var formatBundleToOrigin = function formatBundleToOrigin(bundle) {
294
300
  if (!(bundle !== null && bundle !== void 0 && bundle.length)) return [];
295
301
  return bundle.map(function (d) {
302
+ var getBundleValueByKey = function getBundleValueByKey(key) {
303
+ var _d$originBundleItem;
304
+ return (d === null || d === void 0 ? void 0 : d[key]) || (d === null || d === void 0 || (_d$originBundleItem = d.originBundleItem) === null || _d$originBundleItem === void 0 ? void 0 : _d$originBundleItem[key]);
305
+ };
296
306
  return {
297
- bundle_group_id: d.group_id,
307
+ bundle_group_id: getBundleValueByKey('group_id'),
298
308
  bundle_id: d.id,
299
- bundle_product_id: (d === null || d === void 0 ? void 0 : d._bundle_product_id) || (d === null || d === void 0 ? void 0 : d.product_id),
300
- bundle_variant_id: d.bundle_variant_id,
309
+ bundle_product_id: getBundleValueByKey('_bundle_product_id') || getBundleValueByKey('product_id'),
310
+ bundle_variant_id: getBundleValueByKey('bundle_variant_id'),
301
311
  num: d.num,
302
- extension_id: d.extension_id,
303
- extension_type: d.extension_type,
304
- option: formatOptionsToOrigin(d.option)
312
+ extension_id: getBundleValueByKey('extension_id'),
313
+ extension_type: getBundleValueByKey('extension_type'),
314
+ option: formatOptionsToOrigin(getBundleValueByKey('option')),
315
+ discount_list: d.discount_list,
316
+ "bundle_selling_price": d === null || d === void 0 ? void 0 : d.price,
317
+ metadata: {
318
+ custom_product_bundle_map_id: d._id
319
+ }
305
320
  };
306
321
  });
307
322
  };
@@ -299,7 +299,8 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
299
299
  }
300
300
  if (discount.appliedProductDetails) {
301
301
  return discount.appliedProductDetails.reduce(function (total, product) {
302
- var price = new Decimal((product === null || product === void 0 ? void 0 : product.amount) || 0).mul((product === null || product === void 0 ? void 0 : product.num) || 1);
302
+ var _product$discount;
303
+ var price = new Decimal((product === null || product === void 0 || (_product$discount = product.discount) === null || _product$discount === void 0 ? void 0 : _product$discount.fixed_amount) || 0).mul((product === null || product === void 0 ? void 0 : product._num) || 1);
303
304
  return new Decimal(total).plus(price).toNumber();
304
305
  }, 0);
305
306
  }
@@ -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;
@@ -29,12 +34,14 @@ interface ApplicableProductDetails {
29
34
  original_amount: string;
30
35
  num: number;
31
36
  discount?: {
37
+ fixed_amount?: number;
32
38
  product_id?: number;
33
39
  original_amount?: string;
34
40
  percent?: string;
35
41
  resource_id?: number;
36
42
  title?: string;
37
43
  };
44
+ _num: number;
38
45
  }
39
46
  interface UsageCreditsValue {
40
47
  total_credits: number;
@@ -72,6 +79,7 @@ export interface Discount {
72
79
  format_title: Formattitle;
73
80
  metadata?: {
74
81
  discount_card_type?: 'fixed_amount' | 'percent';
82
+ custom_product_bundle_map_id?: string;
75
83
  validity_type?: "custom_schedule_validity" | "fixed_validity";
76
84
  };
77
85
  product: Product;
@@ -102,6 +110,7 @@ export interface Discount {
102
110
  custom_schedule_snapshot?: {
103
111
  data: any[];
104
112
  };
113
+ num?: number;
105
114
  }
106
115
  export interface DiscountState {
107
116
  discountList: Discount[];
@@ -24,7 +24,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
24
24
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
25
25
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
26
26
  import { BaseModule } from "../BaseModule";
27
- import { generateDuration, mergeRelationForms } from "./utils";
27
+ import { generateDuration, getAllDiscountList, mergeRelationForms } from "./utils";
28
28
  import { isNormalProduct } from "../Product/utils";
29
29
  import dayjs from 'dayjs';
30
30
  export var OrderModule = /*#__PURE__*/function (_BaseModule) {
@@ -145,6 +145,9 @@ export var OrderModule = /*#__PURE__*/function (_BaseModule) {
145
145
  item._origin.duration = duration;
146
146
  item._origin.sub_type = durationType;
147
147
  }
148
+ var discountList = getAllDiscountList(item);
149
+ item._origin.product.discount_list = discountList;
150
+
148
151
  // 购物车是否为普通商品
149
152
  if (isNormalProduct(item._origin)) {
150
153
  var _order$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;
@@ -51,4 +51,13 @@ export var mergeRelationForms = function mergeRelationForms(relationForms) {
51
51
  }, {})).filter(function (item) {
52
52
  return item.form_record_ids.length > 0;
53
53
  }); // 过滤掉没有有效记录的表单
54
+ };
55
+ export var getAllDiscountList = function getAllDiscountList(cartItem) {
56
+ var _cartItem$_origin, _cartItem$_origin2;
57
+ var discountList = (cartItem === null || cartItem === void 0 || (_cartItem$_origin = cartItem._origin) === null || _cartItem$_origin === void 0 || (_cartItem$_origin = _cartItem$_origin.product) === null || _cartItem$_origin === void 0 ? void 0 : _cartItem$_origin.discount_list) || [];
58
+ ((cartItem === null || cartItem === void 0 || (_cartItem$_origin2 = cartItem._origin) === null || _cartItem$_origin2 === void 0 || (_cartItem$_origin2 = _cartItem$_origin2.product) === null || _cartItem$_origin2 === void 0 ? void 0 : _cartItem$_origin2.product_bundle) || []).forEach(function (item) {
59
+ discountList = [].concat(_toConsumableArray(discountList), _toConsumableArray(item.discount_list));
60
+ item.discount_list = undefined;
61
+ });
62
+ return discountList;
54
63
  };
@@ -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
  }