guzhi/.trae/documents/修复后台管理接口与统一上传接口的改造方案.md
邹方成 f536178428 feat: 新增交易记录管理功能与统一上传接口
feat(交易记录): 新增交易记录管理页面与API接口
feat(上传): 添加统一上传接口支持自动识别文件类型
feat(用户管理): 为用户模型添加备注字段并更新相关接口
feat(邮件): 实现SMTP邮件发送功能并添加测试脚本
feat(短信): 增强短信服务配置灵活性与日志记录

fix(发票): 修复发票列表时间筛选功能
fix(nginx): 调整上传大小限制与超时配置

docs: 添加多个功能模块的说明文档
docs(估值): 补充估值计算流程与API提交数据说明

chore: 更新依赖与Docker镜像版本
2025-11-20 20:53:09 +08:00

99 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 背景与确认
* 备注为“用户维度”,按指示在 `app_user` 增加备注字段并贯通列表与配额调整流程。
* 操作记录需补充时间字段以便前端展示。
* 交易管理列表需支持“提交时间区间、状态、手机号、公司名称、公司税号”搜索。
* 上传接口从两个合并为一个,统一入参与返回结构。
## 改动总览
* 模型:为 `AppUser` 增加 `notes: CharField(256, null=True)`
* 接口:
* `admin-App用户管理`:列表返回 `notes`;配额调整将 `remark` 同步写入 `AppUser.notes`;配额日志返回 `created_at`
* `交易管理`:对公转账列表增加“提交时间区间”筛选。
* `上传`:新增统一上传接口 `/api/v1/upload/upload`(或 `/api/v1/upload`),老接口内部复用统一实现保留兼容。
* 迁移:使用现有 Aerich 流程生成并升级迁移。
## 详细实施
### 1. App 用户备注(用户维度)
* 文件:`app/models/user.py`
*`AppUser` 增加字段 `notes = fields.CharField(max_length=256, null=True, description="备注")`
* 文件:`app/api/v1/app_users/admin_manage.py`
* `/list`:返回 `notes = u.notes or ""`
* `/quota`:接收 `remark` 后,除写入 `AppUserQuotaLog`
### 2. 操作记录时间字段
* 文件:`app/schemas/app_user.py`
* `AppUserQuotaLogOut` 增加 `created_at: str`
* 文件:`app/api/v1/app_users/admin_manage.py`
* `/ {user_id}/quota-logs`:为每条日志填充 `created_at = r.created_at.isoformat()` 返回。
### 3. 交易管理列表搜索增强
* 文件:`app/controllers/invoice.py`
* `list_receipts(...)`:增加对 `PaymentReceipt.created_at` 的区间筛选:
* 支持 `created_at`(数组,毫秒时间戳)或 `submitted_start/submitted_end`ISO 或毫秒)。
* 文件:`app/api/v1/transactions/transactions.py`
* `list_receipts`:路由签名增加上述可选查询参数并传入控制器。
### 4. 上传接口统一
* 文件:`app/controllers/upload.py`
* 新增 `upload_any(file: UploadFile)`
* `image/*` 保存到 `static/images`;其他受支持类型保存到 `static/files`
* 返回 `{ url, filename, content_type }`
* 文件:`app/api/v1/upload/upload.py`
* 新增 `/upload`(或 `/upload/upload` 按路由前缀安排):统一入口;
*`/image``/file` 内部调用 `upload_any` 保持兼容。
* 文件:`app/schemas/upload.py`
* 若需要,补充统一响应模型,或复用 `FileUploadResponse`(包含 `content_type`)。
## 迁移与兼容
* Aerich`init_db` 已集成迁移流程,生成迁移后执行 `upgrade`,自动创建 `app_user.notes` 列。
* 旧接口兼容:上传旧路径保留;交易列表与日志返回仅新增字段,不影响既有消费逻辑。
## 验证与测试
* 备注更新:调用 `/app-user-admin/quota``remark`,再查 `/app-user-admin/list` 验证 `notes`;查 `/app-user-admin/{id}/quota-logs` 验证 `created_at` 存在。
* 交易筛选:造两条不同日期的凭证,分别用时间区间查询命中与不命中。
* 上传统一:上传 PNG 与 PDF 验证保存路径与返回结构;旧接口路由到统一实现成功。
## 交付
* 提交代码与迁移;更新接口文档的路由说明与字段变化;前端无需大改即可使用新返回的 `notes` 与日志 `created_at`,交易列表按“凭证时间”筛选可用。