@pisell/pisellos 1.0.77 → 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.
@@ -174,18 +174,6 @@ 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
- if (bundle !== null && bundle !== void 0 && bundle.length) {
178
- price = bundle.reduce(function (accumulator, currentValue) {
179
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
180
- }, price);
181
- }
182
-
183
- // 单规格
184
- if (options !== null && options !== void 0 && options.length) {
185
- price = options.reduce(function (accumulator, currentValue) {
186
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
187
- }, price);
188
- }
189
177
 
190
178
  // 如果商品有折扣,则计算折扣
191
179
  if (discounts !== null && discounts !== void 0 && discounts.length) {
@@ -204,6 +192,18 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
204
192
  }
205
193
  });
206
194
  }
195
+ if (bundle !== null && bundle !== void 0 && bundle.length) {
196
+ price = bundle.reduce(function (accumulator, currentValue) {
197
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
198
+ }, price);
199
+ }
200
+
201
+ // 单规格
202
+ if (options !== null && options !== void 0 && options.length) {
203
+ price = options.reduce(function (accumulator, currentValue) {
204
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
205
+ }, price);
206
+ }
207
207
  return price;
208
208
  };
209
209
 
@@ -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
  };
@@ -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[];
@@ -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
  };
@@ -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
  }