refactor(money): 统一金额分为纯整数工具
This commit is contained in:
@@ -0,0 +1,35 @@
|
||||
# 金额分与精度统一(第 1 步)验收
|
||||
|
||||
> 日期:2026-10-30
|
||||
> 范围:`backend/pkg/money` 去浮点、精确分解析与格式化。
|
||||
|
||||
## 1. 本次完成
|
||||
|
||||
- `backend/pkg/money/format.go`
|
||||
- 新增 `ParseYuan(string) (int64, error)`:按字符串精确解析元到分,不经过 `float64`。
|
||||
- `Format(cent)` 改为精确两位小数,整数除法和余数补零,不再四舍五入到角。
|
||||
- `FormatWithSymbol` 复用精确格式化。
|
||||
- 保留 `MinCent`、`MaxCent`。
|
||||
- 移除 `Round`、`ToCent`、`ToDisplayYuan`、`Min/Max` 等浮点 API。
|
||||
- `backend/pkg/money/format_test.go`
|
||||
- 覆盖整数、一位/两位小数、负数、非法输入。
|
||||
- 覆盖精确格式化与末位零保留。
|
||||
- 历史链路兼容
|
||||
- 钱包移除未使用的 `roundWalletMoney` 浮点封装。
|
||||
- 订单与商品外部上传/审核链路保留局部角精度兼容函数,不再依赖 `money` 包浮点 API;后续按业务链路继续迁移。
|
||||
|
||||
## 2. 验证
|
||||
|
||||
| 检查 | 结果 |
|
||||
|---|---|
|
||||
| `go build ./...` | 通过 |
|
||||
| `go test ./pkg/money` | 通过 |
|
||||
| `go test ./internal/modules/wallet` | 通过 |
|
||||
| `go test ./internal/modules/order` | 通过 |
|
||||
| `go test ./internal/modules/listing` | 通过 |
|
||||
|
||||
## 3. 边界
|
||||
|
||||
- 第 1 步只统一了金额工具包;订单历史链路仍保留 0.1 元兼容逻辑,避免一次性改变结算结果。
|
||||
- 第 2 步(发布定价整数分/基点、旧字段双读、前端同步)尚未包含在本次提交中。
|
||||
- `Format` 现在输出两位小数,历史消息中依赖一位小数的文案会显示为 `12.30` 这类格式,这是有意修正。
|
||||
Reference in New Issue
Block a user