@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 {};
@@ -122,12 +122,6 @@ var BookingTicketImpl = class extends import_BaseModule.BaseModule {
122
122
  throw error;
123
123
  }
124
124
  }
125
- /**
126
- * 初始化外设扫码结果监听
127
- */
128
- initPeripheralsListener() {
129
- this.scan.initPeripheralsListener();
130
- }
131
125
  /**
132
126
  * 获取商品列表(不加载到模块中)
133
127
  * @returns 商品列表
@@ -342,7 +342,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
342
342
  if (item.booking_id) {
343
343
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
344
344
  (item.discount_list || []).forEach((discount) => {
345
- var _a3, _b, _c;
345
+ var _a3, _b, _c, _d, _e;
346
346
  if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
347
347
  const index = editModeDiscountList.findIndex((n) => {
348
348
  var _a4;
@@ -352,7 +352,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
352
352
  editModeDiscountList[index] = {
353
353
  ...editModeDiscountList[index],
354
354
  amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
355
- savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
355
+ savedAmount: new import_decimal.default(discount.amount || 0).times(((_a3 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a3.num) || (product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
356
356
  };
357
357
  } else {
358
358
  if (discount.type && !discount.tag) {
@@ -363,13 +363,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
363
363
  name: discount.name || discount.discount.title.auto,
364
364
  isEditMode: true,
365
365
  limited_relation_product_data: {},
366
- savedAmount: discount.amount * ((product == null ? void 0 : product.num) || 1),
366
+ savedAmount: discount.amount * (((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.num) || (product == null ? void 0 : product.num) || 1),
367
367
  isAvailable: true,
368
- id: ((_a3 = discount.discount) == null ? void 0 : _a3.resource_id) || discount.id,
369
- format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
368
+ id: ((_c = discount.discount) == null ? void 0 : _c.resource_id) || discount.id,
369
+ format_title: ((_d = discount.discount) == null ? void 0 : _d.title) || discount.format_title,
370
370
  isDisabled: true,
371
371
  isSelected: true,
372
- product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
372
+ product_id: ((_e = discount.discount) == null ? void 0 : _e.product_id) || discount.product_id
373
373
  });
374
374
  }
375
375
  }
@@ -383,15 +383,17 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
383
383
  const isProductFree = (id) => {
384
384
  var _a2;
385
385
  const targetProduct = productList.find((n) => n.id === id);
386
+ if (!targetProduct)
387
+ return false;
386
388
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(targetProduct);
387
389
  return Number(product == null ? void 0 : product.total) <= 0 && (Number(product == null ? void 0 : product.origin_total) <= 0 || !(product == null ? void 0 : product.origin_total)) || (0, import_lodash_es.isBoolean)(product == null ? void 0 : product.vouchersApplicable) && !(product == null ? void 0 : product.vouchersApplicable);
388
390
  };
389
391
  const allUsedProductIds = newDiscountList.map((n) => {
390
392
  var _a2;
391
- return n.isSelected ? (_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
393
+ return n.isSelected ? ((_a2 = n.appliedProductDetails) == null ? void 0 : _a2.map((n2) => {
392
394
  var _a3;
393
395
  return (_a3 = n2.discount) == null ? void 0 : _a3.product_id;
394
- }) : [];
396
+ })) || n.product_id : [];
395
397
  }).flat();
396
398
  newDiscountList.forEach((item) => {
397
399
  var _a2;
@@ -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 | {
@@ -32,6 +32,8 @@ __export(utils_exports, {
32
32
  filterDiscountListByBookingTime: () => filterDiscountListByBookingTime,
33
33
  getDateIsInSchedule: () => getDateIsInSchedule,
34
34
  getDiscountAmount: () => getDiscountAmount,
35
+ getDiscountListAmount: () => getDiscountListAmount,
36
+ getDiscountListAmountTotal: () => getDiscountListAmountTotal,
35
37
  isAllNormalProduct: () => isAllNormalProduct,
36
38
  isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
37
39
  uniqueById: () => uniqueById
@@ -53,13 +55,23 @@ var isAllNormalProduct = (items) => {
53
55
  var getDiscountAmount = (discount, total, price) => {
54
56
  var _a;
55
57
  if (discount.tag === "good_pass") {
56
- return new import_decimal.default(total).minus(new import_decimal.default(price || 0)).toNumber();
58
+ return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
57
59
  }
58
60
  const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
59
61
  if (isFixedAmount) {
60
- return Math.max(new import_decimal.default(total).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
62
+ return Math.max(new import_decimal.default(price).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
61
63
  }
62
- return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(total)).toNumber();
64
+ return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
65
+ };
66
+ var getDiscountListAmountTotal = (discount) => {
67
+ return discount.reduce((acc, cur) => {
68
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.num || 1).mul(new import_decimal.default(cur.amount || 0))).toNumber();
69
+ }, new import_decimal.default(0));
70
+ };
71
+ var getDiscountListAmount = (discount) => {
72
+ return discount.reduce((acc, cur) => {
73
+ return new import_decimal.default(acc).plus(new import_decimal.default(cur.amount || 0)).toNumber();
74
+ }, new import_decimal.default(0));
63
75
  };
64
76
  var getDateIsInSchedule = (dateTime, scheduleList) => {
65
77
  if (!dateTime || !scheduleList || scheduleList.length === 0) {
@@ -222,6 +234,8 @@ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
222
234
  filterDiscountListByBookingTime,
223
235
  getDateIsInSchedule,
224
236
  getDiscountAmount,
237
+ getDiscountListAmount,
238
+ getDiscountListAmountTotal,
225
239
  isAllNormalProduct,
226
240
  isNormalProductByDurationSchedule,
227
241
  uniqueById
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.338",
4
+ "version": "0.0.340",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",