@pisell/pisellos 2.1.103 → 2.1.104

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 (100) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +3 -0
  6. package/dist/model/strategy/adapter/index.js +4 -0
  7. package/dist/model/strategy/adapter/type.d.ts +28 -0
  8. package/dist/model/strategy/adapter/type.js +1 -0
  9. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  10. package/dist/model/strategy/adapter/walletPass/evaluator.js +498 -0
  11. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  12. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  13. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  14. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  15. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  16. package/dist/model/strategy/adapter/walletPass/locales.js +26 -0
  17. package/dist/model/strategy/adapter/walletPass/type.d.ts +169 -0
  18. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  19. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  20. package/dist/model/strategy/adapter/walletPass/utils.js +1064 -0
  21. package/dist/model/strategy/index.d.ts +94 -0
  22. package/dist/model/strategy/index.js +551 -0
  23. package/dist/model/strategy/strategy-example.d.ts +5 -0
  24. package/dist/model/strategy/strategy-example.js +331 -0
  25. package/dist/model/strategy/type.d.ts +228 -0
  26. package/dist/model/strategy/type.js +94 -0
  27. package/dist/modules/Cart/types.d.ts +2 -0
  28. package/dist/modules/Cart/utils/cartProduct.js +11 -0
  29. package/dist/modules/Discount/types.d.ts +16 -0
  30. package/dist/modules/Payment/index.d.ts +2 -1
  31. package/dist/modules/Payment/index.js +10 -7
  32. package/dist/modules/Payment/utils.js +3 -0
  33. package/dist/modules/Payment/walletpass.d.ts +23 -0
  34. package/dist/modules/Payment/walletpass.js +191 -95
  35. package/dist/modules/Product/index.d.ts +1 -1
  36. package/dist/modules/Rules/index.d.ts +9 -5
  37. package/dist/modules/Rules/index.js +545 -129
  38. package/dist/modules/Rules/types.d.ts +1 -0
  39. package/dist/modules/Summary/types.d.ts +2 -0
  40. package/dist/modules/Summary/utils.d.ts +6 -0
  41. package/dist/modules/Summary/utils.js +21 -0
  42. package/dist/plugins/window.d.ts +2 -0
  43. package/dist/solution/BookingByStep/index.d.ts +3 -2
  44. package/dist/solution/BookingTicket/index.d.ts +1 -1
  45. package/dist/solution/Checkout/index.js +3 -1
  46. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  47. package/dist/solution/ShopDiscount/index.js +23 -7
  48. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  49. package/dist/solution/ShopDiscount/types.js +2 -1
  50. package/dist/solution/ShopDiscount/utils.js +26 -12
  51. package/lib/index.d.ts +1 -0
  52. package/lib/index.js +3 -1
  53. package/lib/model/index.d.ts +1 -0
  54. package/lib/model/index.js +23 -0
  55. package/lib/model/strategy/adapter/index.d.ts +3 -0
  56. package/lib/model/strategy/adapter/index.js +45 -0
  57. package/lib/model/strategy/adapter/type.d.ts +28 -0
  58. package/lib/model/strategy/adapter/type.js +17 -0
  59. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  60. package/lib/model/strategy/adapter/walletPass/evaluator.js +422 -0
  61. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  62. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  63. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  64. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  65. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  66. package/lib/model/strategy/adapter/walletPass/locales.js +54 -0
  67. package/lib/model/strategy/adapter/walletPass/type.d.ts +169 -0
  68. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  69. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  70. package/lib/model/strategy/adapter/walletPass/utils.js +720 -0
  71. package/lib/model/strategy/index.d.ts +94 -0
  72. package/lib/model/strategy/index.js +413 -0
  73. package/lib/model/strategy/strategy-example.d.ts +5 -0
  74. package/lib/model/strategy/strategy-example.js +318 -0
  75. package/lib/model/strategy/type.d.ts +228 -0
  76. package/lib/model/strategy/type.js +44 -0
  77. package/lib/modules/Cart/types.d.ts +2 -0
  78. package/lib/modules/Cart/utils/cartProduct.js +9 -0
  79. package/lib/modules/Discount/types.d.ts +16 -0
  80. package/lib/modules/Payment/index.d.ts +2 -1
  81. package/lib/modules/Payment/index.js +1 -0
  82. package/lib/modules/Payment/utils.js +3 -0
  83. package/lib/modules/Payment/walletpass.d.ts +23 -0
  84. package/lib/modules/Payment/walletpass.js +94 -17
  85. package/lib/modules/Product/index.d.ts +1 -1
  86. package/lib/modules/Rules/index.d.ts +9 -5
  87. package/lib/modules/Rules/index.js +671 -262
  88. package/lib/modules/Rules/types.d.ts +1 -0
  89. package/lib/modules/Summary/types.d.ts +2 -0
  90. package/lib/modules/Summary/utils.d.ts +6 -0
  91. package/lib/modules/Summary/utils.js +15 -0
  92. package/lib/plugins/window.d.ts +2 -0
  93. package/lib/solution/BookingByStep/index.d.ts +3 -2
  94. package/lib/solution/BookingTicket/index.d.ts +1 -1
  95. package/lib/solution/Checkout/index.js +3 -1
  96. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  97. package/lib/solution/ShopDiscount/index.js +22 -8
  98. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  99. package/lib/solution/ShopDiscount/utils.js +10 -6
  100. package/package.json +1 -1
@@ -28,6 +28,7 @@ export interface RulesModuleAPI {
28
28
  calcDiscount: (params: {
29
29
  discountList: any[];
30
30
  productList: any[];
31
+ orderTotalAmount: number;
31
32
  holders: {
32
33
  form_record_id: number;
33
34
  }[];
@@ -6,6 +6,8 @@ export interface ISummaryState {
6
6
  subtotal: string | number;
7
7
  /** 最终总价 */
8
8
  total: string | number;
9
+ /** 最终原始价格 不包含折扣卡商品券折扣 */
10
+ originTotal: string | number;
9
11
  /** 税率标题 */
10
12
  taxTitle?: string;
11
13
  /** 商品总费率 */
@@ -58,6 +58,12 @@ export declare const getTax: ({ service, addons, bookingDetail, bookingId }: {
58
58
  * @returns 商品总价字符串,保留2位小数
59
59
  */
60
60
  export declare const calculateSubtotal: (items: CartItem[]) => string;
61
+ /**
62
+ * 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
63
+ * @param items - 购物车商品数组
64
+ * @returns 商品总价字符串,保留2位小数
65
+ */
66
+ export declare const calculateOriginSubtotal: (items: CartItem[]) => string;
61
67
  /**
62
68
  * @title: 单个商品的税费
63
69
  * @description:
@@ -20,6 +20,7 @@ import { isNormalProduct } from "../Product/utils";
20
20
  import dayjs from 'dayjs';
21
21
  export var calculatePriceDetails = function calculatePriceDetails(shopInfo, items, isInScheduleByDate, surchargeList, scheduleById) {
22
22
  var subtotal = new Decimal(calculateSubtotal(items));
23
+ var subOriginTotal = new Decimal(calculateOriginSubtotal(items));
23
24
  var totalTaxFee = new Decimal(calculateTaxFee(shopInfo, items));
24
25
  // 订单附加费列表
25
26
  var surcharge = getSurcharge({
@@ -58,11 +59,15 @@ export var calculatePriceDetails = function calculatePriceDetails(shopInfo, item
58
59
  originTax = _getTax.originTax;
59
60
  var total = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subtotal.plus(surchargeAmount) : subtotal.plus(tax).plus(surchargeAmount);
60
61
 
62
+ // 计算总价 不包含折扣卡商品券折扣信息价格
63
+ var originTotal = shopInfo !== null && shopInfo !== void 0 && shopInfo.is_price_include_tax ? subOriginTotal : subOriginTotal.plus(totalTaxFee);
64
+
61
65
  // 计算定金
62
66
  var deposit = calculateDeposit(items);
63
67
  return {
64
68
  subtotal: subtotal.toFixed(2),
65
69
  total: total.toFixed(2),
70
+ originTotal: originTotal.toFixed(2),
66
71
  taxTitle: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_title,
67
72
  taxRate: shopInfo === null || shopInfo === void 0 ? void 0 : shopInfo.tax_rate,
68
73
  totalTaxFee: tax,
@@ -572,6 +577,22 @@ export var calculateSubtotal = function calculateSubtotal(items) {
572
577
  return subtotal.toFixed(2);
573
578
  };
574
579
 
580
+ /**
581
+ * 计算商品小计(不含其他费用 不包含折扣卡商品券抵扣金额)
582
+ * @param items - 购物车商品数组
583
+ * @returns 商品总价字符串,保留2位小数
584
+ */
585
+ export var calculateOriginSubtotal = function calculateOriginSubtotal(items) {
586
+ if (!(items !== null && items !== void 0 && items.length)) {
587
+ return '0.00';
588
+ }
589
+ var subtotal = items.reduce(function (sum, item) {
590
+ var cartItemTotalPrice = new Decimal(item.summaryOriginTotal || 0);
591
+ return sum.plus(cartItemTotalPrice);
592
+ }, new Decimal(0));
593
+ return subtotal.toFixed(2);
594
+ };
595
+
575
596
  /**
576
597
  * @title: 单个商品的税费
577
598
  * @description:
@@ -1,3 +1,4 @@
1
+ import { WalletPassEvaluator } from '../model';
1
2
  import { Plugin } from '../types';
2
3
  /**
3
4
  * WindowPlugin 接口定义
@@ -14,6 +15,7 @@ export interface WindowPlugin extends Plugin {
14
15
  document: Partial<Document>;
15
16
  history: History;
16
17
  interaction?: any;
18
+ getWalletPassEvaluator?: () => WalletPassEvaluator;
17
19
  }
18
20
  /**
19
21
  * 简单的 Storage 接口实现
@@ -144,6 +144,7 @@ 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;
147
148
  taxTitle?: string | undefined;
148
149
  totalTaxFee?: string | number | undefined;
149
150
  isPriceIncludeTax?: 0 | 1 | undefined;
@@ -310,7 +311,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
310
311
  date: string;
311
312
  status: string;
312
313
  week: string;
313
- weekNum: 0 | 1 | 2 | 3 | 4 | 5 | 6;
314
+ weekNum: 0 | 2 | 1 | 3 | 4 | 5 | 6;
314
315
  }[]>;
315
316
  submitTimeSlot(timeSlots: TimeSliceItem): void;
316
317
  private getScheduleDataByIds;
@@ -357,7 +358,7 @@ export declare class BookingByStepImpl extends BaseModule implements Module {
357
358
  };
358
359
  setOtherData(key: string, value: any): void;
359
360
  getOtherData(key: string): any;
360
- getProductTypeById(id: number): Promise<"duration" | "session" | "normal">;
361
+ getProductTypeById(id: number): Promise<"normal" | "duration" | "session">;
361
362
  /**
362
363
  * 提供给 UI 的方法,减轻 UI 层的计算压力,UI 层只需要传递 cartItemId 和 resourceCode 即返回对应的 renderList
363
364
  *
@@ -115,7 +115,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
115
115
  * 获取当前的客户搜索条件
116
116
  * @returns 当前搜索条件
117
117
  */
118
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
118
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
119
119
  /**
120
120
  * 获取客户列表状态(包含滚动加载相关状态)
121
121
  * @returns 客户状态
@@ -403,6 +403,7 @@ 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,
406
407
  // 商品是否含税:1;0
407
408
  is_charge_tax: (_item$is_charge_tax = item.is_charge_tax) !== null && _item$is_charge_tax !== void 0 ? _item$is_charge_tax : 0,
408
409
  // 若商品不含税,计算得到的税费,单位(元)
@@ -425,8 +426,9 @@ export var CheckoutImpl = /*#__PURE__*/function (_BaseModule) {
425
426
  // 可选,附加费均摊舍入金额
426
427
  "surcharge_rounding_remainder": item.metadata.surcharge_rounding_remainder
427
428
  },
428
- product_bundle: item.product_bundle.map(function (bundle) {
429
+ product_bundle: (item.product_bundle || []).map(function (bundle) {
429
430
  return {
431
+ is_price_include_tax: item.is_price_include_tax,
430
432
  bundle_id: bundle.bundle_id,
431
433
  bundle_product_id: bundle.bundle_product_id,
432
434
  bundle_variant_id: bundle.bundle_variant_id,
@@ -22,6 +22,7 @@ export declare class ShopDiscountImpl extends BaseModule implements Module {
22
22
  getCurrentBookingTime(): string | null;
23
23
  private filterDiscountListByBookingTime;
24
24
  setCustomer(customer: Customer): Promise<void>;
25
+ setOriginTotalAmount(amount: number): void;
25
26
  setHolders(holders: {
26
27
  form_record_id: number;
27
28
  }[]): void;
@@ -56,7 +56,8 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
56
56
  originalDiscountList: [],
57
57
  currentBookingTime: "",
58
58
  filteredDiscountList: [],
59
- bookingSubject: undefined
59
+ bookingSubject: undefined,
60
+ orderTotalAmount: 0
60
61
  };
61
62
  return _this;
62
63
  }
@@ -288,7 +289,14 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
288
289
  return _setCustomer.apply(this, arguments);
289
290
  }
290
291
  return setCustomer;
291
- }() // 设置holders
292
+ }()
293
+ }, {
294
+ key: "setOriginTotalAmount",
295
+ value: function setOriginTotalAmount(amount) {
296
+ this.store.orderTotalAmount = amount;
297
+ }
298
+
299
+ // 设置holders
292
300
  }, {
293
301
  key: "setHolders",
294
302
  value: function setHolders(holders) {
@@ -316,6 +324,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
316
324
  var _ref = rulesModule.calcDiscount({
317
325
  productList: productList,
318
326
  discountList: this.getDiscountList(),
327
+ orderTotalAmount: this.store.orderTotalAmount || 0,
319
328
  holders: this.store.holders || [],
320
329
  isFormSubject: ((_this$store$bookingSu = this.store.bookingSubject) === null || _this$store$bookingSu === void 0 ? void 0 : _this$store$bookingSu.type) === 'form'
321
330
  }, options) || {
@@ -495,6 +504,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
495
504
  productList: this.store.productList || [],
496
505
  oldDiscountList: this.getDiscountList(),
497
506
  newDiscountList: withScanList,
507
+ orderTotalAmount: this.store.orderTotalAmount || 0,
498
508
  holders: this.store.holders || [],
499
509
  isFormSubject: ((_this$store$bookingSu2 = this.store.bookingSubject) === null || _this$store$bookingSu2 === void 0 ? void 0 : _this$store$bookingSu2.type) === 'form'
500
510
  }) || {
@@ -608,21 +618,27 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
608
618
  return n.id === (((_discount$discount = discount.discount) === null || _discount$discount === void 0 ? void 0 : _discount$discount.resource_id) || discount.id);
609
619
  });
610
620
  if (index !== -1) {
611
- var _discount$metadata;
621
+ var _editModeDiscountList, _discount$metadata, _discount$metadata2;
612
622
  editModeDiscountList[index] = _objectSpread(_objectSpread({}, editModeDiscountList[index]), {}, {
623
+ metadata: _objectSpread(_objectSpread({}, discount.metadata || {}), {}, {
624
+ num: ((editModeDiscountList === null || editModeDiscountList === void 0 || (_editModeDiscountList = editModeDiscountList[index]) === null || _editModeDiscountList === void 0 || (_editModeDiscountList = _editModeDiscountList.metadata) === null || _editModeDiscountList === void 0 ? void 0 : _editModeDiscountList.num) || 1) + (((_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.num) || 1)
625
+ }),
613
626
  amount: new Decimal(discount.amount || 0).plus(new Decimal(editModeDiscountList[index].amount || 0)).toNumber(),
614
- 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()
627
+ 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).plus(new Decimal(editModeDiscountList[index].savedAmount || 0)).toNumber()
615
628
  });
616
629
  } else {
617
- var _discount$metadata2, _discount$discount2, _discount$discount3, _discount$discount4;
630
+ var _discount$metadata3, _discount$metadata4, _discount$discount2, _discount$discount3, _discount$discount4;
618
631
  if (discount.type && !discount.tag) {
619
632
  discount.tag = discount.type;
620
633
  }
621
634
  editModeDiscountList.push(_objectSpread(_objectSpread({}, discount), {}, {
635
+ metadata: _objectSpread(_objectSpread({}, discount.metadata || {}), {}, {
636
+ num: ((_discount$metadata3 = discount.metadata) === null || _discount$metadata3 === void 0 ? void 0 : _discount$metadata3.num) || 1
637
+ }),
622
638
  name: discount.name || discount.discount.title.auto,
623
639
  isEditMode: true,
624
640
  limited_relation_product_data: {},
625
- 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(),
641
+ 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$metadata4 = discount.metadata) === null || _discount$metadata4 === void 0 ? void 0 : _discount$metadata4.product_discount_difference) || 0).toNumber(),
626
642
  isAvailable: true,
627
643
  id: ((_discount$discount2 = discount.discount) === null || _discount$discount2 === void 0 ? void 0 : _discount$discount2.resource_id) || discount.id,
628
644
  format_title: ((_discount$discount3 = discount.discount) === null || _discount$discount3 === void 0 ? void 0 : _discount$discount3.title) || discount.format_title,
@@ -815,7 +831,7 @@ export var ShopDiscountImpl = /*#__PURE__*/function (_BaseModule) {
815
831
  return this.core.effects.emit("".concat(this.name, ":onLoadPrepareCalcResult"), _result3);
816
832
  case 19:
817
833
  _context10.next = 21;
818
- return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), filteredDiscountList);
834
+ return this.core.effects.emit("".concat(this.name, ":onLoadDiscountList"), newDiscountList);
819
835
  case 21:
820
836
  _context10.next = 26;
821
837
  break;
@@ -23,6 +23,7 @@ export interface ShopDiscountState {
23
23
  discount: DiscountModule | null;
24
24
  rules: RulesModule | null;
25
25
  productList: Record<string, any>[];
26
+ orderTotalAmount?: number;
26
27
  holders?: {
27
28
  form_record_id: number;
28
29
  form_id?: number;
@@ -8,4 +8,5 @@ export var ShopDiscountHooks = /*#__PURE__*/function (ShopDiscountHooks) {
8
8
  ShopDiscountHooks["onRulesListChange"] = "shopDiscount:onRulesListChange";
9
9
  ShopDiscountHooks["onLoadPrepareCalcResult"] = "shopDiscount:onLoadPrepareCalcResult";
10
10
  return ShopDiscountHooks;
11
- }({});
11
+ }({});
12
+ ;
@@ -40,23 +40,37 @@ export var isAllNormalProduct = function isAllNormalProduct(items) {
40
40
  * @returns
41
41
  */
42
42
  export var getDiscountAmount = function getDiscountAmount(discount, total, price) {
43
- var _discount$metadata;
43
+ var discountedPrice = 0;
44
+
44
45
  // 商品券
45
46
  if (discount.tag === 'good_pass') {
46
- return new Decimal(price).minus(new Decimal(price || 0)).toNumber();
47
+ discountedPrice = new Decimal(price).minus(new Decimal(price || 0)).toNumber();
48
+ } else {
49
+ var _discount$metadata;
50
+ // 判断是否是固定金额
51
+ 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';
52
+
53
+ // 固定金额 小于0时返回0
54
+ if (isFixedAmount) {
55
+ discountedPrice = Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
56
+ } else {
57
+ // 百分比:根据折扣卡金额计算
58
+ discountedPrice = new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
59
+ }
47
60
  }
48
61
 
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
- }
62
+ /*
63
+ // 🔥 如果有 maxDeductionAmount 限制,确保折扣金额不超过限制
64
+ if (discount.config?.maxDeductionAmount) {
65
+ const actualDiscountAmount = new Decimal(price).minus(discountedPrice).toNumber();
66
+ if (actualDiscountAmount > discount.config.maxDeductionAmount) {
67
+ // 折扣金额超过限制,重新计算折扣后价格
68
+ discountedPrice = new Decimal(price).minus(discount.config.maxDeductionAmount).toNumber();
69
+ }
70
+ }
71
+ */
57
72
 
58
- // 百分比:根据折扣卡金额计算
59
- return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
73
+ return discountedPrice;
60
74
  };
61
75
  export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
62
76
  return discount.reduce(function (acc, cur) {
package/lib/index.d.ts CHANGED
@@ -6,6 +6,7 @@ export * from './types';
6
6
  export * from './modules';
7
7
  export * from './plugins';
8
8
  export * from './solution';
9
+ export * from './model';
9
10
  export { PisellOSCore } from './core';
10
11
  import PisellOSCore from './core';
11
12
  export default PisellOSCore;
package/lib/index.js CHANGED
@@ -38,6 +38,7 @@ __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);
41
42
  var import_core = require("./core");
42
43
  var import_core2 = __toESM(require("./core"));
43
44
  var src_default = import_core2.default;
@@ -47,5 +48,6 @@ var src_default = import_core2.default;
47
48
  ...require("./types"),
48
49
  ...require("./modules"),
49
50
  ...require("./plugins"),
50
- ...require("./solution")
51
+ ...require("./solution"),
52
+ ...require("./model")
51
53
  });
@@ -0,0 +1 @@
1
+ export * from './strategy';
@@ -0,0 +1,23 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
14
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
15
+
16
+ // src/model/index.ts
17
+ var model_exports = {};
18
+ module.exports = __toCommonJS(model_exports);
19
+ __reExport(model_exports, require("./strategy"), module.exports);
20
+ // Annotate the CommonJS export names for ESM import in node:
21
+ 0 && (module.exports = {
22
+ ...require("./strategy")
23
+ });
@@ -0,0 +1,3 @@
1
+ export * from './type';
2
+ export { default as WalletPassAdapter } from './walletPass';
3
+ export { WalletPassEvaluator } from './walletPass/evaluator';
@@ -0,0 +1,45 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/model/strategy/adapter/index.ts
31
+ var adapter_exports = {};
32
+ __export(adapter_exports, {
33
+ WalletPassAdapter: () => import_walletPass.default,
34
+ WalletPassEvaluator: () => import_evaluator.WalletPassEvaluator
35
+ });
36
+ module.exports = __toCommonJS(adapter_exports);
37
+ __reExport(adapter_exports, require("./type"), module.exports);
38
+ var import_walletPass = __toESM(require("./walletPass"));
39
+ var import_evaluator = require("./walletPass/evaluator");
40
+ // Annotate the CommonJS export names for ESM import in node:
41
+ 0 && (module.exports = {
42
+ WalletPassAdapter,
43
+ WalletPassEvaluator,
44
+ ...require("./type")
45
+ });
@@ -0,0 +1,28 @@
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
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/model/strategy/adapter/type.ts
16
+ var type_exports = {};
17
+ module.exports = __toCommonJS(type_exports);
@@ -0,0 +1,84 @@
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
+ }