@pisell/pisellos 2.2.59 → 2.2.60

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 (51) 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 +213 -0
  4. package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
  5. package/dist/model/strategy/adapter/promotion/index.d.ts +206 -0
  6. package/dist/model/strategy/adapter/promotion/index.js +0 -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/Payment/index.js +5 -5
  17. package/dist/modules/Rules/index.d.ts +1 -0
  18. package/dist/modules/Rules/index.js +30 -22
  19. package/dist/modules/Schedule/index.d.ts +2 -2
  20. package/dist/modules/Schedule/index.js +0 -2
  21. package/dist/solution/BookingByStep/index.js +1 -0
  22. package/dist/solution/BookingTicket/index.d.ts +1 -1
  23. package/dist/solution/Checkout/index.js +39 -43
  24. package/lib/model/strategy/adapter/index.d.ts +2 -0
  25. package/lib/model/strategy/adapter/index.js +5 -0
  26. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  27. package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
  28. package/lib/model/strategy/adapter/promotion/index.d.ts +206 -0
  29. package/lib/model/strategy/adapter/promotion/index.js +0 -0
  30. package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
  31. package/lib/model/strategy/adapter/promotion/type.js +51 -0
  32. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -1
  33. package/lib/model/strategy/engine.d.ts +106 -0
  34. package/lib/model/strategy/engine.js +450 -0
  35. package/lib/model/strategy/index.d.ts +2 -93
  36. package/lib/model/strategy/index.js +6 -381
  37. package/lib/modules/BaseModule.d.ts +4 -0
  38. package/lib/modules/BaseModule.js +3 -0
  39. package/lib/modules/Payment/index.js +5 -4
  40. package/lib/modules/Rules/index.d.ts +1 -0
  41. package/lib/modules/Rules/index.js +25 -23
  42. package/lib/modules/Schedule/index.d.ts +2 -2
  43. package/lib/modules/Schedule/index.js +0 -2
  44. package/lib/solution/BookingByStep/index.js +1 -0
  45. package/lib/solution/BookingTicket/index.d.ts +1 -1
  46. package/lib/solution/Checkout/index.js +5 -6
  47. package/package.json +1 -1
  48. package/dist/modules/Schedule/getDateIsInSchedule.d.ts +0 -32
  49. package/dist/modules/Schedule/getDateIsInSchedule.js +0 -747
  50. package/lib/modules/Schedule/getDateIsInSchedule.d.ts +0 -32
  51. package/lib/modules/Schedule/getDateIsInSchedule.js +0 -451
@@ -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 };
@@ -1,4 +1,5 @@
1
1
  export * from "./type";
2
2
  export { default as WalletPassAdapter } from "./walletPass";
3
3
  export { WalletPassEvaluator } from "./walletPass/evaluator";
4
- // export * from './walletPass/type';
4
+ import { PromotionEvaluator, PromotionAdapter } from "./promotion";
5
+ export { PromotionEvaluator, PromotionAdapter };
@@ -0,0 +1,213 @@
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
+ * @param matchVariant 是否需要匹配 product_variant_id,默认 true(严格匹配),false 时只匹配 product_id
115
+ * @returns 每个商品的适用策略完整数据
116
+ */
117
+ getProductsApplicableStrategies(input: PromotionEvaluatorInput, matchVariant?: boolean): Array<{
118
+ product: PromotionProduct;
119
+ applicableStrategies: Array<{
120
+ strategyId: string;
121
+ strategyName: string | Record<string, string>;
122
+ strategyMetadata: any;
123
+ actionType: string;
124
+ actionDetail: PromotionActionDetail;
125
+ display?: {
126
+ text: string | Record<string, string>;
127
+ type: string;
128
+ };
129
+ strategyConfig: StrategyConfig;
130
+ /** 满足促销所需的商品数量 */
131
+ requiredQuantity: number;
132
+ /** 可参与此促销的商品列表 */
133
+ eligibleProducts: Array<{
134
+ product_id: number;
135
+ product_variant_id: number;
136
+ }>;
137
+ }>;
138
+ hasApplicableStrategy: boolean;
139
+ }>;
140
+ /**
141
+ * 获取促销所需数量和可参与商品列表
142
+ *
143
+ * @param actionType 促销类型
144
+ * @param actionDetail 促销详情
145
+ * @param config 策略配置
146
+ * @returns { requiredQuantity, eligibleProducts }
147
+ */
148
+ private getPromotionRequirements;
149
+ /**
150
+ * 按优先级排序促销组
151
+ * 优先级从 strategyConfig.actions[0].priority 获取,数值越小优先级越高
152
+ */
153
+ private sortPromotionGroupsByPriority;
154
+ /**
155
+ * 处理 X件Y元 促销
156
+ *
157
+ * 1. 展开商品为单件列表,按价格从高到低排序
158
+ * 2. 计算可凑成的组数
159
+ * 3. 按原价比例均摊价格
160
+ * 4. 拆分商品(部分参与促销、部分原价)
161
+ *
162
+ * 注意:每个商品按 id 独立处理,不会合并不同 id 的商品
163
+ */
164
+ private processXItemsForYPrice;
165
+ /**
166
+ * 处理 买X送Y 促销
167
+ *
168
+ * 计算赠品数量,商品本身价格不变
169
+ * 支持 bundle 子商品的数量计算(主商品数量 × 子商品数量)
170
+ */
171
+ private processBuyXGetYFree;
172
+ /**
173
+ * 获取未参与任何促销的商品
174
+ */
175
+ private getRemainingProducts;
176
+ /**
177
+ * 价格统一保留两位小数
178
+ */
179
+ private formatPrice;
180
+ /**
181
+ * 获取商品唯一标识 key
182
+ * 使用商品的 id 作为唯一标识,不同 id 的商品不会被合并
183
+ */
184
+ private getProductKey;
185
+ /**
186
+ * 生成随机ID
187
+ */
188
+ private generateRandomId;
189
+ /**
190
+ * 商品匹配结果信息
191
+ */
192
+ private getProductMatchInfo;
193
+ /**
194
+ * 检查商品是否在策略的适用范围内
195
+ */
196
+ private isProductInStrategy;
197
+ /**
198
+ * 查找商品匹配规则
199
+ */
200
+ private findProductMatchRule;
201
+ /**
202
+ * 检查商品ID是否匹配配置列表
203
+ */
204
+ private isProductIdMatch;
205
+ /**
206
+ * 检查商品是否匹配配置(兼容旧方法)
207
+ */
208
+ private isProductMatch;
209
+ /**
210
+ * 获取展示配置
211
+ */
212
+ private getDisplayConfig;
213
+ }