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

2.8 KiB
Raw Permalink Blame History

Change: 企业卡授权管理模块

Why

代理商需要将卡授权给企业客户使用:

  1. 授权前预检(检查卡是否绑定设备,整体授权)
  2. 将卡授权给企业(不改变归属,只是让企业能看到)
  3. 回收卡授权
  4. 查询企业被授权的卡列表
  5. 企业对授权卡执行停机/复机操作

核心设计:卡的归属始终是代理商,企业通过授权表"看到"被授权的卡。

What Changes

新增 API 接口

方法 路径 说明
POST /api/admin/enterprises/:id/allocate-cards/preview 授权预检
POST /api/admin/enterprises/:id/allocate-cards 授权卡
POST /api/admin/enterprises/:id/recall-cards 回收授权
GET /api/admin/enterprises/:id/cards 企业卡列表
POST /api/admin/enterprises/:id/cards/:card_id/suspend 停机
POST /api/admin/enterprises/:id/cards/:card_id/resume 复机

技术实现

  • 新增 Handlerinternal/handler/admin/enterprise_card.go
  • 新增 Serviceinternal/service/enterprise_card/service.go
  • 新增 DTOinternal/model/dto/enterprise_card_dto.go
  • 新增 Storeinternal/store/postgres/enterprise_card_authorization_store.go

业务逻辑

授权预检

  1. 接收 ICCID 列表
  2. 检查每张卡是否存在、是否有权限
  3. 检查卡是否绑定设备
  4. 如果绑定设备,获取设备下所有卡
  5. 返回分配预览(独立卡、设备包、失败项)

授权卡

  1. 验证企业存在且归属当前代理商
  2. 验证卡属于当前代理商
  3. 如果卡绑定设备,整体授权设备下所有卡
  4. 创建授权记录(不修改卡的 owner

回收授权

  1. 验证授权记录存在且有效
  2. 更新授权记录状态为已回收
  3. 卡的 owner 不变

GORM Callback 修改

  • 企业用户查询卡时,通过授权表过滤

Impact

影响的规范

  • 新增 Capabilityenterprise-card-authorization

影响的代码

新增文件(约 600 行):

  • internal/handler/admin/enterprise_card.go~150 行)
  • internal/service/enterprise_card/service.go~300 行)
  • internal/model/dto/enterprise_card_dto.go~100 行)
  • internal/store/postgres/enterprise_card_authorization_store.go~50 行)

修改文件

  • pkg/gorm/callback.go(企业用户卡查询特殊处理)

兼容性

  • 向后兼容:新增 API

风险评估

  • 中等风险:涉及 GORM Callback 修改
  • 缓解措施:充分测试数据权限过滤

Dependencies

  • 依赖提案:add-commission-model-changesadd-enterprise-management
  • 依赖现有模型:EnterpriseIotCardDeviceDeviceSimBinding

Testing Strategy

  1. 单元测试:授权/回收逻辑
  2. 集成测试:完整授权流程
  3. 数据权限测试:企业用户只能看到被授权的卡