@pisell/pisellos 2.1.118 → 2.1.120

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 (232) hide show
  1. package/dist/apis/picoding.d.ts +0 -0
  2. package/dist/apis/picoding.js +1 -0
  3. package/dist/index.d.ts +0 -1
  4. package/dist/index.js +0 -1
  5. package/dist/model/strategy/adapter/index.d.ts +4 -0
  6. package/dist/model/strategy/adapter/index.js +4 -1
  7. package/dist/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
  8. package/dist/model/strategy/adapter/itemRule/adapter.js +439 -0
  9. package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  10. package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
  11. package/dist/model/strategy/adapter/itemRule/examples.d.ts +64 -0
  12. package/dist/model/strategy/adapter/itemRule/examples.js +315 -0
  13. package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
  14. package/dist/model/strategy/adapter/itemRule/index.js +5 -0
  15. package/dist/model/strategy/adapter/itemRule/type.d.ts +206 -0
  16. package/dist/model/strategy/adapter/itemRule/type.js +101 -0
  17. package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  18. package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
  19. package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  20. package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
  21. package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
  22. package/dist/model/strategy/adapter/promotion/examples.js +166 -0
  23. package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
  24. package/dist/model/strategy/adapter/promotion/index.js +0 -0
  25. package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
  26. package/dist/model/strategy/adapter/promotion/type.js +209 -0
  27. package/dist/model/strategy/adapter/walletPass/evaluator.js +4 -1
  28. package/dist/model/strategy/engine.d.ts +106 -0
  29. package/dist/model/strategy/engine.js +611 -0
  30. package/dist/model/strategy/index.d.ts +2 -93
  31. package/dist/model/strategy/index.js +6 -549
  32. package/dist/modules/Cart/types.d.ts +0 -2
  33. package/dist/modules/Cart/utils/cartProduct.js +25 -56
  34. package/dist/modules/Discount/types.d.ts +0 -18
  35. package/dist/modules/OpenData/index.d.ts +23 -0
  36. package/dist/modules/OpenData/index.js +167 -0
  37. package/dist/modules/OpenData/types.d.ts +73 -0
  38. package/dist/modules/OpenData/types.js +1 -0
  39. package/dist/modules/OpenData/utils.d.ts +2 -0
  40. package/dist/modules/OpenData/utils.js +75 -0
  41. package/dist/modules/Order/index.d.ts +58 -1
  42. package/dist/modules/Order/index.js +780 -29
  43. package/dist/modules/Order/types.d.ts +144 -12
  44. package/dist/modules/Order/utils.d.ts +25 -0
  45. package/dist/modules/Order/utils.js +225 -1
  46. package/dist/modules/Payment/index.d.ts +1 -2
  47. package/dist/modules/Payment/index.js +7 -10
  48. package/dist/modules/Payment/utils.js +0 -3
  49. package/dist/modules/Payment/walletpass.d.ts +0 -23
  50. package/dist/modules/Payment/walletpass.js +95 -191
  51. package/dist/modules/Product/utils.js +2 -2
  52. package/dist/modules/ProductList/index.d.ts +1 -1
  53. package/dist/modules/ProductList/index.js +2 -1
  54. package/dist/modules/Quotation/index.d.ts +48 -0
  55. package/dist/modules/Quotation/index.js +245 -0
  56. package/dist/modules/Quotation/types.d.ts +42 -0
  57. package/dist/modules/Quotation/types.js +1 -0
  58. package/dist/modules/Rules/index.d.ts +5 -9
  59. package/dist/modules/Rules/index.js +164 -673
  60. package/dist/modules/Rules/types.d.ts +0 -2
  61. package/dist/modules/SalesSummary/index.d.ts +63 -0
  62. package/dist/modules/SalesSummary/index.js +174 -0
  63. package/dist/modules/SalesSummary/types.d.ts +59 -0
  64. package/dist/modules/SalesSummary/types.js +1 -0
  65. package/dist/modules/SalesSummary/utils.d.ts +30 -0
  66. package/dist/modules/SalesSummary/utils.js +513 -0
  67. package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
  68. package/dist/modules/ScanOrderLogger/index.js +161 -0
  69. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  70. package/dist/modules/ScanOrderLogger/providers/feishu.js +95 -0
  71. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  72. package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
  73. package/dist/modules/ScanOrderLogger/types.d.ts +46 -0
  74. package/dist/modules/ScanOrderLogger/types.js +1 -0
  75. package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
  76. package/dist/modules/Summary/types.d.ts +0 -2
  77. package/dist/modules/Summary/utils.d.ts +3 -9
  78. package/dist/modules/Summary/utils.js +4 -25
  79. package/dist/modules/index.d.ts +4 -0
  80. package/dist/modules/index.js +5 -1
  81. package/dist/plugins/window.d.ts +0 -2
  82. package/dist/solution/BookingByStep/index.d.ts +1 -2
  83. package/dist/solution/BookingByStep/index.js +44 -42
  84. package/dist/solution/BookingByStep/types.d.ts +3 -1
  85. package/dist/solution/BookingByStep/types.js +5 -1
  86. package/dist/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  87. package/dist/solution/BookingByStep/utils/timeslots.js +19 -12
  88. package/dist/solution/Checkout/index.js +0 -2
  89. package/dist/solution/ScanOrder/index.d.ts +90 -0
  90. package/dist/solution/ScanOrder/index.js +1853 -0
  91. package/dist/solution/ScanOrder/types.d.ts +210 -0
  92. package/dist/solution/ScanOrder/types.js +16 -0
  93. package/dist/solution/ScanOrder/utils.d.ts +93 -0
  94. package/dist/solution/ScanOrder/utils.js +397 -0
  95. package/dist/solution/ShopDiscount/index.d.ts +0 -1
  96. package/dist/solution/ShopDiscount/index.js +7 -23
  97. package/dist/solution/ShopDiscount/types.d.ts +0 -1
  98. package/dist/solution/ShopDiscount/types.js +1 -2
  99. package/dist/solution/ShopDiscount/utils.js +12 -26
  100. package/dist/solution/VenueBooking/index.d.ts +158 -0
  101. package/dist/solution/VenueBooking/index.js +2873 -0
  102. package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  103. package/dist/solution/VenueBooking/types.d.ts +130 -0
  104. package/dist/solution/VenueBooking/types.js +21 -0
  105. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
  106. package/dist/solution/VenueBooking/utils/dateSummary.js +102 -0
  107. package/dist/solution/VenueBooking/utils/resource.d.ts +4 -0
  108. package/dist/solution/VenueBooking/utils/resource.js +94 -0
  109. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
  110. package/dist/solution/VenueBooking/utils/slotMerge.js +204 -0
  111. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  112. package/dist/solution/VenueBooking/utils/timeSlot.js +256 -0
  113. package/dist/solution/VenueBooking/utils.d.ts +1 -0
  114. package/dist/solution/VenueBooking/utils.js +1 -0
  115. package/dist/solution/index.d.ts +2 -0
  116. package/dist/solution/index.js +3 -1
  117. package/lib/apis/picoding.d.ts +0 -0
  118. package/lib/apis/picoding.js +0 -0
  119. package/lib/index.d.ts +0 -1
  120. package/lib/index.js +1 -3
  121. package/lib/model/strategy/adapter/index.d.ts +4 -0
  122. package/lib/model/strategy/adapter/index.js +12 -0
  123. package/lib/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
  124. package/lib/model/strategy/adapter/itemRule/adapter.js +338 -0
  125. package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
  126. package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
  127. package/lib/model/strategy/adapter/itemRule/examples.d.ts +64 -0
  128. package/lib/model/strategy/adapter/itemRule/examples.js +269 -0
  129. package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
  130. package/lib/model/strategy/adapter/itemRule/index.js +58 -0
  131. package/lib/model/strategy/adapter/itemRule/type.d.ts +206 -0
  132. package/lib/model/strategy/adapter/itemRule/type.js +46 -0
  133. package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
  134. package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
  135. package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
  136. package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
  137. package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
  138. package/lib/model/strategy/adapter/promotion/examples.js +192 -0
  139. package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
  140. package/lib/model/strategy/adapter/promotion/index.js +0 -0
  141. package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
  142. package/lib/model/strategy/adapter/promotion/type.js +51 -0
  143. package/lib/model/strategy/adapter/walletPass/evaluator.js +2 -1
  144. package/lib/model/strategy/engine.d.ts +106 -0
  145. package/lib/model/strategy/engine.js +450 -0
  146. package/lib/model/strategy/index.d.ts +2 -93
  147. package/lib/model/strategy/index.js +6 -381
  148. package/lib/modules/Cart/types.d.ts +0 -2
  149. package/lib/modules/Cart/utils/cartProduct.js +12 -39
  150. package/lib/modules/Discount/types.d.ts +0 -18
  151. package/lib/modules/OpenData/index.d.ts +23 -0
  152. package/lib/modules/OpenData/index.js +116 -0
  153. package/lib/modules/OpenData/types.d.ts +73 -0
  154. package/lib/modules/OpenData/types.js +17 -0
  155. package/lib/modules/OpenData/utils.d.ts +2 -0
  156. package/lib/modules/OpenData/utils.js +111 -0
  157. package/lib/modules/Order/index.d.ts +58 -1
  158. package/lib/modules/Order/index.js +423 -1
  159. package/lib/modules/Order/types.d.ts +144 -12
  160. package/lib/modules/Order/utils.d.ts +25 -0
  161. package/lib/modules/Order/utils.js +229 -0
  162. package/lib/modules/Payment/index.d.ts +1 -2
  163. package/lib/modules/Payment/index.js +0 -1
  164. package/lib/modules/Payment/utils.js +0 -3
  165. package/lib/modules/Payment/walletpass.d.ts +0 -23
  166. package/lib/modules/Payment/walletpass.js +17 -94
  167. package/lib/modules/Product/utils.js +2 -2
  168. package/lib/modules/ProductList/index.d.ts +1 -1
  169. package/lib/modules/ProductList/index.js +2 -1
  170. package/lib/modules/Quotation/index.d.ts +48 -0
  171. package/lib/modules/Quotation/index.js +149 -0
  172. package/lib/modules/Quotation/types.d.ts +42 -0
  173. package/lib/modules/Quotation/types.js +17 -0
  174. package/lib/modules/Rules/index.d.ts +5 -9
  175. package/lib/modules/Rules/index.js +286 -778
  176. package/lib/modules/Rules/types.d.ts +0 -2
  177. package/lib/modules/SalesSummary/index.d.ts +63 -0
  178. package/lib/modules/SalesSummary/index.js +105 -0
  179. package/lib/modules/SalesSummary/types.d.ts +59 -0
  180. package/lib/modules/SalesSummary/types.js +17 -0
  181. package/lib/modules/SalesSummary/utils.d.ts +30 -0
  182. package/lib/modules/SalesSummary/utils.js +452 -0
  183. package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
  184. package/lib/modules/ScanOrderLogger/index.js +135 -0
  185. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
  186. package/lib/modules/ScanOrderLogger/providers/feishu.js +82 -0
  187. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
  188. package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
  189. package/lib/modules/ScanOrderLogger/types.d.ts +46 -0
  190. package/lib/modules/ScanOrderLogger/types.js +17 -0
  191. package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
  192. package/lib/modules/Summary/types.d.ts +0 -2
  193. package/lib/modules/Summary/utils.d.ts +3 -9
  194. package/lib/modules/Summary/utils.js +4 -19
  195. package/lib/modules/index.d.ts +4 -0
  196. package/lib/modules/index.js +9 -1
  197. package/lib/plugins/window.d.ts +0 -2
  198. package/lib/solution/BookingByStep/index.d.ts +1 -2
  199. package/lib/solution/BookingByStep/index.js +4 -2
  200. package/lib/solution/BookingByStep/types.d.ts +3 -1
  201. package/lib/solution/BookingByStep/types.js +10 -0
  202. package/lib/solution/BookingByStep/utils/timeslots.d.ts +3 -1
  203. package/lib/solution/BookingByStep/utils/timeslots.js +19 -11
  204. package/lib/solution/Checkout/index.js +0 -2
  205. package/lib/solution/ScanOrder/index.d.ts +90 -0
  206. package/lib/solution/ScanOrder/index.js +1071 -0
  207. package/lib/solution/ScanOrder/types.d.ts +210 -0
  208. package/lib/solution/ScanOrder/types.js +36 -0
  209. package/lib/solution/ScanOrder/utils.d.ts +93 -0
  210. package/lib/solution/ScanOrder/utils.js +359 -0
  211. package/lib/solution/ShopDiscount/index.d.ts +0 -1
  212. package/lib/solution/ShopDiscount/index.js +8 -22
  213. package/lib/solution/ShopDiscount/types.d.ts +0 -1
  214. package/lib/solution/ShopDiscount/utils.js +6 -10
  215. package/lib/solution/VenueBooking/index.d.ts +158 -0
  216. package/lib/solution/VenueBooking/index.js +1545 -0
  217. package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
  218. package/lib/solution/VenueBooking/types.d.ts +130 -0
  219. package/lib/solution/VenueBooking/types.js +44 -0
  220. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
  221. package/lib/solution/VenueBooking/utils/dateSummary.js +101 -0
  222. package/lib/solution/VenueBooking/utils/resource.d.ts +4 -0
  223. package/lib/solution/VenueBooking/utils/resource.js +80 -0
  224. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
  225. package/lib/solution/VenueBooking/utils/slotMerge.js +209 -0
  226. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
  227. package/lib/solution/VenueBooking/utils/timeSlot.js +200 -0
  228. package/lib/solution/VenueBooking/utils.d.ts +1 -0
  229. package/lib/solution/VenueBooking/utils.js +69 -0
  230. package/lib/solution/index.d.ts +2 -0
  231. package/lib/solution/index.js +5 -1
  232. package/package.json +1 -1
@@ -20,394 +20,19 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
20
20
  // src/model/strategy/index.ts
21
21
  var strategy_exports = {};
22
22
  __export(strategy_exports, {
23
- StrategyEngine: () => StrategyEngine,
24
- createStrategyEngine: () => createStrategyEngine,
25
- evaluate: () => evaluate
23
+ StrategyEngine: () => import_engine.StrategyEngine,
24
+ createStrategyEngine: () => import_engine.createStrategyEngine,
25
+ evaluate: () => import_engine.evaluate
26
26
  });
27
27
  module.exports = __toCommonJS(strategy_exports);
28
- var import_type = require("./type");
28
+ var import_engine = require("./engine");
29
+ __reExport(strategy_exports, require("./type"), module.exports);
29
30
  __reExport(strategy_exports, require("./adapter"), module.exports);
30
- var StrategyEngine = class {
31
- constructor(options = {}) {
32
- this.options = {
33
- debug: options.debug ?? false,
34
- enableTrace: options.enableTrace ?? false,
35
- operatorHandlers: options.operatorHandlers ?? {},
36
- errorHandler: options.errorHandler ?? ((error) => console.error(error))
37
- };
38
- this.operatorHandlers = new Map(
39
- Object.entries(this.options.operatorHandlers)
40
- );
41
- this.initializeBuiltInOperators();
42
- }
43
- /**
44
- * 评估策略
45
- */
46
- evaluate(config, context) {
47
- var _a;
48
- const startTime = Date.now();
49
- const trace = {
50
- steps: [],
51
- duration: 0,
52
- errors: []
53
- };
54
- try {
55
- this.validateConfig(config);
56
- if (this.options.enableTrace) {
57
- trace.steps.push({
58
- step: "validate_config",
59
- status: "success",
60
- duration: Date.now() - startTime
61
- });
62
- }
63
- const evaluateStart = Date.now();
64
- const evaluationResult = this.evaluateConditionGroup(
65
- config.conditions,
66
- context
67
- );
68
- if (this.options.enableTrace) {
69
- trace.steps.push({
70
- step: "evaluate_conditions",
71
- status: "success",
72
- duration: Date.now() - evaluateStart,
73
- details: {
74
- satisfied: evaluationResult.satisfied,
75
- collectedActionIds: evaluationResult.actionIds
76
- }
77
- });
78
- }
79
- const actionStart = Date.now();
80
- const matchedActions = this.getActionsByIds(
81
- evaluationResult.actionIds,
82
- config.actions
83
- );
84
- if (this.options.enableTrace) {
85
- trace.steps.push({
86
- step: "get_actions",
87
- status: "success",
88
- duration: Date.now() - actionStart,
89
- details: { matchedCount: matchedActions.length }
90
- });
91
- }
92
- const sortStart = Date.now();
93
- const sortedActions = this.sortActionsByPriority(matchedActions);
94
- if (this.options.enableTrace) {
95
- trace.steps.push({
96
- step: "sort_actions",
97
- status: "success",
98
- duration: Date.now() - sortStart
99
- });
100
- }
101
- const applicable = evaluationResult.satisfied;
102
- const result = {
103
- success: true,
104
- applicable,
105
- code: applicable ? import_type.SUCCESS_CODES.SUCCESS : import_type.NOT_APPLICABLE_CODES.CONDITION_NOT_MET,
106
- message: applicable ? "Strategy is applicable" : "Conditions not met",
107
- matched: {
108
- conditions: applicable,
109
- actionIds: evaluationResult.actionIds,
110
- details: {}
111
- },
112
- matchedActions: sortedActions,
113
- outputs: {},
114
- config
115
- };
116
- trace.duration = Date.now() - startTime;
117
- if (this.options.enableTrace) {
118
- result.trace = trace;
119
- }
120
- return result;
121
- } catch (error) {
122
- const errorMessage = error instanceof Error ? error.message : "Unknown error";
123
- if (this.options.enableTrace) {
124
- (_a = trace.errors) == null ? void 0 : _a.push({
125
- step: "evaluation",
126
- error: errorMessage,
127
- timestamp: Date.now()
128
- });
129
- trace.duration = Date.now() - startTime;
130
- }
131
- this.options.errorHandler(error, context);
132
- return {
133
- success: false,
134
- applicable: false,
135
- code: import_type.ERROR_CODES.EVALUATION_ERROR,
136
- message: errorMessage,
137
- matched: {
138
- conditions: false,
139
- actionIds: [],
140
- details: {}
141
- },
142
- matchedActions: [],
143
- outputs: {},
144
- trace: this.options.enableTrace ? trace : void 0,
145
- config
146
- };
147
- }
148
- }
149
- /**
150
- * 递归评估条件组
151
- *
152
- * @param group 条件组
153
- * @param context 运行时上下文
154
- * @returns 评估结果对象,包含条件是否满足和收集到的 actionIds
155
- */
156
- evaluateConditionGroup(group, context) {
157
- const collectedActionIds = [];
158
- const isCurrentLayerSatisfied = this.evaluateGroupLogic(group, context);
159
- if (isCurrentLayerSatisfied) {
160
- collectedActionIds.push(...group.actionIds);
161
- for (const rule of group.rules) {
162
- if (this.isConditionGroup(rule)) {
163
- const nestedResult = this.evaluateConditionGroup(rule, context);
164
- collectedActionIds.push(...nestedResult.actionIds);
165
- }
166
- }
167
- }
168
- return {
169
- satisfied: isCurrentLayerSatisfied,
170
- actionIds: collectedActionIds
171
- };
172
- }
173
- /**
174
- * 评估条件组的逻辑运算
175
- */
176
- evaluateGroupLogic(group, context) {
177
- const { operator, rules } = group;
178
- switch (operator) {
179
- case "and":
180
- return rules.every((rule) => this.evaluateRule(rule, context));
181
- case "or":
182
- return rules.some((rule) => this.evaluateRule(rule, context));
183
- case "not":
184
- if (rules.length === 0)
185
- return false;
186
- return !this.evaluateRule(rules[0], context);
187
- default:
188
- throw new Error(`Unknown operator: ${operator}`);
189
- }
190
- }
191
- /**
192
- * 评估单个规则
193
- */
194
- evaluateRule(rule, context) {
195
- if (this.isConditionGroup(rule)) {
196
- return this.evaluateGroupLogic(rule, context);
197
- }
198
- const conditionRule = rule;
199
- if (conditionRule.type === "code" && conditionRule.code) {
200
- return this.evaluateCodeCondition(conditionRule.code, context);
201
- }
202
- return this.evaluateOperatorCondition(conditionRule, context);
203
- }
204
- /**
205
- * 评估代码模式条件
206
- */
207
- evaluateCodeCondition(code, context) {
208
- try {
209
- const { entities, attributes, metadata } = context;
210
- const evalFunc = new Function(
211
- "entities",
212
- "attributes",
213
- "metadata",
214
- `return (${code})`
215
- );
216
- const result = evalFunc(entities, attributes, metadata);
217
- return Boolean(result);
218
- } catch (error) {
219
- if (this.options.debug) {
220
- console.error("Code evaluation error:", error);
221
- }
222
- return false;
223
- }
224
- }
225
- /**
226
- * 评估运算符模式条件
227
- */
228
- evaluateOperatorCondition(rule, context) {
229
- const { field, operator, value } = rule;
230
- if (!field || !operator) {
231
- return false;
232
- }
233
- const fieldValue = this.getFieldValue(field, context);
234
- const handler = this.operatorHandlers.get(operator);
235
- if (handler) {
236
- return handler(fieldValue, value, rule);
237
- }
238
- return this.evaluateBuiltInOperator(fieldValue, operator, value);
239
- }
240
- /**
241
- * 获取字段值
242
- */
243
- getFieldValue(field, context) {
244
- const path = field.split(".");
245
- let value = context.attributes;
246
- for (const key of path) {
247
- if (value && typeof value === "object" && key in value) {
248
- value = value[key];
249
- } else {
250
- return void 0;
251
- }
252
- }
253
- return value;
254
- }
255
- /**
256
- * 评估内置运算符
257
- */
258
- evaluateBuiltInOperator(fieldValue, operator, compareValue) {
259
- switch (operator) {
260
- case "=":
261
- case "==":
262
- return fieldValue == compareValue;
263
- case "!=":
264
- return fieldValue != compareValue;
265
- case ">":
266
- return fieldValue > compareValue;
267
- case ">=":
268
- return fieldValue >= compareValue;
269
- case "<":
270
- return fieldValue < compareValue;
271
- case "<=":
272
- return fieldValue <= compareValue;
273
- case "in":
274
- return Array.isArray(compareValue) && compareValue.includes(fieldValue);
275
- case "not_in":
276
- return Array.isArray(compareValue) && !compareValue.includes(fieldValue);
277
- case "contains":
278
- if (Array.isArray(fieldValue)) {
279
- return fieldValue.includes(compareValue);
280
- }
281
- if (typeof fieldValue === "string") {
282
- return fieldValue.includes(compareValue);
283
- }
284
- return false;
285
- case "not_contains":
286
- if (Array.isArray(fieldValue)) {
287
- return !fieldValue.includes(compareValue);
288
- }
289
- if (typeof fieldValue === "string") {
290
- return !fieldValue.includes(compareValue);
291
- }
292
- return true;
293
- case "starts_with":
294
- return typeof fieldValue === "string" && fieldValue.startsWith(compareValue);
295
- case "ends_with":
296
- return typeof fieldValue === "string" && fieldValue.endsWith(compareValue);
297
- case "regex":
298
- return typeof fieldValue === "string" && new RegExp(compareValue).test(fieldValue);
299
- case "between":
300
- if (!Array.isArray(compareValue) || compareValue.length !== 2)
301
- return false;
302
- return fieldValue >= compareValue[0] && fieldValue <= compareValue[1];
303
- case "is_null":
304
- return fieldValue === null || fieldValue === void 0;
305
- case "is_not_null":
306
- return fieldValue !== null && fieldValue !== void 0;
307
- case "is_empty":
308
- if (Array.isArray(fieldValue))
309
- return fieldValue.length === 0;
310
- if (typeof fieldValue === "string")
311
- return fieldValue.length === 0;
312
- if (typeof fieldValue === "object")
313
- return Object.keys(fieldValue).length === 0;
314
- return !fieldValue;
315
- case "is_not_empty":
316
- if (Array.isArray(fieldValue))
317
- return fieldValue.length > 0;
318
- if (typeof fieldValue === "string")
319
- return fieldValue.length > 0;
320
- if (typeof fieldValue === "object")
321
- return Object.keys(fieldValue).length > 0;
322
- return Boolean(fieldValue);
323
- default:
324
- throw new Error(`Unsupported operator: ${operator}`);
325
- }
326
- }
327
- /**
328
- * 根据 actionIds 获取 ActionEffect 对象
329
- */
330
- getActionsByIds(actionIds, actions) {
331
- const matchedActions = [];
332
- const actionMap = new Map(actions.map((action) => [action.id, action]));
333
- for (const id of actionIds) {
334
- const action = actionMap.get(id);
335
- if (action) {
336
- matchedActions.push(action);
337
- } else {
338
- if (this.options.debug) {
339
- console.warn(`Action with id "${id}" not found in actions array`);
340
- }
341
- }
342
- }
343
- return matchedActions;
344
- }
345
- /**
346
- * 按 priority 排序(降序)
347
- */
348
- sortActionsByPriority(actions) {
349
- return [...actions].sort((a, b) => {
350
- const priorityA = a.priority ?? 0;
351
- const priorityB = b.priority ?? 0;
352
- return priorityB - priorityA;
353
- });
354
- }
355
- /**
356
- * 判断是否为条件组
357
- */
358
- isConditionGroup(rule) {
359
- return "operator" in rule && "rules" in rule && Array.isArray(rule.rules);
360
- }
361
- /**
362
- * 验证配置
363
- */
364
- validateConfig(config) {
365
- if (!config) {
366
- throw new Error("Strategy config is required");
367
- }
368
- if (!config.metadata || !config.metadata.id) {
369
- throw new Error("Strategy metadata.id is required");
370
- }
371
- if (!config.conditions) {
372
- throw new Error("Strategy conditions is required");
373
- }
374
- if (!Array.isArray(config.actions)) {
375
- throw new Error("Strategy actions must be an array");
376
- }
377
- }
378
- /**
379
- * 初始化内置运算符处理器
380
- */
381
- initializeBuiltInOperators() {
382
- }
383
- /**
384
- * 注册自定义运算符
385
- */
386
- registerOperator(operator, handler) {
387
- this.operatorHandlers.set(operator, handler);
388
- }
389
- /**
390
- * 获取调试信息
391
- */
392
- getDebugInfo() {
393
- return {
394
- debug: this.options.debug,
395
- enableTrace: this.options.enableTrace,
396
- registeredOperators: Array.from(this.operatorHandlers.keys())
397
- };
398
- }
399
- };
400
- function createStrategyEngine(options) {
401
- return new StrategyEngine(options);
402
- }
403
- function evaluate(config, context) {
404
- const engine = new StrategyEngine();
405
- return engine.evaluate(config, context);
406
- }
407
31
  // Annotate the CommonJS export names for ESM import in node:
408
32
  0 && (module.exports = {
409
33
  StrategyEngine,
410
34
  createStrategyEngine,
411
35
  evaluate,
36
+ ...require("./type"),
412
37
  ...require("./adapter")
413
38
  });
@@ -75,8 +75,6 @@ export interface CartItem {
75
75
  summaryTotal?: number | string;
76
76
  /** 商品原价总价,排除原始价格为0的场景 */
77
77
  origin_total?: number | string;
78
- /** 基于 origin_total 乘以 商品数量的价格 */
79
- summaryOriginTotal?: number | string;
80
78
  /** 商品数量 */
81
79
  num?: number;
82
80
  /** 商品图片 */
@@ -46,18 +46,6 @@ var import_decimal = __toESM(require("decimal.js"));
46
46
  var import_utils = require("../../Product/utils");
47
47
  var import_utils2 = require("../../../solution/ShopDiscount/utils");
48
48
  var import_utils3 = require("../../Summary/utils");
49
- var toDiscountPayload = (discountItem) => {
50
- var _a, _b;
51
- return {
52
- amount: discountItem.amount,
53
- tag: discountItem.type,
54
- par_value: (_a = discountItem.discount) == null ? void 0 : _a.percent,
55
- config: discountItem.config,
56
- metadata: {
57
- discount_card_type: (_b = discountItem == null ? void 0 : discountItem.discount) == null ? void 0 : _b.discount_card_type
58
- }
59
- };
60
- };
61
49
  var handleVariantProduct = (product) => {
62
50
  var _a;
63
51
  if (product == null ? void 0 : product.product_variant_id) {
@@ -102,14 +90,6 @@ var formatProductToCartItem = (params) => {
102
90
  num,
103
91
  discounts
104
92
  });
105
- const origin_total = getProductTotalPrice({
106
- product: cartItem._productInit || cartItem._productOrigin,
107
- bundle,
108
- options,
109
- num,
110
- discounts: []
111
- });
112
- cartItem.summaryOriginTotal = (origin_total || 0) * (num || 1);
113
93
  cartItem.image = product == null ? void 0 : product.cover;
114
94
  cartItem.like_status = "common";
115
95
  cartItem.duration = product == null ? void 0 : product.duration;
@@ -204,24 +184,17 @@ var formatProductToCartItemOrigin = (params) => {
204
184
  var getProductTotalPrice = (params) => {
205
185
  const { product, bundle, options, discounts } = params;
206
186
  let price = Number(product.price);
207
- const optionRows = (options == null ? void 0 : options.map((currentValue) => ({
208
- unit: Number(currentValue.price ?? currentValue.add_price ?? 0),
209
- num: Number(currentValue.num ?? currentValue.quantity ?? 1)
210
- }))) ?? [];
211
187
  if (discounts == null ? void 0 : discounts.length) {
212
188
  discounts.forEach((currentValue) => {
213
189
  var _a;
214
- const payload = toDiscountPayload(currentValue);
215
- price = (0, import_utils2.getDiscountAmount)(payload, price, price);
216
- if (((_a = currentValue == null ? void 0 : currentValue.config) == null ? void 0 : _a.deductOptionPrice) && optionRows.length) {
217
- for (let i = 0; i < optionRows.length; i++) {
218
- const row = optionRows[i];
219
- optionRows[i] = {
220
- ...row,
221
- unit: (0, import_utils2.getDiscountAmount)(payload, row.unit, row.unit)
222
- };
190
+ price = (0, import_utils2.getDiscountAmount)({
191
+ amount: currentValue.amount,
192
+ tag: currentValue.type,
193
+ par_value: currentValue.discount.percent,
194
+ metadata: {
195
+ discount_card_type: (_a = currentValue == null ? void 0 : currentValue.discount) == null ? void 0 : _a.discount_card_type
223
196
  }
224
- }
197
+ }, price, price);
225
198
  });
226
199
  }
227
200
  if (bundle == null ? void 0 : bundle.length) {
@@ -229,11 +202,10 @@ var getProductTotalPrice = (params) => {
229
202
  return accumulator + Number(currentValue.price) * Number(currentValue.num);
230
203
  }, price);
231
204
  }
232
- if (optionRows.length) {
233
- price = optionRows.reduce(
234
- (accumulator, row) => accumulator + row.unit * row.num,
235
- price
236
- );
205
+ if (options == null ? void 0 : options.length) {
206
+ price = options.reduce((accumulator, currentValue) => {
207
+ return accumulator + Number(currentValue.price) * Number(currentValue.num);
208
+ }, price);
237
209
  }
238
210
  return Math.max(0, price);
239
211
  };
@@ -341,6 +313,7 @@ var formatBundleToOrigin = (bundle) => {
341
313
  option: formatOptionsToOrigin(getBundleValueByKey("option")),
342
314
  discount_list: d.discount_list,
343
315
  "bundle_selling_price": d == null ? void 0 : d.price,
316
+ "custom_price": d == null ? void 0 : d.price,
344
317
  metadata: {
345
318
  custom_product_bundle_map_id: d._id,
346
319
  product_discount_difference
@@ -33,8 +33,6 @@ interface Limitedrelationproductdata {
33
33
  product_ids: number[];
34
34
  product_collection_id: number[];
35
35
  package_sub_item_usage_rules?: PackageSubItemUsageRules;
36
- filter: 0 | 1;
37
- exclude_product_ids: number[];
38
36
  }
39
37
  interface ApplicableProductDetails {
40
38
  amount: string;
@@ -91,7 +89,6 @@ export interface Discount {
91
89
  balance: string;
92
90
  format_title: Formattitle;
93
91
  metadata?: {
94
- num?: number;
95
92
  discount_card_type?: 'fixed_amount' | 'percent';
96
93
  custom_product_bundle_map_id?: string;
97
94
  validity_type?: "custom_schedule_validity" | "fixed_validity";
@@ -116,21 +113,6 @@ export interface Discount {
116
113
  isSelected?: boolean;
117
114
  isAvailable?: boolean;
118
115
  isUsed?: boolean;
119
- config?: {
120
- isAvailable?: boolean;
121
- /** 最大抵扣金额 */
122
- maxDeductionAmount?: number;
123
- /** 每单最多使用张数 */
124
- maxUsagePerOrder?: number;
125
- /** 是否抵扣税费与附加费 */
126
- deductTaxAndFee?: boolean;
127
- /** 适用粒度(多商品共用) */
128
- allowCrossProduct?: boolean;
129
- /** 可用商品数量上限 */
130
- applicableProductLimit?: number;
131
- /** 是否抵扣单规格价格 (Option Price) */
132
- deductOptionPrice?: boolean;
133
- };
134
116
  applicableProductIds?: number[];
135
117
  applicableProductDetails: ApplicableProductDetails[];
136
118
  appliedProductDetails: ApplicableProductDetails[];
@@ -0,0 +1,23 @@
1
+ import { Module, PisellCore, ModuleOptions } from '../../types';
2
+ import { BaseModule } from '../BaseModule';
3
+ import type { ScheduleModule } from '../Schedule';
4
+ import type { OpenDataConfig, OpenDataFetchParams, OpenDataAvailabilityResult } from './types';
5
+ export * from './types';
6
+ export { computeAvailability } from './utils';
7
+ export declare class OpenDataModule extends BaseModule implements Module {
8
+ protected defaultName: string;
9
+ protected defaultVersion: string;
10
+ private request;
11
+ private window;
12
+ private store;
13
+ private cacheId;
14
+ private openCache;
15
+ private fatherModule;
16
+ private otherParams;
17
+ constructor(name?: string, version?: string);
18
+ initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
19
+ fetchOpenData(params: OpenDataFetchParams): Promise<OpenDataConfig>;
20
+ getOpenData(): OpenDataConfig | null;
21
+ checkAvailability(scheduleModule?: ScheduleModule): OpenDataAvailabilityResult;
22
+ storeChange(): void;
23
+ }
@@ -0,0 +1,116 @@
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+
20
+ // src/modules/OpenData/index.ts
21
+ var OpenData_exports = {};
22
+ __export(OpenData_exports, {
23
+ OpenDataModule: () => OpenDataModule,
24
+ computeAvailability: () => import_utils2.computeAvailability
25
+ });
26
+ module.exports = __toCommonJS(OpenData_exports);
27
+ var import_BaseModule = require("../BaseModule");
28
+ var import_utils = require("./utils");
29
+ __reExport(OpenData_exports, require("./types"), module.exports);
30
+ var import_utils2 = require("./utils");
31
+ var OpenDataModule = class extends import_BaseModule.BaseModule {
32
+ constructor(name, version) {
33
+ super(name, version);
34
+ this.defaultName = "openData";
35
+ this.defaultVersion = "1.0.0";
36
+ this.openCache = false;
37
+ this.otherParams = {};
38
+ }
39
+ async initialize(core, options) {
40
+ var _a, _b;
41
+ this.core = core;
42
+ this.store = options.store;
43
+ this.store.data = ((_a = options.initialState) == null ? void 0 : _a.data) ?? null;
44
+ this.store.lastFetchedAt = ((_b = options.initialState) == null ? void 0 : _b.lastFetchedAt) ?? null;
45
+ this.otherParams = options.otherParams || {};
46
+ if (this.otherParams.cacheId) {
47
+ this.openCache = this.otherParams.openCache ?? false;
48
+ this.cacheId = this.otherParams.cacheId;
49
+ }
50
+ if (this.otherParams.fatherModule) {
51
+ this.fatherModule = this.otherParams.fatherModule;
52
+ }
53
+ this.request = core.getPlugin("request");
54
+ this.window = core.getPlugin("window");
55
+ if (!this.request)
56
+ throw new Error("OpenDataModule 需要 request 插件支持");
57
+ if (!this.window)
58
+ throw new Error("OpenDataModule 需要 window 插件支持");
59
+ console.log("[OpenDataModule] 初始化完成");
60
+ }
61
+ async fetchOpenData(params) {
62
+ var _a, _b, _c, _d;
63
+ const shopId = (_b = (_a = this.otherParams) == null ? void 0 : _a.getStateData) == null ? void 0 : _b.call(_a, "shop_id");
64
+ if (!shopId)
65
+ throw new Error("[OpenDataModule] 无法获取 shop_id");
66
+ const tenantId = (_d = (_c = this.otherParams) == null ? void 0 : _c.getStateData) == null ? void 0 : _d.call(_c, "tenant_id");
67
+ const headers = {};
68
+ if (tenantId)
69
+ headers["Tenant-Id"] = String(tenantId);
70
+ const response = await this.request.post(
71
+ `/open/my-pisell/${shopId}/setting`,
72
+ {
73
+ scope: params.scope,
74
+ target: params.target,
75
+ section_code: params.section_code
76
+ },
77
+ { pisell2: true, headers }
78
+ );
79
+ if ((response == null ? void 0 : response.status) === false) {
80
+ throw new Error((response == null ? void 0 : response.message) || "获取 OpenData 配置失败");
81
+ }
82
+ const data = (response == null ? void 0 : response.data) || {};
83
+ this.store.data = data;
84
+ this.store.lastFetchedAt = Date.now();
85
+ return data;
86
+ }
87
+ getOpenData() {
88
+ return this.store.data;
89
+ }
90
+ checkAvailability(scheduleModule) {
91
+ var _a;
92
+ const scheduleList = scheduleModule ? scheduleModule.getScheduleListByIds(
93
+ ((_a = this.store.data) == null ? void 0 : _a["availability.operating_hours"]) || []
94
+ ) : void 0;
95
+ return (0, import_utils.computeAvailability)({
96
+ config: this.store.data,
97
+ scheduleList
98
+ });
99
+ }
100
+ storeChange() {
101
+ if (this.openCache) {
102
+ this.checkSaveCache({
103
+ cacheId: this.cacheId,
104
+ fatherModule: this.fatherModule,
105
+ store: this.store,
106
+ cacheKey: ["data", "lastFetchedAt"]
107
+ });
108
+ }
109
+ }
110
+ };
111
+ // Annotate the CommonJS export names for ESM import in node:
112
+ 0 && (module.exports = {
113
+ OpenDataModule,
114
+ computeAvailability,
115
+ ...require("./types")
116
+ });