@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
@@ -0,0 +1,209 @@
1
+ /**
2
+ * Promotion 策略类型定义
3
+ *
4
+ * 定义促销活动相关的 Action 类型、值结构和配置
5
+ */
6
+
7
+ // ============================================
8
+ // Action Type 常量
9
+ // ============================================
10
+
11
+ /**
12
+ * 促销活动 Action 类型
13
+ */
14
+ export var PROMOTION_ACTION_TYPES = {
15
+ /** X件Y元(每X件固定价格Y元,可累计) */
16
+ X_ITEMS_FOR_Y_PRICE: 'X_ITEMS_FOR_Y_PRICE',
17
+ /** 买X送Y(买X件送Y件,可累计) */
18
+ BUY_X_GET_Y_FREE: 'BUY_X_GET_Y_FREE',
19
+ /** 固定折扣 */
20
+ DISCOUNT_RATE: 'DISCOUNT_RATE',
21
+ /** 固定减价 */
22
+ DEDUCT_AMOUNT: 'DEDUCT_AMOUNT'
23
+ };
24
+
25
+ // ============================================
26
+ // Action Value 类型定义
27
+ // ============================================
28
+
29
+ /**
30
+ * X件Y元 - Action Value
31
+ *
32
+ * @example
33
+ * value: { x: 2, price: 10 } // 每2件10元
34
+ */
35
+
36
+ /**
37
+ * X件Y元 - Action Config
38
+ */
39
+
40
+ /**
41
+ * 买X送Y - Action Value
42
+ *
43
+ * @example
44
+ * value: { buyQuantity: 1, freeQuantity: 1 } // 买1送1
45
+ */
46
+
47
+ /**
48
+ * 赠品选择模式
49
+ */
50
+
51
+ // 自动选最便宜的
52
+
53
+ /**
54
+ * 买X送Y - Action Config
55
+ */
56
+
57
+ // ============================================
58
+ // 商品标识
59
+ // ============================================
60
+
61
+ /**
62
+ * 商品标识
63
+ *
64
+ * 匹配规则:
65
+ * - product_variant_id = 0 表示匹配任意变体
66
+ * - product_variant_id != 0 表示精确匹配该变体
67
+ */
68
+
69
+ // ============================================
70
+ // 完整的 Promotion Action 类型
71
+ // ============================================
72
+
73
+ /**
74
+ * X件Y元 Action
75
+ */
76
+
77
+ /**
78
+ * 买X送Y Action
79
+ */
80
+
81
+ /**
82
+ * 促销活动 Action 联合类型
83
+ */
84
+
85
+ // ============================================
86
+ // 运算符常量
87
+ // ============================================
88
+
89
+ /**
90
+ * 促销相关运算符
91
+ */
92
+ export var PROMOTION_OPERATORS = {
93
+ /**
94
+ * 商品匹配运算符
95
+ *
96
+ * 匹配规则:
97
+ * - 首先匹配 product_id
98
+ * - 如果配置的 product_variant_id = 0,只需要 product_id 匹配
99
+ * - 如果配置的 product_variant_id != 0,还需要 product_variant_id 匹配
100
+ */
101
+ PRODUCT_MATCH: 'product_match'
102
+ };
103
+
104
+ // ============================================
105
+ // 业务数据类型(输入)
106
+ // ============================================
107
+
108
+ /**
109
+ * 促销活动业务数据
110
+ *
111
+ * 由业务层传入,用于策略评估
112
+ */
113
+
114
+ var obj = {
115
+ product_id: 1,
116
+ product_variant_id: 0,
117
+ quantity: 1,
118
+ price: 100,
119
+ original_price: 100,
120
+ id: 1
121
+ };
122
+
123
+ /**
124
+ * 促销商品信息
125
+ */
126
+
127
+ // ============================================
128
+ // 适配器输出类型
129
+ // ============================================
130
+
131
+ /**
132
+ * 促销活动适配器转换结果
133
+ *
134
+ * 返回给业务层,包含策略匹配信息
135
+ */
136
+
137
+ /**
138
+ * Action 详情联合类型
139
+ */
140
+
141
+ /**
142
+ * X件Y元 Action 详情
143
+ */
144
+
145
+ /**
146
+ * 买X送Y Action 详情
147
+ */
148
+
149
+ // ============================================
150
+ // 业务层输出类型(供参考)
151
+ // ============================================
152
+
153
+ /**
154
+ * X件Y元 - 业务层计算结果
155
+ *
156
+ * 由业务层根据 matchedAction 计算后返回
157
+ */
158
+
159
+ /**
160
+ * 买X送Y - 业务层计算结果
161
+ *
162
+ * 由业务层根据 matchedAction 计算后返回
163
+ */
164
+
165
+ /**
166
+ * 评估器输入
167
+ */
168
+
169
+ /**
170
+ * 单商品评估结果
171
+ */
172
+
173
+ /**
174
+ * 适用的促销信息
175
+ */
176
+
177
+ /**
178
+ * 购物车评估结果
179
+ */
180
+
181
+ /**
182
+ * 购物车适用的促销
183
+ */
184
+
185
+ /**
186
+ * 促销分组
187
+ */
188
+
189
+ // ============================================
190
+ // 带定价的购物车评估结果类型
191
+ // ============================================
192
+
193
+ /**
194
+ * 带定价的商品
195
+ *
196
+ * 在 PromotionProduct 基础上增加了均摊后的最终价格和促销信息
197
+ */
198
+
199
+ /**
200
+ * 赠品信息
201
+ *
202
+ * 记录某个促销产生的赠品数量和可选赠品列表
203
+ */
204
+
205
+ /**
206
+ * 带定价的购物车评估结果
207
+ *
208
+ * evaluateCartWithPricing 方法的返回结果
209
+ */
@@ -40,7 +40,10 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
40
40
  _createClass(WalletPassEvaluator, [{
41
41
  key: "setStrategyConfigs",
42
42
  value: function setStrategyConfigs(strategyConfigs) {
43
- this.strategyConfigs = strategyConfigs;
43
+ var newStrategyConfigs = strategyConfigs.filter(function (item) {
44
+ return item.metadata.type === 'wallet_pass';
45
+ });
46
+ this.strategyConfigs = newStrategyConfigs;
44
47
  }
45
48
  }, {
46
49
  key: "getStrategyConfigs",
@@ -0,0 +1,106 @@
1
+ import { StrategyConfig, RuntimeContext, EvaluationResult, EngineOptions, OperatorHandler } from './type';
2
+ /**
3
+ * 策略模型 - 核心实现
4
+ *
5
+ * 完全业务无关的通用策略引擎
6
+ * 支持条件评估、动作匹配、结果返回
7
+ */
8
+ /**
9
+ * 策略引擎
10
+ *
11
+ * 核心职责:
12
+ * 1. 递归评估条件组
13
+ * 2. 收集满足条件的 actionIds
14
+ * 3. 根据 actionIds 获取 ActionEffect 对象
15
+ * 4. 按 priority 排序返回
16
+ */
17
+ export declare class StrategyEngine {
18
+ private options;
19
+ private operatorHandlers;
20
+ constructor(options?: EngineOptions);
21
+ /**
22
+ * 评估策略
23
+ */
24
+ evaluate(config: StrategyConfig, context: RuntimeContext): EvaluationResult;
25
+ /**
26
+ * 递归评估条件组
27
+ *
28
+ * @param group 条件组
29
+ * @param context 运行时上下文
30
+ * @returns 评估结果对象,包含条件是否满足和收集到的 actionIds
31
+ */
32
+ private evaluateConditionGroup;
33
+ /**
34
+ * 评估条件组的逻辑运算
35
+ */
36
+ private evaluateGroupLogic;
37
+ /**
38
+ * 评估单个规则
39
+ */
40
+ private evaluateRule;
41
+ /**
42
+ * 评估代码模式条件
43
+ */
44
+ private evaluateCodeCondition;
45
+ /**
46
+ * 评估运算符模式条件
47
+ */
48
+ private evaluateOperatorCondition;
49
+ /**
50
+ * 获取字段值
51
+ */
52
+ private getFieldValue;
53
+ /**
54
+ * 评估内置运算符
55
+ */
56
+ private evaluateBuiltInOperator;
57
+ /**
58
+ * 根据 actionIds 获取 ActionEffect 对象
59
+ */
60
+ private getActionsByIds;
61
+ /**
62
+ * 按 priority 排序(降序)
63
+ */
64
+ private sortActionsByPriority;
65
+ /**
66
+ * 判断是否为条件组
67
+ */
68
+ private isConditionGroup;
69
+ /**
70
+ * 验证配置
71
+ */
72
+ private validateConfig;
73
+ /**
74
+ * 初始化内置运算符处理器
75
+ */
76
+ private initializeBuiltInOperators;
77
+ /**
78
+ * 评估商品匹配运算符
79
+ *
80
+ * 匹配规则:
81
+ * - 首先匹配 product_id
82
+ * - 如果配置的 product_variant_id = 0,只需要 product_id 匹配(表示任意变体)
83
+ * - 如果配置的 product_variant_id != 0,还需要 product_variant_id 精确匹配
84
+ *
85
+ * @param fieldValue 实际商品 { product_id: number, product_variant_id: number }
86
+ * @param configValue 配置的商品列表 Array<{ product_id: number, product_variant_id: number }>
87
+ * @returns 是否匹配
88
+ */
89
+ private evaluateProductMatch;
90
+ /**
91
+ * 注册自定义运算符
92
+ */
93
+ registerOperator(operator: string, handler: OperatorHandler): void;
94
+ /**
95
+ * 获取调试信息
96
+ */
97
+ getDebugInfo(): Record<string, any>;
98
+ }
99
+ /**
100
+ * 创建策略引擎实例
101
+ */
102
+ export declare function createStrategyEngine(options?: EngineOptions): StrategyEngine;
103
+ /**
104
+ * 快速评估(使用默认引擎配置)
105
+ */
106
+ export declare function evaluate(config: StrategyConfig, context: RuntimeContext): EvaluationResult;