@pisell/pisellos 0.0.521 → 0.0.522

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,9 @@
1
+ // 导出评估器
2
+ export { PromotionEvaluator } from "./evaluator";
3
+
4
+ // 导出适配器
5
+ export { PromotionAdapter } from "./adapter";
6
+ export { default } from "./adapter";
7
+
8
+ // 导出策略配置示例常量
9
+ export { X_ITEMS_FOR_Y_PRICE_STRATEGY, BUY_X_GET_Y_FREE_STRATEGY } from "./examples";
@@ -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
  };
@@ -1,49 +0,0 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __export = (target, all) => {
8
- for (var name in all)
9
- __defProp(target, name, { get: all[name], enumerable: true });
10
- };
11
- var __copyProps = (to, from, except, desc) => {
12
- if (from && typeof from === "object" || typeof from === "function") {
13
- for (let key of __getOwnPropNames(from))
14
- if (!__hasOwnProp.call(to, key) && key !== except)
15
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
- }
17
- return to;
18
- };
19
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
20
- // If the importer is in node compatibility mode or this is not an ESM
21
- // file that has been converted to a CommonJS file using a Babel-
22
- // compatible transform (i.e. "__esModule" has not been set), then set
23
- // "default" to the CommonJS "module.exports" for node compatibility.
24
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
25
- mod
26
- ));
27
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
28
-
29
- // src/model/strategy/adapter/promotion/index.ts
30
- var promotion_exports = {};
31
- __export(promotion_exports, {
32
- BUY_X_GET_Y_FREE_STRATEGY: () => import_examples.BUY_X_GET_Y_FREE_STRATEGY,
33
- PromotionAdapter: () => import_adapter.PromotionAdapter,
34
- PromotionEvaluator: () => import_evaluator.PromotionEvaluator,
35
- X_ITEMS_FOR_Y_PRICE_STRATEGY: () => import_examples.X_ITEMS_FOR_Y_PRICE_STRATEGY,
36
- default: () => import_adapter2.default
37
- });
38
- module.exports = __toCommonJS(promotion_exports);
39
- var import_evaluator = require("./evaluator");
40
- var import_adapter = require("./adapter");
41
- var import_adapter2 = __toESM(require("./adapter"));
42
- var import_examples = require("./examples");
43
- // Annotate the CommonJS export names for ESM import in node:
44
- 0 && (module.exports = {
45
- BUY_X_GET_Y_FREE_STRATEGY,
46
- PromotionAdapter,
47
- PromotionEvaluator,
48
- X_ITEMS_FOR_Y_PRICE_STRATEGY
49
- });
@@ -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
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "private": false,
3
3
  "name": "@pisell/pisellos",
4
- "version": "0.0.521",
4
+ "version": "0.0.522",
5
5
  "description": "一个可扩展的前端模块化SDK框架,支持插件系统",
6
6
  "main": "dist/index.js",
7
7
  "types": "dist/index.d.ts",