Files
junhong_cmp_fiber/openspec/changes/add-shop-package-allocation/tasks.md
huang 79c061b6fa
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m24s
feat: 实现套餐管理模块,包含套餐系列、双状态管理、废弃模型清理
- 新增套餐系列管理 (CRUD + 状态切换)
- 新增套餐管理 (CRUD + 启用/禁用 + 上架/下架双状态)
- 清理 8 个废弃分佣模型及对应数据库表
- Package 模型新增建议成本价、建议售价、上架状态字段
- 完整的 Store/Service/Handler 三层实现
- 包含单元测试和集成测试
- 归档 add-package-module change
- 新增多个 OpenSpec changes (订单支付、店铺套餐分配、一次性分佣、卡设备系列绑定)
2026-01-27 19:55:47 +08:00

7.0 KiB
Raw Blame History

1. 新增模型

  • 1.1 创建 internal/model/shop_series_allocation.go,定义 ShopSeriesAllocation 模型shop_id, series_id, allocator_shop_id, pricing_mode, pricing_value, one_time_commission_trigger, one_time_commission_threshold, one_time_commission_amount, status
  • 1.2 创建 internal/model/shop_series_commission_tier.go,定义 ShopSeriesCommissionTier 模型allocation_id, tier_type, period_type, period_start_date, period_end_date, threshold_value, commission_amount
  • 1.3 创建 internal/model/shop_package_allocation.go,定义 ShopPackageAllocation 模型shop_id, package_id, allocation_id, cost_price, status

2. 数据库迁移

  • 2.1 创建迁移文件,创建 tb_shop_series_allocation 表
  • 2.2 创建 tb_shop_series_commission_tier 表
  • 2.3 创建 tb_shop_package_allocation 表
  • 2.4 添加必要的索引shop_id, series_id, allocation_id
  • 2.5 本地执行迁移验证

3. 套餐系列分配 DTO

  • 3.1 创建 internal/model/dto/shop_series_allocation.go,定义 CreateShopSeriesAllocationRequest含 one_time_commission_trigger, one_time_commission_threshold, one_time_commission_amount 可选字段)
  • 3.2 定义 UpdateShopSeriesAllocationRequest
  • 3.3 定义 ShopSeriesAllocationListRequest支持 shop_id, series_id, status 筛选)
  • 3.4 定义 UpdateStatusRequest
  • 3.5 定义 ShopSeriesAllocationResponse包含计算后的成本价

4. 梯度佣金 DTO

  • 4.1 定义 CreateCommissionTierRequesttier_type, period_type, period_start_date, period_end_date, threshold_value, commission_amount
  • 4.2 定义 UpdateCommissionTierRequest
  • 4.3 定义 CommissionTierResponse

5. 单套餐分配 DTO

  • 5.1 创建 internal/model/dto/shop_package_allocation.go,定义 CreateShopPackageAllocationRequest
  • 5.2 定义 UpdateShopPackageAllocationRequest
  • 5.3 定义 ShopPackageAllocationListRequest
  • 5.4 定义 ShopPackageAllocationResponse

6. 代理可售套餐 DTO

  • 6.1 定义 MyPackageListRequestseries_id, package_type 筛选)
  • 6.2 定义 MyPackageResponse包含成本价、建议售价、价格来源
  • 6.3 定义 MySeriesAllocationResponse

7. 套餐系列分配 Store

  • 7.1 创建 internal/store/postgres/shop_series_allocation_store.go,实现 Create 方法
  • 7.2 实现 GetByID 方法
  • 7.3 实现 GetByShopAndSeries 方法(检查重复分配)
  • 7.4 实现 Update 方法
  • 7.5 实现 Delete 方法
  • 7.6 实现 List 方法(支持分页和筛选)
  • 7.7 实现 UpdateStatus 方法
  • 7.8 实现 HasDependentAllocations 方法(检查下级依赖)
  • 7.9 实现 GetByShopID 方法(获取店铺的所有分配)

8. 梯度佣金 Store

  • 8.1 创建 internal/store/postgres/shop_series_commission_tier_store.go,实现 Create 方法
  • 8.2 实现 GetByID 方法
  • 8.3 实现 Update 方法
  • 8.4 实现 Delete 方法
  • 8.5 实现 ListByAllocationID 方法

9. 单套餐分配 Store

  • 9.1 创建 internal/store/postgres/shop_package_allocation_store.go,实现 Create 方法
  • 9.2 实现 GetByID 方法
  • 9.3 实现 GetByShopAndPackage 方法
  • 9.4 实现 Update 方法
  • 9.5 实现 Delete 方法
  • 9.6 实现 List 方法
  • 9.7 实现 UpdateStatus 方法

10. 套餐系列分配 Service

  • 10.1 创建 internal/service/shop_series_allocation/service.go,实现 Create 方法(验证权限、检查重复、计算成本价)
  • 10.2 实现 Get 方法
  • 10.3 实现 Update 方法
  • 10.4 实现 Delete 方法(检查下级依赖)
  • 10.5 实现 List 方法
  • 10.6 实现 UpdateStatus 方法
  • 10.7 实现 GetParentCostPrice 辅助方法(递归获取上级成本价)
  • 10.8 实现 CalculateCostPrice 辅助方法(根据加价模式计算)

11. 梯度佣金 Service

  • 11.1 在 shop_series_allocation service 中实现 AddTier 方法
  • 11.2 实现 UpdateTier 方法
  • 11.3 实现 DeleteTier 方法
  • 11.4 实现 ListTiers 方法

12. 单套餐分配 Service

  • 12.1 创建 internal/service/shop_package_allocation/service.go,实现 Create 方法(验证系列已分配、验证成本价)
  • 12.2 实现 Get 方法
  • 12.3 实现 Update 方法
  • 12.4 实现 Delete 方法
  • 12.5 实现 List 方法
  • 12.6 实现 UpdateStatus 方法

13. 代理可售套餐 Service

  • 13.1 创建 internal/service/my_package/service.go,实现 ListMyPackages 方法(获取可售套餐列表)
  • 13.2 实现 GetMyPackage 方法(获取单个套餐详情含成本价)
  • 13.3 实现 ListMySeriesAllocations 方法(获取被分配的系列)
  • 13.4 实现 GetCostPrice 核心方法(成本价计算,考虑优先级)

14. 套餐系列分配 Handler

  • 14.1 创建 internal/handler/admin/shop_series_allocation.go,实现 Create 接口
  • 14.2 实现 Get 接口
  • 14.3 实现 Update 接口
  • 14.4 实现 Delete 接口
  • 14.5 实现 List 接口
  • 14.6 实现 UpdateStatus 接口
  • 14.7 实现 AddTier 接口
  • 14.8 实现 UpdateTier 接口
  • 14.9 实现 DeleteTier 接口
  • 14.10 实现 ListTiers 接口

15. 单套餐分配 Handler

  • 15.1 创建 internal/handler/admin/shop_package_allocation.go,实现 Create 接口
  • 15.2 实现 Get 接口
  • 15.3 实现 Update 接口
  • 15.4 实现 Delete 接口
  • 15.5 实现 List 接口
  • 15.6 实现 UpdateStatus 接口

16. 代理可售套餐 Handler

  • 16.1 创建 internal/handler/admin/my_package.go,实现 ListMyPackages 接口
  • 16.2 实现 GetMyPackage 接口
  • 16.3 实现 ListMySeriesAllocations 接口

17. Bootstrap 注册

  • 17.1 在 stores.go 中注册 ShopSeriesAllocationStore, ShopSeriesCommissionTierStore, ShopPackageAllocationStore
  • 17.2 在 services.go 中注册 ShopSeriesAllocationService, ShopPackageAllocationService, MyPackageService
  • 17.3 在 handlers.go 中注册 ShopSeriesAllocationHandler, ShopPackageAllocationHandler, MyPackageHandler

18. 路由注册

  • 18.1 注册 /api/admin/shop-series-allocations 路由组
  • 18.2 注册 /api/admin/shop-series-allocations/:id/tiers 嵌套路由
  • 18.3 注册 /api/admin/shop-package-allocations 路由组
  • 18.4 注册 /api/admin/my-packages 路由
  • 18.5 注册 /api/admin/my-series-allocations 路由

19. 文档生成器更新

  • 19.1 在 docs.go 和 gendocs/main.go 中添加新 Handler
  • 19.2 执行文档生成验证

20. 测试

  • 20.1 ShopSeriesAllocationStore 单元测试
  • 20.2 ShopPackageAllocationStore 单元测试
  • 20.3 ShopSeriesAllocationService 单元测试(覆盖权限验证、成本价计算)
  • 20.4 MyPackageService 单元测试(覆盖成本价优先级)
  • 20.5 套餐系列分配 API 集成测试
  • 20.6 代理可售套餐 API 集成测试
  • 20.7 执行 go test ./... 确认通过

21. 最终验证

  • 21.1 执行 go build ./... 确认编译通过
  • 21.2 启动服务,手动测试分配流程
  • 21.3 验证成本价计算逻辑正确