73 lines
2.4 KiB
Python
73 lines
2.4 KiB
Python
"""客户 360 路由(业务在 service/advisor/customers.py,路由只做编排)。"""
|
|||
|
|
from fastapi import APIRouter, Depends, Query
|
||
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
||
|
|
|
||
|
|
from api.deps import require_advisor
|
||
|
|
from config.deps import get_db
|
||
|
|
from model.sys_user import SysUser
|
||
|
|
from schemas.advisor import RelationReq
|
||
|
|
from service.advisor import customers as customers_service
|
||
|
|
from utils.response import success
|
||
|
|
|
||
|
|
router = APIRouter()
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/customers", summary="名下客户列表(只读 + 脱敏)")
|
||
|
|
async def list_customers(
|
||
|
|
status: str | None = Query(None, max_length=16),
|
||
|
|
keyword: str | None = Query(None, max_length=64),
|
||
|
|
page: int = Query(1, ge=1),
|
||
|
|
page_size: int = Query(20, ge=1, le=100),
|
||
|
|
user: SysUser = Depends(require_advisor),
|
||
|
|
db: AsyncSession = Depends(get_db),
|
||
|
|
):
|
||
|
|
return success(
|
||
|
|
await customers_service.list_customers(
|
||
|
|
db, user, status=status, keyword=keyword, page=page, page_size=page_size
|
||
|
|
)
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/customers/{customer_id}", summary="客户详情(unmask=true 查看完整手机号并留痕)")
|
||
|
|
async def get_customer(
|
||
|
|
customer_id: int,
|
||
|
|
unmask: bool = Query(False),
|
||
|
|
user: SysUser = Depends(require_advisor),
|
||
|
|
db: AsyncSession = Depends(get_db),
|
||
|
|
):
|
||
|
|
return success(await customers_service.get_customer(db, user, customer_id, unmask=unmask))
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/customers/{customer_id}/holdings", summary="客户持仓(只读)")
|
||
|
|
async def get_holdings(
|
||
|
|
customer_id: int,
|
||
|
|
user: SysUser = Depends(require_advisor),
|
||
|
|
db: AsyncSession = Depends(get_db),
|
||
|
|
):
|
||
|
|
return success(await customers_service.get_customer_holdings(db, user, customer_id))
|
||
|
|
|
||
|
|
|
||
|
|
@router.get("/customers/{customer_id}/reports", summary="客户历史建议报告")
|
||
|
|
async def get_reports(
|
||
|
|
customer_id: int,
|
||
|
|
page: int = Query(1, ge=1),
|
||
|
|
page_size: int = Query(20, ge=1, le=100),
|
||
|
|
user: SysUser = Depends(require_advisor),
|
||
|
|
db: AsyncSession = Depends(get_db),
|
||
|
|
):
|
||
|
|
return success(
|
||
|
|
await customers_service.get_customer_reports(
|
||
|
|
db, user, customer_id, page=page, page_size=page_size
|
||
|
|
)
|
||
|
|
)
|
||
|
|
|
||
|
|
|
||
|
|
@router.post("/customers/{customer_id}/relation", summary="签约/结束服务(工作台唯一写入方)")
|
||
|
|
async def update_relation(
|
||
|
|
customer_id: int,
|
||
|
|
req: RelationReq,
|
||
|
|
user: SysUser = Depends(require_advisor),
|
||
|
|
db: AsyncSession = Depends(get_db),
|
||
|
|
):
|
||
|
|
return success(await customers_service.update_relation(db, user, customer_id, req))
|