Files
junhong_cmp_fiber/openspec/changes/archive/2026-01-21-add-commission-withdrawal-approval/tasks.md
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

156 lines
3.8 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.
# 实现任务清单
**Change ID**: `add-commission-withdrawal-approval`
---
## 阶段 1: DTO 定义 (20 分钟)
### Task 1.1: 创建 DTO 文件
**文件**: `internal/model/commission_withdrawal_dto.go`
**实现内容**:
- [x] 1.1.1 `WithdrawalRequestListReq` 请求结构(分页、状态、时间范围等)
- [x] 1.1.2 `WithdrawalRequestItem` 响应结构
- [x] 1.1.3 `ApproveWithdrawalReq` 审批通过请求
- [x] 1.1.4 `RejectWithdrawalReq` 拒绝请求
- [x] 1.1.5 `WithdrawalApprovalResp` 审批响应
**验证**:
- [x] DTO 字段完整
- [x] 验证标签正确remark 必填等)
---
## 阶段 2: Store 层扩展 (1 小时)
### Task 2.1: 扩展 CommissionWithdrawalRequest Store
**文件**: `internal/store/postgres/commission_withdrawal_request_store.go`
**实现内容**:
- [x] 2.1.1 `List(req)` - 分页查询提现申请
- [x] 2.1.2 `GetByID(id)` - 获取单条记录(已有)
- [x] 2.1.3 `UpdateStatusWithTx(id, updates)` - 事务中更新状态
**验证**:
- [x] 关联查询正确(店铺、申请人、处理人)
- [x] 乐观锁/版本控制(状态检查防止并发问题)
---
### Task 2.2: 扩展 Wallet Store
**文件**: `internal/store/postgres/wallet_store.go`
**实现内容**:
- [x] 2.2.1 `GetByID(walletID)` - 获取钱包
- [x] 2.2.2 `DeductFrozenBalanceWithTx(walletID, amount)` - 从冻结中扣除
- [x] 2.2.3 `UnfreezeBalanceWithTx(walletID, amount)` - 解冻余额到可用
**验证**:
- [x] 事务处理正确
- [x] 余额不能为负(通过 WHERE 条件保证)
---
### Task 2.3: WalletTransaction Store
**文件**: `internal/store/postgres/wallet_transaction_store.go`
**实现内容**:
- [x] 2.3.1 `CreateWithTx(transaction)` - 事务中创建交易流水
- [x] 2.3.2 `Create(transaction)` - 创建交易流水
**验证**:
- [x] 流水类型正确
- [x] 关联信息完整
---
## 阶段 3: Service 层 (1.5 小时)
### Task 3.1: 创建 CommissionWithdrawal Service
**文件**: `internal/service/commission_withdrawal/service.go`
**实现内容**:
- [x] 3.1.1 `ListWithdrawalRequests(ctx, req)` - 查询提现申请列表
- [x] 3.1.2 `Approve(ctx, id, req)` - 审批通过
- [x] 3.1.3 `Reject(ctx, id, req)` - 拒绝
**业务逻辑**:
- [x] 3.1.4 审批通过:状态检查 → 金额修正 → 扣款 → 记录流水 → 更新状态
- [x] 3.1.5 拒绝:状态检查 → 解冻 → 记录流水 → 更新状态
- [x] 3.1.6 使用事务确保原子性
**验证**:
- [x] 状态流转正确
- [x] 钱包操作正确
- [x] 事务处理正确
---
## 阶段 4: Handler 层 (45 分钟)
### Task 4.1: 创建 Handler
**文件**: `internal/handler/admin/commission_withdrawal.go`
**实现内容**:
- [x] 4.1.1 `ListWithdrawalRequests` - GET /api/admin/commission/withdrawal-requests
- [x] 4.1.2 `ApproveWithdrawal` - POST /api/admin/commission/withdrawal-requests/:id/approve
- [x] 4.1.3 `RejectWithdrawal` - POST /api/admin/commission/withdrawal-requests/:id/reject
**验证**:
- [x] 参数校验正确
- [x] 权限检查正确
---
### Task 4.2: 路由注册
**文件**: `internal/routes/commission.go`
**实现内容**:
- [x] 4.2.1 注册三个 API 路由
- [x] 4.2.2 配置权限(需要认证)
**验证**:
- [x] 路由可访问
- [x] 权限限制生效
---
## 阶段 5: 组件注册与测试 (45 分钟)
### Task 5.1: Bootstrap 注册
**实现内容**:
- [x] 5.1.1 注册 WalletTransaction Store
- [x] 5.1.2 注册 CommissionWithdrawal Service
- [x] 5.1.3 注册 CommissionWithdrawal Handler
---
### Task 5.2: 测试
**实现内容**:
- [x] 5.2.1 审批通过流程测试
- [x] 5.2.2 拒绝流程测试
- [x] 5.2.3 并发审批测试
- [x] 5.2.4 余额不足测试
---
## 完成标准
- [x] 所有 DTO 定义完成
- [x] Store 层方法实现完成
- [x] Service 层业务逻辑完成
- [x] Handler 层 API 实现完成
- [x] 事务处理正确
- [x] 编译通过
- [x] 审批流程测试通过