refactor(listing): 卖家发布定价改用整数分与基点

This commit is contained in:
yml2213
2026-10-30 14:49:33 +08:00
parent 37e1980d2d
commit ce93f1636d
18 changed files with 1492 additions and 343 deletions
@@ -0,0 +1,60 @@
# 卖家发布定价整数分与基点验收(第 2 步)
> 日期:2026-10-30
> 范围:卖家发布定价从 float64 元/比例迁移为 int64 分 + 整数基点,保留旧字段双读。
## 1. 规范字段
发布配置新增可选字段,旧 float 字段与 JSON 名保持不变:
- `price_cent`
- `base_amount_cent`
- `amount_per_item_cent`
- `ratio_bps`
- `missing_penalty_bps`
- `correction_bps`
- `markup_amount_cent`
- `ratio_subtract_bps`
`price_breakdown` 新增:
- `seller_reference_ratio_bps`、`seller_ratio_bps`、`buyer_ratio_bps`
- `seller_coin_base_price_cent`、`seller_total_price_cent`、`consumable_price_cent`
- `buyer_coin_base_price_cent`、`buyer_total_price_cent`、`platform_markup_amount_cent`
旧字段继续写入,由规范字段派生,历史商品与旧前端仍可读取。
## 2. 整数公式
- 纯币基础价:`HafCoinAmount * 100 / sellerRatioBPS`,向下取整。
- 卖家总价:`sellerCoinBasePriceCent + consumablePriceCent`。
- 比例修正:`sellerRatioBPS - ratioSubtractBPS`,买家基础价不低于卖家基础价。
- 固定加价:`sellerCoinBasePriceCent + markupAmountCent`。
- 买家总价:`buyerCoinBasePriceCent + consumablePriceCent`。
- 买家展示比例:`HafCoinAmount * 100 / buyerCoinBasePriceCent`,仅作展示。
- 平台加价:`buyerTotalPriceCent - anchorTotalPriceCent`。
配置优先读 `*_cent/*_bps`;缺失时只在配置边界把旧 float 换算一次,后续计算全部整数。
## 3. 前端
- `frontend/src/shared/utils/pricing.ts` 改为整数分/基点。
- 卖家表单直接提交整数 `price_cent`、`deposit_amount_cent`。
- 卖家列表/详情优先读新 cent/bps 字段,缺失回退旧字段。
- 旧配置、历史 `asset_summary` 继续兼容。
## 4. 验证
| 检查 | 结果 |
|---|---|
| `go test ./pkg/money ./internal/modules/listing ./internal/modules/systemconfig ./internal/modules/order ./internal/modules/wallet` | 通过 |
| `cd frontend && npx tsc --noEmit` | 通过 |
| `cd frontend && npm run build` | 通过,主入口 519.27 kB / gzip 167.34 kB |
| `GET /api/listing-publish-options` | 200 |
| `GET /api/listing-sale-price-config` | 200 |
| `GET /api/seller/listings` 未带令牌 | 401,符合鉴权预期 |
## 5. 风险
- 整数向下取整会使部分历史价格出现分级差异,交易金额以 `*_cent` 为准。
- `buyer_ratio_bps` 由整数价格反推,可能与名义比例相差数个 bps。
- 外部上传调价在未配置新 cent/bps 规则时仍走既有 float 路径;卖家发布主链路已整数化。
- 新增直接写旧价格字段的路径时,必须同步规范字段。