815cbf9d8c
- 更新 .gitignore:全面覆盖环境变量、数据库、日志、缓存、上传文件 - 移除误跟踪的 server/venv/、crm_data.db、.env 文件 - 新增 server/.env.example 模板 - 新增合同管理、利润核算、AI教练等功能模块 - 新增 Playwright e2e 测试套件 - 前后端多项功能升级和 bug 修复
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
"""
|
|
利润核算路由 —— /api/profit
|
|
"""
|
|
from __future__ import annotations
|
|
import uuid
|
|
from fastapi import APIRouter, Depends, Query
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
from app.api.deps import get_current_user, get_current_company_id
|
|
from app.db.database import get_db
|
|
from app.schemas.auth import CurrentUserPayload
|
|
from app.schemas.response import ok
|
|
from app.services import profit_service as svc
|
|
|
|
router = APIRouter(prefix="/profit", tags=["利润核算"])
|
|
|
|
|
|
@router.get("/report", summary="利润报表(订单维度)")
|
|
async def profit_report(
|
|
start_date: str | None = Query(None, description="起始日期 YYYY-MM-DD"),
|
|
end_date: str | None = Query(None, description="结束日期 YYYY-MM-DD"),
|
|
db: AsyncSession = Depends(get_db),
|
|
current_user: CurrentUserPayload = Depends(get_current_user),
|
|
company_id: uuid.UUID = Depends(get_current_company_id),
|
|
) -> dict:
|
|
result = await svc.get_profit_report(db, company_id, start_date, end_date)
|
|
return ok(data=result)
|
|
|
|
|
|
@router.post("/snapshot/{order_id}", summary="为订单锚定成本快照")
|
|
async def snapshot_costs(
|
|
order_id: uuid.UUID,
|
|
db: AsyncSession = Depends(get_db),
|
|
current_user: CurrentUserPayload = Depends(get_current_user),
|
|
company_id: uuid.UUID = Depends(get_current_company_id),
|
|
) -> dict:
|
|
result = await svc.snapshot_order_item_costs(db, order_id, company_id)
|
|
return ok(data=result, message=f"已为 {len(result)} 项明细锚定成本")
|