@pisell/pisellos 2.1.149 → 2.1.151

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 (197) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/strategy/adapter/promotion/evaluator.js +99 -26
  4. package/dist/model/strategy/adapter/promotion/index.js +0 -9
  5. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  6. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  7. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  8. package/dist/model/strategy/engine.d.ts +18 -5
  9. package/dist/model/strategy/engine.js +145 -45
  10. package/dist/model/strategy/type.d.ts +17 -0
  11. package/dist/model/strategy/type.js +4 -0
  12. package/dist/modules/Cart/types.d.ts +2 -0
  13. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  14. package/dist/modules/Discount/types.d.ts +19 -1
  15. package/dist/modules/Order/index.d.ts +1 -65
  16. package/dist/modules/Order/index.js +30 -899
  17. package/dist/modules/Order/types.d.ts +12 -174
  18. package/dist/modules/Order/types.js +0 -2
  19. package/dist/modules/Order/utils.d.ts +0 -118
  20. package/dist/modules/Order/utils.js +2 -586
  21. package/dist/modules/Payment/index.d.ts +2 -1
  22. package/dist/modules/Payment/index.js +10 -7
  23. package/dist/modules/Payment/utils.js +3 -0
  24. package/dist/modules/Payment/walletpass.d.ts +23 -0
  25. package/dist/modules/Payment/walletpass.js +191 -95
  26. package/dist/modules/Product/utils.js +2 -2
  27. package/dist/modules/ProductList/index.d.ts +1 -1
  28. package/dist/modules/ProductList/index.js +3 -4
  29. package/dist/modules/Rules/index.d.ts +9 -5
  30. package/dist/modules/Rules/index.js +677 -168
  31. package/dist/modules/Rules/types.d.ts +2 -0
  32. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -11
  33. package/dist/modules/Schedule/utils.d.ts +1 -1
  34. package/dist/modules/Summary/types.d.ts +2 -0
  35. package/dist/modules/Summary/utils.d.ts +9 -3
  36. package/dist/modules/Summary/utils.js +52 -41
  37. package/dist/modules/index.d.ts +0 -4
  38. package/dist/modules/index.js +1 -5
  39. package/dist/plugins/window.d.ts +2 -0
  40. package/dist/solution/BookingByStep/index.d.ts +3 -2
  41. package/dist/solution/BookingByStep/index.js +43 -46
  42. package/dist/solution/BookingByStep/types.d.ts +1 -3
  43. package/dist/solution/BookingByStep/types.js +1 -5
  44. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  45. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  46. package/dist/solution/Checkout/index.js +2 -0
  47. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  48. package/dist/solution/ShopDiscount/index.js +23 -7
  49. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  50. package/dist/solution/ShopDiscount/types.js +2 -1
  51. package/dist/solution/ShopDiscount/utils.js +26 -12
  52. package/dist/solution/index.d.ts +0 -2
  53. package/dist/solution/index.js +1 -3
  54. package/lib/index.d.ts +1 -0
  55. package/lib/index.js +3 -1
  56. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  57. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  58. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  59. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  60. package/lib/model/strategy/engine.d.ts +18 -5
  61. package/lib/model/strategy/engine.js +85 -21
  62. package/lib/model/strategy/type.d.ts +17 -0
  63. package/lib/modules/Cart/types.d.ts +2 -0
  64. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  65. package/lib/modules/Discount/types.d.ts +19 -1
  66. package/lib/modules/Order/index.d.ts +1 -65
  67. package/lib/modules/Order/index.js +1 -513
  68. package/lib/modules/Order/types.d.ts +12 -174
  69. package/lib/modules/Order/utils.d.ts +0 -118
  70. package/lib/modules/Order/utils.js +2 -483
  71. package/lib/modules/Payment/index.d.ts +2 -1
  72. package/lib/modules/Payment/index.js +1 -0
  73. package/lib/modules/Payment/utils.js +3 -0
  74. package/lib/modules/Payment/walletpass.d.ts +23 -0
  75. package/lib/modules/Payment/walletpass.js +94 -17
  76. package/lib/modules/Product/utils.js +2 -2
  77. package/lib/modules/ProductList/index.d.ts +1 -1
  78. package/lib/modules/ProductList/index.js +3 -5
  79. package/lib/modules/Rules/index.d.ts +9 -5
  80. package/lib/modules/Rules/index.js +780 -288
  81. package/lib/modules/Rules/types.d.ts +2 -0
  82. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -9
  83. package/lib/modules/Schedule/utils.d.ts +1 -1
  84. package/lib/modules/Summary/types.d.ts +2 -0
  85. package/lib/modules/Summary/utils.d.ts +9 -3
  86. package/lib/modules/Summary/utils.js +31 -22
  87. package/lib/modules/index.d.ts +0 -4
  88. package/lib/modules/index.js +1 -9
  89. package/lib/plugins/window.d.ts +2 -0
  90. package/lib/solution/BookingByStep/index.d.ts +3 -2
  91. package/lib/solution/BookingByStep/index.js +4 -6
  92. package/lib/solution/BookingByStep/types.d.ts +1 -3
  93. package/lib/solution/BookingByStep/types.js +0 -10
  94. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  95. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  96. package/lib/solution/Checkout/index.js +2 -0
  97. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  98. package/lib/solution/ShopDiscount/index.js +22 -8
  99. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  100. package/lib/solution/ShopDiscount/utils.js +10 -6
  101. package/lib/solution/index.d.ts +0 -2
  102. package/lib/solution/index.js +1 -5
  103. package/package.json +1 -1
  104. package/dist/apis/picoding.d.ts +0 -0
  105. package/dist/apis/picoding.js +0 -1
  106. package/dist/modules/OpenData/index.d.ts +0 -24
  107. package/dist/modules/OpenData/index.js +0 -173
  108. package/dist/modules/OpenData/types.d.ts +0 -73
  109. package/dist/modules/OpenData/types.js +0 -1
  110. package/dist/modules/OpenData/utils.d.ts +0 -2
  111. package/dist/modules/OpenData/utils.js +0 -75
  112. package/dist/modules/Quotation/index.d.ts +0 -48
  113. package/dist/modules/Quotation/index.js +0 -248
  114. package/dist/modules/Quotation/types.d.ts +0 -42
  115. package/dist/modules/Quotation/types.js +0 -1
  116. package/dist/modules/SalesSummary/index.d.ts +0 -63
  117. package/dist/modules/SalesSummary/index.js +0 -174
  118. package/dist/modules/SalesSummary/types.d.ts +0 -60
  119. package/dist/modules/SalesSummary/types.js +0 -1
  120. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  121. package/dist/modules/SalesSummary/utils.js +0 -480
  122. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  123. package/dist/modules/ScanOrderLogger/index.js +0 -174
  124. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  125. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  126. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  127. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  128. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  129. package/dist/modules/ScanOrderLogger/types.js +0 -1
  130. package/dist/solution/ScanOrder/index.d.ts +0 -152
  131. package/dist/solution/ScanOrder/index.js +0 -3132
  132. package/dist/solution/ScanOrder/types.d.ts +0 -287
  133. package/dist/solution/ScanOrder/types.js +0 -35
  134. package/dist/solution/ScanOrder/utils.d.ts +0 -167
  135. package/dist/solution/ScanOrder/utils.js +0 -764
  136. package/dist/solution/VenueBooking/index.d.ts +0 -199
  137. package/dist/solution/VenueBooking/index.js +0 -3459
  138. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  139. package/dist/solution/VenueBooking/types.d.ts +0 -154
  140. package/dist/solution/VenueBooking/types.js +0 -21
  141. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  142. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -104
  143. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  144. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  145. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
  146. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -239
  147. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
  148. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -453
  149. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  150. package/dist/solution/VenueBooking/utils.js +0 -1
  151. package/lib/apis/picoding.d.ts +0 -0
  152. package/lib/apis/picoding.js +0 -0
  153. package/lib/modules/OpenData/index.d.ts +0 -24
  154. package/lib/modules/OpenData/index.js +0 -119
  155. package/lib/modules/OpenData/types.d.ts +0 -73
  156. package/lib/modules/OpenData/types.js +0 -17
  157. package/lib/modules/OpenData/utils.d.ts +0 -2
  158. package/lib/modules/OpenData/utils.js +0 -111
  159. package/lib/modules/Quotation/index.d.ts +0 -48
  160. package/lib/modules/Quotation/index.js +0 -152
  161. package/lib/modules/Quotation/types.d.ts +0 -42
  162. package/lib/modules/Quotation/types.js +0 -17
  163. package/lib/modules/SalesSummary/index.d.ts +0 -63
  164. package/lib/modules/SalesSummary/index.js +0 -105
  165. package/lib/modules/SalesSummary/types.d.ts +0 -60
  166. package/lib/modules/SalesSummary/types.js +0 -17
  167. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  168. package/lib/modules/SalesSummary/utils.js +0 -420
  169. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  170. package/lib/modules/ScanOrderLogger/index.js +0 -147
  171. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  172. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  173. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  174. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  175. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  176. package/lib/modules/ScanOrderLogger/types.js +0 -17
  177. package/lib/solution/ScanOrder/index.d.ts +0 -152
  178. package/lib/solution/ScanOrder/index.js +0 -1901
  179. package/lib/solution/ScanOrder/types.d.ts +0 -287
  180. package/lib/solution/ScanOrder/types.js +0 -36
  181. package/lib/solution/ScanOrder/utils.d.ts +0 -167
  182. package/lib/solution/ScanOrder/utils.js +0 -635
  183. package/lib/solution/VenueBooking/index.d.ts +0 -199
  184. package/lib/solution/VenueBooking/index.js +0 -1926
  185. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  186. package/lib/solution/VenueBooking/types.d.ts +0 -154
  187. package/lib/solution/VenueBooking/types.js +0 -44
  188. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  189. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -110
  190. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  191. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  192. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
  193. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -237
  194. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
  195. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -339
  196. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  197. package/lib/solution/VenueBooking/utils.js +0 -69
@@ -6,6 +6,8 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
6
6
  function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
7
7
  function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
8
8
  function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
9
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
10
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
9
11
  function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
10
12
  function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
11
13
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
@@ -68,6 +70,7 @@ export var StrategyEngine = /*#__PURE__*/function () {
68
70
  errors: []
69
71
  };
70
72
  try {
73
+ var _evaluationResult$fai;
71
74
  // 验证配置
72
75
  this.validateConfig(config);
73
76
  if (this.options.enableTrace) {
@@ -125,11 +128,14 @@ export var StrategyEngine = /*#__PURE__*/function () {
125
128
  applicable: applicable,
126
129
  code: applicable ? SUCCESS_CODES.SUCCESS : NOT_APPLICABLE_CODES.CONDITION_NOT_MET,
127
130
  message: applicable ? 'Strategy is applicable' : 'Conditions not met',
128
- matched: {
131
+ matched: _objectSpread({
129
132
  conditions: applicable,
130
133
  actionIds: evaluationResult.actionIds,
131
134
  details: {}
132
- },
135
+ }, applicable ? {} : {
136
+ failedField: (_evaluationResult$fai = evaluationResult.failedRules[0]) === null || _evaluationResult$fai === void 0 ? void 0 : _evaluationResult$fai.field,
137
+ failedRules: evaluationResult.failedRules
138
+ }),
133
139
  matchedActions: sortedActions,
134
140
  outputs: {},
135
141
  config: config
@@ -174,19 +180,18 @@ export var StrategyEngine = /*#__PURE__*/function () {
174
180
  *
175
181
  * @param group 条件组
176
182
  * @param context 运行时上下文
177
- * @returns 评估结果对象,包含条件是否满足和收集到的 actionIds
183
+ * @returns 评估结果对象,包含条件是否满足、收集到的 actionIds、以及失败的原子规则信息
178
184
  */
179
185
  }, {
180
186
  key: "evaluateConditionGroup",
181
187
  value: function evaluateConditionGroup(group, context) {
182
188
  var collectedActionIds = [];
183
189
 
184
- // 评估当前层的 operator 和 rules
185
- var isCurrentLayerSatisfied = this.evaluateGroupLogic(group, context);
186
-
187
- // 如果当前层条件满足
188
- if (isCurrentLayerSatisfied) {
189
- // 收集当前层的 actionIds
190
+ // 评估当前层的 operator 和 rules(同时收集失败信息)
191
+ var _this$evaluateGroupLo = this.evaluateGroupLogicDetailed(group, context),
192
+ satisfied = _this$evaluateGroupLo.satisfied,
193
+ failedRules = _this$evaluateGroupLo.failedRules;
194
+ if (satisfied) {
190
195
  collectedActionIds.push.apply(collectedActionIds, _toConsumableArray(group.actionIds));
191
196
 
192
197
  // 递归评估嵌套的 ConditionGroup,收集嵌套层的 actionIds
@@ -207,54 +212,134 @@ export var StrategyEngine = /*#__PURE__*/function () {
207
212
  }
208
213
  }
209
214
  return {
210
- satisfied: isCurrentLayerSatisfied,
211
- actionIds: collectedActionIds
215
+ satisfied: satisfied,
216
+ actionIds: collectedActionIds,
217
+ failedRules: failedRules
212
218
  };
213
219
  }
214
220
 
215
221
  /**
216
- * 评估条件组的逻辑运算
222
+ * 评估条件组的逻辑运算(带失败规则收集)
223
+ *
224
+ * 失败规则收集策略:
225
+ * - `and`:返回第一个失败的原子规则(嵌套 group 递归取其首个失败原子规则)
226
+ * - `or`:所有分支失败时,聚合每个分支的失败规则
227
+ * - `not`:被取反规则实际通过时,记录该规则
217
228
  */
218
229
  }, {
219
- key: "evaluateGroupLogic",
220
- value: function evaluateGroupLogic(group, context) {
221
- var _this = this;
230
+ key: "evaluateGroupLogicDetailed",
231
+ value: function evaluateGroupLogicDetailed(group, context) {
222
232
  var operator = group.operator,
223
233
  rules = group.rules;
224
234
  switch (operator) {
225
235
  case 'and':
226
- // 所有规则都必须满足
227
- return rules.every(function (rule) {
228
- return _this.evaluateRule(rule, context);
229
- });
236
+ {
237
+ var _iterator2 = _createForOfIteratorHelper(rules),
238
+ _step2;
239
+ try {
240
+ for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
241
+ var rule = _step2.value;
242
+ var ruleResult = this.evaluateRuleDetailed(rule, context);
243
+ if (!ruleResult.satisfied) {
244
+ return {
245
+ satisfied: false,
246
+ failedRules: ruleResult.failedRules
247
+ };
248
+ }
249
+ }
250
+ } catch (err) {
251
+ _iterator2.e(err);
252
+ } finally {
253
+ _iterator2.f();
254
+ }
255
+ return {
256
+ satisfied: true,
257
+ failedRules: []
258
+ };
259
+ }
230
260
  case 'or':
231
- // 任一规则满足即可
232
- return rules.some(function (rule) {
233
- return _this.evaluateRule(rule, context);
234
- });
261
+ {
262
+ var aggregated = [];
263
+ var _iterator3 = _createForOfIteratorHelper(rules),
264
+ _step3;
265
+ try {
266
+ for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
267
+ var _rule = _step3.value;
268
+ var _ruleResult = this.evaluateRuleDetailed(_rule, context);
269
+ if (_ruleResult.satisfied) {
270
+ return {
271
+ satisfied: true,
272
+ failedRules: []
273
+ };
274
+ }
275
+ aggregated.push.apply(aggregated, _toConsumableArray(_ruleResult.failedRules));
276
+ }
277
+ } catch (err) {
278
+ _iterator3.e(err);
279
+ } finally {
280
+ _iterator3.f();
281
+ }
282
+ return {
283
+ satisfied: false,
284
+ failedRules: aggregated
285
+ };
286
+ }
235
287
  case 'not':
236
- // 对第一个规则取反
237
- if (rules.length === 0) return false;
238
- return !this.evaluateRule(rules[0], context);
288
+ {
289
+ if (rules.length === 0) {
290
+ return {
291
+ satisfied: false,
292
+ failedRules: []
293
+ };
294
+ }
295
+ var _ruleResult2 = this.evaluateRuleDetailed(rules[0], context);
296
+ if (_ruleResult2.satisfied) {
297
+ // 被取反规则实际通过,导致 not 失败
298
+ var failed = this.isConditionGroup(rules[0]) ? [] : [this.buildFailedRuleInfo(rules[0], context)];
299
+ return {
300
+ satisfied: false,
301
+ failedRules: failed
302
+ };
303
+ }
304
+ return {
305
+ satisfied: true,
306
+ failedRules: []
307
+ };
308
+ }
239
309
  default:
240
310
  throw new Error("Unknown operator: ".concat(operator));
241
311
  }
242
312
  }
243
313
 
244
314
  /**
245
- * 评估单个规则
315
+ * 评估单个规则(带失败规则收集)
246
316
  */
247
317
  }, {
248
- key: "evaluateRule",
249
- value: function evaluateRule(rule, context) {
250
- // 如果是嵌套的条件组,递归评估
318
+ key: "evaluateRuleDetailed",
319
+ value: function evaluateRuleDetailed(rule, context) {
251
320
  if (this.isConditionGroup(rule)) {
252
- return this.evaluateGroupLogic(rule, context);
321
+ return this.evaluateGroupLogicDetailed(rule, context);
253
322
  }
254
-
255
- // 原子条件规则
256
323
  var conditionRule = rule;
324
+ var satisfied = this.evaluateAtomicRule(conditionRule, context);
325
+ if (satisfied) {
326
+ return {
327
+ satisfied: true,
328
+ failedRules: []
329
+ };
330
+ }
331
+ return {
332
+ satisfied: false,
333
+ failedRules: [this.buildFailedRuleInfo(conditionRule, context)]
334
+ };
335
+ }
257
336
 
337
+ /**
338
+ * 评估原子规则(不收集失败信息,仅返回布尔结果)
339
+ */
340
+ }, {
341
+ key: "evaluateAtomicRule",
342
+ value: function evaluateAtomicRule(conditionRule, context) {
258
343
  // Code 模式:使用 eval 执行
259
344
  if (conditionRule.type === 'code' && conditionRule.code) {
260
345
  return this.evaluateCodeCondition(conditionRule.code, context);
@@ -264,6 +349,21 @@ export var StrategyEngine = /*#__PURE__*/function () {
264
349
  return this.evaluateOperatorCondition(conditionRule, context);
265
350
  }
266
351
 
352
+ /**
353
+ * 构建失败规则信息
354
+ */
355
+ }, {
356
+ key: "buildFailedRuleInfo",
357
+ value: function buildFailedRuleInfo(conditionRule, context) {
358
+ var actualValue = conditionRule.field ? this.getFieldValue(conditionRule.field, context) : undefined;
359
+ return {
360
+ field: conditionRule.field,
361
+ operator: conditionRule.operator,
362
+ value: conditionRule.value,
363
+ actualValue: actualValue
364
+ };
365
+ }
366
+
267
367
  /**
268
368
  * 评估代码模式条件
269
369
  */
@@ -323,11 +423,11 @@ export var StrategyEngine = /*#__PURE__*/function () {
323
423
  // 支持点号路径,如 "order.total"
324
424
  var path = field.split('.');
325
425
  var value = context.attributes;
326
- var _iterator2 = _createForOfIteratorHelper(path),
327
- _step2;
426
+ var _iterator4 = _createForOfIteratorHelper(path),
427
+ _step4;
328
428
  try {
329
- for (_iterator2.s(); !(_step2 = _iterator2.n()).done;) {
330
- var key = _step2.value;
429
+ for (_iterator4.s(); !(_step4 = _iterator4.n()).done;) {
430
+ var key = _step4.value;
331
431
  if (value && _typeof(value) === 'object' && key in value) {
332
432
  value = value[key];
333
433
  } else {
@@ -335,9 +435,9 @@ export var StrategyEngine = /*#__PURE__*/function () {
335
435
  }
336
436
  }
337
437
  } catch (err) {
338
- _iterator2.e(err);
438
+ _iterator4.e(err);
339
439
  } finally {
340
- _iterator2.f();
440
+ _iterator4.f();
341
441
  }
342
442
  return value;
343
443
  }
@@ -437,11 +537,11 @@ export var StrategyEngine = /*#__PURE__*/function () {
437
537
  var actionMap = new Map(actions.map(function (action) {
438
538
  return [action.id, action];
439
539
  }));
440
- var _iterator3 = _createForOfIteratorHelper(actionIds),
441
- _step3;
540
+ var _iterator5 = _createForOfIteratorHelper(actionIds),
541
+ _step5;
442
542
  try {
443
- for (_iterator3.s(); !(_step3 = _iterator3.n()).done;) {
444
- var id = _step3.value;
543
+ for (_iterator5.s(); !(_step5 = _iterator5.n()).done;) {
544
+ var id = _step5.value;
445
545
  var action = actionMap.get(id);
446
546
  if (action) {
447
547
  matchedActions.push(action);
@@ -453,9 +553,9 @@ export var StrategyEngine = /*#__PURE__*/function () {
453
553
  }
454
554
  }
455
555
  } catch (err) {
456
- _iterator3.e(err);
556
+ _iterator5.e(err);
457
557
  } finally {
458
- _iterator3.f();
558
+ _iterator5.f();
459
559
  }
460
560
  return matchedActions;
461
561
  }
@@ -165,6 +165,23 @@ export interface MatchedInfo {
165
165
  actionIds: string[];
166
166
  /** 详细匹配信息 */
167
167
  details: Record<string, any>;
168
+ /** 顶层第一个失败的 field(仅在 conditions=false 时存在,便于直接消费) */
169
+ failedField?: string;
170
+ /** 失败的原子规则列表(仅在 conditions=false 时存在;or 全失败时可能有多条) */
171
+ failedRules?: FailedRuleInfo[];
172
+ }
173
+ /**
174
+ * 失败规则信息
175
+ */
176
+ export interface FailedRuleInfo {
177
+ /** 字段名 */
178
+ field?: string;
179
+ /** 运算符 */
180
+ operator?: string;
181
+ /** 配置的比较值(阈值) */
182
+ value?: any;
183
+ /** 实际取到的字段值 */
184
+ actualValue?: any;
168
185
  }
169
186
  /**
170
187
  * 执行轨迹
@@ -51,6 +51,10 @@
51
51
  * 匹配信息
52
52
  */
53
53
 
54
+ /**
55
+ * 失败规则信息
56
+ */
57
+
54
58
  /**
55
59
  * 执行轨迹
56
60
  */
@@ -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
  /** 商品图片 */
@@ -15,6 +15,20 @@ import { isNormalProduct } from "../../Product/utils";
15
15
  import { getDiscountAmount } from "../../../solution/ShopDiscount/utils";
16
16
  import { calcDiscountListDifference } from "../../Summary/utils";
17
17
 
18
+ /** 与 Rules / ShopDiscount 一致的折扣入参,用于主价与 option 单价 */
19
+ var toDiscountPayload = function toDiscountPayload(discountItem) {
20
+ var _discountItem$discoun, _discountItem$discoun2;
21
+ return {
22
+ amount: discountItem.amount,
23
+ tag: discountItem.type,
24
+ par_value: (_discountItem$discoun = discountItem.discount) === null || _discountItem$discoun === void 0 ? void 0 : _discountItem$discoun.percent,
25
+ config: discountItem.config,
26
+ metadata: {
27
+ discount_card_type: discountItem === null || discountItem === void 0 || (_discountItem$discoun2 = discountItem.discount) === null || _discountItem$discoun2 === void 0 ? void 0 : _discountItem$discoun2.discount_card_type
28
+ }
29
+ };
30
+ };
31
+
18
32
  /**
19
33
  * @title 处理组合商品
20
34
  * @description 组合商品需要直接修改 product 里的价格和 is_charge_tax
@@ -58,6 +72,7 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
58
72
  quantity = _params$quantity === void 0 ? 1 : _params$quantity,
59
73
  discounts = params.discounts;
60
74
  var num = quantity; // 当前按照单个商品加入购物车
75
+
61
76
  if (product) {
62
77
  cartItem.id = product === null || product === void 0 ? void 0 : product.id;
63
78
  cartItem.name = product === null || product === void 0 ? void 0 : product.title;
@@ -83,6 +98,15 @@ export var formatProductToCartItem = function formatProductToCartItem(params) {
83
98
  num: num,
84
99
  discounts: discounts
85
100
  });
101
+ // 不包含折扣卡商品券的总价
102
+ var origin_total = getProductTotalPrice({
103
+ product: cartItem._productInit || cartItem._productOrigin,
104
+ bundle: bundle,
105
+ options: options,
106
+ num: num,
107
+ discounts: []
108
+ });
109
+ cartItem.summaryOriginTotal = (origin_total || 0) * (num || 1);
86
110
  cartItem.image = product === null || product === void 0 ? void 0 : product.cover;
87
111
  cartItem.like_status = 'common';
88
112
  cartItem.duration = product === null || product === void 0 ? void 0 : product.duration;
@@ -185,6 +209,7 @@ export var formatProductToCartItemOrigin = function formatProductToCartItemOrigi
185
209
  * @returns 商品总价
186
210
  */
187
211
  export var getProductTotalPrice = function getProductTotalPrice(params) {
212
+ var _options$map;
188
213
  var product = params.product,
189
214
  bundle = params.bundle,
190
215
  options = params.options,
@@ -192,22 +217,29 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
192
217
  // const num = params.num || 1;
193
218
  var price = Number(product.price);
194
219
 
220
+ // option 行:unit 折后价在循环中与主商品使用同一套 getDiscountAmount(含 deductOptionPrice)
221
+ var optionRows = (_options$map = options === null || options === void 0 ? void 0 : options.map(function (currentValue) {
222
+ var _ref, _currentValue$price, _ref2, _currentValue$num;
223
+ return {
224
+ unit: Number((_ref = (_currentValue$price = currentValue.price) !== null && _currentValue$price !== void 0 ? _currentValue$price : currentValue.add_price) !== null && _ref !== void 0 ? _ref : 0),
225
+ num: Number((_ref2 = (_currentValue$num = currentValue.num) !== null && _currentValue$num !== void 0 ? _currentValue$num : currentValue.quantity) !== null && _ref2 !== void 0 ? _ref2 : 1)
226
+ };
227
+ })) !== null && _options$map !== void 0 ? _options$map : [];
228
+
195
229
  // 如果商品有折扣,则计算折扣
196
230
  if (discounts !== null && discounts !== void 0 && discounts.length) {
197
231
  discounts.forEach(function (currentValue) {
198
- var _currentValue$discoun;
199
- // 不是商品券则代表折扣卡,计算打折后的价格
200
- // 一个商品折扣卡只能存在于一张
201
- // if (currentValue.type !== 'good_pass') {
202
- price = getDiscountAmount({
203
- amount: currentValue.amount,
204
- tag: currentValue.type,
205
- par_value: currentValue.discount.percent,
206
- metadata: {
207
- discount_card_type: currentValue === null || currentValue === void 0 || (_currentValue$discoun = currentValue.discount) === null || _currentValue$discoun === void 0 ? void 0 : _currentValue$discoun.discount_card_type
232
+ var _currentValue$config;
233
+ var payload = toDiscountPayload(currentValue);
234
+ price = getDiscountAmount(payload, price, price);
235
+ if (currentValue !== null && currentValue !== void 0 && (_currentValue$config = currentValue.config) !== null && _currentValue$config !== void 0 && _currentValue$config.deductOptionPrice && optionRows.length) {
236
+ for (var i = 0; i < optionRows.length; i++) {
237
+ var row = optionRows[i];
238
+ optionRows[i] = _objectSpread(_objectSpread({}, row), {}, {
239
+ unit: getDiscountAmount(payload, row.unit, row.unit)
240
+ });
208
241
  }
209
- }, price, price);
210
- // }
242
+ }
211
243
  });
212
244
  }
213
245
  if (bundle !== null && bundle !== void 0 && bundle.length) {
@@ -216,10 +248,10 @@ export var getProductTotalPrice = function getProductTotalPrice(params) {
216
248
  }, price);
217
249
  }
218
250
 
219
- // 单规格
220
- if (options !== null && options !== void 0 && options.length) {
221
- price = options.reduce(function (accumulator, currentValue) {
222
- return accumulator + Number(currentValue.price) * Number(currentValue.num);
251
+ // 单规格 / 加购 option
252
+ if (optionRows.length) {
253
+ price = optionRows.reduce(function (accumulator, row) {
254
+ return accumulator + row.unit * row.num;
223
255
  }, price);
224
256
  }
225
257
  return Math.max(0, price);
@@ -350,7 +382,6 @@ export var formatBundleToOrigin = function formatBundleToOrigin(bundle) {
350
382
  option: formatOptionsToOrigin(getBundleValueByKey('option')),
351
383
  discount_list: d.discount_list,
352
384
  "bundle_selling_price": d === null || d === void 0 ? void 0 : d.price,
353
- // "custom_price": d?.price,
354
385
  metadata: {
355
386
  custom_product_bundle_map_id: d._id,
356
387
  product_discount_difference: product_discount_difference
@@ -379,11 +410,11 @@ export var getProductDeposit = function getProductDeposit(params) {
379
410
  // 判定商品是否有定金规则
380
411
  if ((product === null || product === void 0 || (_product$custom_depos2 = product.custom_deposit_data) === null || _product$custom_depos2 === void 0 ? void 0 : _product$custom_depos2.has_deposit) == 1) {
381
412
  var total = new Decimal(0);
382
- var _ref = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
383
- deposit_fixed = _ref.deposit_fixed,
384
- deposit_percentage = _ref.deposit_percentage,
385
- deposit_policy_data = _ref.deposit_policy_data,
386
- self_deposit_policy_ids = _ref.self_deposit_policy_ids;
413
+ var _ref3 = (product === null || product === void 0 ? void 0 : product.custom_deposit_data) || {},
414
+ deposit_fixed = _ref3.deposit_fixed,
415
+ deposit_percentage = _ref3.deposit_percentage,
416
+ deposit_policy_data = _ref3.deposit_policy_data,
417
+ self_deposit_policy_ids = _ref3.self_deposit_policy_ids;
387
418
  // 所有协议数据
388
419
  var allProtocols = deposit_policy_data || [];
389
420
  // 是否存在定金,主商品has_deposit为1,但是自身没有定金设置,需要判定子商品是否存在定金,如果不存在最终判定也是不存在定金
@@ -477,9 +508,9 @@ export var handleProductDeposit = function handleProductDeposit(params) {
477
508
  depositTotal: new Decimal(0)
478
509
  };
479
510
  }
480
- var _ref2 = depositData || {},
481
- deposit_fixed = _ref2.deposit_fixed,
482
- deposit_percentage = _ref2.deposit_percentage;
511
+ var _ref4 = depositData || {},
512
+ deposit_fixed = _ref4.deposit_fixed,
513
+ deposit_percentage = _ref4.deposit_percentage;
483
514
  if (typeof deposit_fixed === 'string' && typeof deposit_percentage === 'string') {
484
515
  var depositFixed = Decimal(deposit_fixed || 0);
485
516
  var depositPercent = Decimal(deposit_percentage || 0);
@@ -19,7 +19,7 @@ interface PackageSubItemUsageRules {
19
19
  type: 'universal_discount' | 'package_exclusive' | 'single_item_promo' | 'custom_usage_rules';
20
20
  rules: ("original_price" | "markup_price")[];
21
21
  package_scope?: {
22
- type: 'all_packages' | 'specific_packages' | 'product_all' | 'products';
22
+ type: 'all_packages' | 'specific_packages';
23
23
  exclude_bundle_product_ids: number[];
24
24
  include_bundle_product_ids: number[];
25
25
  filter: 0 | 1;
@@ -33,6 +33,8 @@ 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[];
36
38
  }
37
39
  interface ApplicableProductDetails {
38
40
  amount: string;
@@ -89,6 +91,7 @@ export interface Discount {
89
91
  balance: string;
90
92
  format_title: Formattitle;
91
93
  metadata?: {
94
+ num?: number;
92
95
  discount_card_type?: 'fixed_amount' | 'percent';
93
96
  custom_product_bundle_map_id?: string;
94
97
  validity_type?: "custom_schedule_validity" | "fixed_validity";
@@ -113,6 +116,21 @@ export interface Discount {
113
116
  isSelected?: boolean;
114
117
  isAvailable?: boolean;
115
118
  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
+ };
116
134
  applicableProductIds?: number[];
117
135
  applicableProductDetails: ApplicableProductDetails[];
118
136
  appliedProductDetails: ApplicableProductDetails[];
@@ -1,26 +1,13 @@
1
1
  import { Module, PisellCore, ModuleOptions } from '../../types';
2
2
  import { BaseModule } from '../BaseModule';
3
- import { OrderModuleAPI, CommitOrderParams, SubmitScanOrderParams, ScanOrderMoreParams, CheckoutOrderParams, UpdateProductInOrderParams } from './types';
3
+ import { OrderModuleAPI, CommitOrderParams, CheckoutOrderParams } from './types';
4
4
  import { CartItem } from '../Cart/types';
5
- import { type SubmitPayloadEnhancer } from './utils';
6
- import type { ScanOrderOrderProduct, ScanOrderOrderProductIdentity, ScanOrderSummary, ScanOrderTempOrder } from '../../solution/ScanOrder/types';
7
- import type { Discount } from '../Discount/types';
8
- import { UnavailableReason } from '../Rules/types';
9
5
  export declare class OrderModule extends BaseModule implements Module, OrderModuleAPI {
10
6
  protected defaultName: string;
11
7
  protected defaultVersion: string;
12
8
  private store;
13
9
  private request;
14
10
  private logger;
15
- private window;
16
- private cacheId;
17
- private salesSummaryModuleName;
18
- private rulesHooksOverride?;
19
- /**
20
- * Populate `savedAmount` on each discount based on product-level discount details.
21
- * Only selected discounts get a non-zero value.
22
- */
23
- static populateSavedAmounts(productList: Array<Record<string, any>>, discountList: Array<Record<string, any>>): void;
24
11
  constructor(name?: string, version?: string);
25
12
  initialize(core: PisellCore, options: ModuleOptions): Promise<void>;
26
13
  /**
@@ -35,52 +22,6 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
35
22
  * 记录错误日志
36
23
  */
37
24
  private logError;
38
- private registerDiscountModules;
39
- private createDefaultRulesHooks;
40
- loadDiscountConfig(params: {
41
- customerId: number;
42
- action?: 'create';
43
- }): Promise<void>;
44
- getDiscountList(): Discount[];
45
- scanCode(code: string, customerId?: number): Promise<{
46
- isAvailable: boolean;
47
- discountList: Discount[];
48
- type: 'server' | 'clientCalc';
49
- unavailableReason?: UnavailableReason;
50
- }>;
51
- applyDiscount(): void;
52
- initTempOrder(params: {
53
- cacheId?: string;
54
- salesSummaryModuleName?: string;
55
- }): void;
56
- private getTempOrderStorageKey;
57
- private restoreTempOrderFromStorage;
58
- persistTempOrder(): void;
59
- private createDefaultTempOrderInstance;
60
- ensureTempOrder(): ScanOrderTempOrder;
61
- restoreOrder(): ScanOrderTempOrder;
62
- getTempOrder(): ScanOrderTempOrder | null;
63
- addNewOrder(): Promise<ScanOrderTempOrder>;
64
- getOrderProducts(): ScanOrderOrderProduct[];
65
- private getSalesSummary;
66
- recalculateSummary(options?: {
67
- createIfMissing?: boolean;
68
- }): Promise<ScanOrderSummary | null>;
69
- getScanOrderSummary(): Promise<ScanOrderSummary>;
70
- updateTempOrderNote(note: string): string;
71
- updateTempOrderBuzzer(buzzer: string): string;
72
- updateTempOrderContactsInfo(contactsInfo: any[]): any[];
73
- addProductToOrder(product: Partial<ScanOrderOrderProduct> & ScanOrderOrderProductIdentity): Promise<ScanOrderOrderProduct[]>;
74
- updateProductInOrder(params: UpdateProductInOrderParams): Promise<ScanOrderOrderProduct[]>;
75
- removeProductFromOrder(identity: ScanOrderOrderProductIdentity): Promise<ScanOrderOrderProduct[]>;
76
- submitTempOrder<T = any>(params?: {
77
- cacheId?: string;
78
- platform?: string;
79
- businessCode?: string;
80
- channel?: string;
81
- type?: string;
82
- enhancePayload?: SubmitPayloadEnhancer;
83
- }): Promise<T>;
84
25
  createOrder(params: CommitOrderParams['query']): {
85
26
  type: "virtual" | "appointment_booking";
86
27
  platform: string;
@@ -110,9 +51,4 @@ export declare class OrderModule extends BaseModule implements Module, OrderModu
110
51
  * @returns 后端返回的订单数据(包含订单ID等)
111
52
  */
112
53
  createOrderByCheckout(params: CheckoutOrderParams): Promise<any>;
113
- submitScanOrder<T = any>(params: SubmitScanOrderParams): Promise<T>;
114
- scanOrderMore<T = any>(params: ScanOrderMoreParams): Promise<T>;
115
- getOrderInfoByRemote(order_id: number): Promise<any>;
116
- getLastOrderInfo(): Record<string, any> | undefined;
117
54
  }
118
- export type { UpdateProductInOrderParams } from './types';