@pisell/pisellos 2.1.52 → 2.1.54
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 +1 -0
- package/dist/index.js +1 -0
- package/dist/model/index.d.ts +1 -0
- package/dist/model/index.js +1 -0
- package/dist/model/strategy/adapter/index.d.ts +3 -0
- package/dist/model/strategy/adapter/index.js +4 -0
- package/dist/model/strategy/adapter/type.d.ts +28 -0
- package/dist/model/strategy/adapter/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/dist/model/strategy/adapter/walletPass/evaluator.js +496 -0
- package/dist/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/dist/model/strategy/adapter/walletPass/example.js +258 -0
- package/dist/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/dist/model/strategy/adapter/walletPass/index.js +182 -0
- package/dist/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/dist/model/strategy/adapter/walletPass/locales.js +23 -0
- package/dist/model/strategy/adapter/walletPass/type.d.ts +163 -0
- package/dist/model/strategy/adapter/walletPass/type.js +1 -0
- package/dist/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/dist/model/strategy/adapter/walletPass/utils.js +965 -0
- package/dist/model/strategy/index.d.ts +94 -0
- package/dist/model/strategy/index.js +551 -0
- package/dist/model/strategy/strategy-example.d.ts +5 -0
- package/dist/model/strategy/strategy-example.js +331 -0
- package/dist/model/strategy/type.d.ts +228 -0
- package/dist/model/strategy/type.js +94 -0
- package/dist/modules/Cart/types.d.ts +2 -0
- package/dist/modules/Cart/utils/cartProduct.js +11 -0
- package/dist/modules/Discount/index.d.ts +1 -0
- package/dist/modules/Discount/index.js +1 -1
- package/dist/modules/Discount/types.d.ts +15 -0
- package/dist/modules/Payment/index.d.ts +2 -1
- package/dist/modules/Payment/index.js +10 -7
- package/dist/modules/Payment/utils.js +3 -0
- package/dist/modules/Payment/walletpass.d.ts +23 -0
- package/dist/modules/Payment/walletpass.js +191 -95
- package/dist/modules/Rules/index.d.ts +15 -3
- package/dist/modules/Rules/index.js +194 -28
- package/dist/modules/Rules/types.d.ts +5 -0
- package/dist/modules/Summary/types.d.ts +2 -0
- package/dist/modules/Summary/utils.d.ts +6 -0
- package/dist/modules/Summary/utils.js +21 -0
- package/dist/plugins/window.d.ts +2 -0
- package/dist/solution/BookingByStep/index.d.ts +1 -0
- package/dist/solution/BookingByStep/utils/capacity.js +1 -2
- package/dist/solution/Checkout/index.js +2 -0
- package/dist/solution/ShopDiscount/index.d.ts +4 -0
- package/dist/solution/ShopDiscount/index.js +26 -5
- package/dist/solution/ShopDiscount/types.d.ts +6 -0
- package/dist/solution/ShopDiscount/utils.js +26 -11
- package/lib/index.d.ts +1 -0
- package/lib/index.js +3 -1
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js +23 -0
- package/lib/model/strategy/adapter/index.d.ts +3 -0
- package/lib/model/strategy/adapter/index.js +45 -0
- package/lib/model/strategy/adapter/type.d.ts +28 -0
- package/lib/model/strategy/adapter/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.d.ts +84 -0
- package/lib/model/strategy/adapter/walletPass/evaluator.js +420 -0
- package/lib/model/strategy/adapter/walletPass/example.d.ts +4 -0
- package/lib/model/strategy/adapter/walletPass/example.js +207 -0
- package/lib/model/strategy/adapter/walletPass/index.d.ts +32 -0
- package/lib/model/strategy/adapter/walletPass/index.js +142 -0
- package/lib/model/strategy/adapter/walletPass/locales.d.ts +1 -0
- package/lib/model/strategy/adapter/walletPass/locales.js +51 -0
- package/lib/model/strategy/adapter/walletPass/type.d.ts +163 -0
- package/lib/model/strategy/adapter/walletPass/type.js +17 -0
- package/lib/model/strategy/adapter/walletPass/utils.d.ts +50 -0
- package/lib/model/strategy/adapter/walletPass/utils.js +660 -0
- package/lib/model/strategy/index.d.ts +94 -0
- package/lib/model/strategy/index.js +413 -0
- package/lib/model/strategy/strategy-example.d.ts +5 -0
- package/lib/model/strategy/strategy-example.js +318 -0
- package/lib/model/strategy/type.d.ts +228 -0
- package/lib/model/strategy/type.js +44 -0
- package/lib/modules/Cart/types.d.ts +2 -0
- package/lib/modules/Cart/utils/cartProduct.js +9 -0
- package/lib/modules/Discount/index.d.ts +1 -0
- package/lib/modules/Discount/index.js +1 -1
- package/lib/modules/Discount/types.d.ts +15 -0
- package/lib/modules/Payment/index.d.ts +2 -1
- package/lib/modules/Payment/index.js +1 -0
- package/lib/modules/Payment/utils.js +3 -0
- package/lib/modules/Payment/walletpass.d.ts +23 -0
- package/lib/modules/Payment/walletpass.js +94 -17
- package/lib/modules/Rules/index.d.ts +15 -3
- package/lib/modules/Rules/index.js +409 -195
- package/lib/modules/Rules/types.d.ts +5 -0
- package/lib/modules/Summary/types.d.ts +2 -0
- package/lib/modules/Summary/utils.d.ts +6 -0
- package/lib/modules/Summary/utils.js +15 -0
- package/lib/plugins/window.d.ts +2 -0
- package/lib/solution/BookingByStep/index.d.ts +1 -0
- package/lib/solution/BookingByStep/utils/capacity.js +1 -2
- package/lib/solution/Checkout/index.js +2 -0
- package/lib/solution/ShopDiscount/index.d.ts +4 -0
- package/lib/solution/ShopDiscount/index.js +18 -4
- package/lib/solution/ShopDiscount/types.d.ts +6 -0
- package/lib/solution/ShopDiscount/utils.js +10 -6
- package/package.json +1 -1
|
@@ -23,9 +23,15 @@ export interface ShopDiscountState {
|
|
|
23
23
|
discount: DiscountModule | null;
|
|
24
24
|
rules: RulesModule | null;
|
|
25
25
|
productList: Record<string, any>[];
|
|
26
|
+
holders?: {
|
|
27
|
+
form_record_id: number;
|
|
28
|
+
form_id?: number;
|
|
29
|
+
main_field?: string;
|
|
30
|
+
}[];
|
|
26
31
|
originalDiscountList: Discount[];
|
|
27
32
|
currentBookingTime: string | null;
|
|
28
33
|
filteredDiscountList: Discount[];
|
|
34
|
+
orderTotalAmount?: number;
|
|
29
35
|
}
|
|
30
36
|
export interface SetDiscountSelectedParams {
|
|
31
37
|
discountId: number;
|
|
@@ -34,22 +34,37 @@ export var isAllNormalProduct = function isAllNormalProduct(items) {
|
|
|
34
34
|
* @returns
|
|
35
35
|
*/
|
|
36
36
|
export var getDiscountAmount = function getDiscountAmount(discount, total, price) {
|
|
37
|
-
var
|
|
37
|
+
var discountedPrice = 0;
|
|
38
|
+
|
|
38
39
|
// 商品券
|
|
39
40
|
if (discount.tag === 'good_pass') {
|
|
40
|
-
|
|
41
|
+
discountedPrice = new Decimal(price).minus(new Decimal(price || 0)).toNumber();
|
|
42
|
+
} else {
|
|
43
|
+
var _discount$metadata;
|
|
44
|
+
// 判断是否是固定金额
|
|
45
|
+
var isFixedAmount = (discount === null || discount === void 0 || (_discount$metadata = discount.metadata) === null || _discount$metadata === void 0 ? void 0 : _discount$metadata.discount_card_type) === 'fixed_amount';
|
|
46
|
+
|
|
47
|
+
// 固定金额 小于0时返回0
|
|
48
|
+
if (isFixedAmount) {
|
|
49
|
+
discountedPrice = Math.max(new Decimal(price).minus(new Decimal(discount.par_value || 0)).toNumber(), 0);
|
|
50
|
+
} else {
|
|
51
|
+
// 百分比:根据折扣卡金额计算
|
|
52
|
+
discountedPrice = new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
|
|
53
|
+
}
|
|
41
54
|
}
|
|
42
55
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
56
|
+
/*
|
|
57
|
+
// 🔥 如果有 maxDeductionAmount 限制,确保折扣金额不超过限制
|
|
58
|
+
if (discount.config?.maxDeductionAmount) {
|
|
59
|
+
const actualDiscountAmount = new Decimal(price).minus(discountedPrice).toNumber();
|
|
60
|
+
if (actualDiscountAmount > discount.config.maxDeductionAmount) {
|
|
61
|
+
// 折扣金额超过限制,重新计算折扣后价格
|
|
62
|
+
discountedPrice = new Decimal(price).minus(discount.config.maxDeductionAmount).toNumber();
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
*/
|
|
50
66
|
|
|
51
|
-
|
|
52
|
-
return new Decimal(100).minus(discount.par_value || 0).div(100).mul(new Decimal(price)).toNumber();
|
|
67
|
+
return discountedPrice;
|
|
53
68
|
};
|
|
54
69
|
export var getDiscountListAmountTotal = function getDiscountListAmountTotal(discount) {
|
|
55
70
|
return discount.reduce(function (acc, cur) {
|
package/lib/index.d.ts
CHANGED
package/lib/index.js
CHANGED
|
@@ -38,6 +38,7 @@ __reExport(src_exports, require("./types"), module.exports);
|
|
|
38
38
|
__reExport(src_exports, require("./modules"), module.exports);
|
|
39
39
|
__reExport(src_exports, require("./plugins"), module.exports);
|
|
40
40
|
__reExport(src_exports, require("./solution"), module.exports);
|
|
41
|
+
__reExport(src_exports, require("./model"), module.exports);
|
|
41
42
|
var import_core = require("./core");
|
|
42
43
|
var import_core2 = __toESM(require("./core"));
|
|
43
44
|
var src_default = import_core2.default;
|
|
@@ -47,5 +48,6 @@ var src_default = import_core2.default;
|
|
|
47
48
|
...require("./types"),
|
|
48
49
|
...require("./modules"),
|
|
49
50
|
...require("./plugins"),
|
|
50
|
-
...require("./solution")
|
|
51
|
+
...require("./solution"),
|
|
52
|
+
...require("./model")
|
|
51
53
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './strategy';
|
|
@@ -0,0 +1,23 @@
|
|
|
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 __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
14
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
15
|
+
|
|
16
|
+
// src/model/index.ts
|
|
17
|
+
var model_exports = {};
|
|
18
|
+
module.exports = __toCommonJS(model_exports);
|
|
19
|
+
__reExport(model_exports, require("./strategy"), module.exports);
|
|
20
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
21
|
+
0 && (module.exports = {
|
|
22
|
+
...require("./strategy")
|
|
23
|
+
});
|
|
@@ -0,0 +1,45 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1,28 @@
|
|
|
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
|
+
}
|
|
@@ -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/type.ts
|
|
16
|
+
var type_exports = {};
|
|
17
|
+
module.exports = __toCommonJS(type_exports);
|
|
@@ -0,0 +1,84 @@
|
|
|
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
|
+
}
|