@pisell/pisellos 2.2.144 → 2.2.146

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.
@@ -8,10 +8,12 @@ export declare class WalletPassEvaluator {
8
8
  private engine;
9
9
  private strategyConfigs;
10
10
  private locale;
11
+ private otherParams;
11
12
  constructor();
12
13
  setStrategyConfigs(strategyConfigs: StrategyConfig[]): void;
13
14
  getStrategyConfigs(): StrategyConfig[];
14
15
  setLocale(locale: string): void;
16
+ setOtherParams(otherParams: any): void;
15
17
  getText(key: string): string;
16
18
  /**
17
19
  * 搜索券的格式
@@ -35,12 +35,22 @@ var FIELD_REASON_CODE_MAP = {
35
35
  };
36
36
 
37
37
  /**
38
- * 用阈值替换文案中的占位符(同时兼容 ${value} 和 {value})
38
+ * 金额类型 field 集合(需要在文案前拼货币符号)
39
+ */
40
+ var AMOUNT_FIELDS = new Set(['orderTotalAmount', 'applicableProductTotalAmount']);
41
+
42
+ /**
43
+ * 用阈值与货币符号替换文案中的占位符
44
+ * 支持占位符:{value} / ${value} / {currency}
39
45
  */
40
46
  function formatReason(template, value) {
47
+ var currency = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : '';
41
48
  if (!template) return template;
42
- var replacement = value === undefined || value === null ? '' : String(value);
43
- return template.replace(/\$\{value\}/g, replacement).replace(/\{value\}/g, replacement);
49
+ var v = value === undefined || value === null ? '' : String(value);
50
+ var c = currency === undefined || currency === null ? '' : String(currency);
51
+ // 注意:必须先替换 value,再替换 currency
52
+ // 否则 currency 注入的 "$" 会被后续的 /\$\{value\}/ 正则误吞
53
+ return template.replace(/\$\{value\}/g, v).replace(/\{value\}/g, v).replace(/\{currency\}/g, c);
44
54
  }
45
55
 
46
56
  /**
@@ -53,6 +63,7 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
53
63
  _defineProperty(this, "engine", void 0);
54
64
  _defineProperty(this, "strategyConfigs", []);
55
65
  _defineProperty(this, "locale", 'en');
66
+ _defineProperty(this, "otherParams", {});
56
67
  this.engine = new StrategyEngine({
57
68
  debug: false,
58
69
  enableTrace: false
@@ -76,6 +87,11 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
76
87
  value: function setLocale(locale) {
77
88
  this.locale = locale;
78
89
  }
90
+ }, {
91
+ key: "setOtherParams",
92
+ value: function setOtherParams(otherParams) {
93
+ this.otherParams = otherParams;
94
+ }
79
95
  }, {
80
96
  key: "getText",
81
97
  value: function getText(key) {
@@ -210,7 +226,7 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
210
226
  strategyResult: evaluationResult
211
227
  });
212
228
  } else {
213
- var _evaluationResult$mat, _evaluationResult$mat2;
229
+ var _evaluationResult$mat, _evaluationResult$mat2, _this$otherParams, _this$otherParams$get, _this$otherParams2;
214
230
  // 优先根据失败的 field 映射到具体的 reasonCode(更精确的失败原因)
215
231
  var reasonCode = 'not_meet_the_required_conditions';
216
232
  var thresholdValue = undefined;
@@ -231,7 +247,9 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
231
247
  reasonCode = codeMapping[evaluationResult.code] || 'not_meet_the_required_conditions';
232
248
  }
233
249
  var rawText = this.getText(reasonCode);
234
- var reason = thresholdValue !== undefined ? formatReason(rawText, thresholdValue) : rawText;
250
+ // 金额类型字段:从 otherParams.getData 取货币符号;非金额或取不到则留空
251
+ var currency = failedField && AMOUNT_FIELDS.has(failedField) ? ((_this$otherParams = this.otherParams) === null || _this$otherParams === void 0 || (_this$otherParams$get = (_this$otherParams2 = _this$otherParams).getData) === null || _this$otherParams$get === void 0 ? void 0 : _this$otherParams$get.call(_this$otherParams2, 'shop_symbol')) || '' : '';
252
+ var reason = thresholdValue !== undefined ? formatReason(rawText, thresholdValue, currency) : rawText;
235
253
  results.push({
236
254
  voucher: voucher,
237
255
  isApplicable: false,
@@ -479,6 +497,7 @@ export var WalletPassEvaluator = /*#__PURE__*/function () {
479
497
  }, {
480
498
  key: "calculateApplicableProducts",
481
499
  value: function calculateApplicableProducts(products, applicableProductIds, deductTaxAndFee) {
500
+ console.log(products, 'products1234');
482
501
  var total = 0;
483
502
  var count = 0;
484
503
 
@@ -6,8 +6,8 @@ export var locales = {
6
6
  'max_passes_per_item_reached': '该商品已达到卡券使用上限',
7
7
  'not_available_for_this_channel': '当前渠道不可使用',
8
8
  'not_valid_for_this_order_type': '当前订单类型不适用',
9
- 'order_total_amount_not_enough': '订单满 ${value} 才可用',
10
- 'applicable_product_total_amount_not_enough': '适用商品满 ${value} 才可用',
9
+ 'order_total_amount_not_enough': '订单满 {currency}{value} 才可用',
10
+ 'applicable_product_total_amount_not_enough': '适用商品满 {currency}{value} 才可用',
11
11
  'applicable_product_count_not_enough': '至少购买 {value} 件适用商品才可用'
12
12
  },
13
13
  'en': {
@@ -17,8 +17,8 @@ export var locales = {
17
17
  'max_passes_per_item_reached': 'Max passes per item reached.',
18
18
  'not_available_for_this_channel': 'Not available for this channel.',
19
19
  'not_valid_for_this_order_type': 'Not valid for this order type.',
20
- 'order_total_amount_not_enough': 'Spend ${value} to use',
21
- 'applicable_product_total_amount_not_enough': '${value} on eligible items',
20
+ 'order_total_amount_not_enough': 'Spend {currency}{value} to use',
21
+ 'applicable_product_total_amount_not_enough': '{currency}{value} on eligible items',
22
22
  'applicable_product_count_not_enough': 'Buy {value} eligible items to use'
23
23
  },
24
24
  'zh-HK': {
@@ -28,8 +28,8 @@ export var locales = {
28
28
  'max_passes_per_item_reached': '該商品已達卡券使用上限',
29
29
  'not_available_for_this_channel': '當前渠道不可使用',
30
30
  'not_valid_for_this_order_type': '當前訂單類型不適用',
31
- 'order_total_amount_not_enough': '訂單滿 ${value} 才可用',
32
- 'applicable_product_total_amount_not_enough': '適用商品滿 ${value} 才可用',
31
+ 'order_total_amount_not_enough': '訂單滿 {currency}{value} 才可用',
32
+ 'applicable_product_total_amount_not_enough': '適用商品滿 {currency}{value} 才可用',
33
33
  'applicable_product_count_not_enough': '至少購買 {value} 件適用商品才可用'
34
34
  }
35
35
  };
@@ -160,7 +160,7 @@ function matchBooking(booking, orderInfo, ctx) {
160
160
  }
161
161
  if (ctx.appointmentStatusSet && !ctx.appointmentStatusSet.has(getBookingAppointmentStatus(booking))) return false;
162
162
  if (ctx.bookingTimeRange) {
163
- var ts = toTimestamp(booking.start_date);
163
+ var ts = toTimestamp(bookingDateTimeString(booking.start_date, booking.start_time));
164
164
  if (ts < ctx.bookingTimeRange[0] || ts > ctx.bookingTimeRange[1]) return false;
165
165
  }
166
166
  if (ctx.afterExecutionTimeMs != null) {
@@ -308,6 +308,7 @@ export function filterBookingsFromOrders(orders, filters) {
308
308
 
309
309
  // 订单级预过滤
310
310
  if (!matchOrder(order, ctx)) continue;
311
+ debugger;
311
312
 
312
313
  // 订单通过,遍历其 bookings;orderInfo 延迟创建
313
314
  var orderInfo = null;
@@ -8,10 +8,12 @@ export declare class WalletPassEvaluator {
8
8
  private engine;
9
9
  private strategyConfigs;
10
10
  private locale;
11
+ private otherParams;
11
12
  constructor();
12
13
  setStrategyConfigs(strategyConfigs: StrategyConfig[]): void;
13
14
  getStrategyConfigs(): StrategyConfig[];
14
15
  setLocale(locale: string): void;
16
+ setOtherParams(otherParams: any): void;
15
17
  getText(key: string): string;
16
18
  /**
17
19
  * 搜索券的格式
@@ -50,16 +50,22 @@ var FIELD_REASON_CODE_MAP = {
50
50
  applicableProductTotalAmount: "applicable_product_total_amount_not_enough",
51
51
  applicableProductCount: "applicable_product_count_not_enough"
52
52
  };
53
- function formatReason(template, value) {
53
+ var AMOUNT_FIELDS = /* @__PURE__ */ new Set([
54
+ "orderTotalAmount",
55
+ "applicableProductTotalAmount"
56
+ ]);
57
+ function formatReason(template, value, currency = "") {
54
58
  if (!template)
55
59
  return template;
56
- const replacement = value === void 0 || value === null ? "" : String(value);
57
- return template.replace(/\$\{value\}/g, replacement).replace(/\{value\}/g, replacement);
60
+ const v = value === void 0 || value === null ? "" : String(value);
61
+ const c = currency === void 0 || currency === null ? "" : String(currency);
62
+ return template.replace(/\$\{value\}/g, v).replace(/\{value\}/g, v).replace(/\{currency\}/g, c);
58
63
  }
59
64
  var WalletPassEvaluator = class {
60
65
  constructor() {
61
66
  this.strategyConfigs = [];
62
67
  this.locale = "en";
68
+ this.otherParams = {};
63
69
  this.engine = new import__.StrategyEngine({
64
70
  debug: false,
65
71
  enableTrace: false
@@ -75,6 +81,9 @@ var WalletPassEvaluator = class {
75
81
  setLocale(locale) {
76
82
  this.locale = locale;
77
83
  }
84
+ setOtherParams(otherParams) {
85
+ this.otherParams = otherParams;
86
+ }
78
87
  getText(key) {
79
88
  var _a, _b;
80
89
  return (_b = (_a = import_locales.locales) == null ? void 0 : _a[this.locale]) == null ? void 0 : _b[key];
@@ -112,7 +121,7 @@ var WalletPassEvaluator = class {
112
121
  * 评估可用的 vouchers
113
122
  */
114
123
  evaluate(input) {
115
- var _a, _b, _c, _d, _e;
124
+ var _a, _b, _c, _d, _e, _f, _g;
116
125
  const { orderTotalAmount, products, vouchers, strategyConfigs } = input;
117
126
  const productIds = products.map((p) => p.product_id);
118
127
  const results = [];
@@ -204,7 +213,8 @@ var WalletPassEvaluator = class {
204
213
  reasonCode = codeMapping[evaluationResult.code] || "not_meet_the_required_conditions";
205
214
  }
206
215
  const rawText = this.getText(reasonCode);
207
- const reason = thresholdValue !== void 0 ? formatReason(rawText, thresholdValue) : rawText;
216
+ const currency = failedField && AMOUNT_FIELDS.has(failedField) ? ((_g = (_f = this.otherParams) == null ? void 0 : _f.getData) == null ? void 0 : _g.call(_f, "shop_symbol")) || "" : "";
217
+ const reason = thresholdValue !== void 0 ? formatReason(rawText, thresholdValue, currency) : rawText;
208
218
  results.push({
209
219
  voucher,
210
220
  isApplicable: false,
@@ -405,6 +415,7 @@ var WalletPassEvaluator = class {
405
415
  * 计算适用商品的总金额和数量
406
416
  */
407
417
  calculateApplicableProducts(products, applicableProductIds, deductTaxAndFee) {
418
+ console.log(products, "products1234");
408
419
  let total = 0;
409
420
  let count = 0;
410
421
  if (applicableProductIds !== null && applicableProductIds.length === 0) {
@@ -30,8 +30,8 @@ var locales = {
30
30
  "max_passes_per_item_reached": "该商品已达到卡券使用上限",
31
31
  "not_available_for_this_channel": "当前渠道不可使用",
32
32
  "not_valid_for_this_order_type": "当前订单类型不适用",
33
- "order_total_amount_not_enough": "订单满 ${value} 才可用",
34
- "applicable_product_total_amount_not_enough": "适用商品满 ${value} 才可用",
33
+ "order_total_amount_not_enough": "订单满 {currency}{value} 才可用",
34
+ "applicable_product_total_amount_not_enough": "适用商品满 {currency}{value} 才可用",
35
35
  "applicable_product_count_not_enough": "至少购买 {value} 件适用商品才可用"
36
36
  },
37
37
  "en": {
@@ -41,8 +41,8 @@ var locales = {
41
41
  "max_passes_per_item_reached": "Max passes per item reached.",
42
42
  "not_available_for_this_channel": "Not available for this channel.",
43
43
  "not_valid_for_this_order_type": "Not valid for this order type.",
44
- "order_total_amount_not_enough": "Spend ${value} to use",
45
- "applicable_product_total_amount_not_enough": "${value} on eligible items",
44
+ "order_total_amount_not_enough": "Spend {currency}{value} to use",
45
+ "applicable_product_total_amount_not_enough": "{currency}{value} on eligible items",
46
46
  "applicable_product_count_not_enough": "Buy {value} eligible items to use"
47
47
  },
48
48
  "zh-HK": {
@@ -52,8 +52,8 @@ var locales = {
52
52
  "max_passes_per_item_reached": "該商品已達卡券使用上限",
53
53
  "not_available_for_this_channel": "當前渠道不可使用",
54
54
  "not_valid_for_this_order_type": "當前訂單類型不適用",
55
- "order_total_amount_not_enough": "訂單滿 ${value} 才可用",
56
- "applicable_product_total_amount_not_enough": "適用商品滿 ${value} 才可用",
55
+ "order_total_amount_not_enough": "訂單滿 {currency}{value} 才可用",
56
+ "applicable_product_total_amount_not_enough": "適用商品滿 {currency}{value} 才可用",
57
57
  "applicable_product_count_not_enough": "至少購買 {value} 件適用商品才可用"
58
58
  }
59
59
  };
@@ -178,7 +178,7 @@ function matchBooking(booking, orderInfo, ctx) {
178
178
  if (ctx.appointmentStatusSet && !ctx.appointmentStatusSet.has(getBookingAppointmentStatus(booking)))
179
179
  return false;
180
180
  if (ctx.bookingTimeRange) {
181
- const ts = toTimestamp(booking.start_date);
181
+ const ts = toTimestamp(bookingDateTimeString(booking.start_date, booking.start_time));
182
182
  if (ts < ctx.bookingTimeRange[0] || ts > ctx.bookingTimeRange[1])
183
183
  return false;
184
184
  }
@@ -308,6 +308,7 @@ function filterBookingsFromOrders(orders, filters) {
308
308
  continue;
309
309
  if (!matchOrder(order, ctx))
310
310
  continue;
311
+ debugger;
311
312
  let orderInfo = null;
312
313
  for (let j = 0, bLen = bookings.length; j < bLen; j++) {
313
314
  const booking = bookings[j];
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "2.2.144",
4
+ "version": "2.2.146",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",