1
0
forked from erp-dev/erp

feat: big

This commit is contained in:
2026-07-01 11:51:13 +08:00
parent 7c9b77afb0
commit 5170700234
28 changed files with 933 additions and 37 deletions

View File

@@ -2,6 +2,29 @@
本文档面向前端,描述 `cost` 成本模块的 API。
## 2026-06-30 前端变更摘要
本次支出明细接口兼容新增“倍数型支出”字段。支出类目接口无变化,按类目汇总接口的响应结构无变化,但汇总金额仍来自 `amount`
**新增字段(支出明细列表、详情、创建、修改均涉及):**
| 字段 | 类型 | 位置 | 说明 |
|------|------|------|------|
| `unit_amount` | decimal string / null | request + response | 单价 / 基数金额,如临时工日薪。响应中为字符串,如 `"200.0000"` |
| `quantity` | decimal string / null | request + response | 数量 / 倍数,如 `"3.0000"` |
| `unit_name` | string | request + response | 单位名称,如 `人天``小时``件`,可为空字符串 |
**兼容规则:**
- 普通支出:继续传 `amount`,不传 `unit_amount``quantity` 即可。
- 倍数型支出:传 `unit_amount + quantity``amount` 可不传;后端保存时计算 `amount = unit_amount * quantity`
- 如果同时传 `amount``unit_amount + quantity`,后端以公式计算结果为准,返回的 `amount` 是计算后的最终金额。
- `unit_amount``quantity` 必须同时填写或同时为 `null`/不传;只传一个会返回 `400`
- 将倍数型支出改回普通支出时PUT 需要同时传:`amount``unit_amount: null``quantity: null``unit_name` 可传空字符串。
---
## 基本约定
- Base URL: `/api/v2`
@@ -153,6 +176,9 @@ GET /api/v2/cost-entries/
"category_id": 1,
"category_name": "电费",
"amount": "350.00",
"unit_amount": null,
"quantity": null,
"unit_name": "",
"occurred_at": "2026-06-01",
"operator_id": 12,
"image1": "",
@@ -170,7 +196,10 @@ GET /api/v2/cost-entries/
| 字段 | 类型 | 说明 |
|------|------|------|
| `amount` | string | 金额Decimal 转字符串,前端展示时注意格式化) |
| `amount` | string | 最终支出金额 / 统计金额Decimal 转字符串,前端展示时注意格式化) |
| `unit_amount` | string/null | 单价 / 基数金额;普通支出为 `null` |
| `quantity` | string/null | 数量 / 倍数;普通支出为 `null` |
| `unit_name` | string | 单位名称;普通支出为空字符串 |
| `occurred_at` | string | 发生日期,`YYYY-MM-DD` |
| `operator_id` | int | 经办人 ID自动从当前登录用户获取 |
| `image1` | string | 凭证图片 URL七牛云 CDN无则为空字符串 |
@@ -191,7 +220,10 @@ Content-Type: `multipart/form-data`(支持图片上传)或 `application/json
| 字段 | 类型 | 必填 | 说明 |
|------|------|------|------|
| `category_id` | int | **是** | 支出类目 ID |
| `amount` | decimal | **是** | 金额,如 `"350.00"` |
| `amount` | decimal | 条件必填 | 普通支出必填;倍数型支出可不传。最终统计金额,如 `"350.00"` |
| `unit_amount` | decimal | 否 | **新增**。单价 / 基数金额;和 `quantity` 必须同时填写或同时为空 |
| `quantity` | decimal | 否 | **新增**。数量 / 倍数;和 `unit_amount` 必须同时填写或同时为空 |
| `unit_name` | string | 否 | **新增**。单位名称,如 `人天``小时``件` |
| `occurred_at` | date | **是** | 发生日期,`YYYY-MM-DD` |
| `image1` | file | 否 | 凭证图片 |
| `image2` | file | 否 | 备用凭证图片 |
@@ -199,7 +231,7 @@ Content-Type: `multipart/form-data`(支持图片上传)或 `application/json
| `source_id` | string | 否 | 来源记录 ID |
| `remarks` | string | 否 | 备注 |
请求示例JSON
请求示例JSON,普通支出
```json
{
@@ -210,6 +242,21 @@ Content-Type: `multipart/form-data`(支持图片上传)或 `application/json
}
```
请求示例JSON**新增:倍数型支出**
```json
{
"category_id": 2,
"unit_amount": "200.00",
"quantity": "3",
"unit_name": "人天",
"occurred_at": "2026-06-01",
"remarks": "临时工 3 人天"
}
```
倍数型支出成功响应中的 `amount` 会是后端计算后的最终金额,例如 `"600.00"`
成功响应 `201`:返回创建的支出明细对象。
错误响应 `400`:校验失败。
@@ -238,7 +285,10 @@ Content-Type: `multipart/form-data` 或 `application/json`
| 字段 | 类型 | 说明 |
|------|------|------|
| `category_id` | int | 切换类目 |
| `amount` | decimal | 金额 |
| `amount` | decimal/null | 普通支出金额;倍数型支出若公式字段存在,会被后端公式结果覆盖 |
| `unit_amount` | decimal/null | **新增**。单价 / 基数金额;传 `null` 可清除公式字段 |
| `quantity` | decimal/null | **新增**。数量 / 倍数;传 `null` 可清除公式字段 |
| `unit_name` | string | **新增**。单位名称;可传空字符串清空 |
| `occurred_at` | date | 发生日期 |
| `image1` | file | 凭证图片 |
| `image2` | file | 备用凭证图片 |
@@ -248,6 +298,27 @@ Content-Type: `multipart/form-data` 或 `application/json`
成功响应 `200`:返回更新后的支出明细对象。
修改倍数型支出数量示例:
```json
{
"quantity": "4"
}
```
后端会按已有 `unit_amount * quantity` 重算并返回新的 `amount`
将倍数型支出改回普通支出示例:
```json
{
"amount": "550.00",
"unit_amount": null,
"quantity": null,
"unit_name": ""
}
```
### 2.5 删除支出明细
```