📊 Budget Alerts 预算预警
预算预警规则管理,当指定账单的某类目支出达到设定阈值时触发通知。预警实时计算当前类目已支出金额(从 transactions 汇总)。
接口列表
1. 查询预算预警列表
GET /api/admin/budget-alerts
获取所有预算预警规则列表,含实时计算的使用进度。
认证:需要 Bearer Token(Admin 权限)
查询参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| bill_id | integer | 选填 | 按账单 ID 精确筛选 |
| is_active | boolean | 选填 | 按启用状态筛选(true / false) |
| search | string | 选填 | 模糊搜索:账单名 / 类目名 / 用户昵称 |
响应:数组
[{
"id": 1,
"budget_id": 10,
"user_id": 5,
"is_active": 1,
"threshold_pct": 80,
"last_triggered_at": "2026-04-15T08:00:00.000Z",
"created_at": "2026-04-01T10:00:00.000Z",
"bill_name": "家庭账单",
"category_name": "餐饮",
"user_nickname": "张三",
"user_phone": "13800138000",
"budget_amount": 5000,
"spent": 4230,
"tx_count": 12
}]
说明:spent 和 tx_count 为实时从 transactions 表汇总的结果,不存储在 budget_alerts 表中。
2. 更新预算预警规则
PUT /api/admin/budget-alerts/:id
更新指定预警规则的启用状态或阈值。
认证:需要 Bearer Token(Admin 权限)
路径参数:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| id | integer | 必填 | 预警规则 ID |
请求体:
| 参数 | 类型 | 必填 | 说明 |
|---|---|---|---|
| is_active | integer (0/1) | 必填 | 是否启用(1=启用,0=停用) |
| threshold_pct | integer | 选填 | 触发阈值百分比(1-100) |
响应:
{"message": "预警规则已更新", "alert": {...}}