@pisell/pisellos 2.2.45 → 2.2.47

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 (37) hide show
  1. package/dist/model/strategy/adapter/index.d.ts +2 -0
  2. package/dist/model/strategy/adapter/index.js +2 -1
  3. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +212 -0
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +1180 -0
  5. package/dist/model/strategy/adapter/promotion/index.d.ts +206 -0
  6. package/dist/model/strategy/adapter/promotion/index.js +447 -0
  7. package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
  8. package/dist/model/strategy/adapter/promotion/type.js +209 -0
  9. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -1
  10. package/dist/model/strategy/engine.d.ts +106 -0
  11. package/dist/model/strategy/engine.js +611 -0
  12. package/dist/model/strategy/index.d.ts +2 -93
  13. package/dist/model/strategy/index.js +6 -549
  14. package/dist/modules/BaseModule.d.ts +4 -0
  15. package/dist/modules/BaseModule.js +5 -0
  16. package/dist/modules/Rules/index.d.ts +1 -0
  17. package/dist/modules/Rules/index.js +28 -16
  18. package/dist/solution/BookingTicket/index.d.ts +1 -1
  19. package/lib/model/strategy/adapter/index.d.ts +2 -0
  20. package/lib/model/strategy/adapter/index.js +5 -0
  21. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +212 -0
  22. package/lib/model/strategy/adapter/promotion/evaluator.js +824 -0
  23. package/lib/model/strategy/adapter/promotion/index.d.ts +206 -0
  24. package/lib/model/strategy/adapter/promotion/index.js +386 -0
  25. package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
  26. package/lib/model/strategy/adapter/promotion/type.js +51 -0
  27. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -1
  28. package/lib/model/strategy/engine.d.ts +106 -0
  29. package/lib/model/strategy/engine.js +450 -0
  30. package/lib/model/strategy/index.d.ts +2 -93
  31. package/lib/model/strategy/index.js +6 -381
  32. package/lib/modules/BaseModule.d.ts +4 -0
  33. package/lib/modules/BaseModule.js +3 -0
  34. package/lib/modules/Rules/index.d.ts +1 -0
  35. package/lib/modules/Rules/index.js +23 -17
  36. package/lib/solution/BookingTicket/index.d.ts +1 -1
  37. package/package.json +1 -1
@@ -201,6 +201,13 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
201
201
  productList: hasApplicableDiscount ? result.productList : productList
202
202
  };
203
203
  }
204
+ }, {
205
+ key: "filterDiscountListByType",
206
+ value: function filterDiscountListByType(discountList, type) {
207
+ return (discountList || []).filter(function (item) {
208
+ return item.type === type || item.tag === type;
209
+ });
210
+ }
204
211
  }, {
205
212
  key: "calcDiscount",
206
213
  value: function calcDiscount(_ref2, options) {
@@ -953,6 +960,9 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
953
960
  }) && (!((_product$discount_lis5 = product.discount_list) !== null && _product$discount_lis5 !== void 0 && _product$discount_lis5.length) || ((_product11 = product) === null || _product11 === void 0 || (_product11 = _product11.discount_list) === null || _product11 === void 0 || (_product11$every = _product11.every) === null || _product11$every === void 0 ? void 0 : _product11$every.call(_product11, function (item) {
954
961
  return item.type === 'product';
955
962
  })));
963
+ if (product.inPromotion) {
964
+ isManualDiscount = false;
965
+ }
956
966
  } else {
957
967
  // bundle子商品:判断父主商品是否手动折扣
958
968
  var parentProduct = flatItem.parentProduct;
@@ -1048,25 +1058,27 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1048
1058
  }),
1049
1059
  price: product.price
1050
1060
  }), {}, {
1051
- discount_list: []
1061
+ discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
1052
1062
  }))]);
1053
1063
  } else {
1064
+ var _ref7, _product$_promotion$f, _product12;
1054
1065
  processedProductsMap.set(product._id, [_this3.hooks.setProduct(originProduct, _objectSpread(_objectSpread({}, isManualDiscount ? {
1055
1066
  price: product.price,
1056
1067
  main_product_selling_price: product.price
1057
1068
  } : {
1058
1069
  _id: product._id.split('___')[0] + '___' + index,
1059
- total: product.origin_total || product.total,
1070
+ total: product.inPromotion ? (_ref7 = (_product$_promotion$f = (_product12 = product) === null || _product12 === void 0 || (_product12 = _product12._promotion) === null || _product12 === void 0 ? void 0 : _product12.finalPrice) !== null && _product$_promotion$f !== void 0 ? _product$_promotion$f : product.origin_total) !== null && _ref7 !== void 0 ? _ref7 : product.total : product.origin_total || product.total,
1060
1071
  price: product.price,
1061
1072
  main_product_selling_price: product.price
1062
1073
  }), {}, {
1063
- discount_list: []
1074
+ discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion')
1064
1075
  }))]);
1065
1076
  }
1066
1077
  } else {
1078
+ var _flatItem$bundleItem8;
1067
1079
  // bundle子商品:保存到扁平化Map
1068
1080
  processedFlatItemsMap.set(flatItem._id, [_objectSpread(_objectSpread({}, flatItem), {}, {
1069
- discount_list: [],
1081
+ discount_list: _this3.filterDiscountListByType(((_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.discount_list) || [], 'promotion'),
1070
1082
  price: isManualDiscount ? flatItem.bundleItem.price : flatItem.bundleItem.original_price,
1071
1083
  processed: true
1072
1084
  })]);
@@ -1099,14 +1111,14 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1099
1111
  // 主商品:保持原有逻辑
1100
1112
  if (splitCount < totalQuantity && isNeedSplit) {
1101
1113
  arr.push(_this3.hooks.setProduct(originProduct, {
1102
- discount_list: [],
1114
+ discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
1103
1115
  quantity: totalQuantity - splitCount,
1104
1116
  _id: product._id.split('___')[0],
1105
1117
  total: product.origin_total || product.total
1106
1118
  }));
1107
1119
  }
1108
1120
  for (var i = 0; i < splitCount; i++) {
1109
- var _product$discount_lis10, _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
1121
+ var _originProduct, _selectedDiscount$met, _selectedDiscount$met2;
1110
1122
  // 如果用过折扣卡,也就不存在拆分的情况了,这里直接使用上面计算出来的折扣卡
1111
1123
  var _selectedDiscount = selectedDiscountCard || applicableDiscounts[i];
1112
1124
  // 标记优惠券为已使用
@@ -1123,7 +1135,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1123
1135
  // 优先从 origin_total拿,可能会拿不到(比如用户端预约在没有配置 original_price 的情况下)
1124
1136
  var productOriginTotal = product.origin_total || product.total || 0;
1125
1137
  // 如果当前 product 有 discount_list,则先从 origin_total 拿
1126
- if ((_product$discount_lis10 = product.discount_list) !== null && _product$discount_lis10 !== void 0 && _product$discount_lis10.length && product.origin_total) {
1138
+ if (_this3.filterDiscountListByType(product.discount_list, 'promotion').length && product.origin_total) {
1127
1139
  productOriginTotal = product.origin_total;
1128
1140
  }
1129
1141
  // 如果originProduct?._productInit?.original_price为 0,product.origin_total可能为空,此时取 product.total
@@ -1205,7 +1217,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1205
1217
  }));
1206
1218
  } else {
1207
1219
  arr.push(_this3.hooks.setProduct(originProduct, {
1208
- discount_list: [discountDetail],
1220
+ discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion').concat([discountDetail]),
1209
1221
  _id: product._id.split('___')[0] + '___' + _selectedDiscount.id + index,
1210
1222
  price: _selectedDiscount.tag === 'good_pass' ? 0 : product.price,
1211
1223
  quantity: isNeedSplit ? 1 : product.quantity,
@@ -1376,7 +1388,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1376
1388
  var getDefaultProduct = function getDefaultProduct() {
1377
1389
  if (product.isClient) {
1378
1390
  return _this3.hooks.setProduct(originProduct, {
1379
- discount_list: [],
1391
+ discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
1380
1392
  price: product.price,
1381
1393
  origin_total: getProductOriginTotalPrice({
1382
1394
  product: {
@@ -1397,7 +1409,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1397
1409
  });
1398
1410
  } else {
1399
1411
  return _this3.hooks.setProduct(originProduct, {
1400
- discount_list: [],
1412
+ discount_list: _this3.filterDiscountListByType(product.discount_list, 'promotion'),
1401
1413
  total: product.total,
1402
1414
  origin_total: product.origin_total,
1403
1415
  price: product.price
@@ -1853,10 +1865,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1853
1865
  return true; // 单独购买时可用
1854
1866
  }
1855
1867
  if (isBundleItem) {
1856
- var _flatItem$bundleItem8, _flatItem$bundleItem9;
1868
+ var _flatItem$bundleItem9, _flatItem$bundleItem10;
1857
1869
  // 套餐中购买时,判断是否为原价
1858
- var priceType = (_flatItem$bundleItem8 = flatItem.bundleItem) === null || _flatItem$bundleItem8 === void 0 ? void 0 : _flatItem$bundleItem8.price_type;
1859
- var priceTypeExt = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type_ext;
1870
+ var priceType = (_flatItem$bundleItem9 = flatItem.bundleItem) === null || _flatItem$bundleItem9 === void 0 ? void 0 : _flatItem$bundleItem9.price_type;
1871
+ var priceTypeExt = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type_ext;
1860
1872
  // original_price 对应:
1861
1873
  // 1. price_type: "markup" && price_type_ext: "product_price"
1862
1874
  // markup_price 对应:
@@ -1894,10 +1906,10 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1894
1906
  return false; // 单独购买时不可用
1895
1907
  }
1896
1908
  if (isBundleItem) {
1897
- var _flatItem$bundleItem10, _flatItem$bundleItem11;
1909
+ var _flatItem$bundleItem11, _flatItem$bundleItem12;
1898
1910
  // 套餐中购买时,判断是否为原价
1899
- var _priceType = (_flatItem$bundleItem10 = flatItem.bundleItem) === null || _flatItem$bundleItem10 === void 0 ? void 0 : _flatItem$bundleItem10.price_type;
1900
- var _priceTypeExt = (_flatItem$bundleItem11 = flatItem.bundleItem) === null || _flatItem$bundleItem11 === void 0 ? void 0 : _flatItem$bundleItem11.price_type_ext;
1911
+ var _priceType = (_flatItem$bundleItem11 = flatItem.bundleItem) === null || _flatItem$bundleItem11 === void 0 ? void 0 : _flatItem$bundleItem11.price_type;
1912
+ var _priceTypeExt = (_flatItem$bundleItem12 = flatItem.bundleItem) === null || _flatItem$bundleItem12 === void 0 ? void 0 : _flatItem$bundleItem12.price_type_ext;
1901
1913
 
1902
1914
  // original_price 对应:
1903
1915
  // 1. price_type: "markup" && price_type_ext: "product_price"
@@ -123,7 +123,7 @@ export declare class BookingTicketImpl extends BaseModule implements Module {
123
123
  * 获取当前的客户搜索条件
124
124
  * @returns 当前搜索条件
125
125
  */
126
- getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "num" | "skip">;
126
+ getCurrentCustomerSearchParams(): Omit<import("../../modules").ShopGetCustomerListParams, "skip" | "num">;
127
127
  /**
128
128
  * 获取客户列表状态(包含滚动加载相关状态)
129
129
  * @returns 客户状态
@@ -1,3 +1,5 @@
1
1
  export * from './type';
2
2
  export { default as WalletPassAdapter } from './walletPass';
3
3
  export { WalletPassEvaluator } from './walletPass/evaluator';
4
+ import { PromotionEvaluator, PromotionAdapter } from './promotion';
5
+ export { PromotionEvaluator, PromotionAdapter };
@@ -30,6 +30,8 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
30
30
  // src/model/strategy/adapter/index.ts
31
31
  var adapter_exports = {};
32
32
  __export(adapter_exports, {
33
+ PromotionAdapter: () => import_promotion.PromotionAdapter,
34
+ PromotionEvaluator: () => import_promotion.PromotionEvaluator,
33
35
  WalletPassAdapter: () => import_walletPass.default,
34
36
  WalletPassEvaluator: () => import_evaluator.WalletPassEvaluator
35
37
  });
@@ -37,8 +39,11 @@ module.exports = __toCommonJS(adapter_exports);
37
39
  __reExport(adapter_exports, require("./type"), module.exports);
38
40
  var import_walletPass = __toESM(require("./walletPass"));
39
41
  var import_evaluator = require("./walletPass/evaluator");
42
+ var import_promotion = require("./promotion");
40
43
  // Annotate the CommonJS export names for ESM import in node:
41
44
  0 && (module.exports = {
45
+ PromotionAdapter,
46
+ PromotionEvaluator,
42
47
  WalletPassAdapter,
43
48
  WalletPassEvaluator,
44
49
  ...require("./type")
@@ -0,0 +1,212 @@
1
+ import type { StrategyConfig } from '../../type';
2
+ import { type PromotionProduct, type PromotionActionDetail, type PromotionEvaluatorInput, type ProductPromotionResult, type ApplicablePromotion, type CartEvaluationResult, type CartWithPricingResult } from './type';
3
+ /**
4
+ * Promotion 评估器
5
+ *
6
+ * 用于评估商品适用的促销活动
7
+ * 封装了 StrategyEngine 和 PromotionAdapter 的调用逻辑
8
+ */
9
+ export declare class PromotionEvaluator {
10
+ private engine;
11
+ private adapter;
12
+ private strategyConfigs;
13
+ private locale;
14
+ private locales;
15
+ constructor();
16
+ /**
17
+ * 设置策略配置列表
18
+ */
19
+ setStrategyConfigs(strategyConfigs: StrategyConfig[]): void;
20
+ /**
21
+ * 获取策略配置列表
22
+ */
23
+ getStrategyConfigs(): StrategyConfig[];
24
+ /**
25
+ * 添加策略配置
26
+ */
27
+ addStrategyConfig(strategyConfig: StrategyConfig): void;
28
+ /**
29
+ * 设置语言
30
+ */
31
+ setLocale(locale: string): void;
32
+ /**
33
+ * 设置自定义多语言文案
34
+ */
35
+ setLocales(locales: Record<string, Record<string, string>>): void;
36
+ /**
37
+ * 获取多语言文案
38
+ */
39
+ getText(key: string): string;
40
+ /**
41
+ * 获取多语言名称
42
+ */
43
+ getLocalizedName(name: string | Record<string, string>): string;
44
+ /**
45
+ * 评估商品列表
46
+ *
47
+ * 判断每个商品适用哪些促销活动
48
+ * 支持主商品和 bundle 子商品的匹配
49
+ *
50
+ * @param input 评估输入
51
+ * @returns 每个商品的促销评估结果
52
+ */
53
+ evaluateProducts(input: PromotionEvaluatorInput): ProductPromotionResult[];
54
+ /**
55
+ * 评估购物车
56
+ *
57
+ * 返回所有适用的促销及按促销分组的商品
58
+ * 支持 bundle 子商品的数量计算(主商品数量 × 子商品数量)
59
+ *
60
+ * @param input 评估输入
61
+ * @returns 购物车评估结果
62
+ */
63
+ evaluateCart(input: PromotionEvaluatorInput): CartEvaluationResult;
64
+ /**
65
+ * 评估购物车并计算定价
66
+ *
67
+ * 返回处理后的商品数组(包含拆分、finalPrice)和赠品信息
68
+ * - 对于 X_ITEMS_FOR_Y_PRICE:按原价比例均摊价格,优先使用高价商品
69
+ * - 对于 BUY_X_GET_Y_FREE:计算赠品数量和可选赠品列表
70
+ *
71
+ * @param input 评估输入
72
+ * @returns 带定价的购物车评估结果
73
+ */
74
+ evaluateCartWithPricing(input: PromotionEvaluatorInput): CartWithPricingResult;
75
+ /**
76
+ * 获取商品适用的促销列表
77
+ *
78
+ * 简化方法,用于商品卡片展示
79
+ *
80
+ * @param product 商品
81
+ * @param strategyConfigs 策略配置(可选)
82
+ * @returns 适用的促销列表
83
+ */
84
+ getProductPromotions(product: PromotionProduct, strategyConfigs?: StrategyConfig[]): ApplicablePromotion[];
85
+ /**
86
+ * 获取商品的促销标签
87
+ *
88
+ * 用于商品卡片展示
89
+ *
90
+ * @param product 商品
91
+ * @param strategyConfigs 策略配置(可选)
92
+ * @returns 促销标签列表
93
+ */
94
+ getProductPromotionTags(product: PromotionProduct, strategyConfigs?: StrategyConfig[]): Array<{
95
+ text: string;
96
+ type: string;
97
+ strategyId: string;
98
+ }>;
99
+ /**
100
+ * 查找商品适用的策略配置
101
+ *
102
+ * @param product 商品
103
+ * @param strategyConfigs 策略配置列表(可选)
104
+ * @returns 适用的策略配置列表
105
+ */
106
+ findApplicableStrategies(product: PromotionProduct, strategyConfigs?: StrategyConfig[]): StrategyConfig[];
107
+ /**
108
+ * 批量获取商品列表的适用策略信息
109
+ *
110
+ * 用于给商品列表追加策略标签信息
111
+ * 只检查商品 ID 匹配和策略时间范围
112
+ *
113
+ * @param input 评估输入(商品列表)
114
+ * @returns 每个商品的适用策略完整数据
115
+ */
116
+ getProductsApplicableStrategies(input: PromotionEvaluatorInput): Array<{
117
+ product: PromotionProduct;
118
+ applicableStrategies: Array<{
119
+ strategyId: string;
120
+ strategyName: string | Record<string, string>;
121
+ strategyMetadata: any;
122
+ actionType: string;
123
+ actionDetail: PromotionActionDetail;
124
+ display?: {
125
+ text: string | Record<string, string>;
126
+ type: string;
127
+ };
128
+ strategyConfig: StrategyConfig;
129
+ /** 满足促销所需的商品数量 */
130
+ requiredQuantity: number;
131
+ /** 可参与此促销的商品列表 */
132
+ eligibleProducts: Array<{
133
+ product_id: number;
134
+ product_variant_id: number;
135
+ }>;
136
+ }>;
137
+ hasApplicableStrategy: boolean;
138
+ }>;
139
+ /**
140
+ * 获取促销所需数量和可参与商品列表
141
+ *
142
+ * @param actionType 促销类型
143
+ * @param actionDetail 促销详情
144
+ * @param config 策略配置
145
+ * @returns { requiredQuantity, eligibleProducts }
146
+ */
147
+ private getPromotionRequirements;
148
+ /**
149
+ * 按优先级排序促销组
150
+ * 优先级从 strategyConfig.actions[0].priority 获取,数值越小优先级越高
151
+ */
152
+ private sortPromotionGroupsByPriority;
153
+ /**
154
+ * 处理 X件Y元 促销
155
+ *
156
+ * 1. 展开商品为单件列表,按价格从高到低排序
157
+ * 2. 计算可凑成的组数
158
+ * 3. 按原价比例均摊价格
159
+ * 4. 拆分商品(部分参与促销、部分原价)
160
+ *
161
+ * 注意:每个商品按 id 独立处理,不会合并不同 id 的商品
162
+ */
163
+ private processXItemsForYPrice;
164
+ /**
165
+ * 处理 买X送Y 促销
166
+ *
167
+ * 计算赠品数量,商品本身价格不变
168
+ * 支持 bundle 子商品的数量计算(主商品数量 × 子商品数量)
169
+ */
170
+ private processBuyXGetYFree;
171
+ /**
172
+ * 获取未参与任何促销的商品
173
+ */
174
+ private getRemainingProducts;
175
+ /**
176
+ * 价格统一保留两位小数
177
+ */
178
+ private formatPrice;
179
+ /**
180
+ * 获取商品唯一标识 key
181
+ * 使用商品的 id 作为唯一标识,不同 id 的商品不会被合并
182
+ */
183
+ private getProductKey;
184
+ /**
185
+ * 生成随机ID
186
+ */
187
+ private generateRandomId;
188
+ /**
189
+ * 商品匹配结果信息
190
+ */
191
+ private getProductMatchInfo;
192
+ /**
193
+ * 检查商品是否在策略的适用范围内
194
+ */
195
+ private isProductInStrategy;
196
+ /**
197
+ * 查找商品匹配规则
198
+ */
199
+ private findProductMatchRule;
200
+ /**
201
+ * 检查商品ID是否匹配配置列表
202
+ */
203
+ private isProductIdMatch;
204
+ /**
205
+ * 检查商品是否匹配配置(兼容旧方法)
206
+ */
207
+ private isProductMatch;
208
+ /**
209
+ * 获取展示配置
210
+ */
211
+ private getDisplayConfig;
212
+ }