diff --git a/backend/app/api/visits.py b/backend/app/api/visits.py index f02ab82..736707b 100644 --- a/backend/app/api/visits.py +++ b/backend/app/api/visits.py @@ -167,6 +167,33 @@ async def create_visit( current_user["name"], "拜访自动完成", ) + # Auto-create follow-up logs for active mini business opportunities + from app.models.mini_business import MiniBusiness + from app.models.mini_business_log import MiniBusinessLog + method_map = {"上门": "上门", "电话": "电话", "微信": "微信", "出差": "其他"} + active_biz = await db.execute( + select(MiniBusiness).where( + MiniBusiness.customer_id == data.customer_id, + MiniBusiness.status == "跟进中", + ) + ) + for biz in active_biz.scalars().all(): + parts = [] + if data.communication_content and data.communication_content.strip(): + parts.append(f"沟通内容:{data.communication_content.strip()}") + if data.customer_demand and data.customer_demand.strip(): + parts.append(f"客户需求:{data.customer_demand.strip()}") + log_content = "\n".join(parts) if parts else "拜访跟进" + follow_method = method_map.get(data.visit_method, "其他") + log = MiniBusinessLog( + business_id=biz.id, + log_date=parse_date(data.visit_date), + method=follow_method, + content=log_content, + created_by=uuid.UUID(current_user["user_id"]), + ) + db.add(log) + # Create draft copies for companions for companion_id in data.companions: if companion_id != uuid.UUID(current_user["user_id"]):