Files
huang 91c9bbfeb8
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 4m35s
feat: 实现账号与佣金管理模块
新增功能:
- 店铺佣金查询:店铺佣金统计、店铺佣金记录列表、店铺提现记录
- 佣金提现审批:提现申请列表、审批通过、审批拒绝
- 提现配置管理:配置列表、新增配置、获取当前生效配置
- 企业管理:企业列表、创建、更新、删除、获取详情
- 企业卡授权:授权列表、批量授权、批量取消授权、统计
- 客户账号管理:账号列表、创建、更新状态、重置密码
- 我的佣金:佣金统计、佣金记录、提现申请、提现记录

数据库变更:
- 扩展 tb_commission_withdrawal_request 新增提现单号等字段
- 扩展 tb_account 新增 is_primary 字段
- 扩展 tb_commission_record 新增 shop_id、balance_after
- 扩展 tb_commission_withdrawal_setting 新增每日提现次数限制
- 扩展 tb_iot_card、tb_device 新增 shop_id 冗余字段
- 新建 tb_enterprise_card_authorization 企业卡授权表
- 新建 tb_asset_allocation_record 资产分配记录表
- 数据迁移:owner_type 枚举值 agent 统一为 shop

测试:
- 新增 7 个单元测试文件覆盖各服务
- 修复集成测试 Redis 依赖问题
2026-01-21 18:20:44 +08:00

172 lines
4.3 KiB
Markdown
Raw Permalink 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.
# 实现任务清单
**Change ID**: `add-commission-model-changes`
---
## 阶段 1: 数据库迁移 (1-2 小时)
### Task 1.1: 创建迁移文件
**文件**: `migrations/000010_add_commission_model_changes.up.sql`
**实现内容**:
- [x] 1.1.1 新增 `tb_commission_withdrawal_request` 表字段
- [x] 1.1.2 新增 `tb_account.is_primary` 字段
- [x] 1.1.3 新增 `tb_commission_record` 表字段(`shop_id`, `balance_after`
- [x] 1.1.4 新增 `tb_commission_withdrawal_setting.daily_withdrawal_limit` 字段
- [x] 1.1.5 新增 `tb_iot_card.shop_id` 字段
- [x] 1.1.6 新增 `tb_device.shop_id` 字段
- [x] 1.1.7 创建 `tb_enterprise_card_authorization`
- [x] 1.1.8 创建 `tb_asset_allocation_record`
- [x] 1.1.9 创建必要的索引
**验证**:
- [x] 迁移脚本语法正确
- [x] 字段类型与需求文档一致
---
### Task 1.2: 数据迁移 - owner_type 枚举统一
**文件**: `migrations/000010_add_commission_model_changes.up.sql`
**实现内容**:
- [x] 1.2.1 更新 `tb_iot_card``owner_type='agent'``owner_type='shop'`
- [x] 1.2.2 更新 `tb_device``owner_type='agent'``owner_type='shop'`
- [x] 1.2.3 填充 `tb_iot_card.shop_id` 字段(`owner_type='shop'` 时等于 `owner_id`
- [x] 1.2.4 填充 `tb_device.shop_id` 字段(`owner_type='shop'` 时等于 `owner_id`
**验证**:
- [x] 数据迁移逻辑正确
- [x] 无数据丢失
---
### Task 1.3: 创建回滚迁移
**文件**: `migrations/000010_add_commission_model_changes.down.sql`
**实现内容**:
- [x] 1.3.1 删除新增的表字段
- [x] 1.3.2 删除新增的表
- [x] 1.3.3 恢复 `owner_type` 枚举值(`shop``agent`
**验证**:
- [x] 回滚脚本可以正确执行
- [x] 回滚后数据库状态正确
---
## 阶段 2: Model 更新 (1 小时)
### Task 2.1: 更新现有 Model
**文件**:
- `internal/model/financial.go`
- `internal/model/commission.go`
- `internal/model/account.go`
- `internal/model/iot_card.go`
- `internal/model/device.go`
**实现内容**:
- [x] 2.1.1 `CommissionWithdrawalRequest` 新增字段
- [x] 2.1.2 `Account` 新增 `IsPrimary` 字段
- [x] 2.1.3 `CommissionRecord` 新增 `ShopID`, `BalanceAfter` 字段
- [x] 2.1.4 `CommissionWithdrawalSetting` 新增 `DailyWithdrawalLimit` 字段
- [x] 2.1.5 `IotCard` 新增 `ShopID` 字段
- [x] 2.1.6 `Device` 新增 `ShopID` 字段
**验证**:
- [x] 字段标签正确(`gorm`, `json`
- [x] 字段类型与数据库一致
---
### Task 2.2: 新增 Model
**文件**:
- `internal/model/enterprise_card_authorization.go`
- `internal/model/asset_allocation_record.go`
**实现内容**:
- [x] 2.2.1 创建 `EnterpriseCardAuthorization` 模型
- [x] 2.2.2 创建 `AssetAllocationRecord` 模型
- [x] 2.2.3 实现 `TableName()` 方法
**验证**:
- [x] 模型定义完整
- [x] 遵循项目 Model 规范
---
### Task 2.3: 更新常量定义
**文件**: `pkg/constants/iot.go`
**实现内容**:
- [x] 2.3.1 更新 `OwnerType` 常量(移除 `agent`, `user`, `device`,保留 `platform`, `shop`
- [x] 2.3.2 新增 `EnterpriseCardAuthorizationStatus` 常量
- [x] 2.3.3 新增 `AssetAllocationType` 常量
- [x] 2.3.4 新增 `PaymentType` 常量
- [x] 2.3.5 新增 Redis Key 生成函数(如有需要)
**验证**:
- [x] 常量命名符合规范
- [x] 中文注释完整
---
## 阶段 3: 代码兼容性修复 (30 分钟)
### Task 3.1: 更新现有代码中的 owner_type 引用
**实现内容**:
- [x] 3.1.1 全局搜索 `owner_type.*agent` 引用
- [x] 3.1.2 更新为 `shop`
- [x] 3.1.3 验证无遗漏
**验证**:
- [x] 编译通过
- [x] 无运行时错误
---
## 阶段 4: 验证 (30 分钟)
### Task 4.1: 执行迁移
**实现内容**:
- [x] 4.1.1 在开发环境执行迁移
- [x] 4.1.2 验证表结构正确
- [x] 4.1.3 验证数据迁移正确
- [x] 4.1.4 验证索引创建正确
**验证**:
- [x] `migrate up` 成功
- [x] `migrate down` 可以回滚
---
### Task 4.2: Model 验证
**实现内容**:
- [x] 4.2.1 验证 Model 与数据库表结构一致
- [x] 4.2.2 简单 CRUD 测试
- [x] 4.2.3 验证 GORM 自动迁移无冲突
**验证**:
- [x] 所有新字段可正常读写
- [x] 新表 CRUD 正常
---
## 完成标准
- [x] 所有迁移文件创建完成
- [x] 所有 Model 更新完成
- [x] 常量定义更新完成
- [x] 代码兼容性修复完成
- [x] 迁移执行成功
- [x] 编译通过,无错误