@pisell/pisellos 2.2.47 → 2.2.49

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 (43) hide show
  1. package/dist/model/strategy/adapter/index.d.ts +0 -2
  2. package/dist/model/strategy/adapter/index.js +1 -2
  3. package/dist/model/strategy/adapter/walletPass/evaluator.js +1 -4
  4. package/dist/model/strategy/index.d.ts +93 -2
  5. package/dist/model/strategy/index.js +549 -6
  6. package/dist/modules/BaseModule.d.ts +0 -4
  7. package/dist/modules/BaseModule.js +0 -5
  8. package/dist/modules/Payment/index.js +4 -0
  9. package/dist/modules/Payment/types.d.ts +2 -0
  10. package/dist/modules/Product/index.d.ts +1 -1
  11. package/dist/modules/Rules/index.d.ts +0 -1
  12. package/dist/modules/Rules/index.js +16 -28
  13. package/dist/solution/BookingTicket/index.d.ts +1 -1
  14. package/lib/model/strategy/adapter/index.d.ts +0 -2
  15. package/lib/model/strategy/adapter/index.js +0 -5
  16. package/lib/model/strategy/adapter/walletPass/evaluator.js +1 -2
  17. package/lib/model/strategy/index.d.ts +93 -2
  18. package/lib/model/strategy/index.js +381 -6
  19. package/lib/modules/BaseModule.d.ts +0 -4
  20. package/lib/modules/BaseModule.js +0 -3
  21. package/lib/modules/Payment/index.js +4 -1
  22. package/lib/modules/Payment/types.d.ts +2 -0
  23. package/lib/modules/Product/index.d.ts +1 -1
  24. package/lib/modules/Rules/index.d.ts +0 -1
  25. package/lib/modules/Rules/index.js +17 -23
  26. package/lib/solution/BookingTicket/index.d.ts +1 -1
  27. package/package.json +1 -1
  28. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +0 -212
  29. package/dist/model/strategy/adapter/promotion/evaluator.js +0 -1180
  30. package/dist/model/strategy/adapter/promotion/index.d.ts +0 -206
  31. package/dist/model/strategy/adapter/promotion/index.js +0 -447
  32. package/dist/model/strategy/adapter/promotion/type.d.ts +0 -447
  33. package/dist/model/strategy/adapter/promotion/type.js +0 -209
  34. package/dist/model/strategy/engine.d.ts +0 -106
  35. package/dist/model/strategy/engine.js +0 -611
  36. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +0 -212
  37. package/lib/model/strategy/adapter/promotion/evaluator.js +0 -824
  38. package/lib/model/strategy/adapter/promotion/index.d.ts +0 -206
  39. package/lib/model/strategy/adapter/promotion/index.js +0 -386
  40. package/lib/model/strategy/adapter/promotion/type.d.ts +0 -447
  41. package/lib/model/strategy/adapter/promotion/type.js +0 -51
  42. package/lib/model/strategy/engine.d.ts +0 -106
  43. package/lib/model/strategy/engine.js +0 -450
@@ -1,206 +0,0 @@
1
- import type { EvaluationResult, RuntimeContext } from '../../type';
2
- import type { BusinessAdapter } from '../type';
3
- import type { PromotionBusinessData, PromotionTransformResult } from './type';
4
- import { PromotionEvaluator } from './evaluator';
5
- export { PromotionEvaluator };
6
- /**
7
- * Promotion 适配器
8
- *
9
- * 用于将促销活动业务数据转换为策略引擎可识别的格式
10
- * 策略引擎只负责匹配,具体的优惠计算由业务层完成
11
- */
12
- export declare class PromotionAdapter implements BusinessAdapter {
13
- name: string;
14
- version: string;
15
- /**
16
- * 准备运行时上下文
17
- *
18
- * 将业务数据转换为策略引擎可识别的 RuntimeContext
19
- */
20
- prepareContext(businessData: PromotionBusinessData): RuntimeContext;
21
- /**
22
- * 转换执行结果
23
- *
24
- * 将策略引擎的通用结果转换为业务层需要的格式
25
- * 主要是整理 matchedActions,让业务层更容易使用
26
- */
27
- transformResult(result: EvaluationResult, businessData?: PromotionBusinessData): PromotionTransformResult;
28
- /**
29
- * 格式化配置
30
- */
31
- formatConfig(result: EvaluationResult, businessData?: PromotionBusinessData): {
32
- result: EvaluationResult;
33
- businessData?: PromotionBusinessData;
34
- };
35
- /**
36
- * 格式化日期时间
37
- */
38
- private formatDateTime;
39
- /**
40
- * 解析 Action 详情
41
- *
42
- * 将 matchedAction 转换为更易用的结构
43
- */
44
- private parseActionDetail;
45
- /**
46
- * 解析 X件Y元 Action
47
- */
48
- private parseXItemsForYPriceAction;
49
- /**
50
- * 解析 买X送Y Action
51
- */
52
- private parseBuyXGetYFreeAction;
53
- /**
54
- * 获取适用的商品列表
55
- *
56
- * 从购物车商品中筛选出符合策略条件的商品
57
- */
58
- private getApplicableProducts;
59
- /**
60
- * 查找商品匹配规则
61
- */
62
- private findProductMatchRule;
63
- /**
64
- * 检查商品是否匹配
65
- */
66
- private isProductMatch;
67
- }
68
- export default PromotionAdapter;
69
- /**
70
- * X件Y元策略配置示例
71
- *
72
- * 业务规则:
73
- * - 每X件商品固定价格Y元(可累计)
74
- * - 支持跨商品组合(A+B可以凑成一组)
75
- * - 买5件 = 2组优惠 + 1件原价
76
- *
77
- * 商品匹配规则:
78
- * - product_variant_id = 0 表示匹配任意变体
79
- * - product_variant_id != 0 表示精确匹配该变体
80
- */
81
- export declare const X_ITEMS_FOR_Y_PRICE_STRATEGY: {
82
- metadata: {
83
- id: string;
84
- name: {
85
- en: string;
86
- 'zh-CN': string;
87
- 'zh-HK': string;
88
- };
89
- type: string;
90
- custom: {
91
- display: {
92
- product_card: {
93
- text: {
94
- en: string;
95
- 'zh-CN': string;
96
- 'zh-HK': string;
97
- };
98
- type: string;
99
- };
100
- };
101
- };
102
- };
103
- conditions: {
104
- operator: string;
105
- rules: ({
106
- type: string;
107
- field: string;
108
- value: string;
109
- operator: string;
110
- } | {
111
- type: string;
112
- field: string;
113
- value: {
114
- product_id: number;
115
- product_variant_id: number;
116
- }[];
117
- operator: string;
118
- })[];
119
- actionIds: string[];
120
- };
121
- actions: {
122
- id: string;
123
- type: string;
124
- value: {
125
- x: number;
126
- price: number;
127
- };
128
- valueType: string;
129
- target: string;
130
- priority: number;
131
- config: {
132
- allowCrossProduct: boolean;
133
- cumulative: boolean;
134
- };
135
- }[];
136
- };
137
- /**
138
- * 买X送Y策略配置示例
139
- *
140
- * 业务规则:
141
- * - 买X件送Y件(可累计:买2送2、买3送3...)
142
- * - 赠品由用户从列表中选择
143
- *
144
- * 商品匹配规则:
145
- * - product_variant_id = 0 表示匹配任意变体
146
- * - product_variant_id != 0 表示精确匹配该变体
147
- */
148
- export declare const BUY_X_GET_Y_FREE_STRATEGY: {
149
- metadata: {
150
- id: string;
151
- name: {
152
- en: string;
153
- 'zh-CN': string;
154
- 'zh-HK': string;
155
- };
156
- type: string;
157
- custom: {
158
- display: {
159
- product_card: {
160
- text: {
161
- en: string;
162
- 'zh-CN': string;
163
- 'zh-HK': string;
164
- };
165
- type: string;
166
- };
167
- };
168
- };
169
- };
170
- conditions: {
171
- operator: string;
172
- rules: ({
173
- type: string;
174
- field: string;
175
- value: string;
176
- operator: string;
177
- } | {
178
- type: string;
179
- field: string;
180
- value: {
181
- product_id: number;
182
- product_variant_id: number;
183
- }[];
184
- operator: string;
185
- })[];
186
- actionIds: string[];
187
- };
188
- actions: {
189
- id: string;
190
- type: string;
191
- value: {
192
- buyQuantity: number;
193
- freeQuantity: number;
194
- };
195
- valueType: string;
196
- target: string;
197
- priority: number;
198
- config: {
199
- cumulative: boolean;
200
- giftProducts: {
201
- product_id: number;
202
- product_variant_id: number;
203
- }[];
204
- };
205
- }[];
206
- };
@@ -1,386 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
- var __getOwnPropNames = Object.getOwnPropertyNames;
4
- var __hasOwnProp = Object.prototype.hasOwnProperty;
5
- var __export = (target, all) => {
6
- for (var name in all)
7
- __defProp(target, name, { get: all[name], enumerable: true });
8
- };
9
- var __copyProps = (to, from, except, desc) => {
10
- if (from && typeof from === "object" || typeof from === "function") {
11
- for (let key of __getOwnPropNames(from))
12
- if (!__hasOwnProp.call(to, key) && key !== except)
13
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
- }
15
- return to;
16
- };
17
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
-
19
- // src/model/strategy/adapter/promotion/index.ts
20
- var promotion_exports = {};
21
- __export(promotion_exports, {
22
- BUY_X_GET_Y_FREE_STRATEGY: () => BUY_X_GET_Y_FREE_STRATEGY,
23
- PromotionAdapter: () => PromotionAdapter,
24
- PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
25
- X_ITEMS_FOR_Y_PRICE_STRATEGY: () => X_ITEMS_FOR_Y_PRICE_STRATEGY,
26
- default: () => promotion_default
27
- });
28
- module.exports = __toCommonJS(promotion_exports);
29
- var import_type = require("./type");
30
- var import_evaluator = require("./evaluator");
31
- var PromotionAdapter = class {
32
- constructor() {
33
- this.name = "PromotionAdapter";
34
- this.version = "1.0.0";
35
- }
36
- /**
37
- * 准备运行时上下文
38
- *
39
- * 将业务数据转换为策略引擎可识别的 RuntimeContext
40
- */
41
- prepareContext(businessData) {
42
- const { products, currentProduct, channel, custom } = businessData;
43
- const now = /* @__PURE__ */ new Date();
44
- const currentDateTime = this.formatDateTime(now);
45
- const evaluatingProduct = currentProduct || (products.length > 0 ? products[0] : null);
46
- return {
47
- entities: {
48
- products,
49
- currentProduct: evaluatingProduct
50
- },
51
- attributes: {
52
- // 当前时间(格式化字符串,用于时间条件判断)
53
- currentDateTime,
54
- // 当前评估的商品信息(用于 product_match 运算符)
55
- productIdAndVariantId: evaluatingProduct ? {
56
- product_id: evaluatingProduct.product_id,
57
- product_variant_id: evaluatingProduct.product_variant_id
58
- } : null,
59
- // 渠道
60
- channel: channel || "",
61
- // 商品总数量
62
- totalQuantity: products.reduce((sum, p) => sum + p.quantity, 0),
63
- // 商品总金额
64
- totalAmount: products.reduce((sum, p) => sum + p.price * p.quantity, 0),
65
- // 自定义属性
66
- ...custom
67
- },
68
- metadata: {
69
- timestamp: Date.now()
70
- }
71
- };
72
- }
73
- /**
74
- * 转换执行结果
75
- *
76
- * 将策略引擎的通用结果转换为业务层需要的格式
77
- * 主要是整理 matchedActions,让业务层更容易使用
78
- */
79
- transformResult(result, businessData) {
80
- const applicableProducts = businessData ? this.getApplicableProducts(result, businessData) : [];
81
- if (!result.applicable) {
82
- return {
83
- isApplicable: false,
84
- applicableProducts: [],
85
- reason: result.message,
86
- reasonCode: result.code,
87
- strategyResult: result
88
- };
89
- }
90
- const matchedAction = result.matchedActions[0];
91
- if (!matchedAction) {
92
- return {
93
- isApplicable: false,
94
- applicableProducts: [],
95
- reason: "No matched action",
96
- reasonCode: "NO_ACTION",
97
- strategyResult: result
98
- };
99
- }
100
- const actionDetail = this.parseActionDetail(matchedAction);
101
- return {
102
- isApplicable: true,
103
- actionType: matchedAction.type,
104
- actionDetail,
105
- applicableProducts,
106
- strategyResult: result
107
- };
108
- }
109
- /**
110
- * 格式化配置
111
- */
112
- formatConfig(result, businessData) {
113
- return { result, businessData };
114
- }
115
- // ============================================
116
- // 私有辅助方法
117
- // ============================================
118
- /**
119
- * 格式化日期时间
120
- */
121
- formatDateTime(date) {
122
- const year = date.getFullYear();
123
- const month = String(date.getMonth() + 1).padStart(2, "0");
124
- const day = String(date.getDate()).padStart(2, "0");
125
- const hours = String(date.getHours()).padStart(2, "0");
126
- const minutes = String(date.getMinutes()).padStart(2, "0");
127
- const seconds = String(date.getSeconds()).padStart(2, "0");
128
- return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
129
- }
130
- /**
131
- * 解析 Action 详情
132
- *
133
- * 将 matchedAction 转换为更易用的结构
134
- */
135
- parseActionDetail(action) {
136
- switch (action.type) {
137
- case import_type.PROMOTION_ACTION_TYPES.X_ITEMS_FOR_Y_PRICE:
138
- return this.parseXItemsForYPriceAction(action);
139
- case import_type.PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE:
140
- return this.parseBuyXGetYFreeAction(action);
141
- default:
142
- return void 0;
143
- }
144
- }
145
- /**
146
- * 解析 X件Y元 Action
147
- */
148
- parseXItemsForYPriceAction(action) {
149
- const value = action.value || {};
150
- const config = action.config || {};
151
- return {
152
- type: import_type.PROMOTION_ACTION_TYPES.X_ITEMS_FOR_Y_PRICE,
153
- x: value.x || 2,
154
- price: value.price || 0,
155
- allowCrossProduct: config.allowCrossProduct ?? true,
156
- cumulative: config.cumulative ?? true
157
- };
158
- }
159
- /**
160
- * 解析 买X送Y Action
161
- */
162
- parseBuyXGetYFreeAction(action) {
163
- const value = action.value || {};
164
- const config = action.config || {};
165
- return {
166
- type: import_type.PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE,
167
- buyQuantity: value.buyQuantity || 1,
168
- freeQuantity: value.freeQuantity || 1,
169
- giftSelectionMode: config.giftSelectionMode || "user_select",
170
- cumulative: config.cumulative ?? true,
171
- giftProducts: config.giftProducts || []
172
- };
173
- }
174
- /**
175
- * 获取适用的商品列表
176
- *
177
- * 从购物车商品中筛选出符合策略条件的商品
178
- */
179
- getApplicableProducts(result, businessData) {
180
- const { products } = businessData;
181
- const productMatchRule = this.findProductMatchRule(result.config);
182
- if (!productMatchRule) {
183
- return products;
184
- }
185
- const configProducts = productMatchRule.value;
186
- return products.filter(
187
- (product) => this.isProductMatch(product, configProducts)
188
- );
189
- }
190
- /**
191
- * 查找商品匹配规则
192
- */
193
- findProductMatchRule(config) {
194
- var _a;
195
- if (!((_a = config == null ? void 0 : config.conditions) == null ? void 0 : _a.rules)) {
196
- return null;
197
- }
198
- return config.conditions.rules.find(
199
- (rule) => rule.field === "productIdAndVariantId" && (rule.operator === "product_match" || rule.operator === "object_in")
200
- );
201
- }
202
- /**
203
- * 检查商品是否匹配
204
- */
205
- isProductMatch(product, configProducts) {
206
- return configProducts.some((config) => {
207
- if (config.product_id !== product.product_id) {
208
- return false;
209
- }
210
- if (config.product_variant_id === 0) {
211
- return true;
212
- }
213
- return config.product_variant_id === product.product_variant_id;
214
- });
215
- }
216
- };
217
- var promotion_default = PromotionAdapter;
218
- var X_ITEMS_FOR_Y_PRICE_STRATEGY = {
219
- metadata: {
220
- id: "STRATEGY_001",
221
- name: {
222
- en: "2 items for $10",
223
- "zh-CN": "2杯10元",
224
- "zh-HK": "2杯10元"
225
- },
226
- type: "promotion",
227
- custom: {
228
- display: {
229
- product_card: {
230
- text: {
231
- en: "2 for $10",
232
- "zh-CN": "2杯10元",
233
- "zh-HK": "2杯10元"
234
- },
235
- type: "tag"
236
- }
237
- }
238
- }
239
- },
240
- conditions: {
241
- operator: "and",
242
- rules: [
243
- {
244
- type: "operator",
245
- field: "currentDateTime",
246
- value: "2023-01-01 00:00:00",
247
- operator: ">="
248
- },
249
- {
250
- type: "operator",
251
- field: "currentDateTime",
252
- value: "2027-01-01 00:00:00",
253
- operator: "<="
254
- },
255
- {
256
- type: "operator",
257
- field: "productIdAndVariantId",
258
- value: [
259
- {
260
- product_id: 60736,
261
- product_variant_id: 0
262
- // 0 = 匹配任意变体
263
- },
264
- {
265
- product_id: 60737,
266
- product_variant_id: 0
267
- // 0 = 匹配任意变体
268
- }
269
- ],
270
- operator: "product_match"
271
- }
272
- ],
273
- actionIds: ["1"]
274
- },
275
- actions: [
276
- {
277
- id: "1",
278
- type: "X_ITEMS_FOR_Y_PRICE",
279
- value: {
280
- x: 2,
281
- // 每X件
282
- price: 10
283
- // 固定价格Y元
284
- },
285
- valueType: "object",
286
- target: "product",
287
- priority: 1,
288
- config: {
289
- allowCrossProduct: true,
290
- // 允许跨商品组合(A+B可以凑成一组)
291
- cumulative: true
292
- // 可累计(买5件 = 2组优惠 + 1件原价)
293
- }
294
- }
295
- ]
296
- };
297
- var BUY_X_GET_Y_FREE_STRATEGY = {
298
- metadata: {
299
- id: "STRATEGY_002",
300
- name: {
301
- en: "Buy 1 Get 1 Free",
302
- "zh-CN": "买1送1",
303
- "zh-HK": "買1送1"
304
- },
305
- type: "promotion",
306
- custom: {
307
- display: {
308
- product_card: {
309
- text: {
310
- en: "Buy 1 Get 1",
311
- "zh-CN": "买1送1",
312
- "zh-HK": "買1送1"
313
- },
314
- type: "tag"
315
- }
316
- }
317
- }
318
- },
319
- conditions: {
320
- operator: "and",
321
- rules: [
322
- {
323
- type: "operator",
324
- field: "currentDateTime",
325
- value: "2023-01-01 00:00:00",
326
- operator: ">="
327
- },
328
- {
329
- type: "operator",
330
- field: "currentDateTime",
331
- value: "2027-01-01 00:00:00",
332
- operator: "<="
333
- },
334
- {
335
- type: "operator",
336
- field: "productIdAndVariantId",
337
- value: [
338
- {
339
- product_id: 60736,
340
- product_variant_id: 0
341
- // 0 = 匹配任意变体
342
- },
343
- {
344
- product_id: 60737,
345
- product_variant_id: 0
346
- // 0 = 匹配任意变体
347
- }
348
- ],
349
- operator: "product_match"
350
- }
351
- ],
352
- actionIds: ["1"]
353
- },
354
- actions: [
355
- {
356
- id: "1",
357
- type: "BUY_X_GET_Y_FREE",
358
- value: {
359
- buyQuantity: 1,
360
- // 买X件
361
- freeQuantity: 1
362
- // 送Y件
363
- },
364
- valueType: "object",
365
- target: "product",
366
- priority: 1,
367
- config: {
368
- // 可累计(买2送2、买3送3...)
369
- cumulative: true,
370
- // 可选的赠品列表
371
- giftProducts: [
372
- { product_id: 60757, product_variant_id: 0 },
373
- { product_id: 38782, product_variant_id: 0 },
374
- { product_id: 60749, product_variant_id: 27267 }
375
- ]
376
- }
377
- }
378
- ]
379
- };
380
- // Annotate the CommonJS export names for ESM import in node:
381
- 0 && (module.exports = {
382
- BUY_X_GET_Y_FREE_STRATEGY,
383
- PromotionAdapter,
384
- PromotionEvaluator,
385
- X_ITEMS_FOR_Y_PRICE_STRATEGY
386
- });