0e42e96ddb
新增 admin 模块接口文档(auth login/me、admins CRUD、audit-logs、feedback 处理、stats 概览、user coins/detail/status、wallet 流水、withdraw 对账/刷新/列表) + admin_user/admin_audit_log 两张表文档,更新 api/database README 索引。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: OuYingJun1024 <1034284404@qq.com> Reviewed-on: #12 Co-authored-by: ouzhou <ouzhou@wonderable.ai> Co-committed-by: ouzhou <ouzhou@wonderable.ai>
30 lines
1.8 KiB
Markdown
30 lines
1.8 KiB
Markdown
# POST /admin/api/users/{user_id}/coins — 手动增减金币(带审计)
|
||
|
||
> 所属:Admin·用户 组(前缀 `/admin/api/users`) | 鉴权:Bearer admin_token(角色:`finance`,`super_admin` 恒通过) | [← 返回 API 索引](./README.md)
|
||
|
||
## 入参
|
||
- 路径:`user_id`(int)
|
||
- **application/json**:
|
||
| 字段 | 类型 | 必填 | 说明 |
|
||
|---|---|---|---|
|
||
| `amount` | int | ✓ | 金币变动(个数):正=增加,负=扣减;不可为 0 |
|
||
| `reason` | string | ✓ | 操作原因,1–128 字(必填,入审计与流水备注) |
|
||
|
||
## 出参
|
||
响应 `200`:`OkResponse` = `{ "ok": true }`
|
||
|
||
## 错误码
|
||
- `400` `amount == 0`(`detail: "amount 不能为 0"`);或负数扣减后余额会变负(`detail: "扣减后金币为负(当前余额 N)"`)
|
||
- `401` 未带/无效/过期 admin token、管理员被禁用(头带 `WWW-Authenticate: Bearer`)
|
||
- `403` 角色不足(需 `finance` 或 `super_admin`)
|
||
- `404` 用户不存在(`detail: "用户不存在"`)
|
||
- `422` 缺 `amount`/`reason`、`reason` 长度不在 1–128、字段类型不合法 / `user_id` 非整数
|
||
|
||
## 说明
|
||
- 金币 = 个数(非现金);本接口只动金币余额,不涉及现金(`*_cents`)。
|
||
- 扣减保护:`amount < 0` 时若扣减后金币余额 < 0 直接拒绝(运营误操作保护)。
|
||
- 金币变动写流水 [coin_transaction](../database/coin_transaction.md):`biz_type` 增加为 `admin_grant`、扣减为 `admin_deduct`,`remark = admin:<reason>`(截断至 128 字)。
|
||
- 写操作记审计 [admin_audit_log](../database/admin_audit_log.md):`action = user.coins.grant`,`target_type = user`,`target_id = user_id`,`detail = {amount, balance_after, reason}`,并记录操作 IP。
|
||
- 金币变动 + 审计在同一事务原子提交(改钱必留痕)。
|
||
- 关联用户表 [user](../database/user.md);金币账户 [coin_account](../database/coin_account.md);金币流水 [coin_transaction](../database/coin_transaction.md)。
|