82 lines
2.8 KiB
Python
82 lines
2.8 KiB
Python
"""Product Management Module Initialization"""
|
|
from ahserver.serverenv import ServerEnv
|
|
from product_management.core import ProductManager
|
|
|
|
MODULE_NAME = "product_management"
|
|
MODULE_VERSION = "1.0.0"
|
|
|
|
# Module instance (lazy-loaded)
|
|
_manager = None
|
|
|
|
|
|
def get_manager():
|
|
"""Get or create the ProductManager singleton."""
|
|
global _manager
|
|
if _manager is None:
|
|
_manager = ProductManager()
|
|
return _manager
|
|
|
|
|
|
# ---- Functions registered with ServerEnv ----
|
|
|
|
async def get_product_brief(product_id=None, product_code=None, category_id=None):
|
|
"""Get product brief info via standardized interface."""
|
|
manager = get_manager()
|
|
return await manager.get_product_brief(product_id, product_code, category_id)
|
|
|
|
|
|
async def get_product_detail(product_id=None, product_code=None, user_id=None):
|
|
"""Get product detail via standardized interface."""
|
|
manager = get_manager()
|
|
return await manager.get_product_detail(product_id, product_code, user_id)
|
|
|
|
|
|
async def purchase_product(product_id, quantity=1, purchase_data=None, user_id=None):
|
|
"""Purchase a product via standardized interface."""
|
|
manager = get_manager()
|
|
return await manager.purchase_product(product_id, quantity, purchase_data, user_id)
|
|
|
|
|
|
async def use_product(product_id, order_id=None, use_data=None, user_id=None):
|
|
"""Use a product via standardized interface."""
|
|
manager = get_manager()
|
|
return await manager.use_product(product_id, order_id, use_data, user_id)
|
|
|
|
|
|
async def get_category_tree(org_id=None):
|
|
"""Get full category tree."""
|
|
manager = get_manager()
|
|
return await manager.get_category_tree(org_id)
|
|
|
|
|
|
async def get_products_by_category(category_id, status='1'):
|
|
"""Get all products under a category."""
|
|
manager = get_manager()
|
|
return await manager.get_products_by_category(category_id, status)
|
|
|
|
|
|
async def get_operator_config(category_id, user_id=None):
|
|
"""Get operator configuration for a category."""
|
|
manager = get_manager()
|
|
return await manager.get_operator_config(category_id, user_id)
|
|
|
|
|
|
async def set_operator_config(category_id, config_name, config_json, user_id=None, org_id=None):
|
|
"""Create or update operator configuration for a category."""
|
|
manager = get_manager()
|
|
return await manager.set_operator_config(category_id, config_name, config_json, user_id, org_id)
|
|
|
|
|
|
def load_product_management():
|
|
"""Register all functions with ServerEnv so they can be called from .ui/.dspy files."""
|
|
env = ServerEnv()
|
|
env.get_product_brief = get_product_brief
|
|
env.get_product_detail = get_product_detail
|
|
env.purchase_product = purchase_product
|
|
env.use_product = use_product
|
|
env.get_category_tree = get_category_tree
|
|
env.get_products_by_category = get_products_by_category
|
|
env.get_operator_config = get_operator_config
|
|
env.set_operator_config = set_operator_config
|
|
return True
|