hl-api-changelog/changelogs/2026-04/2026-04-19_early-bird-vo-align.md
2026-04-19 03:28:11 +08:00

70 行
2.3 KiB
Markdown

此文件含有模棱两可的 Unicode 字符

此文件含有可能会与其他字符混淆的 Unicode 字符。 如果您是想特意这样的,可以安全地忽略该警告。 使用 Escape 按钮显示他们。

# fix(order-v2): 早鸟优惠接口字段名对齐前端(保存不再报"不能为空"
> **服务**: hl-order-service-v2
> **PR**: #911
> **Issue**: #910
> **日期**: 2026-04-19
> **前端是否需要改动**: **无需改动**(后端 VO 字段名已对齐前端现有调用)
---
## 现象
早鸟优惠计划管理页(`/order/early-bird`)新增/编辑计划填完所有字段点提交,后端报:
```
name: 计划名称不能为空; discountPerPerson: 优惠金额不能为空
```
## 根因
后端 VO 字段名和前端、Entity、DB 列三方都不一致:
| UI 标签 | 前端字段 | 旧后端 VO | Entity/DB |
|--------|---------|-----------|-----------|
| 计划名称 | `planName` | `name` ❌ | `plan_name` |
| 优惠金额 | `discountAmount` | `discountPerPerson` ❌ | `discount_amount` |
| 备注 | `remark` | `description` ❌ | `remark` |
**只有后端 VO 是"异类"**,前端、Entity、DB 都用 `planName/discountAmount/remark`
## 修复
### 受影响接口(请求/响应结构变化)
| 方法 | 路径 | 变更 |
|------|------|------|
| POST | `/admin/order/early-bird` | Request body 字段改名 |
| PUT | `/admin/order/early-bird/{id}` | 同上 |
| GET | `/admin/order/early-bird/{id}` | Response body 字段改名 |
| GET | `/admin/order/early-bird` | Response records 字段改名 |
### 字段映射
| 旧字段(已废弃)| 新字段(正在用) |
|---------------|----------------|
| `name` | `planName` |
| `discountPerPerson` | `discountAmount` |
| `description` | `remark` |
| `productType`Request+Response | **已删除**0 调用僵尸字段) |
## 前端行动项
**无需改动**。前端本来就传 `planName/discountAmount/remark`(后端之前用错字段名才导致 bug
## 测试环境验证
```bash
POST /admin/order/early-bird
body: {"planName":"默认早鸟优惠","discountAmount":100.00,"minPeople":1,"startDate":"2026-04-01","endDate":"2026-05-31","remark":"测试"}
响应:
{"code":200,"data":{"planId":"...","planName":"默认早鸟优惠","discountAmount":100.0,"remark":"测试",...}}
```
反向验证(不传 planName
```
错误消息: "planName: 计划名称不能为空"(字段名正确反映前端字段)
```
## 相关
- 后续跟进:列表接口 `GET /admin/order/early-bird` 有一个独立的 400 问题Issue 已建,与本 PR 无关)