@pisell/pisellos 0.0.461 → 0.0.462

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.
@@ -0,0 +1,166 @@
1
+ /**
2
+ * X件Y元策略配置示例
3
+ *
4
+ * 业务规则:
5
+ * - 每X件商品固定价格Y元(可累计)
6
+ * - 支持跨商品组合(A+B可以凑成一组)
7
+ * - 买5件 = 2组优惠 + 1件原价
8
+ *
9
+ * 商品匹配规则:
10
+ * - product_variant_id = 0 表示匹配任意变体
11
+ * - product_variant_id != 0 表示精确匹配该变体
12
+ */
13
+ export var X_ITEMS_FOR_Y_PRICE_STRATEGY = {
14
+ metadata: {
15
+ id: 'STRATEGY_001',
16
+ name: {
17
+ en: '2 items for $10',
18
+ 'zh-CN': '2杯10元',
19
+ 'zh-HK': '2杯10元'
20
+ },
21
+ type: 'promotion',
22
+ custom: {
23
+ display: {
24
+ product_card: {
25
+ text: {
26
+ en: '2 for $10',
27
+ 'zh-CN': '2杯10元',
28
+ 'zh-HK': '2杯10元'
29
+ },
30
+ type: 'tag'
31
+ }
32
+ }
33
+ }
34
+ },
35
+ conditions: {
36
+ operator: 'and',
37
+ rules: [{
38
+ type: 'operator',
39
+ field: 'currentDateTime',
40
+ value: '2023-01-01 00:00:00',
41
+ operator: '>='
42
+ }, {
43
+ type: 'operator',
44
+ field: 'currentDateTime',
45
+ value: '2027-01-01 00:00:00',
46
+ operator: '<='
47
+ }, {
48
+ type: 'operator',
49
+ field: 'productIdAndVariantId',
50
+ value: [{
51
+ product_id: 60736,
52
+ product_variant_id: 0 // 0 = 匹配任意变体
53
+ }, {
54
+ product_id: 60737,
55
+ product_variant_id: 0 // 0 = 匹配任意变体
56
+ }],
57
+ operator: 'product_match'
58
+ }],
59
+ actionIds: ['1']
60
+ },
61
+ actions: [{
62
+ id: '1',
63
+ type: 'X_ITEMS_FOR_Y_PRICE',
64
+ value: {
65
+ x: 2,
66
+ // 每X件
67
+ price: 10 // 固定价格Y元
68
+ },
69
+ valueType: 'object',
70
+ target: 'product',
71
+ priority: 1,
72
+ config: {
73
+ allowCrossProduct: true,
74
+ // 允许跨商品组合(A+B可以凑成一组)
75
+ cumulative: true // 可累计(买5件 = 2组优惠 + 1件原价)
76
+ }
77
+ }]
78
+ };
79
+
80
+ /**
81
+ * 买X送Y策略配置示例
82
+ *
83
+ * 业务规则:
84
+ * - 买X件送Y件(可累计:买2送2、买3送3...)
85
+ * - 赠品由用户从列表中选择
86
+ *
87
+ * 商品匹配规则:
88
+ * - product_variant_id = 0 表示匹配任意变体
89
+ * - product_variant_id != 0 表示精确匹配该变体
90
+ */
91
+ export var BUY_X_GET_Y_FREE_STRATEGY = {
92
+ metadata: {
93
+ id: 'STRATEGY_002',
94
+ name: {
95
+ en: 'Buy 1 Get 1 Free',
96
+ 'zh-CN': '买1送1',
97
+ 'zh-HK': '買1送1'
98
+ },
99
+ type: 'promotion',
100
+ custom: {
101
+ display: {
102
+ product_card: {
103
+ text: {
104
+ en: 'Buy 1 Get 1',
105
+ 'zh-CN': '买1送1',
106
+ 'zh-HK': '買1送1'
107
+ },
108
+ type: 'tag'
109
+ }
110
+ }
111
+ }
112
+ },
113
+ conditions: {
114
+ operator: 'and',
115
+ rules: [{
116
+ type: 'operator',
117
+ field: 'currentDateTime',
118
+ value: '2023-01-01 00:00:00',
119
+ operator: '>='
120
+ }, {
121
+ type: 'operator',
122
+ field: 'currentDateTime',
123
+ value: '2027-01-01 00:00:00',
124
+ operator: '<='
125
+ }, {
126
+ type: 'operator',
127
+ field: 'productIdAndVariantId',
128
+ value: [{
129
+ product_id: 60736,
130
+ product_variant_id: 0 // 0 = 匹配任意变体
131
+ }, {
132
+ product_id: 60737,
133
+ product_variant_id: 0 // 0 = 匹配任意变体
134
+ }],
135
+ operator: 'product_match'
136
+ }],
137
+ actionIds: ['1']
138
+ },
139
+ actions: [{
140
+ id: '1',
141
+ type: 'BUY_X_GET_Y_FREE',
142
+ value: {
143
+ buyQuantity: 1,
144
+ // 买X件
145
+ freeQuantity: 1 // 送Y件
146
+ },
147
+ valueType: 'object',
148
+ target: 'product',
149
+ priority: 1,
150
+ config: {
151
+ // 可累计(买2送2、买3送3...)
152
+ cumulative: true,
153
+ // 可选的赠品列表
154
+ giftProducts: [{
155
+ product_id: 60757,
156
+ product_variant_id: 0
157
+ }, {
158
+ product_id: 38782,
159
+ product_variant_id: 0
160
+ }, {
161
+ product_id: 60749,
162
+ product_variant_id: 27267
163
+ }]
164
+ }
165
+ }]
166
+ };
@@ -1,206 +1,4 @@
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
+ export { PromotionEvaluator } from './evaluator';
2
+ export { PromotionAdapter } from './adapter';
3
+ export { default } from './adapter';
4
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY, } from './examples';
@@ -1660,6 +1660,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1660
1660
  product_id: bundleItem.product_id,
1661
1661
  price: item.price,
1662
1662
  num: item.num,
1663
+ quantity: item.num,
1663
1664
  discount_list: updatedDiscountList
1664
1665
  }));
1665
1666
  });
@@ -1683,6 +1684,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1683
1684
  product_id: bundleItem.product_id,
1684
1685
  price: item.price,
1685
1686
  num: item.num,
1687
+ quantity: item.num,
1686
1688
  discount_list: _updatedDiscountList
1687
1689
  }));
1688
1690
  } else {
@@ -1859,6 +1861,7 @@ export var RulesModule = /*#__PURE__*/function (_BaseModule) {
1859
1861
  product_id: bundleItem.product_id,
1860
1862
  price: item.price,
1861
1863
  num: item.num,
1864
+ quantity: item.num,
1862
1865
  discount_list: updatedDiscountList
1863
1866
  }));
1864
1867
  });
@@ -1,5 +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 };
4
+ export { PromotionEvaluator } from './promotion/evaluator';
5
+ export { PromotionAdapter } from './promotion/adapter';
@@ -30,8 +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
+ PromotionAdapter: () => import_adapter.PromotionAdapter,
34
+ PromotionEvaluator: () => import_evaluator2.PromotionEvaluator,
35
35
  WalletPassAdapter: () => import_walletPass.default,
36
36
  WalletPassEvaluator: () => import_evaluator.WalletPassEvaluator
37
37
  });
@@ -39,7 +39,8 @@ module.exports = __toCommonJS(adapter_exports);
39
39
  __reExport(adapter_exports, require("./type"), module.exports);
40
40
  var import_walletPass = __toESM(require("./walletPass"));
41
41
  var import_evaluator = require("./walletPass/evaluator");
42
- var import_promotion = require("./promotion");
42
+ var import_evaluator2 = require("./promotion/evaluator");
43
+ var import_adapter = require("./promotion/adapter");
43
44
  // Annotate the CommonJS export names for ESM import in node:
44
45
  0 && (module.exports = {
45
46
  PromotionAdapter,
@@ -0,0 +1,66 @@
1
+ import type { EvaluationResult, RuntimeContext } from '../../type';
2
+ import type { BusinessAdapter } from '../type';
3
+ import type { PromotionBusinessData, PromotionTransformResult } from './type';
4
+ /**
5
+ * Promotion 适配器
6
+ *
7
+ * 用于将促销活动业务数据转换为策略引擎可识别的格式
8
+ * 策略引擎只负责匹配,具体的优惠计算由业务层完成
9
+ */
10
+ export declare class PromotionAdapter implements BusinessAdapter {
11
+ name: string;
12
+ version: string;
13
+ /**
14
+ * 准备运行时上下文
15
+ *
16
+ * 将业务数据转换为策略引擎可识别的 RuntimeContext
17
+ */
18
+ prepareContext(businessData: PromotionBusinessData): RuntimeContext;
19
+ /**
20
+ * 转换执行结果
21
+ *
22
+ * 将策略引擎的通用结果转换为业务层需要的格式
23
+ * 主要是整理 matchedActions,让业务层更容易使用
24
+ */
25
+ transformResult(result: EvaluationResult, businessData?: PromotionBusinessData): PromotionTransformResult;
26
+ /**
27
+ * 格式化配置
28
+ */
29
+ formatConfig(result: EvaluationResult, businessData?: PromotionBusinessData): {
30
+ result: EvaluationResult;
31
+ businessData?: PromotionBusinessData;
32
+ };
33
+ /**
34
+ * 格式化日期时间
35
+ */
36
+ private formatDateTime;
37
+ /**
38
+ * 解析 Action 详情
39
+ *
40
+ * 将 matchedAction 转换为更易用的结构
41
+ */
42
+ private parseActionDetail;
43
+ /**
44
+ * 解析 X件Y元 Action
45
+ */
46
+ private parseXItemsForYPriceAction;
47
+ /**
48
+ * 解析 买X送Y Action
49
+ */
50
+ private parseBuyXGetYFreeAction;
51
+ /**
52
+ * 获取适用的商品列表
53
+ *
54
+ * 从购物车商品中筛选出符合策略条件的商品
55
+ */
56
+ private getApplicableProducts;
57
+ /**
58
+ * 查找商品匹配规则
59
+ */
60
+ private findProductMatchRule;
61
+ /**
62
+ * 检查商品是否匹配
63
+ */
64
+ private isProductMatch;
65
+ }
66
+ export default PromotionAdapter;