feat: 新增账号状态管理、头像功能与报表工具,完善账号系统

新增账号状态字段与停用校验,支持账号头像上传管理,新增物料收发汇总表合并工具,优化银行卡检查脚本,新增ERP登录复用模块,重构账号数据库迁移与管理接口
This commit is contained in:
2026-09-16 00:25:13 +08:00
parent 0ab43d0ed8
commit 813bee743b
27 changed files with 2533 additions and 268 deletions
+50 -5
View File
@@ -1,11 +1,12 @@
# -*- coding: utf-8 -*-
"""webhost 宿主「管理台基础」路由:统一账户登录 / 当前账号 / 登出 / 改密 / 概览。"""
"""webhost 宿主「管理台基础」路由:统一账户登录 / 当前账号 / 登出 / 改密 / 概览 / 头像代理。"""
from __future__ import annotations
import time
import uuid
from urllib.parse import quote
from fastapi import APIRouter, HTTPException, Request, Response
from fastapi import APIRouter, File, HTTPException, Request, Response, UploadFile
from pydantic import BaseModel
from webhost.backend import config
@@ -37,14 +38,14 @@ def admin_me(request: Request) -> dict:
"""
account = _sess_account(request)
if not account:
return {"account": "", "is_admin": False, "dept": "", "nickname": ""}
return {"account": "", "is_admin": False, "dept": "", "nickname": "", "avatar": ""}
try:
r = _cp_call("GET", "/api/admin/me", headers=_cp_headers(request))
if r.get("account") == account:
return r
except HTTPException:
pass
return {"account": account, "is_admin": False, "dept": "", "nickname": ""}
return {"account": account, "is_admin": False, "dept": "", "nickname": "", "avatar": ""}
@router.post("/api/admin/login")
@@ -105,4 +106,48 @@ def admin_password(b: _PwdIn, request: Request) -> dict:
@router.get("/api/admin/overview")
def admin_overview(request: Request) -> dict:
"""管理台一次性拉取:全部插件 + 账号 + 管理员。管理入口已在中心机控制面,底座侧置空兜底。"""
return {"plugins": [], "accounts": [], "admins": []}
return {"plugins": [], "accounts": [], "admins": []}
@router.get("/api/avatar/{account}")
def avatar_get(account: str) -> Response:
"""代理中心机头像读取(webhost 前端 img 直接引用;未设置头像返回 404)。"""
if not config.CONTROLPLANE_URL:
raise HTTPException(503, "统一后端未配置(CONTROLPLANE_URL)")
import requests
r = requests.get(f"{config.CONTROLPLANE_URL}/api/avatar/{quote(account)}", timeout=10)
if r.status_code != 200:
raise HTTPException(r.status_code, "头像不存在")
return Response(content=r.content,
media_type=r.headers.get("content-type", "application/octet-stream"))
@router.post("/api/avatar")
def avatar_upload(file: UploadFile = File(...), request: Request = None) -> dict:
"""上传当前登录账号的头像(自服务,账号取本机会话),代理到中心机。"""
if request is None:
raise HTTPException(500, "missing request")
account = _sess_account(request)
if not account:
raise HTTPException(401, "未登录")
if not config.CONTROLPLANE_URL:
raise HTTPException(503, "统一后端未配置(CONTROLPLANE_URL)")
import requests as _rq
data = file.file.read()
if not data:
raise HTTPException(400, "头像文件为空")
resp = _rq.post(
f"{config.CONTROLPLANE_URL}/api/admin/avatar?account={quote(account)}",
headers=_cp_headers(request),
files={"file": (file.filename or f"{account}.png", data,
file.content_type or "application/octet-stream")},
timeout=30)
try:
body = resp.json()
except ValueError:
body = {"detail": resp.text[:300]}
if resp.status_code >= 400:
raise HTTPException(resp.status_code, body.get("detail", f"中心机 {resp.status_code}"))
return body