27f76918b2
本 PR 汇合三块运营后台改动(原 #50 仅含其中「加固」一块,已并入本 PR 并关闭)。 ## 1. review 加固 (436b2a3) - 超管防自锁:降级/禁用最后一个 active super_admin 前校验,杜绝零超管死局 - 时间筛选统一 tz-aware(列为 timestamptz),比较绝对时刻、不依赖 DB 会话时区 - 上报审核 / 调余额(set·扣减)加行锁,防并发/连点重复发钱 - ad_audit 复算排序补 id 次级键;health-check 限 finance;调账/拒绝 reason 去空白校验 ## 2. 反馈改版 (5a18dbb) - contact 可选、截图≤6;admin 反馈列表筛选/排序;admin·wallet 接口调整 + docs ## 3. 列表页码分页 (1a7a624) - CursorPage 加 total;新增 offset_paginate(count 与分页同源) - 上报/审计日志从 id 游标改 offset 分页(支持跳页) - 用户 / 提现 / 上报 / 审计日志 四页接入页码分页 测试:admin 套件 47 passed。前端配套改动见 shaguabijia-admin-web。 --------- Co-authored-by: OuYingJun1024 <1034284404@qq.com> Reviewed-on: #51 Co-authored-by: ouzhou <ouzhou@wonderable.ai> Co-committed-by: ouzhou <ouzhou@wonderable.ai>
72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
"""admin 反馈工单:列表(读,支持 状态/用户ID/内容/时间 筛选 + 排序)+ 标记已处理(写,带审计)。"""
|
|
from __future__ import annotations
|
|
|
|
from datetime import datetime
|
|
from typing import Annotated
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, Query, Request
|
|
|
|
from app.admin.audit import write_audit
|
|
from app.admin.deps import AdminDb, get_client_ip, get_current_admin, require_role
|
|
from app.admin.repositories import mutations, queries
|
|
from app.admin.schemas.common import CursorPage, OkResponse
|
|
from app.admin.schemas.feedback import FeedbackOut
|
|
from app.models.admin import AdminUser
|
|
from app.models.feedback import Feedback
|
|
|
|
router = APIRouter(
|
|
prefix="/admin/api/feedbacks",
|
|
tags=["admin-feedback"],
|
|
dependencies=[Depends(get_current_admin)],
|
|
)
|
|
|
|
|
|
@router.get("", response_model=CursorPage[FeedbackOut], summary="反馈工单列表")
|
|
def list_feedbacks(
|
|
db: AdminDb,
|
|
status: Annotated[str | None, Query()] = None,
|
|
user_id: Annotated[int | None, Query()] = None,
|
|
content: Annotated[str | None, Query(max_length=100)] = None,
|
|
created_from: Annotated[datetime | None, Query()] = None,
|
|
created_to: Annotated[datetime | None, Query()] = None,
|
|
sort_by: Annotated[str, Query(pattern="^(id|created_at)$")] = "id",
|
|
sort_order: Annotated[str, Query(pattern="^(asc|desc)$")] = "desc",
|
|
limit: Annotated[int, Query(ge=1, le=100)] = 20,
|
|
cursor: Annotated[int | None, Query()] = None,
|
|
) -> CursorPage[FeedbackOut]:
|
|
items, next_cursor = queries.list_feedbacks(
|
|
db,
|
|
status=status,
|
|
user_id=user_id,
|
|
content=content,
|
|
created_from=created_from,
|
|
created_to=created_to,
|
|
sort_by=sort_by,
|
|
sort_order=sort_order,
|
|
limit=limit,
|
|
cursor=cursor,
|
|
)
|
|
return CursorPage(
|
|
items=[FeedbackOut.model_validate(f) for f in items], next_cursor=next_cursor,
|
|
)
|
|
|
|
|
|
@router.post("/{feedback_id}/handle", response_model=OkResponse, summary="标记反馈已处理")
|
|
def handle_feedback(
|
|
feedback_id: int,
|
|
request: Request,
|
|
admin: Annotated[AdminUser, Depends(require_role("operator"))],
|
|
db: AdminDb,
|
|
) -> OkResponse:
|
|
fb = db.get(Feedback, feedback_id)
|
|
if fb is None:
|
|
raise HTTPException(status_code=404, detail="反馈不存在")
|
|
before = fb.status
|
|
mutations.update_feedback_status(db, fb, status="handled", commit=False)
|
|
write_audit(
|
|
db, admin, action="feedback.handle", target_type="feedback", target_id=feedback_id,
|
|
detail={"before": before, "after": "handled"}, ip=get_client_ip(request), commit=False,
|
|
)
|
|
db.commit()
|
|
return OkResponse()
|