@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:
@@ -1,21 +1,22 @@
1
+ function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
2
+ function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
3
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
4
+ function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
5
+ function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
6
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
1
7
  import Decimal from 'decimal.js';
2
8
  export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items) {
3
9
  var subtotal = new Decimal(calculateSubtotal(items));
4
- var subOriginTotal = new Decimal(calculateOriginSubtotal(items));
5
10
  var totalTaxFee = new Decimal(calculateTaxFee(shopInfo, items));
6
11
 
7
12
  // 计算总价
8
13
  var total = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subtotal : subtotal.plus(totalTaxFee);
9
14
 
10
- // 计算总价 不包含折扣卡商品券折扣信息价格
11
- var originTotal = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
12
-
13
15
  // 计算定金
14
16
  var deposit = calculateDeposit(items);
15
17
  return {
16
18
  subtotal: subtotal.toFixed(2),
17
19
  total: total.toFixed(2),
18
- originTotal: originTotal.toFixed(2),
19
20
  taxTitle: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_title,
20
21
  totalTaxFee: totalTaxFee.toFixed(2),
21
22
  isPriceIncludeTax: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.is_price_include_tax,
@@ -24,33 +25,46 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
24
25
  };
25
26
 
26
27
  /**
27
- * 计算商品小计(不含其他费用)
28
- * @param items - 购物车商品数组
29
- * @returns 商品总价字符串,保留2位小数
28
+ * 获取子商品折扣信息
29
+ * @param item
30
30
  */
31
- export var calculateSubtotal = function calculateSubtotal(items) {
32
- if (!(items !== null && items !== void 0 && items.length)) {
33
- return '0.00';
31
+ export var getBundleDiscountList = function getBundleDiscountList(bundle) {
32
+ if (!bundle) {
33
+ return [];
34
34
  }
35
- var subtotal = items.reduce(function (sum, item) {
36
- var cartItemTotalPrice = new Decimal(item.summaryTotal || 0);
37
- return sum.plus(cartItemTotalPrice);
38
- }, new Decimal(0));
39
- return subtotal.toFixed(2);
35
+ var discountList = [];
36
+ bundle.forEach(function (d) {
37
+ if (d.discount_list && Array.isArray(d.discount_list)) {
38
+ discountList.push.apply(discountList, _toConsumableArray(d.discount_list.filter(function (item) {
39
+ return !item.id;
40
+ })));
41
+ }
42
+ });
43
+ return discountList;
44
+ };
45
+ var getProductDiscountProductDiscountDifference = function getProductDiscountProductDiscountDifference(item) {
46
+ var _item$_origin, _item$_origin2;
47
+ var mainDiscountList = ((_item$_origin = item._origin) === null || _item$_origin === void 0 || (_item$_origin = _item$_origin.product) === null || _item$_origin === void 0 ? void 0 : _item$_origin.discount_list) || [];
48
+ var bundleDiscountList = getBundleDiscountList(((_item$_origin2 = item._origin) === null || _item$_origin2 === void 0 || (_item$_origin2 = _item$_origin2.product) === null || _item$_origin2 === void 0 ? void 0 : _item$_origin2.product_bundle) || []);
49
+ var discountList = [].concat(_toConsumableArray(mainDiscountList), _toConsumableArray(bundleDiscountList));
50
+ return discountList.reduce(function (pre, cur) {
51
+ return pre + (cur.metadata.product_discount_difference || 0);
52
+ }, 0);
40
53
  };
41
54
 
42
55
  /**
43
- * 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
56
+ * 计算商品小计(不含其他费用)
44
57
  * @param items - 购物车商品数组
45
58
  * @returns 商品总价字符串,保留2位小数
46
59
  */
47
- export var calculateOriginSubtotal = function calculateOriginSubtotal(items) {
60
+ export var calculateSubtotal = function calculateSubtotal(items) {
48
61
  if (!(items !== null && items !== void 0 && items.length)) {
49
62
  return '0.00';
50
63
  }
51
64
  var subtotal = items.reduce(function (sum, item) {
52
- var cartItemTotalPrice = new Decimal(item.summaryOriginTotal || 0);
53
- return sum.plus(cartItemTotalPrice);
65
+ var cartItemTotalPrice = new Decimal(item.summaryTotal || 0);
66
+ var productDiscountProductDiscountDifference = getProductDiscountProductDiscountDifference(item);
67
+ return sum.plus(cartItemTotalPrice).sub(productDiscountProductDiscountDifference);
54
68
  }, new Decimal(0));
55
69
  return subtotal.toFixed(2);
56
70
  };
@@ -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
  *
@@ -2652,7 +2652,8 @@ export var BookingByStepImpl = /*#__PURE__*/function (_BaseModule) {
2652
2652
  start_at: dayjs(item.start),
2653
2653
  end_at: dayjs(item.end)
2654
2654
  })) {
2655
- mSet.set(m.id, m.pax || 1);
2655
+ var _m$pax;
2656
+ mSet.set(m.id, (_m$pax = m.pax) !== null && _m$pax !== void 0 ? _m$pax : 1);
2656
2657
  }
2657
2658
  });
2658
2659
  });
@@ -403,7 +403,6 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
403
403
  product_id: item.product_id,
404
404
  product_variant_id: item.product_variant_id,
405
405
  quantity: item.num,
406
- is_price_include_tax: item.is_price_include_tax,
407
406
  // 商品是否含税:1;0
408
407
  is_charge_tax: (_item$is_charge_tax = item.is_charge_tax) !== null && _item$is_charge_tax !== void 0 ? _item$is_charge_tax : 0,
409
408
  // 若商品不含税,计算得到的税费,单位(元)
@@ -428,7 +427,6 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
428
427
  },
429
428
  product_bundle: item.product_bundle.map(function (bundle) {
430
429
  return {
431
- is_price_include_tax: item.is_price_include_tax,
432
430
  bundle_id: bundle.bundle_id,
433
431
  bundle_product_id: bundle.bundle_product_id,
434
432
  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 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
55
55
  originalDiscountList: [],
56
56
  currentBookingTime: "",
57
57
  filteredDiscountList: [],
58
- orderTotalAmount: 0,
59
58
  bookingSubject: undefined
60
59
  };
61
60
  return _this;
@@ -288,14 +287,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
288
287
  return _setCustomer.apply(this, arguments);
289
288
  }
290
289
  return setCustomer;
291
- }()
292
- }, {
293
- key: "setOriginTotalAmount",
294
- value: function setOriginTotalAmount(amount) {
295
- this.store.orderTotalAmount = amount;
296
- }
297
-
298
- // 设置holders
290
+ }() // 设置holders
299
291
  }, {
300
292
  key: "setHolders",
301
293
  value: function setHolders(holders) {
@@ -324,7 +316,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
324
316
  productList: productList,
325
317
  discountList: this.getDiscountList(),
326
318
  holders: this.store.holders || [],
327
- orderTotalAmount: this.store.orderTotalAmount || 0,
328
319
  isFormSubject: ((_this$store$bookingSu = this.store.bookingSubject) === null || _this$store$bookingSu === void 0 ? void 0 : _this$store$bookingSu.type) === 'form'
329
320
  }, options) || {
330
321
  productList: productList,
@@ -465,7 +456,6 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
465
456
  oldDiscountList: this.getDiscountList(),
466
457
  newDiscountList: withScanList,
467
458
  holders: this.store.holders || [],
468
- orderTotalAmount: this.store.orderTotalAmount || 0,
469
459
  isFormSubject: ((_this$store$bookingSu2 = this.store.bookingSubject) === null || _this$store$bookingSu2 === void 0 ? void 0 : _this$store$bookingSu2.type) === 'form'
470
460
  }) || {
471
461
  isAvailable: false,
@@ -576,12 +566,13 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
576
566
  return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
577
567
  });
578
568
  if (index !== -1) {
569
+ var _discount$metadata;
579
570
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
580
571
  amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
581
- savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
572
+ savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus((discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.product_discount_difference) || 0).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
582
573
  });
583
574
  } else {
584
- var _discount$discount2, _discount$discount3, _discount$discount4;
575
+ var _discount$metadata2, _discount$discount2, _discount$discount3, _discount$discount4;
585
576
  if (discount.type && !discount.tag) {
586
577
  discount.tag = discount.type;
587
578
  }
@@ -589,7 +580,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
589
580
  name: discount.name || discount.discount.title.auto,
590
581
  isEditMode: true,
591
582
  limited_relation_product_data: {},
592
- savedAmount: discount.amount * ((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1),
583
+ savedAmount: new Decimal(discount.amount || 0).times((product === null || product === void 0 ? void 0 : product.quantity) || (product === null || product === void 0 ? void 0 : product.num) || 1).plus((discount === null || discount === void 0 || (_discount$metadata2 = discount.metadata) === null || _discount$metadata2 === void 0 ? void 0 : _discount$metadata2.product_discount_difference) || 0).toNumber(),
593
584
  isAvailable: true,
594
585
  id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
595
586
  format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
@@ -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
+ }>;
@@ -1,3 +1,9 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
3
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
4
+ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
5
+ function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
+ 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); }
1
7
  function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it.return != null) it.return(); } finally { if (didErr) throw err; } } }; }
2
8
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
3
9
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
@@ -34,37 +40,23 @@ export var isAllNormalProduct = function isAllNormalProduct(items) {
34
40
  * @returns
35
41
  */
36
42
  export var getDiscountAmount = function getDiscountAmount(discount, total, price) {
37
- var discountedPrice = 0;
38
-
43
+ var _discount$metadata;
39
44
  // 商品券
40
45
  if (discount.tag === 'good_pass') {
41
- discountedPrice = new Decimal(price).minus(new Decimal(price || 0)).toNumber();
42
- } else {
43
- var _discount$metadata;
44
- // 判断是否是固定金额
45
- var isFixedAmount = (discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type) === 'fixed_amount';
46
-
47
- // 固定金额 小于0时返回0
48
- if (isFixedAmount) {
49
- discountedPrice = Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
50
- } else {
51
- // 百分比:根据折扣卡金额计算
52
- discountedPrice = new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
53
- }
46
+ return new Decimal(price).minus(new Decimal(price || 0)).toNumber();
54
47
  }
55
48
 
56
- /*
57
- // 🔥 如果有 maxDeductionAmount 限制,确保折扣金额不超过限制
58
- if (discount.config?.maxDeductionAmount) {
59
- const actualDiscountAmount = new Decimal(price).minus(discountedPrice).toNumber();
60
- if (actualDiscountAmount > discount.config.maxDeductionAmount) {
61
- // 折扣金额超过限制,重新计算折扣后价格
62
- discountedPrice = new Decimal(price).minus(discount.config.maxDeductionAmount).toNumber();
63
- }
64
- }
65
- */
49
+ // 判断是否是固定金额
50
+ var isFixedAmount = (discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type) === 'fixed_amount';
51
+
52
+ // 固定金额 小于0时返回0
53
+ if (isFixedAmount) {
54
+ var _discount$amount;
55
+ return Math.max(new Decimal(price).minus(new Decimal(((_discount$amount = discount.amount) !== null && _discount$amount !== void 0 ? _discount$amount : discount.par_value) || 0)).toNumber(), 0);
56
+ }
66
57
 
67
- return discountedPrice;
58
+ // 百分比:根据折扣卡金额计算
59
+ return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
68
60
  };
69
61
  export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
70
62
  return discount.reduce(function (acc, cur) {
@@ -477,4 +469,131 @@ export var filterDiscountListByBookingTime = function filterDiscountListByBookin
477
469
  return true;
478
470
  }
479
471
  });
472
+ };
473
+ /**
474
+ * 判断是否是订单级别的固定金额折扣卡
475
+ * @param discount 折扣
476
+ * @returns 是否是订单级别的固定金额折扣卡
477
+ */
478
+ export var isOrderLevelFixedAmountDiscount = function isOrderLevelFixedAmountDiscount(discount) {
479
+ var _discount$metadata3, _discount$metadata4;
480
+ return discount.tag === 'product_discount_card' && (discount === null || discount === void 0 || (_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.discount_card_type) === 'fixed_amount' && (discount === null || discount === void 0 || (_discount$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.discount_calculation_mode) === 'order_level';
481
+ };
482
+
483
+ /**
484
+ * 计算订单级别固定金额折扣卡的分摊结果
485
+ * @param discount 折扣卡
486
+ * @param applicableProducts 适用商品列表 { productId, amount, quantity, parentQuantity }
487
+ * @returns 分摊结果 Map<productId, { discountAmount, difference }>
488
+ * 注意:
489
+ * - discountAmount 是单价折扣金额(不是总折扣金额)
490
+ * - difference(总差值)优先直接加到数量为1的单商品折扣上,如果没有则存储在metadata中
491
+ */
492
+ export var calculateOrderLevelDiscountAllocation = function calculateOrderLevelDiscountAllocation(discount, applicableProducts) {
493
+ var result = new Map();
494
+ if (applicableProducts.length === 0) {
495
+ return result;
496
+ }
497
+
498
+ // 计算适用商品的总金额(数量 × 单价)
499
+ var totalAmount = applicableProducts.reduce(function (acc, product) {
500
+ return new Decimal(acc).plus(new Decimal(product.amount).mul(product.quantity)).toNumber();
501
+ }, 0);
502
+ if (totalAmount <= 0) {
503
+ return result;
504
+ }
505
+
506
+ // 固定减免金额
507
+ var fixedAmount = new Decimal(discount.par_value || 0).toNumber();
508
+
509
+ // 如果固定金额 >= 商品总金额,折扣最高为商品金额(免费)
510
+ var actualDiscountTotal = Math.min(fixedAmount, totalAmount);
511
+
512
+ // 计算每个商品的单价折扣金额
513
+ var allocatedTotal = new Decimal(0);
514
+ applicableProducts.forEach(function (product) {
515
+ // 🔥 分摊公式改为:(单价 / 适用商品总金额) × 固定金额
516
+ // 这样只有一次取整,避免精度损失
517
+ var rawDiscountPerItem = new Decimal(product.amount).div(totalAmount).mul(actualDiscountTotal);
518
+
519
+ // 保留两位小数,向下取整(单价折扣)
520
+ var discountAmountPerItem = rawDiscountPerItem.toDecimalPlaces(2, Decimal.ROUND_DOWN).toNumber();
521
+ result.set(product.productId, {
522
+ discountAmount: discountAmountPerItem,
523
+ // 单价折扣金额
524
+ difference: 0 // 默认差值为0
525
+ });
526
+
527
+ // 累加实际分配的总折扣金额(单价折扣 × 数量)
528
+ allocatedTotal = allocatedTotal.plus(new Decimal(discountAmountPerItem).mul(product.quantity));
529
+ });
530
+
531
+ // 🔥 计算总差值
532
+ // 总差值 = 固定金额 - 所有商品的 (单价折扣 × 数量) 之和
533
+ var totalDifference = new Decimal(actualDiscountTotal).minus(allocatedTotal).toDecimalPlaces(2, Decimal.ROUND_HALF_UP).toNumber();
534
+ if (totalDifference > 0) {
535
+ // 🔥 判断商品是否是真正的"数量为1"
536
+ // 主商品:quantity === 1
537
+ // 子商品:quantity === 1 且 parentQuantity === 1
538
+ var isSingleQuantity = function isSingleQuantity(product) {
539
+ if (product.parentQuantity !== undefined) {
540
+ // 子商品:需要同时满足自身数量为1且主商品数量为1
541
+ return product.quantity === 1 && product.parentQuantity === 1;
542
+ }
543
+ // 主商品:只需要自身数量为1
544
+ return product.quantity === 1;
545
+ };
546
+
547
+ // 🔥 筛选出数量为1的商品
548
+ var singleQuantityProducts = applicableProducts.filter(isSingleQuantity);
549
+ if (singleQuantityProducts.length > 0) {
550
+ // 🔥 优先级1:找到有足够剩余空间且金额最大的商品
551
+ // 剩余空间 = 商品价格 - 当前折扣金额 >= 差值
552
+ var productsWithEnoughSpace = singleQuantityProducts.filter(function (product) {
553
+ var allocation = result.get(product.productId);
554
+ if (!allocation) return false;
555
+ var remainingSpace = new Decimal(product.amount).minus(allocation.discountAmount).toNumber();
556
+ return remainingSpace >= totalDifference;
557
+ });
558
+ if (productsWithEnoughSpace.length > 0) {
559
+ // 按金额降序排序,选择金额最大的
560
+ productsWithEnoughSpace.sort(function (a, b) {
561
+ return b.amount - a.amount;
562
+ });
563
+ var targetProduct = productsWithEnoughSpace[0];
564
+ var targetAllocation = result.get(targetProduct.productId);
565
+ if (targetAllocation) {
566
+ // 差值直接加到折扣金额上
567
+ result.set(targetProduct.productId, {
568
+ discountAmount: new Decimal(targetAllocation.discountAmount).plus(totalDifference).toNumber(),
569
+ difference: 0 // 不需要存储差值
570
+ });
571
+ }
572
+ } else {
573
+ // 🔥 优先级2:所有数量为1的商品都没有足够剩余空间
574
+ // 选择金额最大的商品,差值存储在metadata中
575
+ singleQuantityProducts.sort(function (a, b) {
576
+ return b.amount - a.amount;
577
+ });
578
+ var _targetProduct = singleQuantityProducts[0];
579
+ var _targetAllocation = result.get(_targetProduct.productId);
580
+ if (_targetAllocation) {
581
+ result.set(_targetProduct.productId, _objectSpread(_objectSpread({}, _targetAllocation), {}, {
582
+ difference: totalDifference
583
+ }));
584
+ }
585
+ }
586
+ } else {
587
+ // 🔥 优先级3:没有数量为1的商品,走原有逻辑
588
+ // 差值存储在最后一个商品的metadata中
589
+ var lastProduct = applicableProducts[applicableProducts.length - 1];
590
+ var lastProductAllocation = result.get(lastProduct.productId);
591
+ if (lastProductAllocation) {
592
+ result.set(lastProduct.productId, _objectSpread(_objectSpread({}, lastProductAllocation), {}, {
593
+ difference: totalDifference
594
+ }));
595
+ }
596
+ }
597
+ }
598
+ return result;
480
599
  };
package/lib/index.d.ts CHANGED
@@ -6,7 +6,6 @@ export * from './types';
6
6
  export * from './modules';
7
7
  export * from './plugins';
8
8
  export * from './solution';
9
- export * from './model';
10
9
  export { PisellOSCore } from './core';
11
10
  import PisellOSCore from './core';
12
11
  export default PisellOSCore;
package/lib/index.js CHANGED
@@ -38,7 +38,6 @@ __reExport(src_exports, require("./types"), module.exports);
38
38
  __reExport(src_exports, require("./modules"), module.exports);
39
39
  __reExport(src_exports, require("./plugins"), module.exports);
40
40
  __reExport(src_exports, require("./solution"), module.exports);
41
- __reExport(src_exports, require("./model"), module.exports);
42
41
  var import_core = require("./core");
43
42
  var import_core2 = __toESM(require("./core"));
44
43
  var src_default = import_core2.default;
@@ -48,6 +47,5 @@ var src_default = import_core2.default;
48
47
  ...require("./types"),
49
48
  ...require("./modules"),
50
49
  ...require("./plugins"),
51
- ...require("./solution"),
52
- ...require("./model")
50
+ ...require("./solution")
53
51
  });
@@ -75,8 +75,6 @@ export interface CartItem {
75
75
  summaryTotal?: number | string;
76
76
  /** 商品原价总价,排除原始价格为0的场景 */
77
77
  origin_total?: number | string;
78
- /** 基于 origin_total 乘以 商品数量的价格 */
79
- summaryOriginTotal?: number | string;
80
78
  /** 商品数量 */
81
79
  num?: number;
82
80
  /** 商品图片 */
@@ -88,14 +88,6 @@ var formatProductToCartItem = (params) => {
88
88
  num,
89
89
  discounts
90
90
  });
91
- const origin_total = getProductTotalPrice({
92
- product: cartItem._productInit || cartItem._productOrigin,
93
- bundle,
94
- options,
95
- num,
96
- discounts: []
97
- });
98
- cartItem.summaryOriginTotal = (origin_total || 0) * (num || 1);
99
91
  cartItem.image = product == null ? void 0 : product.cover;
100
92
  cartItem.like_status = "common";
101
93
  cartItem.duration = product == null ? void 0 : product.duration;
@@ -147,7 +139,7 @@ var formatProductToCartItem = (params) => {
147
139
  return cartItem;
148
140
  };
149
141
  var formatProductToCartItemOrigin = (params) => {
150
- var _a, _b, _c, _d;
142
+ var _a, _b, _c, _d, _e;
151
143
  const {
152
144
  cartItem,
153
145
  product,
@@ -157,17 +149,27 @@ var formatProductToCartItemOrigin = (params) => {
157
149
  quantity = 1
158
150
  } = params;
159
151
  let origin = cartItem._origin;
152
+ const product_discount_difference = (((_a = origin.product) == null ? void 0 : _a.discount_list) || []).filter((item) => {
153
+ var _a2;
154
+ return !((_a2 = item == null ? void 0 : item.metadata) == null ? void 0 : _a2.custom_product_bundle_map_id);
155
+ }).reduce((pre, cur) => {
156
+ var _a2;
157
+ return pre + (((_a2 = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a2.product_discount_difference) || 0);
158
+ }, 0);
160
159
  if (product) {
161
160
  origin.product = {
162
161
  ...origin.product || {},
163
162
  num: quantity,
164
163
  product_id: product.id,
165
164
  product_variant_id: product_variant_id || 0,
166
- product_bundle: ((_a = origin.product) == null ? void 0 : _a.product_bundle) || [],
167
- product_option_item: ((_b = origin.product) == null ? void 0 : _b.product_option_item) || []
165
+ product_bundle: ((_b = origin.product) == null ? void 0 : _b.product_bundle) || [],
166
+ product_option_item: ((_c = origin.product) == null ? void 0 : _c.product_option_item) || [],
167
+ metadata: {
168
+ product_discount_difference
169
+ }
168
170
  };
169
- origin.sub_type = (_c = product == null ? void 0 : product.duration) == null ? void 0 : _c.type;
170
- origin.duration = (_d = product == null ? void 0 : product.duration) == null ? void 0 : _d.value;
171
+ origin.sub_type = (_d = product == null ? void 0 : product.duration) == null ? void 0 : _d.type;
172
+ origin.duration = (_e = product == null ? void 0 : product.duration) == null ? void 0 : _e.value;
171
173
  if (bundle == null ? void 0 : bundle.length) {
172
174
  origin.product.product_bundle = formatBundleToOrigin(bundle);
173
175
  }
@@ -184,9 +186,9 @@ var getProductTotalPrice = (params) => {
184
186
  discounts.forEach((currentValue) => {
185
187
  var _a;
186
188
  price = (0, import_utils2.getDiscountAmount)({
189
+ amount: currentValue.amount,
187
190
  tag: currentValue.type,
188
191
  par_value: currentValue.discount.percent,
189
- config: currentValue.config,
190
192
  metadata: {
191
193
  discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
192
194
  }
@@ -281,6 +283,10 @@ var formatBundleToOrigin = (bundle) => {
281
283
  var _a;
282
284
  return (d == null ? void 0 : d[key]) || ((_a = d == null ? void 0 : d.originBundleItem) == null ? void 0 : _a[key]);
283
285
  };
286
+ const product_discount_difference = ((d == null ? void 0 : d.discount_list) || []).reduce((pre, cur) => {
287
+ var _a;
288
+ return pre + (((_a = cur == null ? void 0 : cur.metadata) == null ? void 0 : _a.product_discount_difference) || 0);
289
+ }, 0);
284
290
  return {
285
291
  bundle_group_id: getBundleValueByKey("group_id"),
286
292
  bundle_id: d.id,
@@ -293,7 +299,8 @@ var formatBundleToOrigin = (bundle) => {
293
299
  discount_list: d.discount_list,
294
300
  "bundle_selling_price": d == null ? void 0 : d.price,
295
301
  metadata: {
296
- custom_product_bundle_map_id: d._id
302
+ custom_product_bundle_map_id: d._id,
303
+ product_discount_difference
297
304
  }
298
305
  };
299
306
  });
@@ -176,9 +176,9 @@ var DiscountModule = class extends import_BaseModule.BaseModule {
176
176
  }
177
177
  if (discount.appliedProductDetails) {
178
178
  return discount.appliedProductDetails.reduce((total, product) => {
179
- var _a;
179
+ var _a, _b;
180
180
  const price = new import_decimal.default(((_a = product == null ? void 0 : product.discount) == null ? void 0 : _a.fixed_amount) || 0).mul((product == null ? void 0 : product._num) || 1);
181
- return new import_decimal.default(total).plus(price).toNumber();
181
+ return new import_decimal.default(total).plus(price).add(((_b = product == null ? void 0 : product.metadata) == null ? void 0 : _b.product_discount_difference) || 0).toNumber();
182
182
  }, 0);
183
183
  }
184
184
  }