27 lines
815 B
Python
27 lines
815 B
Python
"""AI获客 - 客户咨询接口"""
|
|
from fastapi import APIRouter, HTTPException
|
|
from pydantic import BaseModel
|
|
import json, os, datetime
|
|
|
|
router = APIRouter(prefix="/api/cma/lead", tags=["AI获客"])
|
|
|
|
class LeadRequest(BaseModel):
|
|
name: str
|
|
phone: str
|
|
requirement: str = ""
|
|
source: str = "sxbh.ltd"
|
|
|
|
@router.post("")
|
|
def create_lead(data: LeadRequest):
|
|
"""接收客户咨询并保存"""
|
|
record = data.model_dump()
|
|
record["timestamp"] = datetime.datetime.now().isoformat()
|
|
record["status"] = "new"
|
|
|
|
log_dir = "/root/leads"
|
|
os.makedirs(log_dir, exist_ok=True)
|
|
with open(f"{log_dir}/leads.json", "a") as f:
|
|
f.write(json.dumps(record, ensure_ascii=False) + "\n")
|
|
|
|
return {"success": True, "message": "咨询已提交,我们将在30分钟内联系您"}
|