@pisell/pisellos 2.1.59 → 2.1.60

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 (95) hide show
  1. package/dist/index.d.ts +1 -0
  2. package/dist/index.js +1 -0
  3. package/dist/model/index.d.ts +1 -0
  4. package/dist/model/index.js +1 -0
  5. package/dist/model/strategy/adapter/index.d.ts +3 -0
  6. package/dist/model/strategy/adapter/index.js +4 -0
  7. package/dist/model/strategy/adapter/type.d.ts +28 -0
  8. package/dist/model/strategy/adapter/type.js +1 -0
  9. package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  10. package/dist/model/strategy/adapter/walletPass/evaluator.js +496 -0
  11. package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
  12. package/dist/model/strategy/adapter/walletPass/example.js +258 -0
  13. package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
  14. package/dist/model/strategy/adapter/walletPass/index.js +182 -0
  15. package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  16. package/dist/model/strategy/adapter/walletPass/locales.js +23 -0
  17. package/dist/model/strategy/adapter/walletPass/type.d.ts +163 -0
  18. package/dist/model/strategy/adapter/walletPass/type.js +1 -0
  19. package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  20. package/dist/model/strategy/adapter/walletPass/utils.js +965 -0
  21. package/dist/model/strategy/index.d.ts +94 -0
  22. package/dist/model/strategy/index.js +551 -0
  23. package/dist/model/strategy/strategy-example.d.ts +5 -0
  24. package/dist/model/strategy/strategy-example.js +331 -0
  25. package/dist/model/strategy/type.d.ts +228 -0
  26. package/dist/model/strategy/type.js +94 -0
  27. package/dist/modules/Cart/types.d.ts +2 -0
  28. package/dist/modules/Cart/utils/cartProduct.js +11 -0
  29. package/dist/modules/Discount/types.d.ts +15 -0
  30. package/dist/modules/Payment/index.d.ts +2 -1
  31. package/dist/modules/Payment/index.js +10 -7
  32. package/dist/modules/Payment/utils.js +3 -0
  33. package/dist/modules/Payment/walletpass.d.ts +23 -0
  34. package/dist/modules/Payment/walletpass.js +191 -95
  35. package/dist/modules/Rules/index.d.ts +8 -3
  36. package/dist/modules/Rules/index.js +152 -26
  37. package/dist/modules/Rules/types.d.ts +1 -0
  38. package/dist/modules/Summary/types.d.ts +2 -0
  39. package/dist/modules/Summary/utils.d.ts +6 -0
  40. package/dist/modules/Summary/utils.js +21 -0
  41. package/dist/plugins/window.d.ts +2 -0
  42. package/dist/solution/BookingByStep/index.d.ts +2 -1
  43. package/dist/solution/Checkout/index.js +2 -0
  44. package/dist/solution/ShopDiscount/index.d.ts +1 -0
  45. package/dist/solution/ShopDiscount/index.js +11 -1
  46. package/dist/solution/ShopDiscount/types.d.ts +1 -0
  47. package/dist/solution/ShopDiscount/utils.js +26 -11
  48. package/lib/index.d.ts +1 -0
  49. package/lib/index.js +3 -1
  50. package/lib/model/index.d.ts +1 -0
  51. package/lib/model/index.js +23 -0
  52. package/lib/model/strategy/adapter/index.d.ts +3 -0
  53. package/lib/model/strategy/adapter/index.js +45 -0
  54. package/lib/model/strategy/adapter/type.d.ts +28 -0
  55. package/lib/model/strategy/adapter/type.js +17 -0
  56. package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
  57. package/lib/model/strategy/adapter/walletPass/evaluator.js +420 -0
  58. package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
  59. package/lib/model/strategy/adapter/walletPass/example.js +207 -0
  60. package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
  61. package/lib/model/strategy/adapter/walletPass/index.js +142 -0
  62. package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
  63. package/lib/model/strategy/adapter/walletPass/locales.js +51 -0
  64. package/lib/model/strategy/adapter/walletPass/type.d.ts +163 -0
  65. package/lib/model/strategy/adapter/walletPass/type.js +17 -0
  66. package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
  67. package/lib/model/strategy/adapter/walletPass/utils.js +660 -0
  68. package/lib/model/strategy/index.d.ts +94 -0
  69. package/lib/model/strategy/index.js +413 -0
  70. package/lib/model/strategy/strategy-example.d.ts +5 -0
  71. package/lib/model/strategy/strategy-example.js +318 -0
  72. package/lib/model/strategy/type.d.ts +228 -0
  73. package/lib/model/strategy/type.js +44 -0
  74. package/lib/modules/Cart/types.d.ts +2 -0
  75. package/lib/modules/Cart/utils/cartProduct.js +9 -0
  76. package/lib/modules/Discount/types.d.ts +15 -0
  77. package/lib/modules/Payment/index.d.ts +2 -1
  78. package/lib/modules/Payment/index.js +1 -0
  79. package/lib/modules/Payment/utils.js +3 -0
  80. package/lib/modules/Payment/walletpass.d.ts +23 -0
  81. package/lib/modules/Payment/walletpass.js +94 -17
  82. package/lib/modules/Rules/index.d.ts +8 -3
  83. package/lib/modules/Rules/index.js +370 -192
  84. package/lib/modules/Rules/types.d.ts +1 -0
  85. package/lib/modules/Summary/types.d.ts +2 -0
  86. package/lib/modules/Summary/utils.d.ts +6 -0
  87. package/lib/modules/Summary/utils.js +15 -0
  88. package/lib/plugins/window.d.ts +2 -0
  89. package/lib/solution/BookingByStep/index.d.ts +2 -1
  90. package/lib/solution/Checkout/index.js +2 -0
  91. package/lib/solution/ShopDiscount/index.d.ts +1 -0
  92. package/lib/solution/ShopDiscount/index.js +6 -0
  93. package/lib/solution/ShopDiscount/types.d.ts +1 -0
  94. package/lib/solution/ShopDiscount/utils.js +10 -6
  95. package/package.json +1 -1
@@ -0,0 +1,207 @@
1
+ // src/model/strategy/adapter/walletPass/example.ts
2
+ var import_evaluator = require("./evaluator");
3
+ var products = [
4
+ {
5
+ product_id: 60734,
6
+ price: 80,
7
+ quantity: 1,
8
+ name: "商品A"
9
+ },
10
+ {
11
+ product_id: 60735,
12
+ price: 50,
13
+ quantity: 2,
14
+ name: "商品B"
15
+ }
16
+ ];
17
+ var vouchers = [
18
+ {
19
+ id: "VOUCHER_001",
20
+ amount: 10,
21
+ balance: 10,
22
+ type: "cash_voucher"
23
+ },
24
+ {
25
+ id: "VOUCHER_002",
26
+ amount: 20,
27
+ balance: 20,
28
+ type: "cash_voucher"
29
+ },
30
+ {
31
+ id: "VOUCHER_003",
32
+ amount: 50,
33
+ balance: 50,
34
+ type: "cash_voucher"
35
+ }
36
+ ];
37
+ var strategyConfigs = [
38
+ // 策略1: 满100减10,适用于 VOUCHER_001
39
+ {
40
+ metadata: {
41
+ id: "STRATEGY_001",
42
+ name: "满100减10",
43
+ type: "wallet_pass",
44
+ custom: {
45
+ maxDeductionAmount: 10,
46
+ // 最大抵扣10元
47
+ maxUsagePerOrder: 1,
48
+ // 每单最多用1张
49
+ deductTaxAndFee: true,
50
+ // 抵扣税费
51
+ applicableProductIds: [60734, 60735]
52
+ // 适用于这两个商品
53
+ }
54
+ },
55
+ conditions: {
56
+ operator: "and",
57
+ rules: [
58
+ // 匹配 voucher ID
59
+ {
60
+ type: "operator",
61
+ field: "voucherId",
62
+ operator: "in",
63
+ value: ["VOUCHER_001"]
64
+ },
65
+ // 适用商品总额需 >= 100
66
+ {
67
+ type: "operator",
68
+ field: "applicableProductTotal",
69
+ operator: ">=",
70
+ value: 100
71
+ }
72
+ ],
73
+ actionIds: ["deduct_10"]
74
+ },
75
+ actions: [
76
+ {
77
+ id: "deduct_10",
78
+ type: "DEDUCT_AMOUNT",
79
+ value: 10,
80
+ target: "applicable_products",
81
+ priority: 1
82
+ }
83
+ ]
84
+ },
85
+ // 策略2: 满150减20,适用于 VOUCHER_002
86
+ {
87
+ metadata: {
88
+ id: "STRATEGY_002",
89
+ name: "满150减20",
90
+ type: "wallet_pass",
91
+ custom: {
92
+ maxDeductionAmount: 20,
93
+ maxUsagePerOrder: 1,
94
+ deductTaxAndFee: true,
95
+ applicableProductIds: [60734, 60735]
96
+ }
97
+ },
98
+ conditions: {
99
+ operator: "and",
100
+ rules: [
101
+ {
102
+ type: "operator",
103
+ field: "voucherId",
104
+ operator: "in",
105
+ value: ["VOUCHER_002"]
106
+ },
107
+ {
108
+ type: "operator",
109
+ field: "applicableProductTotal",
110
+ operator: ">=",
111
+ value: 150
112
+ }
113
+ ],
114
+ actionIds: ["deduct_20"]
115
+ },
116
+ actions: [
117
+ {
118
+ id: "deduct_20",
119
+ type: "DEDUCT_AMOUNT",
120
+ value: 20,
121
+ target: "applicable_products",
122
+ priority: 1
123
+ }
124
+ ]
125
+ },
126
+ // 策略3: 满200减50,适用于 VOUCHER_003
127
+ {
128
+ metadata: {
129
+ id: "STRATEGY_003",
130
+ name: "满200减50",
131
+ type: "wallet_pass",
132
+ custom: {
133
+ maxDeductionAmount: 50,
134
+ maxUsagePerOrder: 2,
135
+ deductTaxAndFee: false,
136
+ applicableProductIds: [60734, 60735]
137
+ }
138
+ },
139
+ conditions: {
140
+ operator: "and",
141
+ rules: [
142
+ {
143
+ type: "operator",
144
+ field: "voucherId",
145
+ operator: "in",
146
+ value: ["VOUCHER_003"]
147
+ },
148
+ {
149
+ type: "operator",
150
+ field: "applicableProductTotal",
151
+ operator: ">=",
152
+ value: 200
153
+ }
154
+ ],
155
+ actionIds: ["deduct_50"]
156
+ },
157
+ actions: [
158
+ {
159
+ id: "deduct_50",
160
+ type: "DEDUCT_AMOUNT",
161
+ value: 50,
162
+ target: "applicable_products",
163
+ priority: 1
164
+ }
165
+ ]
166
+ }
167
+ ];
168
+ function runExample() {
169
+ console.log("========== WalletPass 评估器示例 ==========\n");
170
+ const evaluator = new import_evaluator.WalletPassEvaluator();
171
+ const results = evaluator.evaluate({
172
+ orderTotalAmount: 180,
173
+ products,
174
+ vouchers,
175
+ strategyConfigs
176
+ });
177
+ console.log("订单信息:");
178
+ console.log(`- 总金额: ${180} 元`);
179
+ console.log(`- 商品: ${products.map((p) => `${p.name}(${p.quantity}件)`).join(", ")}
180
+ `);
181
+ console.log("评估结果:\n");
182
+ results.forEach((result, index) => {
183
+ console.log(`Voucher ${index + 1}: ${result.voucher.id}`);
184
+ console.log(` 面额: ${result.voucher.amount} 元`);
185
+ console.log(` 可用: ${result.isApplicable ? "✅ 是" : "❌ 否"}`);
186
+ if (result.isApplicable) {
187
+ console.log(` 最大抵扣: ${result.maxDeduction} 元`);
188
+ console.log(` 每单可用: ${result.canUseCount} 张`);
189
+ console.log(` 抵扣税费: ${result.deductTaxAndFee ? "是" : "否"}`);
190
+ console.log(` 适用商品: ${result.applicableProductIds.join(", ")}`);
191
+ } else {
192
+ console.log(` 原因: ${result.reason}`);
193
+ console.log(` 原因码: ${result.reasonCode}`);
194
+ }
195
+ console.log("");
196
+ });
197
+ const availableVouchers = results.filter((r) => r.isApplicable);
198
+ console.log(`
199
+ 共 ${availableVouchers.length} 张可用`);
200
+ if (availableVouchers.length > 0) {
201
+ console.log("可用 voucher ID:");
202
+ availableVouchers.forEach((v) => {
203
+ console.log(` - ${v.voucher.id}: 最多抵扣 ${v.maxDeduction} 元`);
204
+ });
205
+ }
206
+ }
207
+ runExample();
@@ -0,0 +1,32 @@
1
+ import { EvaluationResult, RuntimeContext } from '../../type';
2
+ import { BusinessAdapter } from '../type';
3
+ import { WalletPassBusinessData, WalletPassTransformResult } from './type';
4
+ /**
5
+ * Wallet Pass 适配器
6
+ * 用于将 wallet pass 业务数据转换为策略引擎可识别的格式
7
+ */
8
+ export default class WalletPassAdapter implements BusinessAdapter {
9
+ name: string;
10
+ version: string;
11
+ /**
12
+ * 准备运行时上下文
13
+ * 将业务数据转换为策略引擎可识别的 RuntimeContext
14
+ */
15
+ prepareContext(businessData: WalletPassBusinessData): RuntimeContext;
16
+ /**
17
+ * 转换执行结果
18
+ * 将策略引擎的通用结果转换为业务层需要的格式
19
+ */
20
+ transformResult(result: EvaluationResult, businessData?: WalletPassBusinessData): WalletPassTransformResult;
21
+ /**
22
+ * 格式化配置
23
+ */
24
+ formatConfig(result: EvaluationResult, businessData?: WalletPassBusinessData): {
25
+ result: EvaluationResult;
26
+ businessData?: WalletPassBusinessData;
27
+ };
28
+ /**
29
+ * 计算适用商品的总金额和数量
30
+ */
31
+ private calculateApplicableProducts;
32
+ }
@@ -0,0 +1,142 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/model/strategy/adapter/walletPass/index.ts
20
+ var walletPass_exports = {};
21
+ __export(walletPass_exports, {
22
+ default: () => WalletPassAdapter
23
+ });
24
+ module.exports = __toCommonJS(walletPass_exports);
25
+ var import_utils = require("./utils");
26
+ var WalletPassAdapter = class {
27
+ constructor() {
28
+ this.name = "WalletPassAdapter";
29
+ this.version = "1.0.0";
30
+ }
31
+ /**
32
+ * 准备运行时上下文
33
+ * 将业务数据转换为策略引擎可识别的 RuntimeContext
34
+ */
35
+ prepareContext(businessData) {
36
+ var _a, _b;
37
+ const { orderTotalAmount, products, voucher, strategyConfig } = businessData;
38
+ const productIds = products.map((p) => p.product_id);
39
+ const applicableProductIds = (0, import_utils.getApplicableProductIds)(voucher);
40
+ const deductTaxAndFee = ((_b = (_a = strategyConfig == null ? void 0 : strategyConfig.metadata) == null ? void 0 : _a.custom) == null ? void 0 : _b.deductTaxAndFee) ?? true;
41
+ const { applicableTotal, applicableCount } = this.calculateApplicableProducts(
42
+ products,
43
+ applicableProductIds,
44
+ deductTaxAndFee
45
+ );
46
+ return {
47
+ entities: {
48
+ voucher,
49
+ products,
50
+ order: {
51
+ orderTotalAmount,
52
+ products
53
+ }
54
+ },
55
+ attributes: {
56
+ // 订单消费金额
57
+ orderTotalAmount,
58
+ // 适用商品金额
59
+ applicableProductTotalAmount: applicableTotal,
60
+ // 适用商品购买数量
61
+ applicableProductCount: applicableCount,
62
+ // 当前评估的 voucher ID
63
+ voucherProductId: voucher.product_id,
64
+ // 订单中的商品ID
65
+ productIds
66
+ },
67
+ metadata: {
68
+ timestamp: Date.now()
69
+ }
70
+ };
71
+ }
72
+ /**
73
+ * 转换执行结果
74
+ * 将策略引擎的通用结果转换为业务层需要的格式
75
+ */
76
+ transformResult(result, businessData) {
77
+ const strategyConfig = businessData == null ? void 0 : businessData.strategyConfig;
78
+ const businessConfig = (strategyConfig == null ? void 0 : strategyConfig.metadata.custom) || {};
79
+ const voucher = businessData == null ? void 0 : businessData.voucher;
80
+ const applicableProductIds = voucher ? (0, import_utils.getApplicableProductIds)(voucher) : null;
81
+ if (!result.applicable) {
82
+ return {
83
+ isApplicable: false,
84
+ canUseCount: 0,
85
+ maxDeduction: 0,
86
+ deductTaxAndFee: false,
87
+ applicableProductIds: [],
88
+ reason: result.message,
89
+ reasonCode: result.code,
90
+ strategyResult: result
91
+ };
92
+ }
93
+ const maxDeduction = businessConfig.maxDeductionAmount || 0;
94
+ const canUseCount = businessConfig.maxUsagePerOrder || 0;
95
+ const deductTaxAndFee = businessConfig.deductTaxAndFee || false;
96
+ return {
97
+ isApplicable: true,
98
+ canUseCount,
99
+ maxDeduction,
100
+ deductTaxAndFee,
101
+ applicableProductIds: applicableProductIds || [],
102
+ strategyResult: result
103
+ };
104
+ }
105
+ /**
106
+ * 格式化配置
107
+ */
108
+ formatConfig(result, businessData) {
109
+ return { result, businessData };
110
+ }
111
+ /**
112
+ * 计算适用商品的总金额和数量
113
+ */
114
+ calculateApplicableProducts(products, applicableProductIds, deductTaxAndFee = true) {
115
+ let total = 0;
116
+ let count = 0;
117
+ if (applicableProductIds !== null && applicableProductIds.length === 0) {
118
+ return { applicableTotal: 0, applicableCount: 0 };
119
+ }
120
+ products.forEach((product) => {
121
+ const productQuantity = (0, import_utils.getProductQuantity)(product);
122
+ const isMainProductApplicable = applicableProductIds === null || applicableProductIds.includes(product.product_id);
123
+ if (isMainProductApplicable) {
124
+ total += (0, import_utils.getMainProductPrice)(product, deductTaxAndFee) * productQuantity;
125
+ count += productQuantity;
126
+ }
127
+ if (product.product_bundle && product.product_bundle.length > 0) {
128
+ product.product_bundle.forEach((bundleItem) => {
129
+ if ((0, import_utils.getBundleItemIsOriginalPrice)(bundleItem)) {
130
+ const isBundleItemApplicable = applicableProductIds === null || applicableProductIds.includes(bundleItem.bundle_product_id);
131
+ if (isBundleItemApplicable) {
132
+ const bundleItemQuantity = bundleItem.num * productQuantity;
133
+ total += (0, import_utils.getBundleItemPrice)(bundleItem, productQuantity, deductTaxAndFee);
134
+ count += bundleItemQuantity;
135
+ }
136
+ }
137
+ });
138
+ }
139
+ });
140
+ return { applicableTotal: total, applicableCount: count };
141
+ }
142
+ };
@@ -0,0 +1 @@
1
+ export declare const locales: Record<string, Record<string, string>>;
@@ -0,0 +1,51 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __export = (target, all) => {
6
+ for (var name in all)
7
+ __defProp(target, name, { get: all[name], enumerable: true });
8
+ };
9
+ var __copyProps = (to, from, except, desc) => {
10
+ if (from && typeof from === "object" || typeof from === "function") {
11
+ for (let key of __getOwnPropNames(from))
12
+ if (!__hasOwnProp.call(to, key) && key !== except)
13
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
14
+ }
15
+ return to;
16
+ };
17
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
18
+
19
+ // src/model/strategy/adapter/walletPass/locales.ts
20
+ var locales_exports = {};
21
+ __export(locales_exports, {
22
+ locales: () => locales
23
+ });
24
+ module.exports = __toCommonJS(locales_exports);
25
+ var locales = {
26
+ "zh-CN": {
27
+ "not_meet_the_required_conditions": "未达到使用条件",
28
+ "exceeds_the_maximum_deduction_limit": "超出最大抵扣金额限制",
29
+ "usage_limit_reached": "已达到使用次数上限",
30
+ "not_available_for_this_channel": "当前渠道不可使用",
31
+ "not_valid_for_this_order_type": "当前订单类型不适用"
32
+ },
33
+ "en": {
34
+ "not_meet_the_required_conditions": "Not meet the required conditions.",
35
+ "exceeds_the_maximum_deduction_limit": "Exceeds the maximum deduction limit.",
36
+ "usage_limit_reached": "Usage limit reached.",
37
+ "not_available_for_this_channel": "Not available for this channel.",
38
+ "not_valid_for_this_order_type": "Not valid for this order type."
39
+ },
40
+ "zh-HK": {
41
+ "not_meet_the_required_conditions": "未達使用條件",
42
+ "exceeds_the_maximum_deduction_limit": "超出最大抵扣金額限制",
43
+ "usage_limit_reached": "已達使用次數上限",
44
+ "not_available_for_this_channel": "當前渠道不可使用",
45
+ "not_valid_for_this_order_type": "當前訂單類型不適用"
46
+ }
47
+ };
48
+ // Annotate the CommonJS export names for ESM import in node:
49
+ 0 && (module.exports = {
50
+ locales
51
+ });
@@ -0,0 +1,163 @@
1
+ import { EvaluationResult, StrategyConfig } from '../../type';
2
+ /**
3
+ * Voucher 数据结构
4
+ */
5
+ export interface Voucher {
6
+ id: number;
7
+ amount: number;
8
+ balance: number;
9
+ type?: string;
10
+ usedCount?: number;
11
+ available_product_type?: 'product_all' | 'product_collection' | 'products';
12
+ available_product_ids?: number[];
13
+ product_id: number;
14
+ unified_available_status: number;
15
+ /** 用户手动编辑的金额,优先于 recommended_usage_amount 使用 */
16
+ edit_current_amount?: number;
17
+ /** 前端基于策略返回的 不可用状态 */
18
+ _unified_available_status?: number;
19
+ /** 前端基于策略返回的 可用最大金额 */
20
+ _available_max_amount?: number;
21
+ /** 前端基于策略返回的 不可用原因 */
22
+ reason?: string;
23
+ /** 前端基于策略返回的 不可用原因码 */
24
+ reasonCode?: string;
25
+ /** 后端计算推荐使用金额 */
26
+ recommended_usage_amount: number;
27
+ /** 后端计算推荐使用金额(仅商品) 不包含税费附加费 */
28
+ recommended_pure_product_usage_amount: number;
29
+ /** 实际抵扣金额 */
30
+ actualDeduction: number;
31
+ /** 抵扣详情 */
32
+ deductionDetails: any[];
33
+ config?: {
34
+ /** 最大抵扣金额 */
35
+ maxDeductionAmount: number;
36
+ /** 每单最多使用张数(同一 product_id 的券)。默认为 0,表示不限制数量。 */
37
+ maxUsagePerOrder: number;
38
+ /** 是否抵扣税费与附加费 */
39
+ deductTaxAndFee: boolean;
40
+ /** 适用粒度(多商品共用) 默认开启勾选项 */
41
+ allowCrossProduct: boolean;
42
+ /** 可用商品数量上限 (仅多商品) 默认为0,表示不限制商品数量。 */
43
+ applicableProductLimit: number;
44
+ };
45
+ }
46
+ /**
47
+ * 商品数据结构
48
+ */
49
+ export interface Product {
50
+ product_id: number;
51
+ price: number;
52
+ quantity: number;
53
+ name?: string;
54
+ selling_price?: number;
55
+ /** 主商品折扣前金额,不包含套餐子商品 */
56
+ main_product_original_price?: number;
57
+ /** 主商品折扣后金额,不包含套餐子商品 */
58
+ main_product_selling_price?: number;
59
+ /** 主商品税费 */
60
+ tax_fee: number;
61
+ metadata: {
62
+ main_product_attached_bundle_tax_fee?: number;
63
+ main_product_attached_bundle_surcharge_fee?: number;
64
+ surcharge_rounding_remainder?: number;
65
+ main_product_selling_price: number;
66
+ };
67
+ is_price_include_tax: 0 | 1;
68
+ product_bundle: {
69
+ is_price_include_tax: 0 | 1;
70
+ bundle_id: number;
71
+ bundle_product_id: number;
72
+ bundle_variant_id: number;
73
+ price_type: string;
74
+ price_type_ext: string;
75
+ bundle_selling_price: number;
76
+ num: number;
77
+ is_charge_tax: number;
78
+ tax_fee: number;
79
+ metadata: {
80
+ surcharge_fee: number;
81
+ surcharge_rounding_remainder?: number;
82
+ };
83
+ }[];
84
+ }
85
+ /**
86
+ * Voucher 评估结果
87
+ */
88
+ export interface VoucherEvaluationResult {
89
+ voucher: Voucher;
90
+ /** 是否可用 */
91
+ isApplicable: boolean;
92
+ /** 每单可使用张数 */
93
+ canUseCount: number;
94
+ /** 最大抵扣金额 */
95
+ maxDeduction: number;
96
+ /** 是否抵扣税费与附加费 */
97
+ deductTaxAndFee: boolean;
98
+ /** 适用商品ID列表 */
99
+ applicableProductIds: number[];
100
+ /** 不可用原因 */
101
+ reason?: string;
102
+ /** 不可用原因码 */
103
+ reasonCode?: string;
104
+ strategyResult?: EvaluationResult;
105
+ }
106
+ /**
107
+ * 评估器输入参数
108
+ */
109
+ export interface EvaluatorInput {
110
+ /** 订单总金额 */
111
+ orderTotalAmount: number;
112
+ /** 商品列表 */
113
+ products: Product[];
114
+ /** 代金券列表 */
115
+ vouchers: Voucher[];
116
+ /** 策略配置列表 */
117
+ strategyConfigs?: StrategyConfig<{
118
+ /** 最大抵扣金额 */
119
+ maxDeductionAmount: number;
120
+ /** 每单最多使用张数(同一 product_id 的券)。默认为 0,表示不限制数量。 */
121
+ maxUsagePerOrder: number;
122
+ /** 是否抵扣税费与附加费 */
123
+ deductTaxAndFee: boolean;
124
+ /** 适用粒度(多商品共用) 默认开启勾选项 */
125
+ allowCrossProduct: boolean;
126
+ /** 可用商品数量上限 (仅多商品) 默认为0,表示不限制商品数量。 */
127
+ applicableProductLimit: number;
128
+ }>[];
129
+ }
130
+ /**
131
+ * WalletPassAdapter 业务数据输入
132
+ */
133
+ export interface WalletPassBusinessData {
134
+ /** 订单总金额 */
135
+ orderTotalAmount: number;
136
+ /** 商品列表 */
137
+ products: Product[];
138
+ /** 当前评估的 voucher */
139
+ voucher: Voucher;
140
+ /** 策略配置 */
141
+ strategyConfig: StrategyConfig;
142
+ }
143
+ /**
144
+ * WalletPassAdapter 转换结果
145
+ */
146
+ export interface WalletPassTransformResult {
147
+ /** 是否可用 */
148
+ isApplicable: boolean;
149
+ /** 每单可使用张数 */
150
+ canUseCount: number;
151
+ /** 最大抵扣金额 */
152
+ maxDeduction: number;
153
+ /** 是否抵扣税费与附加费 */
154
+ deductTaxAndFee: boolean;
155
+ /** 适用商品ID列表 */
156
+ applicableProductIds: number[];
157
+ /** 不可用原因 */
158
+ reason?: string;
159
+ /** 不可用原因码 */
160
+ reasonCode?: string;
161
+ /** 原始策略评估结果 */
162
+ strategyResult?: EvaluationResult;
163
+ }
@@ -0,0 +1,17 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
+ var __getOwnPropNames = Object.getOwnPropertyNames;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __copyProps = (to, from, except, desc) => {
6
+ if (from && typeof from === "object" || typeof from === "function") {
7
+ for (let key of __getOwnPropNames(from))
8
+ if (!__hasOwnProp.call(to, key) && key !== except)
9
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
10
+ }
11
+ return to;
12
+ };
13
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
14
+
15
+ // src/model/strategy/adapter/walletPass/type.ts
16
+ var type_exports = {};
17
+ module.exports = __toCommonJS(type_exports);
@@ -0,0 +1,50 @@
1
+ import { Product, Voucher } from './type';
2
+ export declare const getApplicableProductIds: (voucher: Voucher) => number[] | null;
3
+ /**
4
+ * 优惠券处理函数
5
+ * @param applicableVouchers 可用的券列表
6
+ * @param orderTotalAmount 订单总金额
7
+ * @param products 订单商品列表
8
+ * @returns 返回推荐券列表和全部列表,每个券包含 _available_max_amount 和 _unified_available_status
9
+ */
10
+ export declare function processVouchers(applicableVouchers: Voucher[], orderTotalAmount: number, products: Product[]): {
11
+ recommended: any[];
12
+ transformList: any[];
13
+ };
14
+ /**
15
+ * 重新计算优惠券状态(基于已选券的增量计算)
16
+ * @param allVouchers 所有原始券列表
17
+ * @param selectedVouchers 已选中的券列表(按选中顺序)
18
+ * @param orderTotalAmount 订单总金额
19
+ * @param products 订单商品列表
20
+ * @returns 返回更新后的所有券列表和已选券的详细抵扣信息
21
+ */
22
+ export declare function recalculateVouchers(allVouchers: any[], selectedVouchers: any[], orderTotalAmount: number, products: any[]): {
23
+ allWithUpdatedStatus: any[];
24
+ selectedWithDetails: any[];
25
+ };
26
+ /**
27
+ * 获取主商品价格
28
+ * @param product 商品
29
+ * @param isDeductTaxAndFee 是否抵扣税费与附加费
30
+ * @returns 商品价格
31
+ */
32
+ export declare const getMainProductPrice: (product: Product, isDeductTaxAndFee: boolean) => number;
33
+ /**
34
+ * 获取套餐子商品价格
35
+ * @param bundleItem 套餐子商品
36
+ * @param parentQuantity 父商品数量
37
+ * @param isDeductTaxAndFee 是否抵扣税费与附加费
38
+ * @returns 子商品总价格
39
+ */
40
+ export declare const getBundleItemPrice: (bundleItem: any, parentQuantity: number, isDeductTaxAndFee: boolean) => number;
41
+ /**
42
+ * 获取商品数量
43
+ * @param product 商品
44
+ * @returns 商品数量
45
+ */
46
+ export declare const getProductQuantity: (product: any) => any;
47
+ export declare const getBundleItemIsOriginalPrice: (item: any) => boolean;
48
+ export declare const getBundleItemIsMarkupPrice: (item: any) => boolean;
49
+ export declare const getBundleItemIsDiscountPrice: (item: any) => boolean;
50
+ export declare const getBundleItemIsMarkupOrDiscountPrice: (item: any) => boolean;