@pisell/pisellos 2.1.53 → 2.1.54

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 (95) 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 +496 -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 +23 -0
  17. package/dist/model/strategy/adapter/walletPass/type.d.ts +163 -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 +965 -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 +15 -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/Rules/index.d.ts +8 -3
  36. package/dist/modules/Rules/index.js +155 -29
  37. package/dist/modules/Rules/types.d.ts +1 -0
  38. package/dist/modules/Summary/types.d.ts +2 -0
  39. package/dist/modules/Summary/utils.d.ts +6 -0
  40. package/dist/modules/Summary/utils.js +21 -0
  41. package/dist/plugins/window.d.ts +2 -0
  42. package/dist/solution/BookingByStep/index.d.ts +2 -1
  43. package/dist/solution/Checkout/index.js +2 -0
  44. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  45. package/dist/solution/ShopDiscount/index.js +14 -4
  46. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  47. package/dist/solution/ShopDiscount/utils.js +26 -11
  48. package/lib/index.d.ts +1 -0
  49. package/lib/index.js +3 -1
  50. package/lib/model/index.d.ts +1 -0
  51. package/lib/model/index.js +23 -0
  52. package/lib/model/strategy/adapter/index.d.ts +3 -0
  53. package/lib/model/strategy/adapter/index.js +45 -0
  54. package/lib/model/strategy/adapter/type.d.ts +28 -0
  55. package/lib/model/strategy/adapter/type.js +17 -0
  56. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  57. package/lib/model/strategy/adapter/walletPass/evaluator.js +420 -0
  58. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  59. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  60. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  61. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  62. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  63. package/lib/model/strategy/adapter/walletPass/locales.js +51 -0
  64. package/lib/model/strategy/adapter/walletPass/type.d.ts +163 -0
  65. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  66. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  67. package/lib/model/strategy/adapter/walletPass/utils.js +660 -0
  68. package/lib/model/strategy/index.d.ts +94 -0
  69. package/lib/model/strategy/index.js +413 -0
  70. package/lib/model/strategy/strategy-example.d.ts +5 -0
  71. package/lib/model/strategy/strategy-example.js +318 -0
  72. package/lib/model/strategy/type.d.ts +228 -0
  73. package/lib/model/strategy/type.js +44 -0
  74. package/lib/modules/Cart/types.d.ts +2 -0
  75. package/lib/modules/Cart/utils/cartProduct.js +9 -0
  76. package/lib/modules/Discount/types.d.ts +15 -0
  77. package/lib/modules/Payment/index.d.ts +2 -1
  78. package/lib/modules/Payment/index.js +1 -0
  79. package/lib/modules/Payment/utils.js +3 -0
  80. package/lib/modules/Payment/walletpass.d.ts +23 -0
  81. package/lib/modules/Payment/walletpass.js +94 -17
  82. package/lib/modules/Rules/index.d.ts +8 -3
  83. package/lib/modules/Rules/index.js +373 -195
  84. package/lib/modules/Rules/types.d.ts +1 -0
  85. package/lib/modules/Summary/types.d.ts +2 -0
  86. package/lib/modules/Summary/utils.d.ts +6 -0
  87. package/lib/modules/Summary/utils.js +15 -0
  88. package/lib/plugins/window.d.ts +2 -0
  89. package/lib/solution/BookingByStep/index.d.ts +2 -1
  90. package/lib/solution/Checkout/index.js +2 -0
  91. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  92. package/lib/solution/ShopDiscount/index.js +9 -3
  93. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  94. package/lib/solution/ShopDiscount/utils.js +10 -6
  95. package/package.json +1 -1
@@ -0,0 +1,331 @@
1
+ /**
2
+ * 策略模型使用示例
3
+ */
4
+
5
+ import { createStrategyEngine, evaluate } from "./index";
6
+ // ============================================
7
+ // 示例1: 简单的代金券(单层条件)
8
+ // ============================================
9
+
10
+ var voucherConfig = {
11
+ metadata: {
12
+ id: 'VOUCHER_10',
13
+ name: '10元代金券',
14
+ type: 'wallet_pass',
15
+ calculationType: 'single'
16
+ },
17
+ conditions: {
18
+ operator: 'and',
19
+ rules: [{
20
+ type: 'operator',
21
+ dimension: 'scope_product',
22
+ field: 'productId',
23
+ operator: 'in',
24
+ value: [60734, 60735]
25
+ }, {
26
+ type: 'operator',
27
+ dimension: 'scope_channel',
28
+ field: 'channel',
29
+ operator: 'in',
30
+ value: ['pos', 'mini_program']
31
+ }, {
32
+ type: 'operator',
33
+ dimension: 'transaction',
34
+ field: 'applicableProductTotal',
35
+ operator: '>=',
36
+ value: 100
37
+ }, {
38
+ type: 'operator',
39
+ dimension: 'limit_usage',
40
+ field: 'perUserUsedCount',
41
+ operator: '<',
42
+ value: 1
43
+ }],
44
+ actionIds: ['deduct_10']
45
+ },
46
+ actions: [{
47
+ id: 'deduct_10',
48
+ type: 'DEDUCT_AMOUNT',
49
+ value: 10,
50
+ valueType: 'number',
51
+ valueUnit: '元',
52
+ target: 'applicable_products',
53
+ priority: 1,
54
+ config: {
55
+ allowCrossProduct: true,
56
+ deductTaxAndFee: true
57
+ }
58
+ }]
59
+ };
60
+
61
+ // 运行时上下文
62
+ var voucherContext = {
63
+ entities: {
64
+ order: {
65
+ id: 'ORDER_001',
66
+ total: 150,
67
+ items: [{
68
+ productId: 60734,
69
+ quantity: 2,
70
+ price: 75
71
+ }]
72
+ },
73
+ customer: {
74
+ id: 'USER_001',
75
+ level: 'vip'
76
+ }
77
+ },
78
+ attributes: {
79
+ productId: 60734,
80
+ channel: 'pos',
81
+ applicableProductTotal: 150,
82
+ perUserUsedCount: 0
83
+ },
84
+ metadata: {
85
+ timestamp: Date.now(),
86
+ locale: 'zh-CN'
87
+ }
88
+ };
89
+
90
+ // ============================================
91
+ // 示例2: 阶梯式满减(嵌套条件)
92
+ // ============================================
93
+
94
+ var tieredDiscountConfig = {
95
+ metadata: {
96
+ id: 'TIERED_DISCOUNT',
97
+ name: '阶梯满减',
98
+ type: 'promotion',
99
+ calculationType: 'single'
100
+ },
101
+ conditions: {
102
+ operator: 'or',
103
+ rules: [
104
+ // 档位1:100-199 减10
105
+ {
106
+ operator: 'and',
107
+ rules: [{
108
+ type: 'operator',
109
+ dimension: 'transaction',
110
+ field: 'orderTotal',
111
+ operator: '>=',
112
+ value: 100
113
+ }, {
114
+ type: 'operator',
115
+ dimension: 'transaction',
116
+ field: 'orderTotal',
117
+ operator: '<',
118
+ value: 200
119
+ }],
120
+ actionIds: ['deduct_10']
121
+ },
122
+ // 档位2:200-299 减25
123
+ {
124
+ operator: 'and',
125
+ rules: [{
126
+ type: 'operator',
127
+ dimension: 'transaction',
128
+ field: 'orderTotal',
129
+ operator: '>=',
130
+ value: 200
131
+ }, {
132
+ type: 'operator',
133
+ dimension: 'transaction',
134
+ field: 'orderTotal',
135
+ operator: '<',
136
+ value: 300
137
+ }],
138
+ actionIds: ['deduct_25']
139
+ },
140
+ // 档位3:>= 300 减40
141
+ {
142
+ operator: 'and',
143
+ rules: [{
144
+ type: 'operator',
145
+ dimension: 'transaction',
146
+ field: 'orderTotal',
147
+ operator: '>=',
148
+ value: 300
149
+ }],
150
+ actionIds: ['deduct_40']
151
+ }],
152
+ actionIds: []
153
+ },
154
+ actions: [{
155
+ id: 'deduct_10',
156
+ type: 'DEDUCT_AMOUNT',
157
+ value: 10,
158
+ target: 'order',
159
+ priority: 1
160
+ }, {
161
+ id: 'deduct_25',
162
+ type: 'DEDUCT_AMOUNT',
163
+ value: 25,
164
+ target: 'order',
165
+ priority: 2
166
+ }, {
167
+ id: 'deduct_40',
168
+ type: 'DEDUCT_AMOUNT',
169
+ value: 40,
170
+ target: 'order',
171
+ priority: 3
172
+ }]
173
+ };
174
+ var tieredContext = {
175
+ entities: {
176
+ order: {
177
+ id: 'ORDER_002',
178
+ total: 250
179
+ }
180
+ },
181
+ attributes: {
182
+ orderTotal: 250
183
+ },
184
+ metadata: {
185
+ timestamp: Date.now()
186
+ }
187
+ };
188
+
189
+ // ============================================
190
+ // 示例3: 使用 Code 模式的条件
191
+ // ============================================
192
+
193
+ var codeConditionConfig = {
194
+ metadata: {
195
+ id: 'CODE_CONDITION_EXAMPLE',
196
+ name: '代码条件示例',
197
+ type: 'custom'
198
+ },
199
+ conditions: {
200
+ operator: 'and',
201
+ rules: [
202
+ // 使用 code 模式
203
+ {
204
+ type: 'code',
205
+ code: 'attributes.orderTotal >= 100 && entities.customer.level === "vip"'
206
+ },
207
+ // 混合使用 operator 模式
208
+ {
209
+ type: 'operator',
210
+ field: 'productCount',
211
+ operator: '>=',
212
+ value: 2
213
+ }],
214
+ actionIds: ['vip_discount']
215
+ },
216
+ actions: [{
217
+ id: 'vip_discount',
218
+ type: 'DISCOUNT_RATE',
219
+ value: 0.85,
220
+ target: 'order',
221
+ priority: 1
222
+ }]
223
+ };
224
+ var codeContext = {
225
+ entities: {
226
+ customer: {
227
+ id: 'USER_002',
228
+ level: 'vip'
229
+ },
230
+ order: {
231
+ id: 'ORDER_003',
232
+ total: 150
233
+ }
234
+ },
235
+ attributes: {
236
+ orderTotal: 150,
237
+ productCount: 3
238
+ },
239
+ metadata: {
240
+ timestamp: Date.now()
241
+ }
242
+ };
243
+
244
+ // ============================================
245
+ // 执行示例
246
+ // ============================================
247
+
248
+ function runExamples() {
249
+ console.log('====== 策略模型使用示例 ======\n');
250
+
251
+ // 创建引擎实例(开启调试和追踪)
252
+ var engine = createStrategyEngine({
253
+ debug: true,
254
+ enableTrace: true
255
+ });
256
+
257
+ // 示例1: 代金券
258
+ console.log('示例1: 10元代金券');
259
+ var result1 = engine.evaluate(voucherConfig, voucherContext);
260
+ console.log('结果:', JSON.stringify(result1, null, 2));
261
+ console.log('\n');
262
+
263
+ // 示例2: 阶梯满减
264
+ console.log('示例2: 阶梯满减(订单金额250)');
265
+ var result2 = engine.evaluate(tieredDiscountConfig, tieredContext);
266
+ console.log('结果:', JSON.stringify(result2, null, 2));
267
+ console.log('\n');
268
+
269
+ // 示例3: Code 模式
270
+ console.log('示例3: Code 模式条件');
271
+ var result3 = engine.evaluate(codeConditionConfig, codeContext);
272
+ console.log('结果:', JSON.stringify(result3, null, 2));
273
+ console.log('\n');
274
+
275
+ // 快速评估(不需要创建引擎实例)
276
+ console.log('示例4: 快速评估');
277
+ var result4 = evaluate(voucherConfig, voucherContext);
278
+ console.log('适用:', result4.applicable);
279
+ console.log('匹配动作数:', result4.matchedActions.length);
280
+ console.log('\n');
281
+
282
+ // 注册自定义运算符
283
+ console.log('示例5: 自定义运算符');
284
+ engine.registerOperator('divisible_by', function (fieldValue, compareValue) {
285
+ return Number(fieldValue) % Number(compareValue) === 0;
286
+ });
287
+ var customOperatorConfig = {
288
+ metadata: {
289
+ id: 'CUSTOM_OP',
290
+ name: '自定义运算符',
291
+ type: 'test'
292
+ },
293
+ conditions: {
294
+ operator: 'and',
295
+ rules: [{
296
+ type: 'operator',
297
+ field: 'amount',
298
+ operator: 'divisible_by',
299
+ value: 10
300
+ }],
301
+ actionIds: ['bonus']
302
+ },
303
+ actions: [{
304
+ id: 'bonus',
305
+ type: 'ADD_POINTS',
306
+ value: 100,
307
+ target: 'customer'
308
+ }]
309
+ };
310
+ var customContext = {
311
+ entities: {},
312
+ attributes: {
313
+ amount: 50
314
+ },
315
+ metadata: {
316
+ timestamp: Date.now()
317
+ }
318
+ };
319
+ var result5 = engine.evaluate(customOperatorConfig, customContext);
320
+ console.log('结果:', result5.applicable ? '适用' : '不适用');
321
+ console.log('匹配动作:', result5.matchedActions);
322
+
323
+ // 调试信息
324
+ console.log('\n引擎调试信息:', engine.getDebugInfo());
325
+ }
326
+
327
+ // 运行示例(如果直接执行此文件)
328
+ if (require.main === module) {
329
+ runExamples();
330
+ }
331
+ export { runExamples };
@@ -0,0 +1,228 @@
1
+ /**
2
+ * 策略配置主结构
3
+ */
4
+ export interface StrategyConfig<T = Record<string, any>> {
5
+ /** 元信息 */
6
+ metadata: StrategyMetadata<T>;
7
+ /** 条件组(可嵌套,每层可绑定动作) */
8
+ conditions: ConditionGroup;
9
+ /** 动作列表(带唯一ID) */
10
+ actions: ActionEffect[];
11
+ /** 展示配置(可选) */
12
+ display?: DisplayConfig;
13
+ }
14
+ /**
15
+ * 策略元信息
16
+ */
17
+ export interface StrategyMetadata<T = Record<string, any>> {
18
+ /** 策略ID */
19
+ id: string;
20
+ /** 策略名称 */
21
+ name: string | Record<string, string>;
22
+ /** 策略类型(完全可扩展) */
23
+ type: string;
24
+ /** 计算类型 */
25
+ calculationType?: 'single' | 'cumulative';
26
+ /** 版本 */
27
+ version?: string;
28
+ /** 描述 */
29
+ description?: string | Record<string, string>;
30
+ /** 自定义元数据 */
31
+ custom?: T;
32
+ }
33
+ /**
34
+ * 条件组(支持嵌套)
35
+ */
36
+ export interface ConditionGroup {
37
+ /** 逻辑运算符 */
38
+ operator: 'and' | 'or' | 'not';
39
+ /** 条件规则列表(可以是单条件或嵌套的条件组) */
40
+ rules: Array<ConditionRule | ConditionGroup>;
41
+ /** 关联的动作ID列表(必填,可以为空数组) */
42
+ actionIds: string[];
43
+ }
44
+ /**
45
+ * 条件规则(原子条件)
46
+ * 支持 code 模式使用 eval 执行
47
+ */
48
+ export interface ConditionRule {
49
+ /** 类型 */
50
+ type: 'code' | 'operator';
51
+ /** 代码(code模式使用,使用eval执行) */
52
+ code?: string;
53
+ /** 维度(完全可扩展) */
54
+ dimension?: string;
55
+ /** 字段名 */
56
+ field?: string;
57
+ /** 运算符 */
58
+ operator?: string;
59
+ /** 比较值 */
60
+ value?: any;
61
+ /** 值类型 */
62
+ valueType?: 'number' | 'string' | 'boolean' | 'array' | 'object' | 'date';
63
+ /** 值单位 */
64
+ valueUnit?: string;
65
+ /** 额外配置 */
66
+ config?: Record<string, any>;
67
+ }
68
+ /**
69
+ * 动作效果
70
+ */
71
+ export interface ActionEffect {
72
+ /** 动作的唯一标识 */
73
+ id: string;
74
+ /** 效果类型(完全可扩展) */
75
+ type: string;
76
+ /** 运算符(可选) */
77
+ operator?: string;
78
+ /** 值 */
79
+ value: any;
80
+ /** 值类型 */
81
+ valueType?: 'number' | 'string' | 'boolean' | 'array' | 'object';
82
+ /** 值单位 */
83
+ valueUnit?: string;
84
+ /** 作用目标 */
85
+ target: string;
86
+ /** 优先级(数字越大优先级越高) */
87
+ priority?: number;
88
+ /** 配置(完全可扩展) */
89
+ config?: Record<string, any>;
90
+ }
91
+ /**
92
+ * 展示配置
93
+ */
94
+ export interface DisplayConfig {
95
+ /** 商品卡片展示 */
96
+ productCard?: {
97
+ text: string | Record<string, string>;
98
+ type: 'tag' | 'badge' | 'label';
99
+ image?: string;
100
+ style?: Record<string, any>;
101
+ };
102
+ /** 详情页展示 */
103
+ detail?: {
104
+ title: string | Record<string, string>;
105
+ description: string | Record<string, string>;
106
+ image?: string;
107
+ };
108
+ /** 自定义展示配置 */
109
+ custom?: Record<string, any>;
110
+ }
111
+ /**
112
+ * 运行时上下文结构
113
+ */
114
+ export interface RuntimeContext {
115
+ /** 实体数据(完全开放,由业务层定义) */
116
+ entities: Record<string, any>;
117
+ /** 属性数据(扁平化的计算值,用于条件判断) */
118
+ attributes: Record<string, any>;
119
+ /** 上下文元数据 */
120
+ metadata: ContextMetadata;
121
+ }
122
+ /**
123
+ * 上下文元数据
124
+ */
125
+ export interface ContextMetadata {
126
+ /** 请求ID(用于追踪) */
127
+ requestId?: string;
128
+ /** 时间戳 */
129
+ timestamp: number;
130
+ /** 语言 */
131
+ locale?: string;
132
+ /** 自定义元数据 */
133
+ custom?: Record<string, any>;
134
+ }
135
+ /**
136
+ * 评估结果结构
137
+ */
138
+ export interface EvaluationResult {
139
+ /** 是否成功执行(引擎层面) */
140
+ success: boolean;
141
+ /** 策略是否适用(业务层面) */
142
+ applicable: boolean;
143
+ /** 结果码 */
144
+ code: string;
145
+ /** 消息(多语言key或直接文本) */
146
+ message?: string;
147
+ /** 匹配信息 */
148
+ matched: MatchedInfo;
149
+ /** 匹配的动作列表(按priority排序) */
150
+ matchedActions: ActionEffect[];
151
+ /** 输出结果(完全开放,由适配器定义) */
152
+ outputs: Record<string, any>;
153
+ /** 执行轨迹(可选,用于调试) */
154
+ trace?: ExecutionTrace;
155
+ /** 策略配置 */
156
+ config: StrategyConfig;
157
+ }
158
+ /**
159
+ * 匹配信息
160
+ */
161
+ export interface MatchedInfo {
162
+ /** 条件是否满足 */
163
+ conditions: boolean;
164
+ /** 收集到的 actionIds */
165
+ actionIds: string[];
166
+ /** 详细匹配信息 */
167
+ details: Record<string, any>;
168
+ }
169
+ /**
170
+ * 执行轨迹
171
+ */
172
+ export interface ExecutionTrace {
173
+ /** 执行步骤 */
174
+ steps: TraceStep[];
175
+ /** 总耗时(毫秒) */
176
+ duration: number;
177
+ /** 错误信息 */
178
+ errors?: Array<{
179
+ step: string;
180
+ error: string;
181
+ timestamp: number;
182
+ }>;
183
+ }
184
+ /**
185
+ * 追踪步骤
186
+ */
187
+ export interface TraceStep {
188
+ /** 步骤名称 */
189
+ step: string;
190
+ /** 步骤状态 */
191
+ status: 'success' | 'failed' | 'skipped';
192
+ /** 耗时(毫秒) */
193
+ duration: number;
194
+ /** 详细信息 */
195
+ details?: Record<string, any>;
196
+ }
197
+ /** 成功码 */
198
+ export declare const SUCCESS_CODES: {
199
+ readonly SUCCESS: "SUCCESS";
200
+ };
201
+ /** 不适用码 */
202
+ export declare const NOT_APPLICABLE_CODES: {
203
+ readonly CONDITION_NOT_MET: "CONDITION_NOT_MET";
204
+ };
205
+ /** 错误码 */
206
+ export declare const ERROR_CODES: {
207
+ readonly INVALID_CONFIG: "INVALID_CONFIG";
208
+ readonly INVALID_CONTEXT: "INVALID_CONTEXT";
209
+ readonly EVALUATION_ERROR: "EVALUATION_ERROR";
210
+ readonly UNKNOWN_ERROR: "UNKNOWN_ERROR";
211
+ };
212
+ /**
213
+ * 引擎配置选项
214
+ */
215
+ export interface EngineOptions {
216
+ /** 是否启用调试模式 */
217
+ debug?: boolean;
218
+ /** 是否启用追踪 */
219
+ enableTrace?: boolean;
220
+ /** 运算符处理器映射 */
221
+ operatorHandlers?: Record<string, OperatorHandler>;
222
+ /** 自定义错误处理器 */
223
+ errorHandler?: (error: Error, context: RuntimeContext) => void;
224
+ }
225
+ /**
226
+ * 运算符处理器
227
+ */
228
+ export type OperatorHandler = (fieldValue: any, compareValue: any, rule: ConditionRule) => boolean;
@@ -0,0 +1,94 @@
1
+ // ============================================
2
+ // 核心接口定义
3
+ // ============================================
4
+
5
+ /**
6
+ * 策略配置主结构
7
+ */
8
+
9
+ /**
10
+ * 策略元信息
11
+ */
12
+
13
+ /**
14
+ * 条件组(支持嵌套)
15
+ */
16
+
17
+ /**
18
+ * 条件规则(原子条件)
19
+ * 支持 code 模式使用 eval 执行
20
+ */
21
+
22
+ /**
23
+ * 动作效果
24
+ */
25
+
26
+ /**
27
+ * 展示配置
28
+ */
29
+
30
+ // ============================================
31
+ // 运行时上下文
32
+ // ============================================
33
+
34
+ /**
35
+ * 运行时上下文结构
36
+ */
37
+
38
+ /**
39
+ * 上下文元数据
40
+ */
41
+
42
+ // ============================================
43
+ // 执行结果
44
+ // ============================================
45
+
46
+ /**
47
+ * 评估结果结构
48
+ */
49
+
50
+ /**
51
+ * 匹配信息
52
+ */
53
+
54
+ /**
55
+ * 执行轨迹
56
+ */
57
+
58
+ /**
59
+ * 追踪步骤
60
+ */
61
+
62
+ // ============================================
63
+ // 结果码定义
64
+ // ============================================
65
+
66
+ /** 成功码 */
67
+ export var SUCCESS_CODES = {
68
+ SUCCESS: 'SUCCESS'
69
+ };
70
+
71
+ /** 不适用码 */
72
+ export var NOT_APPLICABLE_CODES = {
73
+ CONDITION_NOT_MET: 'CONDITION_NOT_MET'
74
+ };
75
+
76
+ /** 错误码 */
77
+ export var ERROR_CODES = {
78
+ INVALID_CONFIG: 'INVALID_CONFIG',
79
+ INVALID_CONTEXT: 'INVALID_CONTEXT',
80
+ EVALUATION_ERROR: 'EVALUATION_ERROR',
81
+ UNKNOWN_ERROR: 'UNKNOWN_ERROR'
82
+ };
83
+
84
+ // ============================================
85
+ // 策略引擎配置
86
+ // ============================================
87
+
88
+ /**
89
+ * 引擎配置选项
90
+ */
91
+
92
+ /**
93
+ * 运算符处理器
94
+ */
@@ -75,6 +75,8 @@ export interface CartItem {
75
75
  summaryTotal?: number | string;
76
76
  /** 商品原价总价,排除原始价格为0的场景 */
77
77
  origin_total?: number | string;
78
+ /** 基于 origin_total 乘以 商品数量的价格 */
79
+ summaryOriginTotal?: number | string;
78
80
  /** 商品数量 */
79
81
  num?: number;
80
82
  /** 商品图片 */
@@ -57,6 +57,7 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
57
57
  quantity = _params$quantity === void 0 ? 1 : _params$quantity,
58
58
  discounts = params.discounts;
59
59
  var num = quantity; // 当前按照单个商品加入购物车
60
+
60
61
  if (product) {
61
62
  cartItem.id = product === null || product === void 0 ? void 0 : product.id;
62
63
  cartItem.name = product === null || product === void 0 ? void 0 : product.title;
@@ -77,6 +78,15 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
77
78
  num: num,
78
79
  discounts: discounts
79
80
  });
81
+ // 不包含折扣卡商品券的总价
82
+ var origin_total = getProductTotalPrice({
83
+ product: cartItem._productInit || cartItem._productOrigin,
84
+ bundle: bundle,
85
+ options: options,
86
+ num: num,
87
+ discounts: []
88
+ });
89
+ cartItem.summaryOriginTotal = (origin_total || 0) * (num || 1);
80
90
  cartItem.image = product === null || product === void 0 ? void 0 : product.cover;
81
91
  cartItem.like_status = 'common';
82
92
  cartItem.duration = product === null || product === void 0 ? void 0 : product.duration;
@@ -185,6 +195,7 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
185
195
  price = getDiscountAmount({
186
196
  tag: currentValue.type,
187
197
  par_value: currentValue.discount.percent,
198
+ config: currentValue.config,
188
199
  metadata: {
189
200
  discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
190
201
  }