@pisell/pisellos 2.1.60 → 2.1.61
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.
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -1
- package/dist/modules/Cart/types.d.ts +0 -2
- package/dist/modules/Cart/utils/cartProduct.js +0 -11
- package/dist/modules/Customer/index.js +1 -1
- package/dist/modules/Discount/types.d.ts +0 -15
- package/dist/modules/Payment/index.d.ts +1 -2
- package/dist/modules/Payment/index.js +7 -10
- package/dist/modules/Payment/utils.js +0 -3
- package/dist/modules/Payment/walletpass.d.ts +0 -23
- package/dist/modules/Payment/walletpass.js +95 -191
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Rules/index.d.ts +3 -8
- package/dist/modules/Rules/index.js +28 -158
- package/dist/modules/Rules/types.d.ts +0 -1
- package/dist/modules/Summary/types.d.ts +0 -2
- package/dist/modules/Summary/utils.d.ts +0 -6
- package/dist/modules/Summary/utils.js +0 -21
- package/dist/plugins/window.d.ts +0 -2
- package/dist/solution/BookingByStep/index.d.ts +0 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/Checkout/index.js +0 -2
- package/dist/solution/ShopDiscount/index.d.ts +0 -1
- package/dist/solution/ShopDiscount/index.js +1 -11
- package/dist/solution/ShopDiscount/types.d.ts +0 -1
- package/dist/solution/ShopDiscount/utils.js +11 -26
- package/lib/index.d.ts +0 -1
- package/lib/index.js +1 -3
- package/lib/modules/Cart/types.d.ts +0 -2
- package/lib/modules/Cart/utils/cartProduct.js +0 -9
- package/lib/modules/Customer/index.js +1 -1
- package/lib/modules/Discount/types.d.ts +0 -15
- package/lib/modules/Payment/index.d.ts +1 -2
- package/lib/modules/Payment/index.js +0 -1
- package/lib/modules/Payment/utils.js +0 -3
- package/lib/modules/Payment/walletpass.d.ts +0 -23
- package/lib/modules/Payment/walletpass.js +17 -94
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Rules/index.d.ts +3 -8
- package/lib/modules/Rules/index.js +191 -373
- package/lib/modules/Rules/types.d.ts +0 -1
- package/lib/modules/Summary/types.d.ts +0 -2
- package/lib/modules/Summary/utils.d.ts +0 -6
- package/lib/modules/Summary/utils.js +0 -15
- package/lib/plugins/window.d.ts +0 -2
- package/lib/solution/BookingByStep/index.d.ts +0 -1
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/BookingTicket/index.js +6 -0
- package/lib/solution/Checkout/index.js +0 -2
- package/lib/solution/ShopDiscount/index.d.ts +0 -1
- package/lib/solution/ShopDiscount/index.js +0 -6
- package/lib/solution/ShopDiscount/types.d.ts +0 -1
- package/lib/solution/ShopDiscount/utils.js +6 -10
- package/package.json +1 -1
- package/dist/model/index.d.ts +0 -1
- package/dist/model/index.js +0 -1
- package/dist/model/strategy/adapter/index.d.ts +0 -3
- package/dist/model/strategy/adapter/index.js +0 -4
- package/dist/model/strategy/adapter/type.d.ts +0 -28
- package/dist/model/strategy/adapter/type.js +0 -1
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
- package/dist/model/strategy/adapter/walletPass/evaluator.js +0 -496
- package/dist/model/strategy/adapter/walletPass/example.d.ts +0 -4
- package/dist/model/strategy/adapter/walletPass/example.js +0 -258
- package/dist/model/strategy/adapter/walletPass/index.d.ts +0 -32
- package/dist/model/strategy/adapter/walletPass/index.js +0 -182
- package/dist/model/strategy/adapter/walletPass/locales.d.ts +0 -1
- package/dist/model/strategy/adapter/walletPass/locales.js +0 -23
- package/dist/model/strategy/adapter/walletPass/type.d.ts +0 -163
- package/dist/model/strategy/adapter/walletPass/type.js +0 -1
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +0 -50
- package/dist/model/strategy/adapter/walletPass/utils.js +0 -965
- package/dist/model/strategy/index.d.ts +0 -94
- package/dist/model/strategy/index.js +0 -551
- package/dist/model/strategy/strategy-example.d.ts +0 -5
- package/dist/model/strategy/strategy-example.js +0 -331
- package/dist/model/strategy/type.d.ts +0 -228
- package/dist/model/strategy/type.js +0 -94
- package/lib/model/index.d.ts +0 -1
- package/lib/model/index.js +0 -23
- package/lib/model/strategy/adapter/index.d.ts +0 -3
- package/lib/model/strategy/adapter/index.js +0 -45
- package/lib/model/strategy/adapter/type.d.ts +0 -28
- package/lib/model/strategy/adapter/type.js +0 -17
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +0 -84
- package/lib/model/strategy/adapter/walletPass/evaluator.js +0 -420
- package/lib/model/strategy/adapter/walletPass/example.d.ts +0 -4
- package/lib/model/strategy/adapter/walletPass/example.js +0 -207
- package/lib/model/strategy/adapter/walletPass/index.d.ts +0 -32
- package/lib/model/strategy/adapter/walletPass/index.js +0 -142
- package/lib/model/strategy/adapter/walletPass/locales.d.ts +0 -1
- package/lib/model/strategy/adapter/walletPass/locales.js +0 -51
- package/lib/model/strategy/adapter/walletPass/type.d.ts +0 -163
- package/lib/model/strategy/adapter/walletPass/type.js +0 -17
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +0 -50
- package/lib/model/strategy/adapter/walletPass/utils.js +0 -660
- package/lib/model/strategy/index.d.ts +0 -94
- package/lib/model/strategy/index.js +0 -413
- package/lib/model/strategy/strategy-example.d.ts +0 -5
- package/lib/model/strategy/strategy-example.js +0 -318
- package/lib/model/strategy/type.d.ts +0 -228
- package/lib/model/strategy/type.js +0 -44
|
@@ -1,45 +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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/model/strategy/adapter/index.ts
|
|
31
|
-
var adapter_exports = {};
|
|
32
|
-
__export(adapter_exports, {
|
|
33
|
-
WalletPassAdapter: () => import_walletPass.default,
|
|
34
|
-
WalletPassEvaluator: () => import_evaluator.WalletPassEvaluator
|
|
35
|
-
});
|
|
36
|
-
module.exports = __toCommonJS(adapter_exports);
|
|
37
|
-
__reExport(adapter_exports, require("./type"), module.exports);
|
|
38
|
-
var import_walletPass = __toESM(require("./walletPass"));
|
|
39
|
-
var import_evaluator = require("./walletPass/evaluator");
|
|
40
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
-
0 && (module.exports = {
|
|
42
|
-
WalletPassAdapter,
|
|
43
|
-
WalletPassEvaluator,
|
|
44
|
-
...require("./type")
|
|
45
|
-
});
|
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { EvaluationResult, RuntimeContext } from '../type';
|
|
2
|
-
export interface BusinessAdapter {
|
|
3
|
-
/**
|
|
4
|
-
* 适配器名称
|
|
5
|
-
*/
|
|
6
|
-
name: string;
|
|
7
|
-
/**
|
|
8
|
-
* 适配器版本
|
|
9
|
-
*/
|
|
10
|
-
version: string;
|
|
11
|
-
/**
|
|
12
|
-
* 准备运行时上下文
|
|
13
|
-
* 将业务数据转换为策略引擎可识别的上下文
|
|
14
|
-
*/
|
|
15
|
-
prepareContext(businessData: any): RuntimeContext;
|
|
16
|
-
/**
|
|
17
|
-
* 转换执行结果
|
|
18
|
-
* 将策略引擎的通用结果转换为业务层需要的格式
|
|
19
|
-
*/
|
|
20
|
-
transformResult(result: EvaluationResult, businessData?: any): any;
|
|
21
|
-
/**
|
|
22
|
-
* 根据业务数据重新格式化配置
|
|
23
|
-
*/
|
|
24
|
-
formatConfig(result: EvaluationResult, businessData?: any): {
|
|
25
|
-
result: EvaluationResult;
|
|
26
|
-
businessData?: any;
|
|
27
|
-
};
|
|
28
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
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/type.ts
|
|
16
|
-
var type_exports = {};
|
|
17
|
-
module.exports = __toCommonJS(type_exports);
|
|
@@ -1,84 +0,0 @@
|
|
|
1
|
-
import { StrategyConfig } from '../../type';
|
|
2
|
-
import { Voucher, Product, VoucherEvaluationResult, EvaluatorInput } from './type';
|
|
3
|
-
/**
|
|
4
|
-
* Wallet Pass 评估器
|
|
5
|
-
* 用于评估哪些 voucher 可以在当前订单中使用
|
|
6
|
-
*/
|
|
7
|
-
export declare class WalletPassEvaluator {
|
|
8
|
-
private engine;
|
|
9
|
-
private strategyConfigs;
|
|
10
|
-
private locale;
|
|
11
|
-
constructor();
|
|
12
|
-
setStrategyConfigs(strategyConfigs: StrategyConfig[]): void;
|
|
13
|
-
getStrategyConfigs(): StrategyConfig[];
|
|
14
|
-
setLocale(locale: string): void;
|
|
15
|
-
getText(key: string): string;
|
|
16
|
-
/**
|
|
17
|
-
* 搜索券的格式
|
|
18
|
-
* @param input 输入
|
|
19
|
-
* @returns 返回搜索券的格式
|
|
20
|
-
*/
|
|
21
|
-
searchVoucherFormat(input: EvaluatorInput): Voucher[];
|
|
22
|
-
/**
|
|
23
|
-
* 评估可用的 vouchers
|
|
24
|
-
*/
|
|
25
|
-
evaluate(input: EvaluatorInput): VoucherEvaluationResult[];
|
|
26
|
-
/** 检查代金券/折扣卡是否可用 并返回config */
|
|
27
|
-
checkVoucherAvailability(input: EvaluatorInput): {
|
|
28
|
-
isAvailable: boolean;
|
|
29
|
-
config: {
|
|
30
|
-
[x: string]: any;
|
|
31
|
-
};
|
|
32
|
-
};
|
|
33
|
-
/**
|
|
34
|
-
* 获取推荐券
|
|
35
|
-
* @param input 输入
|
|
36
|
-
* @returns 返回推荐券列表
|
|
37
|
-
*/
|
|
38
|
-
getRecommendedVouchers(input: EvaluatorInput): {
|
|
39
|
-
recommendedAmount: any;
|
|
40
|
-
recommended: any[];
|
|
41
|
-
transformList: any[];
|
|
42
|
-
noApplicableVoucher: Voucher[];
|
|
43
|
-
};
|
|
44
|
-
enhanceWithReason(voucher: any): any;
|
|
45
|
-
/**
|
|
46
|
-
* 优惠券处理函数
|
|
47
|
-
* @param applicableVouchers 可用的券列表
|
|
48
|
-
* @param orderTotalAmount 订单总金额
|
|
49
|
-
* @param products 订单商品列表
|
|
50
|
-
* @returns 返回推荐券列表和全部列表,每个券包含 _available_max_amount 和 _unified_available_status
|
|
51
|
-
*/
|
|
52
|
-
processVouchers(vouchers: Voucher[], orderTotalAmount: number, products: Product[]): {
|
|
53
|
-
recommended: any[];
|
|
54
|
-
transformList: any[];
|
|
55
|
-
};
|
|
56
|
-
/**
|
|
57
|
-
* 重新计算优惠券状态(基于已选券的增量计算)
|
|
58
|
-
* @param allVouchers 所有原始券列表
|
|
59
|
-
* @param selectedVouchers 已选中的券列表(按选中顺序)
|
|
60
|
-
* @param orderTotalAmount 订单总金额
|
|
61
|
-
* @param products 订单商品列表
|
|
62
|
-
* @returns 返回更新后的所有券列表和已选券的详细抵扣信息
|
|
63
|
-
*/
|
|
64
|
-
recalculateVouchers(allVouchers: any[], selectedVouchers: any[], orderTotalAmount: number, products: any[]): {
|
|
65
|
-
allWithUpdatedStatus: any[];
|
|
66
|
-
selectedWithDetails: any[];
|
|
67
|
-
};
|
|
68
|
-
/**
|
|
69
|
-
* 查找适用于指定 voucher 的策略配置
|
|
70
|
-
*/
|
|
71
|
-
private findApplicableStrategies;
|
|
72
|
-
/**
|
|
73
|
-
* 检查策略中是否包含指定的 voucher ID
|
|
74
|
-
*/
|
|
75
|
-
private checkVoucherInStrategy;
|
|
76
|
-
/**
|
|
77
|
-
* 递归检查条件组中是否包含 voucher ID
|
|
78
|
-
*/
|
|
79
|
-
private checkVoucherInConditionGroup;
|
|
80
|
-
/**
|
|
81
|
-
* 计算适用商品的总金额和数量
|
|
82
|
-
*/
|
|
83
|
-
private calculateApplicableProducts;
|
|
84
|
-
}
|
|
@@ -1,420 +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/walletPass/evaluator.ts
|
|
30
|
-
var evaluator_exports = {};
|
|
31
|
-
__export(evaluator_exports, {
|
|
32
|
-
WalletPassEvaluator: () => WalletPassEvaluator
|
|
33
|
-
});
|
|
34
|
-
module.exports = __toCommonJS(evaluator_exports);
|
|
35
|
-
var import__ = require("../../index");
|
|
36
|
-
var import_utils = require("./utils");
|
|
37
|
-
var import_locales = require("./locales");
|
|
38
|
-
var import_decimal = __toESM(require("decimal.js"));
|
|
39
|
-
var defaultStrategyMetadataCustom = {
|
|
40
|
-
maxDeductionAmount: 99999,
|
|
41
|
-
maxUsagePerOrder: 0,
|
|
42
|
-
allowCrossProduct: true,
|
|
43
|
-
applicableProductLimit: 0,
|
|
44
|
-
deductTaxAndFee: true
|
|
45
|
-
};
|
|
46
|
-
var WalletPassEvaluator = class {
|
|
47
|
-
constructor() {
|
|
48
|
-
this.strategyConfigs = [];
|
|
49
|
-
this.locale = "en";
|
|
50
|
-
this.engine = new import__.StrategyEngine({
|
|
51
|
-
debug: false,
|
|
52
|
-
enableTrace: false
|
|
53
|
-
});
|
|
54
|
-
}
|
|
55
|
-
setStrategyConfigs(strategyConfigs) {
|
|
56
|
-
this.strategyConfigs = strategyConfigs;
|
|
57
|
-
}
|
|
58
|
-
getStrategyConfigs() {
|
|
59
|
-
return this.strategyConfigs;
|
|
60
|
-
}
|
|
61
|
-
setLocale(locale) {
|
|
62
|
-
this.locale = locale;
|
|
63
|
-
}
|
|
64
|
-
getText(key) {
|
|
65
|
-
var _a, _b;
|
|
66
|
-
return (_b = (_a = import_locales.locales) == null ? void 0 : _a[this.locale]) == null ? void 0 : _b[key];
|
|
67
|
-
}
|
|
68
|
-
/**
|
|
69
|
-
* 搜索券的格式
|
|
70
|
-
* @param input 输入
|
|
71
|
-
* @returns 返回搜索券的格式
|
|
72
|
-
*/
|
|
73
|
-
searchVoucherFormat(input) {
|
|
74
|
-
const results = this.evaluate(input);
|
|
75
|
-
return results.map((item) => {
|
|
76
|
-
var _a, _b;
|
|
77
|
-
if (item.isApplicable) {
|
|
78
|
-
return {
|
|
79
|
-
...item.voucher,
|
|
80
|
-
config: {
|
|
81
|
-
...(_a = item == null ? void 0 : item.strategyResult) == null ? void 0 : _a.config.metadata.custom
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
} else {
|
|
85
|
-
return {
|
|
86
|
-
...item.voucher,
|
|
87
|
-
config: {
|
|
88
|
-
...(_b = item == null ? void 0 : item.strategyResult) == null ? void 0 : _b.config.metadata.custom
|
|
89
|
-
},
|
|
90
|
-
reason: item.reason,
|
|
91
|
-
reasonCode: item.reasonCode
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
/**
|
|
97
|
-
* 评估可用的 vouchers
|
|
98
|
-
*/
|
|
99
|
-
evaluate(input) {
|
|
100
|
-
var _a, _b;
|
|
101
|
-
const { orderTotalAmount, products, vouchers, strategyConfigs } = input;
|
|
102
|
-
const productIds = products.map((p) => p.product_id);
|
|
103
|
-
const results = [];
|
|
104
|
-
for (const voucher of vouchers) {
|
|
105
|
-
const applicableStrategies = this.findApplicableStrategies(
|
|
106
|
-
voucher,
|
|
107
|
-
strategyConfigs || this.strategyConfigs
|
|
108
|
-
);
|
|
109
|
-
if (applicableStrategies.length === 0) {
|
|
110
|
-
results.push({
|
|
111
|
-
voucher,
|
|
112
|
-
isApplicable: true,
|
|
113
|
-
canUseCount: 0,
|
|
114
|
-
maxDeduction: 0,
|
|
115
|
-
deductTaxAndFee: true,
|
|
116
|
-
applicableProductIds: [],
|
|
117
|
-
reason: "",
|
|
118
|
-
reasonCode: "",
|
|
119
|
-
strategyResult: {
|
|
120
|
-
config: {
|
|
121
|
-
metadata: {
|
|
122
|
-
custom: {
|
|
123
|
-
...defaultStrategyMetadataCustom
|
|
124
|
-
}
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
});
|
|
129
|
-
continue;
|
|
130
|
-
}
|
|
131
|
-
const strategy = applicableStrategies[0];
|
|
132
|
-
const applicableProductIds = (0, import_utils.getApplicableProductIds)(voucher);
|
|
133
|
-
const { applicableTotal, applicableCount } = this.calculateApplicableProducts(
|
|
134
|
-
products,
|
|
135
|
-
applicableProductIds,
|
|
136
|
-
((_b = (_a = strategy == null ? void 0 : strategy.metadata) == null ? void 0 : _a.custom) == null ? void 0 : _b.deductTaxAndFee) ?? true
|
|
137
|
-
);
|
|
138
|
-
const context = {
|
|
139
|
-
entities: {
|
|
140
|
-
voucher,
|
|
141
|
-
products,
|
|
142
|
-
order: {
|
|
143
|
-
orderTotalAmount,
|
|
144
|
-
products
|
|
145
|
-
}
|
|
146
|
-
},
|
|
147
|
-
attributes: {
|
|
148
|
-
orderTotalAmount,
|
|
149
|
-
applicableProductTotalAmount: applicableTotal,
|
|
150
|
-
applicableProductCount: applicableCount,
|
|
151
|
-
voucherProductId: voucher.product_id,
|
|
152
|
-
productIds
|
|
153
|
-
},
|
|
154
|
-
metadata: {
|
|
155
|
-
timestamp: Date.now()
|
|
156
|
-
}
|
|
157
|
-
};
|
|
158
|
-
const evaluationResult = this.engine.evaluate(strategy, context);
|
|
159
|
-
const businessConfig = strategy.metadata.custom || {};
|
|
160
|
-
const maxDeduction = businessConfig.maxDeductionAmount || 0;
|
|
161
|
-
const canUseCount = businessConfig.maxUsagePerOrder || 0;
|
|
162
|
-
const deductTaxAndFee = businessConfig.deductTaxAndFee ?? true;
|
|
163
|
-
if (evaluationResult.applicable) {
|
|
164
|
-
results.push({
|
|
165
|
-
voucher,
|
|
166
|
-
isApplicable: true,
|
|
167
|
-
canUseCount,
|
|
168
|
-
maxDeduction,
|
|
169
|
-
deductTaxAndFee,
|
|
170
|
-
applicableProductIds: applicableProductIds || [],
|
|
171
|
-
strategyResult: evaluationResult
|
|
172
|
-
});
|
|
173
|
-
} else {
|
|
174
|
-
let reasonCode = "not_meet_the_required_conditions";
|
|
175
|
-
if (evaluationResult.code) {
|
|
176
|
-
const codeMapping = {
|
|
177
|
-
INSUFFICIENT_AMOUNT: "not_meet_the_required_conditions",
|
|
178
|
-
USAGE_LIMIT_EXCEEDED: "usage_limit_reached",
|
|
179
|
-
CHANNEL_NOT_ALLOWED: "not_available_for_this_channel",
|
|
180
|
-
ORDER_TYPE_NOT_ALLOWED: "not_valid_for_this_order_type",
|
|
181
|
-
DEDUCTION_LIMIT_EXCEEDED: "exceeds_the_maximum_deduction_limit"
|
|
182
|
-
};
|
|
183
|
-
reasonCode = codeMapping[evaluationResult.code] || "not_meet_the_required_conditions";
|
|
184
|
-
}
|
|
185
|
-
results.push({
|
|
186
|
-
voucher,
|
|
187
|
-
isApplicable: false,
|
|
188
|
-
canUseCount: 0,
|
|
189
|
-
maxDeduction: 0,
|
|
190
|
-
deductTaxAndFee: false,
|
|
191
|
-
applicableProductIds: [],
|
|
192
|
-
reason: this.getText(reasonCode),
|
|
193
|
-
reasonCode,
|
|
194
|
-
strategyResult: evaluationResult
|
|
195
|
-
});
|
|
196
|
-
}
|
|
197
|
-
}
|
|
198
|
-
return results;
|
|
199
|
-
}
|
|
200
|
-
/** 检查代金券/折扣卡是否可用 并返回config */
|
|
201
|
-
checkVoucherAvailability(input) {
|
|
202
|
-
var _a, _b, _c, _d, _e;
|
|
203
|
-
const { orderTotalAmount, products, vouchers } = input;
|
|
204
|
-
const results = this.evaluate(input);
|
|
205
|
-
const isAvailable = ((_a = results[0]) == null ? void 0 : _a.isApplicable) || false;
|
|
206
|
-
return {
|
|
207
|
-
isAvailable,
|
|
208
|
-
config: {
|
|
209
|
-
...(_e = (_d = (_c = (_b = results[0]) == null ? void 0 : _b.strategyResult) == null ? void 0 : _c.config) == null ? void 0 : _d.metadata) == null ? void 0 : _e.custom
|
|
210
|
-
}
|
|
211
|
-
};
|
|
212
|
-
}
|
|
213
|
-
/**
|
|
214
|
-
* 获取推荐券
|
|
215
|
-
* @param input 输入
|
|
216
|
-
* @returns 返回推荐券列表
|
|
217
|
-
*/
|
|
218
|
-
getRecommendedVouchers(input) {
|
|
219
|
-
const { orderTotalAmount, products, vouchers } = input;
|
|
220
|
-
const noApplicableVoucher = [];
|
|
221
|
-
const applicableVoucher = [];
|
|
222
|
-
vouchers.forEach((voucher) => {
|
|
223
|
-
if (voucher.unified_available_status === 1) {
|
|
224
|
-
applicableVoucher.push(voucher);
|
|
225
|
-
} else {
|
|
226
|
-
noApplicableVoucher.push(voucher);
|
|
227
|
-
}
|
|
228
|
-
});
|
|
229
|
-
const results = this.evaluate({
|
|
230
|
-
...input,
|
|
231
|
-
vouchers: applicableVoucher
|
|
232
|
-
});
|
|
233
|
-
const newVouchers = [];
|
|
234
|
-
results.forEach((item) => {
|
|
235
|
-
var _a, _b, _c;
|
|
236
|
-
if (item.isApplicable) {
|
|
237
|
-
newVouchers.push({
|
|
238
|
-
...item.voucher,
|
|
239
|
-
config: {
|
|
240
|
-
...defaultStrategyMetadataCustom,
|
|
241
|
-
...((_c = (_b = (_a = item == null ? void 0 : item.strategyResult) == null ? void 0 : _a.config) == null ? void 0 : _b.metadata) == null ? void 0 : _c.custom) || {}
|
|
242
|
-
}
|
|
243
|
-
});
|
|
244
|
-
} else {
|
|
245
|
-
noApplicableVoucher.push({
|
|
246
|
-
...item.voucher,
|
|
247
|
-
_unified_available_status: 0,
|
|
248
|
-
reason: item.reason,
|
|
249
|
-
reasonCode: item.reasonCode
|
|
250
|
-
});
|
|
251
|
-
}
|
|
252
|
-
});
|
|
253
|
-
const { recommended, transformList } = this.processVouchers(
|
|
254
|
-
newVouchers,
|
|
255
|
-
orderTotalAmount,
|
|
256
|
-
products
|
|
257
|
-
);
|
|
258
|
-
const recommendedAmount = recommended.reduce((sum, item) => {
|
|
259
|
-
return new import_decimal.default(sum).add(item._available_max_amount || 0).toNumber();
|
|
260
|
-
}, 0);
|
|
261
|
-
return {
|
|
262
|
-
// 推荐券总金额
|
|
263
|
-
recommendedAmount,
|
|
264
|
-
// 推荐券列表
|
|
265
|
-
recommended,
|
|
266
|
-
// 格式化后的可用券列表
|
|
267
|
-
transformList,
|
|
268
|
-
// 后端不可用券列表 和前端基于策略返回的 不可用列表 合并
|
|
269
|
-
noApplicableVoucher
|
|
270
|
-
};
|
|
271
|
-
}
|
|
272
|
-
enhanceWithReason(voucher) {
|
|
273
|
-
if (voucher._unified_available_status === 0 && voucher.reasonCode) {
|
|
274
|
-
return {
|
|
275
|
-
...voucher,
|
|
276
|
-
reason: this.getText(voucher.reasonCode)
|
|
277
|
-
};
|
|
278
|
-
}
|
|
279
|
-
return voucher;
|
|
280
|
-
}
|
|
281
|
-
/**
|
|
282
|
-
* 优惠券处理函数
|
|
283
|
-
* @param applicableVouchers 可用的券列表
|
|
284
|
-
* @param orderTotalAmount 订单总金额
|
|
285
|
-
* @param products 订单商品列表
|
|
286
|
-
* @returns 返回推荐券列表和全部列表,每个券包含 _available_max_amount 和 _unified_available_status
|
|
287
|
-
*/
|
|
288
|
-
processVouchers(vouchers, orderTotalAmount, products) {
|
|
289
|
-
const result = (0, import_utils.processVouchers)(vouchers, orderTotalAmount, products);
|
|
290
|
-
return {
|
|
291
|
-
recommended: result.recommended.map(
|
|
292
|
-
(item) => this.enhanceWithReason(item)
|
|
293
|
-
),
|
|
294
|
-
transformList: result.transformList.map(
|
|
295
|
-
(item) => this.enhanceWithReason(item)
|
|
296
|
-
)
|
|
297
|
-
};
|
|
298
|
-
}
|
|
299
|
-
/**
|
|
300
|
-
* 重新计算优惠券状态(基于已选券的增量计算)
|
|
301
|
-
* @param allVouchers 所有原始券列表
|
|
302
|
-
* @param selectedVouchers 已选中的券列表(按选中顺序)
|
|
303
|
-
* @param orderTotalAmount 订单总金额
|
|
304
|
-
* @param products 订单商品列表
|
|
305
|
-
* @returns 返回更新后的所有券列表和已选券的详细抵扣信息
|
|
306
|
-
*/
|
|
307
|
-
recalculateVouchers(allVouchers, selectedVouchers, orderTotalAmount, products) {
|
|
308
|
-
const result = (0, import_utils.recalculateVouchers)(
|
|
309
|
-
allVouchers,
|
|
310
|
-
selectedVouchers,
|
|
311
|
-
orderTotalAmount,
|
|
312
|
-
products
|
|
313
|
-
);
|
|
314
|
-
return {
|
|
315
|
-
allWithUpdatedStatus: result.allWithUpdatedStatus.map(
|
|
316
|
-
(item) => this.enhanceWithReason(item)
|
|
317
|
-
),
|
|
318
|
-
selectedWithDetails: result.selectedWithDetails.map(
|
|
319
|
-
(item) => this.enhanceWithReason(item)
|
|
320
|
-
)
|
|
321
|
-
};
|
|
322
|
-
}
|
|
323
|
-
/**
|
|
324
|
-
* 查找适用于指定 voucher 的策略配置
|
|
325
|
-
*/
|
|
326
|
-
findApplicableStrategies(voucher, strategyConfigs) {
|
|
327
|
-
return strategyConfigs.filter((config) => {
|
|
328
|
-
return this.checkVoucherInStrategy(voucher.product_id, config);
|
|
329
|
-
});
|
|
330
|
-
}
|
|
331
|
-
/**
|
|
332
|
-
* 检查策略中是否包含指定的 voucher ID
|
|
333
|
-
*/
|
|
334
|
-
checkVoucherInStrategy(voucherProductId, config) {
|
|
335
|
-
const rules = config.conditions.rules;
|
|
336
|
-
for (const rule of rules) {
|
|
337
|
-
if ("operator" in rule && "rules" in rule) {
|
|
338
|
-
if (this.checkVoucherInConditionGroup(voucherProductId, rule)) {
|
|
339
|
-
return true;
|
|
340
|
-
}
|
|
341
|
-
} else {
|
|
342
|
-
const conditionRule = rule;
|
|
343
|
-
if (conditionRule.field === "voucherProductId" && conditionRule.operator === "in" && Array.isArray(conditionRule.value)) {
|
|
344
|
-
if (conditionRule.value.includes(voucherProductId)) {
|
|
345
|
-
return true;
|
|
346
|
-
}
|
|
347
|
-
}
|
|
348
|
-
if (conditionRule.field === "voucherProductId" && (conditionRule.operator === "=" || conditionRule.operator === "==")) {
|
|
349
|
-
if (conditionRule.value === voucherProductId) {
|
|
350
|
-
return true;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
}
|
|
354
|
-
}
|
|
355
|
-
return false;
|
|
356
|
-
}
|
|
357
|
-
/**
|
|
358
|
-
* 递归检查条件组中是否包含 voucher ID
|
|
359
|
-
*/
|
|
360
|
-
checkVoucherInConditionGroup(voucherProductId, group) {
|
|
361
|
-
for (const rule of group.rules) {
|
|
362
|
-
if ("operator" in rule && "rules" in rule) {
|
|
363
|
-
if (this.checkVoucherInConditionGroup(voucherProductId, rule)) {
|
|
364
|
-
return true;
|
|
365
|
-
}
|
|
366
|
-
} else {
|
|
367
|
-
if (rule.field === "voucherProductId" && rule.operator === "in" && Array.isArray(rule.value)) {
|
|
368
|
-
if (rule.value.includes(voucherProductId)) {
|
|
369
|
-
return true;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
if (rule.field === "voucherProductId" && (rule.operator === "=" || rule.operator === "==")) {
|
|
373
|
-
if (rule.value === voucherProductId) {
|
|
374
|
-
return true;
|
|
375
|
-
}
|
|
376
|
-
}
|
|
377
|
-
}
|
|
378
|
-
}
|
|
379
|
-
return false;
|
|
380
|
-
}
|
|
381
|
-
/**
|
|
382
|
-
* 计算适用商品的总金额和数量
|
|
383
|
-
*/
|
|
384
|
-
calculateApplicableProducts(products, applicableProductIds, deductTaxAndFee) {
|
|
385
|
-
let total = 0;
|
|
386
|
-
let count = 0;
|
|
387
|
-
if (applicableProductIds !== null && applicableProductIds.length === 0) {
|
|
388
|
-
return { applicableTotal: 0, applicableCount: 0 };
|
|
389
|
-
}
|
|
390
|
-
products.forEach((product) => {
|
|
391
|
-
const productQuantity = (0, import_utils.getProductQuantity)(product);
|
|
392
|
-
const isMainProductApplicable = applicableProductIds === null || applicableProductIds.includes(product.product_id);
|
|
393
|
-
if (isMainProductApplicable) {
|
|
394
|
-
total += (0, import_utils.getMainProductPrice)(product, deductTaxAndFee) * productQuantity;
|
|
395
|
-
count += productQuantity;
|
|
396
|
-
}
|
|
397
|
-
if (product.product_bundle && product.product_bundle.length > 0) {
|
|
398
|
-
product.product_bundle.forEach((bundleItem) => {
|
|
399
|
-
if ((0, import_utils.getBundleItemIsOriginalPrice)(bundleItem)) {
|
|
400
|
-
const isBundleItemApplicable = applicableProductIds === null || applicableProductIds.includes(bundleItem.bundle_product_id);
|
|
401
|
-
if (isBundleItemApplicable) {
|
|
402
|
-
const bundleItemQuantity = bundleItem.num * productQuantity;
|
|
403
|
-
total += (0, import_utils.getBundleItemPrice)(
|
|
404
|
-
bundleItem,
|
|
405
|
-
productQuantity,
|
|
406
|
-
deductTaxAndFee
|
|
407
|
-
);
|
|
408
|
-
count += bundleItemQuantity;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
});
|
|
412
|
-
}
|
|
413
|
-
});
|
|
414
|
-
return { applicableTotal: total, applicableCount: count };
|
|
415
|
-
}
|
|
416
|
-
};
|
|
417
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
418
|
-
0 && (module.exports = {
|
|
419
|
-
WalletPassEvaluator
|
|
420
|
-
});
|