UNPKG

@pisell/pisellos

Version:

一个可扩展的前端模块化SDK框架,支持插件系统

67 lines (66 loc) 1.92 kB
import type { EvaluationResult, RuntimeContext } from '../../type'; import type { BusinessAdapter } from '../type'; import type { PromotionBusinessData, PromotionTransformResult } from './type'; /** * Promotion 适配器 * * 用于将促销活动业务数据转换为策略引擎可识别的格式 * 策略引擎只负责匹配,具体的优惠计算由业务层完成 */ export declare class PromotionAdapter implements BusinessAdapter { name: string; version: string; /** * 准备运行时上下文 * * 将业务数据转换为策略引擎可识别的 RuntimeContext */ prepareContext(businessData: PromotionBusinessData): RuntimeContext; /** * 转换执行结果 * * 将策略引擎的通用结果转换为业务层需要的格式 * 主要是整理 matchedActions,让业务层更容易使用 */ transformResult(result: EvaluationResult, businessData?: PromotionBusinessData): PromotionTransformResult; /** * 格式化配置 */ formatConfig(result: EvaluationResult, businessData?: PromotionBusinessData): { result: EvaluationResult; businessData?: PromotionBusinessData; }; /** * 格式化日期时间 */ private formatDateTime; /** * 解析 Action 详情 * * 将 matchedAction 转换为更易用的结构 */ private parseActionDetail; /** * 解析 X件Y元 Action */ private parseXItemsForYPriceAction; /** * 解析 买X送Y Action */ private parseBuyXGetYFreeAction; /** * 获取适用的商品列表 * * 从购物车商品中筛选出符合策略条件的商品 */ private getApplicableProducts; /** * 查找商品匹配规则 */ private findProductMatchRule; /** * 检查商品是否匹配 */ private isProductMatch; } export default PromotionAdapter;