@pisell/pisellos 2.1.150 → 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 (201) 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/walletPass/evaluator.d.ts +2 -0
  5. package/dist/model/strategy/adapter/walletPass/evaluator.js +61 -8
  6. package/dist/model/strategy/adapter/walletPass/locales.js +12 -3
  7. package/dist/model/strategy/engine.d.ts +18 -5
  8. package/dist/model/strategy/engine.js +145 -45
  9. package/dist/model/strategy/type.d.ts +17 -0
  10. package/dist/model/strategy/type.js +4 -0
  11. package/dist/modules/Cart/types.d.ts +2 -0
  12. package/dist/modules/Cart/utils/cartProduct.js +56 -25
  13. package/dist/modules/Discount/index.d.ts +2 -6
  14. package/dist/modules/Discount/index.js +8 -14
  15. package/dist/modules/Discount/types.d.ts +19 -1
  16. package/dist/modules/Order/index.d.ts +1 -65
  17. package/dist/modules/Order/index.js +30 -901
  18. package/dist/modules/Order/types.d.ts +12 -174
  19. package/dist/modules/Order/types.js +0 -2
  20. package/dist/modules/Order/utils.d.ts +0 -118
  21. package/dist/modules/Order/utils.js +2 -586
  22. package/dist/modules/Payment/index.d.ts +2 -1
  23. package/dist/modules/Payment/index.js +10 -7
  24. package/dist/modules/Payment/utils.js +3 -0
  25. package/dist/modules/Payment/walletpass.d.ts +23 -0
  26. package/dist/modules/Payment/walletpass.js +191 -95
  27. package/dist/modules/Product/utils.js +2 -2
  28. package/dist/modules/ProductList/index.d.ts +1 -1
  29. package/dist/modules/ProductList/index.js +3 -4
  30. package/dist/modules/Rules/index.d.ts +9 -5
  31. package/dist/modules/Rules/index.js +677 -168
  32. package/dist/modules/Rules/types.d.ts +2 -0
  33. package/dist/modules/Schedule/getDateIsInSchedule.js +18 -11
  34. package/dist/modules/Schedule/utils.d.ts +1 -1
  35. package/dist/modules/Summary/types.d.ts +2 -0
  36. package/dist/modules/Summary/utils.d.ts +9 -3
  37. package/dist/modules/Summary/utils.js +52 -41
  38. package/dist/modules/index.d.ts +0 -4
  39. package/dist/modules/index.js +1 -5
  40. package/dist/plugins/window.d.ts +2 -0
  41. package/dist/solution/BookingByStep/index.d.ts +3 -2
  42. package/dist/solution/BookingByStep/index.js +43 -46
  43. package/dist/solution/BookingByStep/types.d.ts +1 -3
  44. package/dist/solution/BookingByStep/types.js +1 -5
  45. package/dist/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  46. package/dist/solution/BookingByStep/utils/timeslots.js +12 -19
  47. package/dist/solution/Checkout/index.js +2 -0
  48. package/dist/solution/ShopDiscount/index.d.ts +2 -2
  49. package/dist/solution/ShopDiscount/index.js +41 -37
  50. package/dist/solution/ShopDiscount/types.d.ts +1 -1
  51. package/dist/solution/ShopDiscount/types.js +2 -1
  52. package/dist/solution/ShopDiscount/utils.js +26 -12
  53. package/dist/solution/index.d.ts +0 -2
  54. package/dist/solution/index.js +1 -3
  55. package/lib/index.d.ts +1 -0
  56. package/lib/index.js +3 -1
  57. package/lib/model/strategy/adapter/promotion/evaluator.js +57 -8
  58. package/lib/model/strategy/adapter/promotion/index.js +49 -0
  59. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +2 -0
  60. package/lib/model/strategy/adapter/walletPass/evaluator.js +34 -3
  61. package/lib/model/strategy/adapter/walletPass/locales.js +12 -3
  62. package/lib/model/strategy/engine.d.ts +18 -5
  63. package/lib/model/strategy/engine.js +85 -21
  64. package/lib/model/strategy/type.d.ts +17 -0
  65. package/lib/modules/Cart/types.d.ts +2 -0
  66. package/lib/modules/Cart/utils/cartProduct.js +39 -12
  67. package/lib/modules/Discount/index.d.ts +2 -6
  68. package/lib/modules/Discount/index.js +1 -3
  69. package/lib/modules/Discount/types.d.ts +19 -1
  70. package/lib/modules/Order/index.d.ts +1 -65
  71. package/lib/modules/Order/index.js +1 -513
  72. package/lib/modules/Order/types.d.ts +12 -174
  73. package/lib/modules/Order/utils.d.ts +0 -118
  74. package/lib/modules/Order/utils.js +2 -483
  75. package/lib/modules/Payment/index.d.ts +2 -1
  76. package/lib/modules/Payment/index.js +1 -0
  77. package/lib/modules/Payment/utils.js +3 -0
  78. package/lib/modules/Payment/walletpass.d.ts +23 -0
  79. package/lib/modules/Payment/walletpass.js +94 -17
  80. package/lib/modules/Product/utils.js +2 -2
  81. package/lib/modules/ProductList/index.d.ts +1 -1
  82. package/lib/modules/ProductList/index.js +3 -5
  83. package/lib/modules/Rules/index.d.ts +9 -5
  84. package/lib/modules/Rules/index.js +780 -288
  85. package/lib/modules/Rules/types.d.ts +2 -0
  86. package/lib/modules/Schedule/getDateIsInSchedule.js +11 -9
  87. package/lib/modules/Schedule/utils.d.ts +1 -1
  88. package/lib/modules/Summary/types.d.ts +2 -0
  89. package/lib/modules/Summary/utils.d.ts +9 -3
  90. package/lib/modules/Summary/utils.js +31 -22
  91. package/lib/modules/index.d.ts +0 -4
  92. package/lib/modules/index.js +1 -9
  93. package/lib/plugins/window.d.ts +2 -0
  94. package/lib/solution/BookingByStep/index.d.ts +3 -2
  95. package/lib/solution/BookingByStep/index.js +4 -6
  96. package/lib/solution/BookingByStep/types.d.ts +1 -3
  97. package/lib/solution/BookingByStep/types.js +0 -10
  98. package/lib/solution/BookingByStep/utils/timeslots.d.ts +1 -3
  99. package/lib/solution/BookingByStep/utils/timeslots.js +11 -19
  100. package/lib/solution/Checkout/index.js +2 -0
  101. package/lib/solution/ShopDiscount/index.d.ts +2 -2
  102. package/lib/solution/ShopDiscount/index.js +24 -16
  103. package/lib/solution/ShopDiscount/types.d.ts +1 -1
  104. package/lib/solution/ShopDiscount/utils.js +10 -6
  105. package/lib/solution/index.d.ts +0 -2
  106. package/lib/solution/index.js +1 -5
  107. package/package.json +1 -1
  108. package/dist/apis/picoding.d.ts +0 -0
  109. package/dist/apis/picoding.js +0 -1
  110. package/dist/modules/OpenData/index.d.ts +0 -24
  111. package/dist/modules/OpenData/index.js +0 -173
  112. package/dist/modules/OpenData/types.d.ts +0 -73
  113. package/dist/modules/OpenData/types.js +0 -1
  114. package/dist/modules/OpenData/utils.d.ts +0 -2
  115. package/dist/modules/OpenData/utils.js +0 -75
  116. package/dist/modules/Quotation/index.d.ts +0 -48
  117. package/dist/modules/Quotation/index.js +0 -248
  118. package/dist/modules/Quotation/types.d.ts +0 -42
  119. package/dist/modules/Quotation/types.js +0 -1
  120. package/dist/modules/SalesSummary/index.d.ts +0 -63
  121. package/dist/modules/SalesSummary/index.js +0 -174
  122. package/dist/modules/SalesSummary/types.d.ts +0 -60
  123. package/dist/modules/SalesSummary/types.js +0 -1
  124. package/dist/modules/SalesSummary/utils.d.ts +0 -30
  125. package/dist/modules/SalesSummary/utils.js +0 -480
  126. package/dist/modules/ScanOrderLogger/index.d.ts +0 -23
  127. package/dist/modules/ScanOrderLogger/index.js +0 -174
  128. package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  129. package/dist/modules/ScanOrderLogger/providers/feishu.js +0 -221
  130. package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  131. package/dist/modules/ScanOrderLogger/providers/grafana.js +0 -50
  132. package/dist/modules/ScanOrderLogger/types.d.ts +0 -53
  133. package/dist/modules/ScanOrderLogger/types.js +0 -1
  134. package/dist/solution/ScanOrder/index.d.ts +0 -152
  135. package/dist/solution/ScanOrder/index.js +0 -3132
  136. package/dist/solution/ScanOrder/types.d.ts +0 -287
  137. package/dist/solution/ScanOrder/types.js +0 -35
  138. package/dist/solution/ScanOrder/utils.d.ts +0 -167
  139. package/dist/solution/ScanOrder/utils.js +0 -764
  140. package/dist/solution/VenueBooking/index.d.ts +0 -199
  141. package/dist/solution/VenueBooking/index.js +0 -3459
  142. package/dist/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  143. package/dist/solution/VenueBooking/types.d.ts +0 -154
  144. package/dist/solution/VenueBooking/types.js +0 -21
  145. package/dist/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  146. package/dist/solution/VenueBooking/utils/dateSummary.js +0 -104
  147. package/dist/solution/VenueBooking/utils/resource.d.ts +0 -14
  148. package/dist/solution/VenueBooking/utils/resource.js +0 -131
  149. package/dist/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
  150. package/dist/solution/VenueBooking/utils/slotMerge.js +0 -239
  151. package/dist/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
  152. package/dist/solution/VenueBooking/utils/timeSlot.js +0 -453
  153. package/dist/solution/VenueBooking/utils.d.ts +0 -1
  154. package/dist/solution/VenueBooking/utils.js +0 -1
  155. package/lib/apis/picoding.d.ts +0 -0
  156. package/lib/apis/picoding.js +0 -0
  157. package/lib/modules/OpenData/index.d.ts +0 -24
  158. package/lib/modules/OpenData/index.js +0 -119
  159. package/lib/modules/OpenData/types.d.ts +0 -73
  160. package/lib/modules/OpenData/types.js +0 -17
  161. package/lib/modules/OpenData/utils.d.ts +0 -2
  162. package/lib/modules/OpenData/utils.js +0 -111
  163. package/lib/modules/Quotation/index.d.ts +0 -48
  164. package/lib/modules/Quotation/index.js +0 -152
  165. package/lib/modules/Quotation/types.d.ts +0 -42
  166. package/lib/modules/Quotation/types.js +0 -17
  167. package/lib/modules/SalesSummary/index.d.ts +0 -63
  168. package/lib/modules/SalesSummary/index.js +0 -105
  169. package/lib/modules/SalesSummary/types.d.ts +0 -60
  170. package/lib/modules/SalesSummary/types.js +0 -17
  171. package/lib/modules/SalesSummary/utils.d.ts +0 -30
  172. package/lib/modules/SalesSummary/utils.js +0 -420
  173. package/lib/modules/ScanOrderLogger/index.d.ts +0 -23
  174. package/lib/modules/ScanOrderLogger/index.js +0 -147
  175. package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +0 -2
  176. package/lib/modules/ScanOrderLogger/providers/feishu.js +0 -157
  177. package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +0 -2
  178. package/lib/modules/ScanOrderLogger/providers/grafana.js +0 -52
  179. package/lib/modules/ScanOrderLogger/types.d.ts +0 -53
  180. package/lib/modules/ScanOrderLogger/types.js +0 -17
  181. package/lib/solution/ScanOrder/index.d.ts +0 -152
  182. package/lib/solution/ScanOrder/index.js +0 -1901
  183. package/lib/solution/ScanOrder/types.d.ts +0 -287
  184. package/lib/solution/ScanOrder/types.js +0 -36
  185. package/lib/solution/ScanOrder/utils.d.ts +0 -167
  186. package/lib/solution/ScanOrder/utils.js +0 -635
  187. package/lib/solution/VenueBooking/index.d.ts +0 -199
  188. package/lib/solution/VenueBooking/index.js +0 -1926
  189. package/lib/solution/VenueBooking/sales-section-4-annotated.json +0 -343
  190. package/lib/solution/VenueBooking/types.d.ts +0 -154
  191. package/lib/solution/VenueBooking/types.js +0 -44
  192. package/lib/solution/VenueBooking/utils/dateSummary.d.ts +0 -11
  193. package/lib/solution/VenueBooking/utils/dateSummary.js +0 -110
  194. package/lib/solution/VenueBooking/utils/resource.d.ts +0 -14
  195. package/lib/solution/VenueBooking/utils/resource.js +0 -92
  196. package/lib/solution/VenueBooking/utils/slotMerge.d.ts +0 -38
  197. package/lib/solution/VenueBooking/utils/slotMerge.js +0 -237
  198. package/lib/solution/VenueBooking/utils/timeSlot.d.ts +0 -32
  199. package/lib/solution/VenueBooking/utils/timeSlot.js +0 -339
  200. package/lib/solution/VenueBooking/utils.d.ts +0 -1
  201. 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);
@@ -17,18 +17,14 @@ export declare class DiscountModule extends BaseModule implements Module, Discou
17
17
  setOriginalDiscountList(originalDiscountList: Discount[]): Promise<void>;
18
18
  getOriginalDiscountList(): Discount[];
19
19
  loadPrepareConfig(params: {
20
- action?: 'create' | 'edit';
20
+ action?: 'create';
21
21
  with_good_pass: 0 | 1;
22
22
  with_discount_card: 0 | 1;
23
23
  customer_id: number;
24
24
  with_wallet_pass_holder: 0 | 1;
25
25
  request_timezone: string;
26
- order_id?: number;
27
- }): Promise<Discount[]>;
28
- batchSearch(code: string, options?: {
29
- customerId?: number;
30
- orderId?: number;
31
26
  }): Promise<Discount[]>;
27
+ batchSearch(code: string, customerId?: number): Promise<Discount[]>;
32
28
  batchSearchByProductIds(productIds: number[]): Promise<any>;
33
29
  filterEnabledDiscountList(discountList: Discount[]): Discount[];
34
30
  private checkUsageCreditsLimit;
@@ -1,6 +1,4 @@
1
1
  function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
- 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; }
3
- 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; }
4
2
  function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
5
3
  function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
6
4
  function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
@@ -178,14 +176,13 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
178
176
  }, {
179
177
  key: "batchSearch",
180
178
  value: function () {
181
- var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, options) {
182
- var _ref, customerId, orderId, result, resultDiscountList;
179
+ var _batchSearch = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee5(code, customerId) {
180
+ var result, resultDiscountList;
183
181
  return _regeneratorRuntime().wrap(function _callee5$(_context5) {
184
182
  while (1) switch (_context5.prev = _context5.next) {
185
183
  case 0:
186
- _ref = options || {}, customerId = _ref.customerId, orderId = _ref.orderId;
187
- _context5.next = 3;
188
- return this.request.get("/machinecode/batch-search", _objectSpread(_objectSpread({
184
+ _context5.next = 2;
185
+ return this.request.get("/machinecode/batch-search", {
189
186
  code: code,
190
187
  translate_flag: 1,
191
188
  tags: ['good_pass', 'product_discount_card'],
@@ -193,17 +190,14 @@ export var DiscountModule = /*#__PURE__*/function (_BaseModule) {
193
190
  relation_product: 1,
194
191
  with: ['extensionData', 'customScheduleSnapshot', 'holder.detail'],
195
192
  order_behavior_count: 1,
196
- order_behavior_count_customer_id: customerId || 1
197
- }, orderId ? {
198
- order_behavior_count_order_id: orderId
199
- } : {}), {}, {
193
+ order_behavior_count_customer_id: customerId || 1,
200
194
  request_timezone: Intl.DateTimeFormat().resolvedOptions().timeZone
201
- }));
202
- case 3:
195
+ });
196
+ case 2:
203
197
  result = _context5.sent;
204
198
  resultDiscountList = this.filterEnabledDiscountList((result === null || result === void 0 ? void 0 : result.data) || []) || [];
205
199
  return _context5.abrupt("return", resultDiscountList);
206
- case 6:
200
+ case 5:
207
201
  case "end":
208
202
  return _context5.stop();
209
203
  }
@@ -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[];