f7d86011c1
- 新增 GET /admin/api/ad-revenue-report:展示条数/收益 + 复用金币审计逐条复算做发奖对账 - ad_ecpm/ad_reward/ad_feed_reward 各加 app_env + our_code_id 两列(alembic 迁移) - ecpm-report / feed-reward 接收并落库 app_env/our_code_id;激励发奖按 ad_session_id 回填 - ad_audit 抽出 audit_rows,报表与逐条审计复用同一复算口径 - 组级 matched 改「组内逐条全一致」,避免应发和==实发和的互相抵消掩盖错误 - list_feedbacks 改 offset 分页并返回 total(配合 admin 页码分页) - 反馈正文上限 _CONTENT_MAX 2000→200 - 文档:新增 admin-ad-revenue-report,更新 ecpm/feed-reward/feedback 及对应 db docs Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com> --------- Co-authored-by: OuYingJun1024 <1034284404@qq.com> Reviewed-on: #54 Co-authored-by: ouzhou <ouzhou@wonderable.ai> Co-committed-by: ouzhou <ouzhou@wonderable.ai>
63 lines
2.2 KiB
Python
63 lines
2.2 KiB
Python
"""帮助与反馈 endpoint。
|
|
|
|
路由前缀 `/api/v1/feedback`,需 Bearer 鉴权(反馈绑到登录用户,便于回访)。
|
|
POST / 提交反馈(multipart:content 必填;contact 可选(原型改版后客户端已不再采集);images 可选 ≤6 张)
|
|
|
|
截图复用 [app.core.media] 落盘到 /media/feedback/。
|
|
"""
|
|
from __future__ import annotations
|
|
|
|
import logging
|
|
|
|
from fastapi import APIRouter, File, Form, HTTPException, UploadFile
|
|
|
|
from app.api.deps import CurrentUser, DbSession
|
|
from app.core import media
|
|
from app.repositories import feedback as feedback_repo
|
|
from app.schemas.feedback import FeedbackOut
|
|
|
|
logger = logging.getLogger("shagua.feedback")
|
|
|
|
router = APIRouter(prefix="/api/v1/feedback", tags=["feedback"])
|
|
|
|
_MAX_IMAGES = 6
|
|
_CONTENT_MAX = 200
|
|
_CONTACT_MAX = 128
|
|
|
|
|
|
@router.post("", response_model=FeedbackOut, summary="提交反馈")
|
|
async def submit_feedback(
|
|
user: CurrentUser,
|
|
db: DbSession,
|
|
content: str = Form(...),
|
|
# 原型改版后客户端不再采集联系方式;保留字段以兼容旧端 + 后续可能复用,默认空串。
|
|
contact: str = Form(default=""),
|
|
images: list[UploadFile] = File(default=[]),
|
|
) -> FeedbackOut:
|
|
content = content.strip()
|
|
contact = contact.strip()
|
|
if not content:
|
|
raise HTTPException(status_code=400, detail="反馈内容不能为空")
|
|
if len(content) > _CONTENT_MAX:
|
|
raise HTTPException(status_code=400, detail="反馈内容过长")
|
|
if len(contact) > _CONTACT_MAX:
|
|
raise HTTPException(status_code=400, detail="联系方式过长")
|
|
|
|
files = [f for f in (images or []) if f is not None and f.filename]
|
|
if len(files) > _MAX_IMAGES:
|
|
raise HTTPException(status_code=400, detail=f"最多上传 {_MAX_IMAGES} 张图片")
|
|
|
|
urls: list[str] = []
|
|
for f in files:
|
|
data = await f.read()
|
|
try:
|
|
urls.append(media.save_feedback_image(user.id, data))
|
|
except media.MediaError as e:
|
|
raise HTTPException(status_code=400, detail=str(e)) from e
|
|
|
|
fb = feedback_repo.create_feedback(
|
|
db, user_id=user.id, content=content, contact=contact, images=urls,
|
|
)
|
|
logger.info("feedback id=%d user_id=%d images=%d", fb.id, user.id, len(urls))
|
|
return FeedbackOut.model_validate(fb)
|