Files
huang 2b3a9cb33f
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 7m19s
feat: 新增套餐使用记录实付金额快照字段 paid_amount
- 新增迁移 000129:tb_package_usage 添加 paid_amount BIGINT 字段,存量数据通过 JOIN tb_order 回填
- PackageUsage Model 新增 PaidAmount *int64 字段
- 4 个写入点(order service 主套餐/加油包、auto_purchase 主套餐/加油包)赋值 order.ActualPaidAmount
- AssetPackageResponse DTO 新增 paid_amount 字段
- GetCurrentPackage / GetPackages 填充 paid_amount,接口直接返回购买价格无需 JOIN 订单表
2026-04-18 10:19:21 +08:00

33 lines
2.6 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
## 1. 数据库迁移
- [x] 1.1 新建迁移文件 `migrations/000129_add_paid_amount_to_package_usage.up.sql``ALTER TABLE tb_package_usage ADD COLUMN IF NOT EXISTS paid_amount BIGINT`,添加字段注释,执行存量数据回填(`UPDATE ... FROM tb_order WHERE order_id != 0`
- [x] 1.2 新建迁移文件 `migrations/000129_add_paid_amount_to_package_usage.down.sql``ALTER TABLE tb_package_usage DROP COLUMN IF EXISTS paid_amount`
- [x] 1.3 执行迁移并通过 PostgreSQL MCP 验证字段已添加,存量数据已回填
## 2. Model 层
- [x] 2.1 在 `internal/model/package.go``PackageUsage` 结构体中新增字段 `PaidAmount *int64`,添加 GORM tag `gorm:"column:paid_amount;type:bigint;comment:购买实付金额快照从订单复制无订单或线下支付时为null"` 及 JSON tag `json:"paid_amount,omitempty"`
## 3. 套餐激活写入点
- [x] 3.1 `internal/service/order/service.go` `activateMainPackage()`:在初始化 `usage := &model.PackageUsage{...}` 中新增 `PaidAmount: order.ActualPaidAmount`
- [x] 3.2 `internal/service/order/service.go` `activateAddonPackage()`:在初始化 `usage := &model.PackageUsage{...}` 中新增 `PaidAmount: order.ActualPaidAmount`
- [x] 3.3 `internal/task/auto_purchase.go` `activateMainPackage()`line ~507在初始化 `usage := &model.PackageUsage{...}` 中新增 `PaidAmount: order.ActualPaidAmount`
- [x] 3.4 `internal/task/auto_purchase.go` `activateAddonPackage()`line ~578在初始化 `usage := &model.PackageUsage{...}` 中新增 `PaidAmount: order.ActualPaidAmount`
## 4. DTO 层
- [x] 4.1 `internal/model/dto/asset_dto.go``AssetPackageResponse` 结构体新增字段 `PaidAmount *int64`,添加 JSON tag `json:"paid_amount,omitempty"`description tag `description:"购买实付金额(分),线下支付或无订单分配时为空"`
## 5. Asset Service 查询填充
- [x] 5.1 `internal/service/asset/service.go` `GetCurrentPackage()` 方法:在构建 `AssetPackageResponse` 时填充 `PaidAmount: usage.PaidAmount`
- [x] 5.2 `internal/service/asset/service.go` `GetPackages()` 方法:在构建每条 `AssetPackageResponse` 时填充 `PaidAmount: usage.PaidAmount`
## 6. 验证
- [x] 6.1 通过 PostgreSQL MCP 验证新套餐记录的 `paid_amount` 字段已正确写入(分别验证钱包支付和线下支付场景)
- [ ] 6.2 调用 `GET /api/admin/assets/{id}/current-package` 验证响应包含 `paid_amount` 字段
- [ ] 6.3 调用 `GET /api/admin/assets/{id}/packages` 验证响应 items 中包含 `paid_amount` 字段
- [x] 6.4 运行 `go build ./...` 确认无编译错误