重构: 店铺套餐分配系统从加价模式改为返佣模式
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m18s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m18s
主要变更: - 重构分配模型:从加价模式(pricing_mode/pricing_value)改为返佣模式(base_commission + tier_commission) - 删除独立的 my_package 接口,统一到 /api/admin/packages(通过数据权限自动过滤) - 新增批量分配和批量调价功能,支持事务和性能优化 - 新增配置版本管理,订单创建时锁定返佣配置 - 新增成本价历史记录,支持审计和纠纷处理 - 新增统计缓存系统(Redis + 异步任务),优化梯度返佣计算性能 - 删除冗余的梯度佣金独立 CRUD 接口(合并到分配配置中) - 归档 3 个已完成的 OpenSpec changes 并同步 8 个新 capabilities 到 main specs 技术细节: - 数据库迁移:000026_refactor_shop_package_allocation - 新增 Store:AllocationConfigStore, PriceHistoryStore, CommissionStatsStore - 新增 Service:BatchAllocationService, BatchPricingService, CommissionStatsService - 新增异步任务:统计更新、定时同步、周期归档 - 测试覆盖:批量操作集成测试、梯度佣金 CRUD 清理验证 影响: - API 变更:删除 4 个梯度 CRUD 接口(POST/GET/PUT/DELETE /:id/tiers) - API 新增:批量分配、批量调价接口 - 数据模型:重构 shop_series_allocation 表结构 - 性能优化:批量操作使用 CreateInBatches,统计使用 Redis 缓存 相关文档: - openspec/changes/archive/2026-01-28-refactor-shop-package-allocation/ - openspec/specs/agent-available-packages/ - openspec/specs/allocation-config-versioning/ - 等 8 个新 capability specs
This commit is contained in:
@@ -1,60 +0,0 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
myPackageService "github.com/break/junhong_cmp_fiber/internal/service/my_package"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type MyPackageHandler struct {
|
||||
service *myPackageService.Service
|
||||
}
|
||||
|
||||
func NewMyPackageHandler(service *myPackageService.Service) *MyPackageHandler {
|
||||
return &MyPackageHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *MyPackageHandler) ListMyPackages(c *fiber.Ctx) error {
|
||||
var req dto.MyPackageListRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
packages, total, err := h.service.ListMyPackages(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, packages, total, req.Page, req.PageSize)
|
||||
}
|
||||
|
||||
func (h *MyPackageHandler) GetMyPackage(c *fiber.Ctx) error {
|
||||
var req dto.IDReq
|
||||
if err := c.ParamsParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的套餐 ID")
|
||||
}
|
||||
|
||||
pkg, err := h.service.GetMyPackage(c.UserContext(), req.ID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, pkg)
|
||||
}
|
||||
|
||||
func (h *MyPackageHandler) ListMySeriesAllocations(c *fiber.Ctx) error {
|
||||
var req dto.MySeriesAllocationListRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocations, total, err := h.service.ListMySeriesAllocations(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, allocations, total, req.Page, req.PageSize)
|
||||
}
|
||||
@@ -110,3 +110,28 @@ func (h *ShopPackageAllocationHandler) UpdateStatus(c *fiber.Ctx) error {
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
// UpdateCostPrice 更新成本价
|
||||
func (h *ShopPackageAllocationHandler) UpdateCostPrice(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
type UpdateCostPriceRequest struct {
|
||||
NewCostPrice int64 `json:"new_cost_price" validate:"required,min=0"`
|
||||
ChangeReason string `json:"change_reason" validate:"omitempty,max=255"`
|
||||
}
|
||||
|
||||
var req UpdateCostPriceRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.UpdateCostPrice(c.UserContext(), uint(id), req.NewCostPrice, req.ChangeReason)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
|
||||
32
internal/handler/admin/shop_package_batch_allocation.go
Normal file
32
internal/handler/admin/shop_package_batch_allocation.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
batchAllocationService "github.com/break/junhong_cmp_fiber/internal/service/shop_package_batch_allocation"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type ShopPackageBatchAllocationHandler struct {
|
||||
service *batchAllocationService.Service
|
||||
}
|
||||
|
||||
func NewShopPackageBatchAllocationHandler(service *batchAllocationService.Service) *ShopPackageBatchAllocationHandler {
|
||||
return &ShopPackageBatchAllocationHandler{service: service}
|
||||
}
|
||||
|
||||
// BatchAllocate 批量分配套餐
|
||||
func (h *ShopPackageBatchAllocationHandler) BatchAllocate(c *fiber.Ctx) error {
|
||||
var req dto.BatchAllocatePackagesRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
if err := h.service.BatchAllocate(c.UserContext(), &req); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
33
internal/handler/admin/shop_package_batch_pricing.go
Normal file
33
internal/handler/admin/shop_package_batch_pricing.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
batchPricingService "github.com/break/junhong_cmp_fiber/internal/service/shop_package_batch_pricing"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type ShopPackageBatchPricingHandler struct {
|
||||
service *batchPricingService.Service
|
||||
}
|
||||
|
||||
func NewShopPackageBatchPricingHandler(service *batchPricingService.Service) *ShopPackageBatchPricingHandler {
|
||||
return &ShopPackageBatchPricingHandler{service: service}
|
||||
}
|
||||
|
||||
// BatchUpdatePricing 批量调价
|
||||
func (h *ShopPackageBatchPricingHandler) BatchUpdatePricing(c *fiber.Ctx) error {
|
||||
var req dto.BatchUpdateCostPriceRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
result, err := h.service.BatchUpdatePricing(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, result)
|
||||
}
|
||||
@@ -110,78 +110,3 @@ func (h *ShopSeriesAllocationHandler) UpdateStatus(c *fiber.Ctx) error {
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) AddTier(c *fiber.Ctx) error {
|
||||
allocationID, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺系列分配 ID")
|
||||
}
|
||||
|
||||
var req dto.CreateCommissionTierRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
tier, err := h.service.AddTier(c.UserContext(), uint(allocationID), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, tier)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) UpdateTier(c *fiber.Ctx) error {
|
||||
allocationID, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺系列分配 ID")
|
||||
}
|
||||
|
||||
tierId, err := strconv.ParseUint(c.Params("tier_id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的佣金等级 ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateCommissionTierRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
tier, err := h.service.UpdateTier(c.UserContext(), uint(allocationID), uint(tierId), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, tier)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) DeleteTier(c *fiber.Ctx) error {
|
||||
allocationID, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺系列分配 ID")
|
||||
}
|
||||
|
||||
tierId, err := strconv.ParseUint(c.Params("tier_id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的佣金等级 ID")
|
||||
}
|
||||
|
||||
if err := h.service.DeleteTier(c.UserContext(), uint(allocationID), uint(tierId)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) ListTiers(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺系列分配 ID")
|
||||
}
|
||||
|
||||
tiers, err := h.service.ListTiers(c.UserContext(), uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, tiers)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user