- 4张表: voucher_template, voucher_rule, voucher_instance, voucher_usage_log - 可配置规则引擎: registry + validators + engine - 8种内置规则: min_amount, max_amount, applicable_product_type, applicable_product, exclude_product, max_usage_count, valid_period, user_level - CRUD定义 + API接口 + 前端页面 - SQL建表脚本 + RBAC权限配置 - 一次性使用,不找零
22 lines
534 B
Python
22 lines
534 B
Python
"""规则注册机制:新增规则只需写一个 validator 函数 + @register_rule 装饰器"""
|
|
|
|
RULE_REGISTRY = {}
|
|
|
|
|
|
def register_rule(rule_type):
|
|
"""装饰器:注册规则类型"""
|
|
def decorator(func):
|
|
RULE_REGISTRY[rule_type] = func
|
|
return func
|
|
return decorator
|
|
|
|
|
|
def get_all_rule_types():
|
|
"""返回所有已注册的规则类型"""
|
|
return list(RULE_REGISTRY.keys())
|
|
|
|
|
|
def get_rule_validator(rule_type):
|
|
"""根据类型获取 validator 函数"""
|
|
return RULE_REGISTRY.get(rule_type)
|