diff --git a/customer_management/core.py b/customer_management/core.py index 09d02b9..7be57ba 100644 --- a/customer_management/core.py +++ b/customer_management/core.py @@ -22,12 +22,17 @@ async def create_customer( region: str = None ) -> Dict: """创建客户档案""" + env = ServerEnv() + + dbname = env.get_module_dbname('customer_management') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('customer_management') as sor: + + async with db.sqlorContext(dbname) as sor: customer_id = str(uuid.uuid4()).replace('-', '') # 数据校验 @@ -78,12 +83,17 @@ async def initiate_handover( reviewer_id: str = None ) -> Dict: """发起客户交接流程""" + env = ServerEnv() + + dbname = env.get_module_dbname('customer_management') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('customer_management') as sor: + + async with db.sqlorContext(dbname) as sor: # 获取客户信息 customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]}) if not customer_records or len(customer_records) == 0: @@ -212,12 +222,17 @@ async def generate_handover_items(sor, handover_id: str, customer_id: str): async def complete_handover_preparation(handover_id: str) -> Dict: """完成交接准备阶段""" + env = ServerEnv() + + dbname = env.get_module_dbname('customer_management') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('customer_management') as sor: + + async with db.sqlorContext(dbname) as sor: handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]}) if not handover_records or len(handover_records) == 0: raise ValueError("交接记录不存在") @@ -242,12 +257,17 @@ async def complete_handover_preparation(handover_id: str) -> Dict: async def approve_handover(handover_id: str, approver_id: str = None) -> Dict: """审核交接清单""" + env = ServerEnv() + + dbname = env.get_module_dbname('customer_management') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('customer_management') as sor: + + async with db.sqlorContext(dbname) as sor: approver_id = approver_id or get_current_user_id() handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]}) @@ -274,12 +294,17 @@ async def approve_handover(handover_id: str, approver_id: str = None) -> Dict: async def confirm_handover(handover_id: str, confirm_by: str = None) -> Dict: """确认接收客户""" + env = ServerEnv() + + dbname = env.get_module_dbname('customer_management') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('customer_management') as sor: + + async with db.sqlorContext(dbname) as sor: confirm_by = confirm_by or get_current_user_id() handover_records = await sor.R("customer_handover", {"filters": [{"field": "id", "op": "=", "value": handover_id}]}) @@ -337,12 +362,17 @@ async def send_customer_notification(sor, customer_id: str, new_owner_id: str): async def recycle_to_pool(customer_id: str, inactive_days: int = None, reason: str = "inactive_days"): """回收客户到公海池""" + env = ServerEnv() + + dbname = env.get_module_dbname('customer_management') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('customer_management') as sor: + + async with db.sqlorContext(dbname) as sor: customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]}) if not customer_records or len(customer_records) == 0: raise ValueError("客户不存在") @@ -382,12 +412,17 @@ async def recycle_to_pool(customer_id: str, inactive_days: int = None, reason: s async def claim_from_pool(pool_id: str, new_owner_id: str = None): """从公海池认领客户""" + env = ServerEnv() + + dbname = env.get_module_dbname('customer_management') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('customer_management') as sor: + + async with db.sqlorContext(dbname) as sor: new_owner_id = new_owner_id or get_current_user_id() pool_records = await sor.R("customer_pool", {"filters": [{"field": "id", "op": "=", "value": pool_id}]}) @@ -427,12 +462,17 @@ async def claim_from_pool(pool_id: str, new_owner_id: str = None): async def get_customer_360_view(customer_id: str) -> Dict: """获取客户360度视图""" + env = ServerEnv() + + dbname = env.get_module_dbname('customer_management') + config = getConfig() db = DBPools() db.databases = config.databases - async with db.sqlorContext('customer_management') as sor: + + async with db.sqlorContext(dbname) as sor: # 客户基本信息 customer_records = await sor.R("customers", {"filters": [{"field": "id", "op": "=", "value": customer_id}]}) if not customer_records or len(customer_records) == 0: