@pisell/pisellos 2.1.64 → 2.1.66

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.
Files changed (104) hide show
  1. package/dist/index.d.ts +0 -1
  2. package/dist/index.js +0 -1
  3. package/dist/modules/Cart/types.d.ts +0 -2
  4. package/dist/modules/Cart/utils/cartProduct.js +21 -15
  5. package/dist/modules/Discount/index.js +2 -2
  6. package/dist/modules/Discount/types.d.ts +9 -15
  7. package/dist/modules/Payment/index.d.ts +1 -2
  8. package/dist/modules/Payment/index.js +7 -10
  9. package/dist/modules/Payment/utils.js +0 -3
  10. package/dist/modules/Payment/walletpass.d.ts +0 -23
  11. package/dist/modules/Payment/walletpass.js +95 -191
  12. package/dist/modules/Product/index.d.ts +1 -1
  13. package/dist/modules/Rules/index.d.ts +3 -8
  14. package/dist/modules/Rules/index.js +408 -240
  15. package/dist/modules/Rules/types.d.ts +0 -1
  16. package/dist/modules/Summary/types.d.ts +0 -2
  17. package/dist/modules/Summary/utils.d.ts +5 -6
  18. package/dist/modules/Summary/utils.js +34 -20
  19. package/dist/plugins/window.d.ts +0 -2
  20. package/dist/solution/BookingByStep/index.d.ts +1 -2
  21. package/dist/solution/BookingByStep/index.js +2 -1
  22. package/dist/solution/Checkout/index.js +0 -2
  23. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  24. package/dist/solution/ShopDiscount/index.js +5 -14
  25. package/dist/solution/ShopDiscount/types.d.ts +0 -1
  26. package/dist/solution/ShopDiscount/utils.d.ts +24 -0
  27. package/dist/solution/ShopDiscount/utils.js +145 -26
  28. package/lib/index.d.ts +0 -1
  29. package/lib/index.js +1 -3
  30. package/lib/modules/Cart/types.d.ts +0 -2
  31. package/lib/modules/Cart/utils/cartProduct.js +22 -15
  32. package/lib/modules/Discount/index.js +2 -2
  33. package/lib/modules/Discount/types.d.ts +9 -15
  34. package/lib/modules/Payment/index.d.ts +1 -2
  35. package/lib/modules/Payment/index.js +0 -1
  36. package/lib/modules/Payment/utils.js +0 -3
  37. package/lib/modules/Payment/walletpass.d.ts +0 -23
  38. package/lib/modules/Payment/walletpass.js +17 -94
  39. package/lib/modules/Product/index.d.ts +1 -1
  40. package/lib/modules/Rules/index.d.ts +3 -8
  41. package/lib/modules/Rules/index.js +441 -399
  42. package/lib/modules/Rules/types.d.ts +0 -1
  43. package/lib/modules/Summary/types.d.ts +0 -2
  44. package/lib/modules/Summary/utils.d.ts +5 -6
  45. package/lib/modules/Summary/utils.js +27 -18
  46. package/lib/plugins/window.d.ts +0 -2
  47. package/lib/solution/BookingByStep/index.d.ts +1 -2
  48. package/lib/solution/BookingByStep/index.js +1 -1
  49. package/lib/solution/BookingTicket/index.js +6 -0
  50. package/lib/solution/Checkout/index.js +0 -2
  51. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  52. package/lib/solution/ShopDiscount/index.js +6 -12
  53. package/lib/solution/ShopDiscount/types.d.ts +0 -1
  54. package/lib/solution/ShopDiscount/utils.d.ts +24 -0
  55. package/lib/solution/ShopDiscount/utils.js +93 -10
  56. package/package.json +1 -1
  57. package/dist/model/index.d.ts +0 -1
  58. package/dist/model/index.js +0 -1
  59. package/dist/model/strategy/adapter/index.d.ts +0 -3
  60. package/dist/model/strategy/adapter/index.js +0 -4
  61. package/dist/model/strategy/adapter/type.d.ts +0 -28
  62. package/dist/model/strategy/adapter/type.js +0 -1
  63. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  64. package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -497
  65. package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
  66. package/dist/model/strategy/adapter/walletPass/example.js +0 -258
  67. package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
  68. package/dist/model/strategy/adapter/walletPass/index.js +0 -182
  69. package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  70. package/dist/model/strategy/adapter/walletPass/locales.js +0 -23
  71. package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -163
  72. package/dist/model/strategy/adapter/walletPass/type.js +0 -1
  73. package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  74. package/dist/model/strategy/adapter/walletPass/utils.js +0 -965
  75. package/dist/model/strategy/index.d.ts +0 -94
  76. package/dist/model/strategy/index.js +0 -551
  77. package/dist/model/strategy/strategy-example.d.ts +0 -5
  78. package/dist/model/strategy/strategy-example.js +0 -331
  79. package/dist/model/strategy/type.d.ts +0 -228
  80. package/dist/model/strategy/type.js +0 -94
  81. package/lib/model/index.d.ts +0 -1
  82. package/lib/model/index.js +0 -23
  83. package/lib/model/strategy/adapter/index.d.ts +0 -3
  84. package/lib/model/strategy/adapter/index.js +0 -45
  85. package/lib/model/strategy/adapter/type.d.ts +0 -28
  86. package/lib/model/strategy/adapter/type.js +0 -17
  87. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
  88. package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -421
  89. package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
  90. package/lib/model/strategy/adapter/walletPass/example.js +0 -207
  91. package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
  92. package/lib/model/strategy/adapter/walletPass/index.js +0 -142
  93. package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
  94. package/lib/model/strategy/adapter/walletPass/locales.js +0 -51
  95. package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -163
  96. package/lib/model/strategy/adapter/walletPass/type.js +0 -17
  97. package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
  98. package/lib/model/strategy/adapter/walletPass/utils.js +0 -660
  99. package/lib/model/strategy/index.d.ts +0 -94
  100. package/lib/model/strategy/index.js +0 -413
  101. package/lib/model/strategy/strategy-example.d.ts +0 -5
  102. package/lib/model/strategy/strategy-example.js +0 -318
  103. package/lib/model/strategy/type.d.ts +0 -228
  104. package/lib/model/strategy/type.js +0 -44
@@ -25,7 +25,6 @@ export interface RulesModuleAPI {
25
25
  holders: {
26
26
  form_record_id: number;
27
27
  }[];
28
- orderTotalAmount: number;
29
28
  isFormSubject: boolean;
30
29
  }) => DiscountResult;
31
30
  }
@@ -5,8 +5,6 @@ export interface ISummaryState {
5
5
  subtotal: string | number;
6
6
  /** 最终总价 */
7
7
  total: string | number;
8
- /** 最终原始价格 不包含折扣卡商品券折扣 */
9
- originTotal: string | number;
10
8
  /** 税率标题 */
11
9
  taxTitle?: string;
12
10
  /** 商品总费率 */
@@ -3,17 +3,16 @@ import { CartItem } from '../Cart/types';
3
3
  import { ISummaryState } from './types';
4
4
  export declare const calculatePriceDetails: (shopInfo: any, items: CartItem[]) => ISummaryState['summary'];
5
5
  /**
6
- * 计算商品小计(不含其他费用)
7
- * @param items - 购物车商品数组
8
- * @returns 商品总价字符串,保留2位小数
6
+ * 获取子商品折扣信息
7
+ * @param item
9
8
  */
10
- export declare const calculateSubtotal: (items: CartItem[]) => string;
9
+ export declare const getBundleDiscountList: (bundle: any[]) => any[];
11
10
  /**
12
- * 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
11
+ * 计算商品小计(不含其他费用)
13
12
  * @param items - 购物车商品数组
14
13
  * @returns 商品总价字符串,保留2位小数
15
14
  */
16
- export declare const calculateOriginSubtotal: (items: CartItem[]) => string;
15
+ export declare const calculateSubtotal: (items: CartItem[]) => string;
17
16
  /**
18
17
  * @title: 单个商品的税费
19
18
  * @description:
@@ -30,47 +30,56 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
32
  calculateDeposit: () => calculateDeposit,
33
- calculateOriginSubtotal: () => calculateOriginSubtotal,
34
33
  calculatePriceDetails: () => calculatePriceDetails,
35
34
  calculateSubtotal: () => calculateSubtotal,
36
- calculateTaxFee: () => calculateTaxFee
35
+ calculateTaxFee: () => calculateTaxFee,
36
+ getBundleDiscountList: () => getBundleDiscountList
37
37
  });
38
38
  module.exports = __toCommonJS(utils_exports);
39
39
  var import_decimal = __toESM(require("decimal.js"));
40
40
  var calculatePriceDetails = (shopInfo, items) => {
41
41
  const subtotal = new import_decimal.default(calculateSubtotal(items));
42
- const subOriginTotal = new import_decimal.default(calculateOriginSubtotal(items));
43
42
  const totalTaxFee = new import_decimal.default(calculateTaxFee(shopInfo, items));
44
43
  const total = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subtotal : subtotal.plus(totalTaxFee);
45
- const originTotal = (shopInfo == null ? void 0 : shopInfo.is_price_include_tax) ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
46
44
  const deposit = calculateDeposit(items);
47
45
  return {
48
46
  subtotal: subtotal.toFixed(2),
49
47
  total: total.toFixed(2),
50
- originTotal: originTotal.toFixed(2),
51
48
  taxTitle: shopInfo == null ? void 0 : shopInfo.tax_title,
52
49
  totalTaxFee: totalTaxFee.toFixed(2),
53
50
  isPriceIncludeTax: shopInfo == null ? void 0 : shopInfo.is_price_include_tax,
54
51
  deposit
55
52
  };
56
53
  };
57
- var calculateSubtotal = (items) => {
58
- if (!(items == null ? void 0 : items.length)) {
59
- return "0.00";
54
+ var getBundleDiscountList = (bundle) => {
55
+ if (!bundle) {
56
+ return [];
60
57
  }
61
- const subtotal = items.reduce((sum, item) => {
62
- const cartItemTotalPrice = new import_decimal.default(item.summaryTotal || 0);
63
- return sum.plus(cartItemTotalPrice);
64
- }, new import_decimal.default(0));
65
- return subtotal.toFixed(2);
58
+ let discountList = [];
59
+ bundle.forEach((d) => {
60
+ if (d.discount_list && Array.isArray(d.discount_list)) {
61
+ discountList.push(...d.discount_list.filter((item) => !item.id));
62
+ }
63
+ });
64
+ return discountList;
65
+ };
66
+ var getProductDiscountProductDiscountDifference = (item) => {
67
+ var _a, _b, _c, _d;
68
+ const mainDiscountList = ((_b = (_a = item._origin) == null ? void 0 : _a.product) == null ? void 0 : _b.discount_list) || [];
69
+ const bundleDiscountList = getBundleDiscountList(((_d = (_c = item._origin) == null ? void 0 : _c.product) == null ? void 0 : _d.product_bundle) || []);
70
+ const discountList = [...mainDiscountList, ...bundleDiscountList];
71
+ return discountList.reduce((pre, cur) => {
72
+ return pre + (cur.metadata.product_discount_difference || 0);
73
+ }, 0);
66
74
  };
67
- var calculateOriginSubtotal = (items) => {
75
+ var calculateSubtotal = (items) => {
68
76
  if (!(items == null ? void 0 : items.length)) {
69
77
  return "0.00";
70
78
  }
71
79
  const subtotal = items.reduce((sum, item) => {
72
- const cartItemTotalPrice = new import_decimal.default(item.summaryOriginTotal || 0);
73
- return sum.plus(cartItemTotalPrice);
80
+ const cartItemTotalPrice = new import_decimal.default(item.summaryTotal || 0);
81
+ const productDiscountProductDiscountDifference = getProductDiscountProductDiscountDifference(item);
82
+ return sum.plus(cartItemTotalPrice).sub(productDiscountProductDiscountDifference);
74
83
  }, new import_decimal.default(0));
75
84
  return subtotal.toFixed(2);
76
85
  };
@@ -115,8 +124,8 @@ var calculateDeposit = (items) => {
115
124
  // Annotate the CommonJS export names for ESM import in node:
116
125
  0 && (module.exports = {
117
126
  calculateDeposit,
118
- calculateOriginSubtotal,
119
127
  calculatePriceDetails,
120
128
  calculateSubtotal,
121
- calculateTaxFee
129
+ calculateTaxFee,
130
+ getBundleDiscountList
122
131
  });
@@ -1,4 +1,3 @@
1
- import { WalletPassEvaluator } from '../model';
2
1
  import { Plugin } from '../types';
3
2
  /**
4
3
  * WindowPlugin 接口定义
@@ -15,7 +14,6 @@ export interface WindowPlugin extends Plugin {
15
14
  document: Partial<Document>;
16
15
  history: History;
17
16
  interaction?: any;
18
- getWalletPassEvaluator?: () => WalletPassEvaluator;
19
17
  }
20
18
  /**
21
19
  * 简单的 Storage 接口实现
@@ -144,7 +144,6 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
144
144
  getSummary(): Promise<{
145
145
  subtotal: string | number;
146
146
  total: string | number;
147
- originTotal: string | number;
148
147
  taxTitle?: string | undefined;
149
148
  totalTaxFee?: string | number | undefined;
150
149
  isPriceIncludeTax?: 0 | 1 | undefined;
@@ -344,7 +343,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
344
343
  };
345
344
  setOtherData(key: string, value: any): void;
346
345
  getOtherData(key: string): any;
347
- getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
346
+ getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
348
347
  /**
349
348
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
350
349
  *
@@ -1868,7 +1868,7 @@ var BookingByStepImpl = class extends import_BaseModule.BaseModule {
1868
1868
  { start_at: m.start_at, end_at: m.end_at },
1869
1869
  { start_at: (0, import_dayjs.default)(item.start), end_at: (0, import_dayjs.default)(item.end) }
1870
1870
  )) {
1871
- mSet.set(m.id, m.pax || 1);
1871
+ mSet.set(m.id, m.pax ?? 1);
1872
1872
  }
1873
1873
  });
1874
1874
  });
@@ -122,6 +122,12 @@ 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
+ }
125
131
  /**
126
132
  * 获取商品列表(不加载到模块中)
127
133
  * @returns 商品列表
@@ -222,7 +222,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
222
222
  product_id: item.product_id,
223
223
  product_variant_id: item.product_variant_id,
224
224
  quantity: item.num,
225
- is_price_include_tax: item.is_price_include_tax,
226
225
  // 商品是否含税:1;0
227
226
  is_charge_tax: item.is_charge_tax ?? 0,
228
227
  // 若商品不含税,计算得到的税费,单位(元)
@@ -247,7 +246,6 @@ var CheckoutImpl = class extends import_BaseModule.BaseModule {
247
246
  },
248
247
  product_bundle: item.product_bundle.map((bundle) => {
249
248
  return {
250
- is_price_include_tax: item.is_price_include_tax,
251
249
  bundle_id: bundle.bundle_id,
252
250
  bundle_product_id: bundle.bundle_product_id,
253
251
  bundle_variant_id: bundle.bundle_variant_id,
@@ -21,7 +21,6 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
21
21
  getCurrentBookingTime(): string | null;
22
22
  private filterDiscountListByBookingTime;
23
23
  setCustomer(customer: Customer): Promise<void>;
24
- setOriginTotalAmount(amount: number): void;
25
24
  setHolders(holders: {
26
25
  form_record_id: number;
27
26
  }[]): void;
@@ -55,7 +55,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
55
55
  originalDiscountList: [],
56
56
  currentBookingTime: "",
57
57
  filteredDiscountList: [],
58
- orderTotalAmount: 0,
59
58
  bookingSubject: void 0
60
59
  };
61
60
  }
@@ -194,9 +193,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
194
193
  );
195
194
  }
196
195
  }
197
- setOriginTotalAmount(amount) {
198
- this.store.orderTotalAmount = amount;
199
- }
200
196
  // 设置holders
201
197
  setHolders(holders) {
202
198
  this.store.holders = holders;
@@ -217,7 +213,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
217
213
  productList,
218
214
  discountList: this.getDiscountList(),
219
215
  holders: this.store.holders || [],
220
- orderTotalAmount: this.store.orderTotalAmount || 0,
221
216
  isFormSubject: ((_a = this.store.bookingSubject) == null ? void 0 : _a.type) === "form"
222
217
  },
223
218
  options
@@ -309,7 +304,6 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
309
304
  oldDiscountList: this.getDiscountList(),
310
305
  newDiscountList: withScanList,
311
306
  holders: this.store.holders || [],
312
- orderTotalAmount: this.store.orderTotalAmount || 0,
313
307
  isFormSubject: ((_b = this.store.bookingSubject) == null ? void 0 : _b.type) === "form"
314
308
  }) || {
315
309
  isAvailable: false,
@@ -375,7 +369,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
375
369
  if (item.booking_id) {
376
370
  const product = (_a2 = this.hooks) == null ? void 0 : _a2.getProduct(item);
377
371
  (item.discount_list || []).forEach((discount) => {
378
- var _a3, _b, _c;
372
+ var _a3, _b, _c, _d, _e;
379
373
  if (discount.id && ["good_pass", "discount_card"].includes(discount.type)) {
380
374
  const index = editModeDiscountList.findIndex((n) => {
381
375
  var _a4;
@@ -385,7 +379,7 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
385
379
  editModeDiscountList[index] = {
386
380
  ...editModeDiscountList[index],
387
381
  amount: new import_decimal.default(discount.amount || 0).plus(new import_decimal.default(editModeDiscountList[index].amount || 0)).toNumber(),
388
- savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
382
+ savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(((_a3 = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a3.product_discount_difference) || 0).plus(new import_decimal.default(editModeDiscountList[index].savedAmount || 0)).toNumber()
389
383
  };
390
384
  } else {
391
385
  if (discount.type && !discount.tag) {
@@ -396,13 +390,13 @@ var ShopDiscountImpl = class extends import_BaseModule.BaseModule {
396
390
  name: discount.name || discount.discount.title.auto,
397
391
  isEditMode: true,
398
392
  limited_relation_product_data: {},
399
- savedAmount: discount.amount * ((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1),
393
+ savedAmount: new import_decimal.default(discount.amount || 0).times((product == null ? void 0 : product.quantity) || (product == null ? void 0 : product.num) || 1).plus(((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.product_discount_difference) || 0).toNumber(),
400
394
  isAvailable: true,
401
- id: ((_a3 = discount.discount) == null ? void 0 : _a3.resource_id) || discount.id,
402
- format_title: ((_b = discount.discount) == null ? void 0 : _b.title) || discount.format_title,
395
+ id: ((_c = discount.discount) == null ? void 0 : _c.resource_id) || discount.id,
396
+ format_title: ((_d = discount.discount) == null ? void 0 : _d.title) || discount.format_title,
403
397
  isDisabled: true,
404
398
  isSelected: true,
405
- product_id: ((_c = discount.discount) == null ? void 0 : _c.product_id) || discount.product_id
399
+ product_id: ((_e = discount.discount) == null ? void 0 : _e.product_id) || discount.product_id
406
400
  });
407
401
  }
408
402
  }
@@ -31,7 +31,6 @@ export interface ShopDiscountState {
31
31
  originalDiscountList: Discount[];
32
32
  currentBookingTime: string | null;
33
33
  filteredDiscountList: Discount[];
34
- orderTotalAmount?: number;
35
34
  bookingSubject?: {
36
35
  type?: 'form' | 'customer';
37
36
  [key: string]: any;
@@ -65,3 +65,27 @@ export declare const getDateIsInSchedule: (dateTime: string, scheduleList: Sched
65
65
  * @returns 过滤后的优惠券列表
66
66
  */
67
67
  export declare const filterDiscountListByBookingTime: (discountList: Discount[], bookingTime: string | null) => Discount[];
68
+ /**
69
+ * 判断是否是订单级别的固定金额折扣卡
70
+ * @param discount 折扣
71
+ * @returns 是否是订单级别的固定金额折扣卡
72
+ */
73
+ export declare const isOrderLevelFixedAmountDiscount: (discount: Discount) => boolean;
74
+ /**
75
+ * 计算订单级别固定金额折扣卡的分摊结果
76
+ * @param discount 折扣卡
77
+ * @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
78
+ * @returns 分摊结果 Map<productId, { discountAmount, difference }>
79
+ * 注意:
80
+ * - discountAmount 是单价折扣金额(不是总折扣金额)
81
+ * - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
82
+ */
83
+ export declare const calculateOrderLevelDiscountAllocation: (discount: Discount, applicableProducts: Array<{
84
+ productId: string | number;
85
+ amount: number;
86
+ quantity: number;
87
+ parentQuantity?: number;
88
+ }>) => Map<string | number, {
89
+ discountAmount: number;
90
+ difference: number;
91
+ }>;
@@ -29,6 +29,7 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
29
29
  // src/solution/ShopDiscount/utils.ts
30
30
  var utils_exports = {};
31
31
  __export(utils_exports, {
32
+ calculateOrderLevelDiscountAllocation: () => calculateOrderLevelDiscountAllocation,
32
33
  filterDiscountListByBookingTime: () => filterDiscountListByBookingTime,
33
34
  getDateIsInSchedule: () => getDateIsInSchedule,
34
35
  getDiscountAmount: () => getDiscountAmount,
@@ -36,6 +37,7 @@ __export(utils_exports, {
36
37
  getDiscountListAmountTotal: () => getDiscountListAmountTotal,
37
38
  isAllNormalProduct: () => isAllNormalProduct,
38
39
  isNormalProductByDurationSchedule: () => isNormalProductByDurationSchedule,
40
+ isOrderLevelFixedAmountDiscount: () => isOrderLevelFixedAmountDiscount,
39
41
  uniqueById: () => uniqueById
40
42
  });
41
43
  module.exports = __toCommonJS(utils_exports);
@@ -54,18 +56,14 @@ var isAllNormalProduct = (items) => {
54
56
  };
55
57
  var getDiscountAmount = (discount, total, price) => {
56
58
  var _a;
57
- let discountedPrice = 0;
58
59
  if (discount.tag === "good_pass") {
59
- discountedPrice = new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
60
- } else {
61
- const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
62
- if (isFixedAmount) {
63
- discountedPrice = Math.max(new import_decimal.default(price).minus(new import_decimal.default(discount.par_value || 0)).toNumber(), 0);
64
- } else {
65
- discountedPrice = new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
66
- }
60
+ return new import_decimal.default(price).minus(new import_decimal.default(price || 0)).toNumber();
67
61
  }
68
- return discountedPrice;
62
+ const isFixedAmount = ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount";
63
+ if (isFixedAmount) {
64
+ return Math.max(new import_decimal.default(price).minus(new import_decimal.default((discount.amount ?? discount.par_value) || 0)).toNumber(), 0);
65
+ }
66
+ return new import_decimal.default(100).minus(discount.par_value || 0).div(100).mul(new import_decimal.default(price)).toNumber();
69
67
  };
70
68
  var getDiscountListAmountTotal = (discount) => {
71
69
  return discount.reduce((acc, cur) => {
@@ -310,8 +308,92 @@ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
310
308
  }
311
309
  });
312
310
  };
311
+ var isOrderLevelFixedAmountDiscount = (discount) => {
312
+ var _a, _b;
313
+ return discount.tag === "product_discount_card" && ((_a = discount == null ? void 0 : discount.metadata) == null ? void 0 : _a.discount_card_type) === "fixed_amount" && ((_b = discount == null ? void 0 : discount.metadata) == null ? void 0 : _b.discount_calculation_mode) === "order_level";
314
+ };
315
+ var calculateOrderLevelDiscountAllocation = (discount, applicableProducts) => {
316
+ const result = /* @__PURE__ */ new Map();
317
+ if (applicableProducts.length === 0) {
318
+ return result;
319
+ }
320
+ const totalAmount = applicableProducts.reduce((acc, product) => {
321
+ return new import_decimal.default(acc).plus(new import_decimal.default(product.amount).mul(product.quantity)).toNumber();
322
+ }, 0);
323
+ if (totalAmount <= 0) {
324
+ return result;
325
+ }
326
+ const fixedAmount = new import_decimal.default(discount.par_value || 0).toNumber();
327
+ const actualDiscountTotal = Math.min(fixedAmount, totalAmount);
328
+ let allocatedTotal = new import_decimal.default(0);
329
+ applicableProducts.forEach((product) => {
330
+ const rawDiscountPerItem = new import_decimal.default(product.amount).div(totalAmount).mul(actualDiscountTotal);
331
+ const discountAmountPerItem = rawDiscountPerItem.toDecimalPlaces(2, import_decimal.default.ROUND_DOWN).toNumber();
332
+ result.set(product.productId, {
333
+ discountAmount: discountAmountPerItem,
334
+ // 单价折扣金额
335
+ difference: 0
336
+ // 默认差值为0
337
+ });
338
+ allocatedTotal = allocatedTotal.plus(
339
+ new import_decimal.default(discountAmountPerItem).mul(product.quantity)
340
+ );
341
+ });
342
+ const totalDifference = new import_decimal.default(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, import_decimal.default.ROUND_HALF_UP).toNumber();
343
+ if (totalDifference > 0) {
344
+ const isSingleQuantity = (product) => {
345
+ if (product.parentQuantity !== void 0) {
346
+ return product.quantity === 1 && product.parentQuantity === 1;
347
+ }
348
+ return product.quantity === 1;
349
+ };
350
+ const singleQuantityProducts = applicableProducts.filter(isSingleQuantity);
351
+ if (singleQuantityProducts.length > 0) {
352
+ const productsWithEnoughSpace = singleQuantityProducts.filter((product) => {
353
+ const allocation = result.get(product.productId);
354
+ if (!allocation)
355
+ return false;
356
+ const remainingSpace = new import_decimal.default(product.amount).minus(allocation.discountAmount).toNumber();
357
+ return remainingSpace >= totalDifference;
358
+ });
359
+ if (productsWithEnoughSpace.length > 0) {
360
+ productsWithEnoughSpace.sort((a, b) => b.amount - a.amount);
361
+ const targetProduct = productsWithEnoughSpace[0];
362
+ const targetAllocation = result.get(targetProduct.productId);
363
+ if (targetAllocation) {
364
+ result.set(targetProduct.productId, {
365
+ discountAmount: new import_decimal.default(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
366
+ difference: 0
367
+ // 不需要存储差值
368
+ });
369
+ }
370
+ } else {
371
+ singleQuantityProducts.sort((a, b) => b.amount - a.amount);
372
+ const targetProduct = singleQuantityProducts[0];
373
+ const targetAllocation = result.get(targetProduct.productId);
374
+ if (targetAllocation) {
375
+ result.set(targetProduct.productId, {
376
+ ...targetAllocation,
377
+ difference: totalDifference
378
+ });
379
+ }
380
+ }
381
+ } else {
382
+ const lastProduct = applicableProducts[applicableProducts.length - 1];
383
+ const lastProductAllocation = result.get(lastProduct.productId);
384
+ if (lastProductAllocation) {
385
+ result.set(lastProduct.productId, {
386
+ ...lastProductAllocation,
387
+ difference: totalDifference
388
+ });
389
+ }
390
+ }
391
+ }
392
+ return result;
393
+ };
313
394
  // Annotate the CommonJS export names for ESM import in node:
314
395
  0 && (module.exports = {
396
+ calculateOrderLevelDiscountAllocation,
315
397
  filterDiscountListByBookingTime,
316
398
  getDateIsInSchedule,
317
399
  getDiscountAmount,
@@ -319,5 +401,6 @@ var filterDiscountListByBookingTime = (discountList, bookingTime) => {
319
401
  getDiscountListAmountTotal,
320
402
  isAllNormalProduct,
321
403
  isNormalProductByDurationSchedule,
404
+ isOrderLevelFixedAmountDiscount,
322
405
  uniqueById
323
406
  });
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.1.64",
4
+ "version": "2.1.66",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",
@@ -1 +0,0 @@
1
- export * from './strategy';
@@ -1 +0,0 @@
1
- export * from "./strategy";
@@ -1,3 +0,0 @@
1
- export * from './type';
2
- export { default as WalletPassAdapter } from './walletPass';
3
- export { WalletPassEvaluator } from './walletPass/evaluator';
@@ -1,4 +0,0 @@
1
- export * from "./type";
2
- export { default as WalletPassAdapter } from "./walletPass";
3
- export { WalletPassEvaluator } from "./walletPass/evaluator";
4
- // export * from './walletPass/type';
@@ -1,28 +0,0 @@
1
- import { EvaluationResult, RuntimeContext } from '../type';
2
- export interface BusinessAdapter {
3
- /**
4
- * 适配器名称
5
- */
6
- name: string;
7
- /**
8
- * 适配器版本
9
- */
10
- version: string;
11
- /**
12
- * 准备运行时上下文
13
- * 将业务数据转换为策略引擎可识别的上下文
14
- */
15
- prepareContext(businessData: any): RuntimeContext;
16
- /**
17
- * 转换执行结果
18
- * 将策略引擎的通用结果转换为业务层需要的格式
19
- */
20
- transformResult(result: EvaluationResult, businessData?: any): any;
21
- /**
22
- * 根据业务数据重新格式化配置
23
- */
24
- formatConfig(result: EvaluationResult, businessData?: any): {
25
- result: EvaluationResult;
26
- businessData?: any;
27
- };
28
- }
@@ -1 +0,0 @@
1
- export {};
@@ -1,84 +0,0 @@
1
- import { StrategyConfig } from '../../type';
2
- import { Voucher, Product, VoucherEvaluationResult, EvaluatorInput } from './type';
3
- /**
4
- * Wallet Pass 评估器
5
- * 用于评估哪些 voucher 可以在当前订单中使用
6
- */
7
- export declare class WalletPassEvaluator {
8
- private engine;
9
- private strategyConfigs;
10
- private locale;
11
- constructor();
12
- setStrategyConfigs(strategyConfigs: StrategyConfig[]): void;
13
- getStrategyConfigs(): StrategyConfig[];
14
- setLocale(locale: string): void;
15
- getText(key: string): string;
16
- /**
17
- * 搜索券的格式
18
- * @param input 输入
19
- * @returns 返回搜索券的格式
20
- */
21
- searchVoucherFormat(input: EvaluatorInput): Voucher[];
22
- /**
23
- * 评估可用的 vouchers
24
- */
25
- evaluate(input: EvaluatorInput): VoucherEvaluationResult[];
26
- /** 检查代金券/折扣卡是否可用 并返回config */
27
- checkVoucherAvailability(input: EvaluatorInput): {
28
- isAvailable: boolean;
29
- config: {
30
- [x: string]: any;
31
- };
32
- };
33
- /**
34
- * 获取推荐券
35
- * @param input 输入
36
- * @returns 返回推荐券列表
37
- */
38
- getRecommendedVouchers(input: EvaluatorInput): {
39
- recommendedAmount: any;
40
- recommended: any[];
41
- transformList: any[];
42
- noApplicableVoucher: Voucher[];
43
- };
44
- enhanceWithReason(voucher: any): any;
45
- /**
46
- * 优惠券处理函数
47
- * @param applicableVouchers 可用的券列表
48
- * @param orderTotalAmount 订单总金额
49
- * @param products 订单商品列表
50
- * @returns 返回推荐券列表和全部列表,每个券包含 _available_max_amount 和 _unified_available_status
51
- */
52
- processVouchers(vouchers: Voucher[], orderTotalAmount: number, products: Product[]): {
53
- recommended: any[];
54
- transformList: any[];
55
- };
56
- /**
57
- * 重新计算优惠券状态(基于已选券的增量计算)
58
- * @param allVouchers 所有原始券列表
59
- * @param selectedVouchers 已选中的券列表(按选中顺序)
60
- * @param orderTotalAmount 订单总金额
61
- * @param products 订单商品列表
62
- * @returns 返回更新后的所有券列表和已选券的详细抵扣信息
63
- */
64
- recalculateVouchers(allVouchers: any[], selectedVouchers: any[], orderTotalAmount: number, products: any[]): {
65
- allWithUpdatedStatus: any[];
66
- selectedWithDetails: any[];
67
- };
68
- /**
69
- * 查找适用于指定 voucher 的策略配置
70
- */
71
- private findApplicableStrategies;
72
- /**
73
- * 检查策略中是否包含指定的 voucher ID
74
- */
75
- private checkVoucherInStrategy;
76
- /**
77
- * 递归检查条件组中是否包含 voucher ID
78
- */
79
- private checkVoucherInConditionGroup;
80
- /**
81
- * 计算适用商品的总金额和数量
82
- */
83
- private calculateApplicableProducts;
84
- }