@pisell/pisellos 2.1.119 → 2.1.120
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/apis/picoding.d.ts +0 -0
- package/dist/apis/picoding.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 +7 -0
- package/dist/model/strategy/adapter/index.js +7 -0
- package/dist/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
- package/dist/model/strategy/adapter/itemRule/adapter.js +439 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/dist/model/strategy/adapter/itemRule/evaluator.js +169 -0
- package/dist/model/strategy/adapter/itemRule/examples.d.ts +64 -0
- package/dist/model/strategy/adapter/itemRule/examples.js +315 -0
- package/dist/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/dist/model/strategy/adapter/itemRule/index.js +5 -0
- package/dist/model/strategy/adapter/itemRule/type.d.ts +206 -0
- package/dist/model/strategy/adapter/itemRule/type.js +101 -0
- package/dist/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/dist/model/strategy/adapter/promotion/adapter.js +271 -0
- package/dist/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/dist/model/strategy/adapter/promotion/evaluator.js +1206 -0
- package/dist/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/dist/model/strategy/adapter/promotion/examples.js +166 -0
- package/dist/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/dist/model/strategy/adapter/promotion/index.js +0 -0
- package/dist/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/dist/model/strategy/adapter/promotion/type.js +209 -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 +502 -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 +26 -0
- package/dist/model/strategy/adapter/walletPass/type.d.ts +187 -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 +1104 -0
- package/dist/model/strategy/engine.d.ts +106 -0
- package/dist/model/strategy/engine.js +611 -0
- package/dist/model/strategy/index.d.ts +3 -0
- package/dist/model/strategy/index.js +8 -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/utils/cartProduct.js +1 -0
- package/dist/modules/OpenData/index.d.ts +23 -0
- package/dist/modules/OpenData/index.js +167 -0
- package/dist/modules/OpenData/types.d.ts +73 -0
- package/dist/modules/OpenData/types.js +1 -0
- package/dist/modules/OpenData/utils.d.ts +2 -0
- package/dist/modules/OpenData/utils.js +75 -0
- package/dist/modules/Order/index.d.ts +58 -1
- package/dist/modules/Order/index.js +780 -29
- package/dist/modules/Order/types.d.ts +144 -12
- package/dist/modules/Order/utils.d.ts +25 -0
- package/dist/modules/Order/utils.js +225 -1
- package/dist/modules/Product/index.d.ts +1 -1
- package/dist/modules/Product/utils.js +2 -2
- package/dist/modules/ProductList/index.d.ts +1 -1
- package/dist/modules/ProductList/index.js +2 -1
- package/dist/modules/Quotation/index.d.ts +48 -0
- package/dist/modules/Quotation/index.js +245 -0
- package/dist/modules/Quotation/types.d.ts +42 -0
- package/dist/modules/Quotation/types.js +1 -0
- package/dist/modules/Rules/index.js +4 -1
- package/dist/modules/SalesSummary/index.d.ts +63 -0
- package/dist/modules/SalesSummary/index.js +174 -0
- package/dist/modules/SalesSummary/types.d.ts +59 -0
- package/dist/modules/SalesSummary/types.js +1 -0
- package/dist/modules/SalesSummary/utils.d.ts +30 -0
- package/dist/modules/SalesSummary/utils.js +513 -0
- package/dist/modules/ScanOrderLogger/index.d.ts +21 -0
- package/dist/modules/ScanOrderLogger/index.js +161 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/feishu.js +95 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/dist/modules/ScanOrderLogger/providers/grafana.js +50 -0
- package/dist/modules/ScanOrderLogger/types.d.ts +46 -0
- package/dist/modules/ScanOrderLogger/types.js +1 -0
- package/dist/modules/Schedule/getDateIsInSchedule.js +11 -18
- package/dist/modules/Summary/utils.d.ts +3 -3
- package/dist/modules/Summary/utils.js +4 -4
- package/dist/modules/index.d.ts +4 -0
- package/dist/modules/index.js +5 -1
- package/dist/solution/BookingByStep/index.d.ts +1 -1
- package/dist/solution/BookingByStep/types.d.ts +3 -1
- package/dist/solution/BookingByStep/types.js +5 -1
- package/dist/solution/BookingTicket/index.d.ts +1 -1
- package/dist/solution/ScanOrder/index.d.ts +90 -0
- package/dist/solution/ScanOrder/index.js +1853 -0
- package/dist/solution/ScanOrder/types.d.ts +210 -0
- package/dist/solution/ScanOrder/types.js +16 -0
- package/dist/solution/ScanOrder/utils.d.ts +93 -0
- package/dist/solution/ScanOrder/utils.js +397 -0
- package/dist/solution/VenueBooking/index.d.ts +158 -0
- package/dist/solution/VenueBooking/index.js +2873 -0
- package/dist/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/dist/solution/VenueBooking/types.d.ts +130 -0
- package/dist/solution/VenueBooking/types.js +21 -0
- package/dist/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
- package/dist/solution/VenueBooking/utils/dateSummary.js +102 -0
- package/dist/solution/VenueBooking/utils/resource.d.ts +4 -0
- package/dist/solution/VenueBooking/utils/resource.js +94 -0
- package/dist/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
- package/dist/solution/VenueBooking/utils/slotMerge.js +204 -0
- package/dist/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/dist/solution/VenueBooking/utils/timeSlot.js +256 -0
- package/dist/solution/VenueBooking/utils.d.ts +1 -0
- package/dist/solution/VenueBooking/utils.js +1 -0
- package/dist/solution/index.d.ts +2 -0
- package/dist/solution/index.js +3 -1
- package/lib/apis/picoding.d.ts +0 -0
- package/lib/apis/picoding.js +0 -0
- package/lib/model/index.d.ts +1 -0
- package/lib/model/index.js +23 -0
- package/lib/model/strategy/adapter/index.d.ts +7 -0
- package/lib/model/strategy/adapter/index.js +57 -0
- package/lib/model/strategy/adapter/itemRule/adapter.d.ts +59 -0
- package/lib/model/strategy/adapter/itemRule/adapter.js +338 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.d.ts +43 -0
- package/lib/model/strategy/adapter/itemRule/evaluator.js +124 -0
- package/lib/model/strategy/adapter/itemRule/examples.d.ts +64 -0
- package/lib/model/strategy/adapter/itemRule/examples.js +269 -0
- package/lib/model/strategy/adapter/itemRule/index.d.ts +5 -0
- package/lib/model/strategy/adapter/itemRule/index.js +58 -0
- package/lib/model/strategy/adapter/itemRule/type.d.ts +206 -0
- package/lib/model/strategy/adapter/itemRule/type.js +46 -0
- package/lib/model/strategy/adapter/promotion/adapter.d.ts +66 -0
- package/lib/model/strategy/adapter/promotion/adapter.js +217 -0
- package/lib/model/strategy/adapter/promotion/evaluator.d.ts +213 -0
- package/lib/model/strategy/adapter/promotion/evaluator.js +844 -0
- package/lib/model/strategy/adapter/promotion/examples.d.ts +138 -0
- package/lib/model/strategy/adapter/promotion/examples.js +192 -0
- package/lib/model/strategy/adapter/promotion/index.d.ts +4 -0
- package/lib/model/strategy/adapter/promotion/index.js +0 -0
- package/lib/model/strategy/adapter/promotion/type.d.ts +447 -0
- package/lib/model/strategy/adapter/promotion/type.js +51 -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 +424 -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 +54 -0
- package/lib/model/strategy/adapter/walletPass/type.d.ts +187 -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 +791 -0
- package/lib/model/strategy/engine.d.ts +106 -0
- package/lib/model/strategy/engine.js +450 -0
- package/lib/model/strategy/index.d.ts +3 -0
- package/lib/model/strategy/index.js +38 -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/utils/cartProduct.js +1 -0
- package/lib/modules/OpenData/index.d.ts +23 -0
- package/lib/modules/OpenData/index.js +116 -0
- package/lib/modules/OpenData/types.d.ts +73 -0
- package/lib/modules/OpenData/types.js +17 -0
- package/lib/modules/OpenData/utils.d.ts +2 -0
- package/lib/modules/OpenData/utils.js +111 -0
- package/lib/modules/Order/index.d.ts +58 -1
- package/lib/modules/Order/index.js +423 -1
- package/lib/modules/Order/types.d.ts +144 -12
- package/lib/modules/Order/utils.d.ts +25 -0
- package/lib/modules/Order/utils.js +229 -0
- package/lib/modules/Product/index.d.ts +1 -1
- package/lib/modules/Product/utils.js +2 -2
- package/lib/modules/ProductList/index.d.ts +1 -1
- package/lib/modules/ProductList/index.js +2 -1
- package/lib/modules/Quotation/index.d.ts +48 -0
- package/lib/modules/Quotation/index.js +149 -0
- package/lib/modules/Quotation/types.d.ts +42 -0
- package/lib/modules/Quotation/types.js +17 -0
- package/lib/modules/Rules/index.js +4 -1
- package/lib/modules/SalesSummary/index.d.ts +63 -0
- package/lib/modules/SalesSummary/index.js +105 -0
- package/lib/modules/SalesSummary/types.d.ts +59 -0
- package/lib/modules/SalesSummary/types.js +17 -0
- package/lib/modules/SalesSummary/utils.d.ts +30 -0
- package/lib/modules/SalesSummary/utils.js +452 -0
- package/lib/modules/ScanOrderLogger/index.d.ts +21 -0
- package/lib/modules/ScanOrderLogger/index.js +135 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/feishu.js +82 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.d.ts +2 -0
- package/lib/modules/ScanOrderLogger/providers/grafana.js +52 -0
- package/lib/modules/ScanOrderLogger/types.d.ts +46 -0
- package/lib/modules/ScanOrderLogger/types.js +17 -0
- package/lib/modules/Schedule/getDateIsInSchedule.js +9 -11
- package/lib/modules/Summary/utils.d.ts +3 -3
- package/lib/modules/Summary/utils.js +4 -4
- package/lib/modules/index.d.ts +4 -0
- package/lib/modules/index.js +9 -1
- package/lib/solution/BookingByStep/index.d.ts +1 -1
- package/lib/solution/BookingByStep/types.d.ts +3 -1
- package/lib/solution/BookingByStep/types.js +10 -0
- package/lib/solution/BookingTicket/index.d.ts +1 -1
- package/lib/solution/ScanOrder/index.d.ts +90 -0
- package/lib/solution/ScanOrder/index.js +1071 -0
- package/lib/solution/ScanOrder/types.d.ts +210 -0
- package/lib/solution/ScanOrder/types.js +36 -0
- package/lib/solution/ScanOrder/utils.d.ts +93 -0
- package/lib/solution/ScanOrder/utils.js +359 -0
- package/lib/solution/VenueBooking/index.d.ts +158 -0
- package/lib/solution/VenueBooking/index.js +1545 -0
- package/lib/solution/VenueBooking/sales-section-4-annotated.json +343 -0
- package/lib/solution/VenueBooking/types.d.ts +130 -0
- package/lib/solution/VenueBooking/types.js +44 -0
- package/lib/solution/VenueBooking/utils/dateSummary.d.ts +10 -0
- package/lib/solution/VenueBooking/utils/dateSummary.js +101 -0
- package/lib/solution/VenueBooking/utils/resource.d.ts +4 -0
- package/lib/solution/VenueBooking/utils/resource.js +80 -0
- package/lib/solution/VenueBooking/utils/slotMerge.d.ts +29 -0
- package/lib/solution/VenueBooking/utils/slotMerge.js +209 -0
- package/lib/solution/VenueBooking/utils/timeSlot.d.ts +32 -0
- package/lib/solution/VenueBooking/utils/timeSlot.js +200 -0
- package/lib/solution/VenueBooking/utils.d.ts +1 -0
- package/lib/solution/VenueBooking/utils.js +69 -0
- package/lib/solution/index.d.ts +2 -0
- package/lib/solution/index.js +5 -1
- package/package.json +1 -1
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
import type { StrategyConfig, EvaluationResult } from '../../type';
|
|
2
|
+
export declare const ITEM_RULE_ACTION_TYPES: {
|
|
3
|
+
/** 数量校验 */
|
|
4
|
+
readonly QUANTITY_CHECK: "QUANTITY_CHECK";
|
|
5
|
+
/** 预填购物车 */
|
|
6
|
+
readonly PREFILL_CART: "PREFILL_CART";
|
|
7
|
+
};
|
|
8
|
+
export type ItemRuleActionType = (typeof ITEM_RULE_ACTION_TYPES)[keyof typeof ITEM_RULE_ACTION_TYPES];
|
|
9
|
+
export declare const ITEM_RULE_TEMPLATES: {
|
|
10
|
+
/** 空白规则 */
|
|
11
|
+
readonly BLANK: "blank";
|
|
12
|
+
/** 人数关联最少量(每人至少N份) */
|
|
13
|
+
readonly MINIMUM_PER_PERSON: "minimum_per_person";
|
|
14
|
+
/** 每桌限量 */
|
|
15
|
+
readonly MAXIMUM_PER_TABLE: "maximum_per_table";
|
|
16
|
+
/** 必选商品 */
|
|
17
|
+
readonly MUST_INCLUDE: "must_include";
|
|
18
|
+
};
|
|
19
|
+
export type ItemRuleTemplate = (typeof ITEM_RULE_TEMPLATES)[keyof typeof ITEM_RULE_TEMPLATES];
|
|
20
|
+
/** 数量比较类型 */
|
|
21
|
+
export type QuantityComparison = 'minimum' | 'maximum' | 'exact' | 'must_include';
|
|
22
|
+
/** 数量来源 */
|
|
23
|
+
export type QuantitySource = 'total_pax' | 'adult_pax' | 'fixed';
|
|
24
|
+
/** 目标类型(当前仅支持按商品) */
|
|
25
|
+
export type TargetType = 'product';
|
|
26
|
+
/** 作用范围 */
|
|
27
|
+
export type RuleScope = 'each_submission' | 'first_submission_only' | 'subsequent_only' | 'cumulative';
|
|
28
|
+
/**
|
|
29
|
+
* 单条数量规则
|
|
30
|
+
*
|
|
31
|
+
* 例如:Minimum + Total Pax 表示"最少数量 = 总人数"
|
|
32
|
+
* 例如:Maximum + Fixed + 10 表示"最多10份"
|
|
33
|
+
*/
|
|
34
|
+
export interface QuantityRule {
|
|
35
|
+
/** 比较方式 */
|
|
36
|
+
comparison: QuantityComparison;
|
|
37
|
+
/** 数量来源 */
|
|
38
|
+
source: QuantitySource;
|
|
39
|
+
/** 固定值(当 source 为 'fixed' 时使用) */
|
|
40
|
+
value?: number;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Quantity Check Action 的详细配置
|
|
44
|
+
*
|
|
45
|
+
* 存储在 ActionEffect.config 中
|
|
46
|
+
*/
|
|
47
|
+
export interface QuantityCheckConfig {
|
|
48
|
+
/** 目标类型 */
|
|
49
|
+
targetType: TargetType;
|
|
50
|
+
/** 目标商品 ID 列表 */
|
|
51
|
+
targets: TargetItem[];
|
|
52
|
+
/** 数量规则列表(多条规则同时生效) */
|
|
53
|
+
quantityRules: QuantityRule[];
|
|
54
|
+
/** 作用范围 */
|
|
55
|
+
scope: RuleScope;
|
|
56
|
+
/** 校验失败时的提示语,支持 {min} {max} 占位符,支持多语言 */
|
|
57
|
+
validationMessage?: string | Record<string, string>;
|
|
58
|
+
}
|
|
59
|
+
/** 目标项 */
|
|
60
|
+
export interface TargetItem {
|
|
61
|
+
/** 目标商品 ID */
|
|
62
|
+
product_id: number;
|
|
63
|
+
/** 变体 ID */
|
|
64
|
+
product_variant_id?: number;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* 预填商品项
|
|
68
|
+
*/
|
|
69
|
+
export interface PrefillProduct {
|
|
70
|
+
/** 商品 ID */
|
|
71
|
+
product_id: number;
|
|
72
|
+
/** 变体 ID(可选,0 或不填表示无变体/默认) */
|
|
73
|
+
product_variant_id?: number;
|
|
74
|
+
/** 数量来源 */
|
|
75
|
+
quantityFrom: QuantitySource;
|
|
76
|
+
/** 固定数量(当 quantityFrom 为 'fixed' 时使用) */
|
|
77
|
+
quantity?: number;
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Prefill Cart Action 的详细配置
|
|
81
|
+
*
|
|
82
|
+
* 存储在 ActionEffect.config 中
|
|
83
|
+
*/
|
|
84
|
+
export interface PrefillCartConfig {
|
|
85
|
+
/** 要预填的商品列表 */
|
|
86
|
+
products: PrefillProduct[];
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* 购物车商品摘要
|
|
90
|
+
*/
|
|
91
|
+
export interface CartItemSummary {
|
|
92
|
+
/** 商品 ID */
|
|
93
|
+
product_id: number;
|
|
94
|
+
/** 变体 ID */
|
|
95
|
+
product_variant_id?: number;
|
|
96
|
+
/** 数量 */
|
|
97
|
+
quantity: number;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* 就餐人数信息
|
|
101
|
+
*/
|
|
102
|
+
export interface PaxInfo {
|
|
103
|
+
/** 总人数 */
|
|
104
|
+
total: number;
|
|
105
|
+
/** 成人人数 */
|
|
106
|
+
adult: number;
|
|
107
|
+
/** 儿童人数 */
|
|
108
|
+
child: number;
|
|
109
|
+
}
|
|
110
|
+
/**
|
|
111
|
+
* ItemRule 评估器的输入业务数据
|
|
112
|
+
*/
|
|
113
|
+
export interface ItemRuleBusinessData {
|
|
114
|
+
/** 就餐人数 */
|
|
115
|
+
pax: PaxInfo;
|
|
116
|
+
/** 当前购物车商品列表 */
|
|
117
|
+
cartItems: CartItemSummary[];
|
|
118
|
+
/** 历史订单商品列表(用于 cumulative scope,主订单+加单的商品汇总) */
|
|
119
|
+
historicalItems?: CartItemSummary[];
|
|
120
|
+
/** 服务类型(如 'dine-in', 'takeaway') */
|
|
121
|
+
serviceType?: string;
|
|
122
|
+
/** 当前提交次数(0=首次提交, >0=追加提交) */
|
|
123
|
+
submissionIndex?: number;
|
|
124
|
+
/** 策略配置列表(可选,如果不传则使用 setStrategyConfigs 设置的) */
|
|
125
|
+
strategyConfigs?: StrategyConfig[];
|
|
126
|
+
/** 自定义属性(会合并到 context.attributes) */
|
|
127
|
+
custom?: Record<string, any>;
|
|
128
|
+
}
|
|
129
|
+
/**
|
|
130
|
+
* 单个 Quantity Check 的校验结果
|
|
131
|
+
*/
|
|
132
|
+
export interface QuantityCheckResult {
|
|
133
|
+
/** 规则 ID(对应 ActionEffect.id) */
|
|
134
|
+
ruleId: string;
|
|
135
|
+
/** 是否通过校验 */
|
|
136
|
+
passed: boolean;
|
|
137
|
+
/** 目标类型 */
|
|
138
|
+
targetType: TargetType;
|
|
139
|
+
/** 目标列表 */
|
|
140
|
+
targets: TargetItem[];
|
|
141
|
+
/** 当前购物车中的实际数量 */
|
|
142
|
+
actualQuantity: number;
|
|
143
|
+
/** 要求的最小数量(根据规则计算后的值) */
|
|
144
|
+
requiredMin?: number;
|
|
145
|
+
/** 要求的最大数量 */
|
|
146
|
+
requiredMax?: number;
|
|
147
|
+
/** 要求的精确数量 */
|
|
148
|
+
requiredExact?: number;
|
|
149
|
+
/** 是否必须包含(must_include) */
|
|
150
|
+
mustInclude?: boolean;
|
|
151
|
+
/** 格式化后的校验提示语 */
|
|
152
|
+
validationMessage?: string;
|
|
153
|
+
/** 作用范围 */
|
|
154
|
+
scope: RuleScope;
|
|
155
|
+
/** 未通过的具体规则 */
|
|
156
|
+
failedRules?: QuantityRule[];
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* 单个 Prefill Cart 的预填结果
|
|
160
|
+
*/
|
|
161
|
+
export interface PrefillItemResult {
|
|
162
|
+
/** 规则 ID(对应 ActionEffect.id) */
|
|
163
|
+
ruleId: string;
|
|
164
|
+
/** 商品 ID */
|
|
165
|
+
product_id: number;
|
|
166
|
+
/** 变体 ID */
|
|
167
|
+
product_variant_id?: number;
|
|
168
|
+
/** 应添加的数量 */
|
|
169
|
+
quantity: number;
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* 单条规则的数量限制(不含校验结果,仅描述配置中的约束)
|
|
173
|
+
*/
|
|
174
|
+
export interface QuantityLimitResult {
|
|
175
|
+
/** 规则 ID(对应 ActionEffect.id) */
|
|
176
|
+
ruleId: string;
|
|
177
|
+
/** 目标类型 */
|
|
178
|
+
targetType: TargetType;
|
|
179
|
+
/** 目标列表 */
|
|
180
|
+
targets: TargetItem[];
|
|
181
|
+
/** 要求的最小数量 */
|
|
182
|
+
requiredMin?: number;
|
|
183
|
+
/** 要求的最大数量 */
|
|
184
|
+
requiredMax?: number;
|
|
185
|
+
/** 要求的精确数量 */
|
|
186
|
+
requiredExact?: number;
|
|
187
|
+
/** 是否必须包含 */
|
|
188
|
+
mustInclude?: boolean;
|
|
189
|
+
/** 作用范围 */
|
|
190
|
+
scope: RuleScope;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* ItemRule 评估器的完整输出结果
|
|
194
|
+
*/
|
|
195
|
+
export interface ItemRuleEvaluationResult {
|
|
196
|
+
/** 所有数量校验结果 */
|
|
197
|
+
quantityChecks: QuantityCheckResult[];
|
|
198
|
+
/** 需要预填的商品列表 */
|
|
199
|
+
prefillItems: PrefillItemResult[];
|
|
200
|
+
/** 所有校验是否全部通过 */
|
|
201
|
+
allPassed: boolean;
|
|
202
|
+
/** 未通过的校验列表 */
|
|
203
|
+
failedChecks: QuantityCheckResult[];
|
|
204
|
+
/** 原始策略评估结果列表 */
|
|
205
|
+
rawResults: EvaluationResult[];
|
|
206
|
+
}
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
// ============================================
|
|
2
|
+
// Action Type 常量
|
|
3
|
+
// ============================================
|
|
4
|
+
|
|
5
|
+
export var ITEM_RULE_ACTION_TYPES = {
|
|
6
|
+
/** 数量校验 */
|
|
7
|
+
QUANTITY_CHECK: 'QUANTITY_CHECK',
|
|
8
|
+
/** 预填购物车 */
|
|
9
|
+
PREFILL_CART: 'PREFILL_CART'
|
|
10
|
+
};
|
|
11
|
+
// ============================================
|
|
12
|
+
// Rule Template 类型(创建规则时的起始模板)
|
|
13
|
+
// ============================================
|
|
14
|
+
|
|
15
|
+
export var ITEM_RULE_TEMPLATES = {
|
|
16
|
+
/** 空白规则 */
|
|
17
|
+
BLANK: 'blank',
|
|
18
|
+
/** 人数关联最少量(每人至少N份) */
|
|
19
|
+
MINIMUM_PER_PERSON: 'minimum_per_person',
|
|
20
|
+
/** 每桌限量 */
|
|
21
|
+
MAXIMUM_PER_TABLE: 'maximum_per_table',
|
|
22
|
+
/** 必选商品 */
|
|
23
|
+
MUST_INCLUDE: 'must_include'
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
// ============================================
|
|
27
|
+
// Quantity Check 相关类型
|
|
28
|
+
// ============================================
|
|
29
|
+
|
|
30
|
+
/** 数量比较类型 */
|
|
31
|
+
|
|
32
|
+
/** 数量来源 */
|
|
33
|
+
|
|
34
|
+
/** 目标类型(当前仅支持按商品) */
|
|
35
|
+
|
|
36
|
+
/** 作用范围 */
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* 单条数量规则
|
|
40
|
+
*
|
|
41
|
+
* 例如:Minimum + Total Pax 表示"最少数量 = 总人数"
|
|
42
|
+
* 例如:Maximum + Fixed + 10 表示"最多10份"
|
|
43
|
+
*/
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Quantity Check Action 的详细配置
|
|
47
|
+
*
|
|
48
|
+
* 存储在 ActionEffect.config 中
|
|
49
|
+
*/
|
|
50
|
+
|
|
51
|
+
/** 目标项 */
|
|
52
|
+
|
|
53
|
+
// ============================================
|
|
54
|
+
// Prefill Cart 相关类型
|
|
55
|
+
// ============================================
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* 预填商品项
|
|
59
|
+
*/
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* Prefill Cart Action 的详细配置
|
|
63
|
+
*
|
|
64
|
+
* 存储在 ActionEffect.config 中
|
|
65
|
+
*/
|
|
66
|
+
|
|
67
|
+
// ============================================
|
|
68
|
+
// 业务数据类型(Evaluator 输入)
|
|
69
|
+
// ============================================
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* 购物车商品摘要
|
|
73
|
+
*/
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* 就餐人数信息
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* ItemRule 评估器的输入业务数据
|
|
81
|
+
*/
|
|
82
|
+
|
|
83
|
+
// ============================================
|
|
84
|
+
// 评估结果类型
|
|
85
|
+
// ============================================
|
|
86
|
+
|
|
87
|
+
/**
|
|
88
|
+
* 单个 Quantity Check 的校验结果
|
|
89
|
+
*/
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* 单个 Prefill Cart 的预填结果
|
|
93
|
+
*/
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* 单条规则的数量限制(不含校验结果,仅描述配置中的约束)
|
|
97
|
+
*/
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* ItemRule 评估器的完整输出结果
|
|
101
|
+
*/
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { EvaluationResult, RuntimeContext } from '../../type';
|
|
2
|
+
import type { BusinessAdapter } from '../type';
|
|
3
|
+
import type { PromotionBusinessData, PromotionTransformResult } from './type';
|
|
4
|
+
/**
|
|
5
|
+
* Promotion 适配器
|
|
6
|
+
*
|
|
7
|
+
* 用于将促销活动业务数据转换为策略引擎可识别的格式
|
|
8
|
+
* 策略引擎只负责匹配,具体的优惠计算由业务层完成
|
|
9
|
+
*/
|
|
10
|
+
export declare class PromotionAdapter implements BusinessAdapter {
|
|
11
|
+
name: string;
|
|
12
|
+
version: string;
|
|
13
|
+
/**
|
|
14
|
+
* 准备运行时上下文
|
|
15
|
+
*
|
|
16
|
+
* 将业务数据转换为策略引擎可识别的 RuntimeContext
|
|
17
|
+
*/
|
|
18
|
+
prepareContext(businessData: PromotionBusinessData): RuntimeContext;
|
|
19
|
+
/**
|
|
20
|
+
* 转换执行结果
|
|
21
|
+
*
|
|
22
|
+
* 将策略引擎的通用结果转换为业务层需要的格式
|
|
23
|
+
* 主要是整理 matchedActions,让业务层更容易使用
|
|
24
|
+
*/
|
|
25
|
+
transformResult(result: EvaluationResult, businessData?: PromotionBusinessData): PromotionTransformResult;
|
|
26
|
+
/**
|
|
27
|
+
* 格式化配置
|
|
28
|
+
*/
|
|
29
|
+
formatConfig(result: EvaluationResult, businessData?: PromotionBusinessData): {
|
|
30
|
+
result: EvaluationResult;
|
|
31
|
+
businessData?: PromotionBusinessData;
|
|
32
|
+
};
|
|
33
|
+
/**
|
|
34
|
+
* 格式化日期时间
|
|
35
|
+
*/
|
|
36
|
+
private formatDateTime;
|
|
37
|
+
/**
|
|
38
|
+
* 解析 Action 详情
|
|
39
|
+
*
|
|
40
|
+
* 将 matchedAction 转换为更易用的结构
|
|
41
|
+
*/
|
|
42
|
+
private parseActionDetail;
|
|
43
|
+
/**
|
|
44
|
+
* 解析 X件Y元 Action
|
|
45
|
+
*/
|
|
46
|
+
private parseXItemsForYPriceAction;
|
|
47
|
+
/**
|
|
48
|
+
* 解析 买X送Y Action
|
|
49
|
+
*/
|
|
50
|
+
private parseBuyXGetYFreeAction;
|
|
51
|
+
/**
|
|
52
|
+
* 获取适用的商品列表
|
|
53
|
+
*
|
|
54
|
+
* 从购物车商品中筛选出符合策略条件的商品
|
|
55
|
+
*/
|
|
56
|
+
private getApplicableProducts;
|
|
57
|
+
/**
|
|
58
|
+
* 查找商品匹配规则
|
|
59
|
+
*/
|
|
60
|
+
private findProductMatchRule;
|
|
61
|
+
/**
|
|
62
|
+
* 检查商品是否匹配
|
|
63
|
+
*/
|
|
64
|
+
private isProductMatch;
|
|
65
|
+
}
|
|
66
|
+
export default PromotionAdapter;
|
|
@@ -0,0 +1,271 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
3
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
4
|
+
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
5
|
+
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
|
|
6
|
+
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
|
7
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
8
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
9
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
10
|
+
import { PROMOTION_ACTION_TYPES } from "./type";
|
|
11
|
+
// ============================================
|
|
12
|
+
// Promotion 适配器实现
|
|
13
|
+
// ============================================
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Promotion 适配器
|
|
17
|
+
*
|
|
18
|
+
* 用于将促销活动业务数据转换为策略引擎可识别的格式
|
|
19
|
+
* 策略引擎只负责匹配,具体的优惠计算由业务层完成
|
|
20
|
+
*/
|
|
21
|
+
export var PromotionAdapter = /*#__PURE__*/function () {
|
|
22
|
+
function PromotionAdapter() {
|
|
23
|
+
_classCallCheck(this, PromotionAdapter);
|
|
24
|
+
_defineProperty(this, "name", 'PromotionAdapter');
|
|
25
|
+
_defineProperty(this, "version", '1.0.0');
|
|
26
|
+
}
|
|
27
|
+
_createClass(PromotionAdapter, [{
|
|
28
|
+
key: "prepareContext",
|
|
29
|
+
value:
|
|
30
|
+
/**
|
|
31
|
+
* 准备运行时上下文
|
|
32
|
+
*
|
|
33
|
+
* 将业务数据转换为策略引擎可识别的 RuntimeContext
|
|
34
|
+
*/
|
|
35
|
+
function prepareContext(businessData) {
|
|
36
|
+
var products = businessData.products,
|
|
37
|
+
currentProduct = businessData.currentProduct,
|
|
38
|
+
channel = businessData.channel,
|
|
39
|
+
custom = businessData.custom;
|
|
40
|
+
|
|
41
|
+
// 当前时间(用于时间条件判断)
|
|
42
|
+
var now = new Date();
|
|
43
|
+
var currentDateTime = this.formatDateTime(now);
|
|
44
|
+
|
|
45
|
+
// 如果有 currentProduct,用于单商品场景(商品卡片展示)
|
|
46
|
+
var evaluatingProduct = currentProduct || (products.length > 0 ? products[0] : null);
|
|
47
|
+
return {
|
|
48
|
+
entities: {
|
|
49
|
+
products: products,
|
|
50
|
+
currentProduct: evaluatingProduct
|
|
51
|
+
},
|
|
52
|
+
attributes: _objectSpread({
|
|
53
|
+
// 当前时间(格式化字符串,用于时间条件判断)
|
|
54
|
+
currentDateTime: currentDateTime,
|
|
55
|
+
// 当前评估的商品信息(用于 product_match 运算符)
|
|
56
|
+
productIdAndVariantId: evaluatingProduct ? {
|
|
57
|
+
product_id: evaluatingProduct.product_id,
|
|
58
|
+
product_variant_id: evaluatingProduct.product_variant_id
|
|
59
|
+
} : null,
|
|
60
|
+
// 渠道
|
|
61
|
+
channel: channel || '',
|
|
62
|
+
// 商品总数量
|
|
63
|
+
totalQuantity: products.reduce(function (sum, p) {
|
|
64
|
+
return sum + p.quantity;
|
|
65
|
+
}, 0),
|
|
66
|
+
// 商品总金额
|
|
67
|
+
totalAmount: products.reduce(function (sum, p) {
|
|
68
|
+
return sum + p.price * p.quantity;
|
|
69
|
+
}, 0)
|
|
70
|
+
}, custom),
|
|
71
|
+
metadata: {
|
|
72
|
+
timestamp: Date.now()
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 转换执行结果
|
|
79
|
+
*
|
|
80
|
+
* 将策略引擎的通用结果转换为业务层需要的格式
|
|
81
|
+
* 主要是整理 matchedActions,让业务层更容易使用
|
|
82
|
+
*/
|
|
83
|
+
}, {
|
|
84
|
+
key: "transformResult",
|
|
85
|
+
value: function transformResult(result, businessData) {
|
|
86
|
+
// 获取适用的商品列表
|
|
87
|
+
var applicableProducts = businessData ? this.getApplicableProducts(result, businessData) : [];
|
|
88
|
+
if (!result.applicable) {
|
|
89
|
+
return {
|
|
90
|
+
isApplicable: false,
|
|
91
|
+
applicableProducts: [],
|
|
92
|
+
reason: result.message,
|
|
93
|
+
reasonCode: result.code,
|
|
94
|
+
strategyResult: result
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
// 获取第一个匹配的 action(按 priority 排序后的)
|
|
99
|
+
var matchedAction = result.matchedActions[0];
|
|
100
|
+
if (!matchedAction) {
|
|
101
|
+
return {
|
|
102
|
+
isApplicable: false,
|
|
103
|
+
applicableProducts: [],
|
|
104
|
+
reason: 'No matched action',
|
|
105
|
+
reasonCode: 'NO_ACTION',
|
|
106
|
+
strategyResult: result
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
// 解析 action 详情
|
|
111
|
+
var actionDetail = this.parseActionDetail(matchedAction);
|
|
112
|
+
return {
|
|
113
|
+
isApplicable: true,
|
|
114
|
+
actionType: matchedAction.type,
|
|
115
|
+
actionDetail: actionDetail,
|
|
116
|
+
applicableProducts: applicableProducts,
|
|
117
|
+
strategyResult: result
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* 格式化配置
|
|
123
|
+
*/
|
|
124
|
+
}, {
|
|
125
|
+
key: "formatConfig",
|
|
126
|
+
value: function formatConfig(result, businessData) {
|
|
127
|
+
return {
|
|
128
|
+
result: result,
|
|
129
|
+
businessData: businessData
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// ============================================
|
|
134
|
+
// 私有辅助方法
|
|
135
|
+
// ============================================
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* 格式化日期时间
|
|
139
|
+
*/
|
|
140
|
+
}, {
|
|
141
|
+
key: "formatDateTime",
|
|
142
|
+
value: function formatDateTime(date) {
|
|
143
|
+
var year = date.getFullYear();
|
|
144
|
+
var month = String(date.getMonth() + 1).padStart(2, '0');
|
|
145
|
+
var day = String(date.getDate()).padStart(2, '0');
|
|
146
|
+
var hours = String(date.getHours()).padStart(2, '0');
|
|
147
|
+
var minutes = String(date.getMinutes()).padStart(2, '0');
|
|
148
|
+
var seconds = String(date.getSeconds()).padStart(2, '0');
|
|
149
|
+
return "".concat(year, "-").concat(month, "-").concat(day, " ").concat(hours, ":").concat(minutes, ":").concat(seconds);
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
/**
|
|
153
|
+
* 解析 Action 详情
|
|
154
|
+
*
|
|
155
|
+
* 将 matchedAction 转换为更易用的结构
|
|
156
|
+
*/
|
|
157
|
+
}, {
|
|
158
|
+
key: "parseActionDetail",
|
|
159
|
+
value: function parseActionDetail(action) {
|
|
160
|
+
switch (action.type) {
|
|
161
|
+
case PROMOTION_ACTION_TYPES.X_ITEMS_FOR_Y_PRICE:
|
|
162
|
+
return this.parseXItemsForYPriceAction(action);
|
|
163
|
+
case PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE:
|
|
164
|
+
return this.parseBuyXGetYFreeAction(action);
|
|
165
|
+
default:
|
|
166
|
+
return undefined;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
/**
|
|
171
|
+
* 解析 X件Y元 Action
|
|
172
|
+
*/
|
|
173
|
+
}, {
|
|
174
|
+
key: "parseXItemsForYPriceAction",
|
|
175
|
+
value: function parseXItemsForYPriceAction(action) {
|
|
176
|
+
var _config$allowCrossPro, _config$cumulative;
|
|
177
|
+
var value = action.value || {};
|
|
178
|
+
var config = action.config || {};
|
|
179
|
+
return {
|
|
180
|
+
type: PROMOTION_ACTION_TYPES.X_ITEMS_FOR_Y_PRICE,
|
|
181
|
+
x: value.x || 2,
|
|
182
|
+
price: value.price || 0,
|
|
183
|
+
allowCrossProduct: (_config$allowCrossPro = config.allowCrossProduct) !== null && _config$allowCrossPro !== void 0 ? _config$allowCrossPro : true,
|
|
184
|
+
cumulative: (_config$cumulative = config.cumulative) !== null && _config$cumulative !== void 0 ? _config$cumulative : true
|
|
185
|
+
};
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/**
|
|
189
|
+
* 解析 买X送Y Action
|
|
190
|
+
*/
|
|
191
|
+
}, {
|
|
192
|
+
key: "parseBuyXGetYFreeAction",
|
|
193
|
+
value: function parseBuyXGetYFreeAction(action) {
|
|
194
|
+
var _config$cumulative2;
|
|
195
|
+
var value = action.value || {};
|
|
196
|
+
var config = action.config || {};
|
|
197
|
+
return {
|
|
198
|
+
type: PROMOTION_ACTION_TYPES.BUY_X_GET_Y_FREE,
|
|
199
|
+
buyQuantity: value.buyQuantity || 1,
|
|
200
|
+
freeQuantity: value.freeQuantity || 1,
|
|
201
|
+
giftSelectionMode: config.giftSelectionMode || 'user_select',
|
|
202
|
+
cumulative: (_config$cumulative2 = config.cumulative) !== null && _config$cumulative2 !== void 0 ? _config$cumulative2 : true,
|
|
203
|
+
giftProducts: config.giftProducts || []
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* 获取适用的商品列表
|
|
209
|
+
*
|
|
210
|
+
* 从购物车商品中筛选出符合策略条件的商品
|
|
211
|
+
*/
|
|
212
|
+
}, {
|
|
213
|
+
key: "getApplicableProducts",
|
|
214
|
+
value: function getApplicableProducts(result, businessData) {
|
|
215
|
+
var _this = this;
|
|
216
|
+
var products = businessData.products;
|
|
217
|
+
|
|
218
|
+
// 从策略配置中获取商品范围条件
|
|
219
|
+
var productMatchRule = this.findProductMatchRule(result.config);
|
|
220
|
+
if (!productMatchRule) {
|
|
221
|
+
// 如果没有商品范围条件,所有商品都适用
|
|
222
|
+
return products;
|
|
223
|
+
}
|
|
224
|
+
var configProducts = productMatchRule.value;
|
|
225
|
+
|
|
226
|
+
// 筛选适用的商品
|
|
227
|
+
return products.filter(function (product) {
|
|
228
|
+
return _this.isProductMatch(product, configProducts);
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
/**
|
|
233
|
+
* 查找商品匹配规则
|
|
234
|
+
*/
|
|
235
|
+
}, {
|
|
236
|
+
key: "findProductMatchRule",
|
|
237
|
+
value: function findProductMatchRule(config) {
|
|
238
|
+
var _config$conditions;
|
|
239
|
+
if (!(config !== null && config !== void 0 && (_config$conditions = config.conditions) !== null && _config$conditions !== void 0 && _config$conditions.rules)) {
|
|
240
|
+
return null;
|
|
241
|
+
}
|
|
242
|
+
return config.conditions.rules.find(function (rule) {
|
|
243
|
+
return rule.field === 'productIdAndVariantId' && (rule.operator === 'product_match' || rule.operator === 'object_in');
|
|
244
|
+
});
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
/**
|
|
248
|
+
* 检查商品是否匹配
|
|
249
|
+
*/
|
|
250
|
+
}, {
|
|
251
|
+
key: "isProductMatch",
|
|
252
|
+
value: function isProductMatch(product, configProducts) {
|
|
253
|
+
return configProducts.some(function (config) {
|
|
254
|
+
// 首先检查 product_id
|
|
255
|
+
if (config.product_id !== product.product_id) {
|
|
256
|
+
return false;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// 如果配置的 product_variant_id = 0,只需要 product_id 匹配
|
|
260
|
+
if (config.product_variant_id === 0) {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
// 否则需要 product_variant_id 精确匹配
|
|
265
|
+
return config.product_variant_id === product.product_variant_id;
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}]);
|
|
269
|
+
return PromotionAdapter;
|
|
270
|
+
}();
|
|
271
|
+
export default PromotionAdapter;
|