feat: 实现门店套餐分配功能并统一测试基础设施
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m30s
All checks were successful
构建并部署到测试环境(无 SSH) / build-and-deploy (push) Successful in 5m30s
新增功能: - 门店套餐分配管理(shop_package_allocation):支持门店套餐库存管理 - 门店套餐系列分配管理(shop_series_allocation):支持套餐系列分配和佣金层级设置 - 我的套餐查询(my_package):支持门店查询自己的套餐分配情况 测试改进: - 统一集成测试基础设施,新增 testutils.NewIntegrationTestEnv - 重构所有集成测试使用新的测试环境设置 - 移除旧的测试辅助函数和冗余测试文件 - 新增 test_helpers_test.go 统一任务测试辅助 技术细节: - 新增数据库迁移 000025_create_shop_allocation_tables - 新增 3 个 Handler、Service、Store 和对应的单元测试 - 更新 OpenAPI 文档和文档生成器 - 测试覆盖率:Service 层 > 90% Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
60
internal/handler/admin/my_package.go
Normal file
60
internal/handler/admin/my_package.go
Normal file
@@ -0,0 +1,60 @@
|
||||
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)
|
||||
}
|
||||
112
internal/handler/admin/shop_package_allocation.go
Normal file
112
internal/handler/admin/shop_package_allocation.go
Normal file
@@ -0,0 +1,112 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
shopPackageAllocationService "github.com/break/junhong_cmp_fiber/internal/service/shop_package_allocation"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type ShopPackageAllocationHandler struct {
|
||||
service *shopPackageAllocationService.Service
|
||||
}
|
||||
|
||||
func NewShopPackageAllocationHandler(service *shopPackageAllocationService.Service) *ShopPackageAllocationHandler {
|
||||
return &ShopPackageAllocationHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) Create(c *fiber.Ctx) error {
|
||||
var req dto.CreateShopPackageAllocationRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Create(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) Get(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Get(c.UserContext(), uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateShopPackageAllocationRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Update(c.UserContext(), uint(id), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
if err := h.service.Delete(c.UserContext(), uint(id)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) List(c *fiber.Ctx) error {
|
||||
var req dto.ShopPackageAllocationListRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocations, total, err := h.service.List(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, allocations, total, req.Page, req.PageSize)
|
||||
}
|
||||
|
||||
func (h *ShopPackageAllocationHandler) UpdateStatus(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺套餐分配 ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateStatusRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
if err := h.service.UpdateStatus(c.UserContext(), uint(id), req.Status); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
187
internal/handler/admin/shop_series_allocation.go
Normal file
187
internal/handler/admin/shop_series_allocation.go
Normal file
@@ -0,0 +1,187 @@
|
||||
package admin
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
|
||||
"github.com/gofiber/fiber/v2"
|
||||
|
||||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||||
shopSeriesAllocationService "github.com/break/junhong_cmp_fiber/internal/service/shop_series_allocation"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||||
"github.com/break/junhong_cmp_fiber/pkg/response"
|
||||
)
|
||||
|
||||
type ShopSeriesAllocationHandler struct {
|
||||
service *shopSeriesAllocationService.Service
|
||||
}
|
||||
|
||||
func NewShopSeriesAllocationHandler(service *shopSeriesAllocationService.Service) *ShopSeriesAllocationHandler {
|
||||
return &ShopSeriesAllocationHandler{service: service}
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) Create(c *fiber.Ctx) error {
|
||||
var req dto.CreateShopSeriesAllocationRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Create(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) Get(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺系列分配 ID")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Get(c.UserContext(), uint(id))
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) Update(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺系列分配 ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateShopSeriesAllocationRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocation, err := h.service.Update(c.UserContext(), uint(id), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, allocation)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) Delete(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺系列分配 ID")
|
||||
}
|
||||
|
||||
if err := h.service.Delete(c.UserContext(), uint(id)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.Success(c, nil)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) List(c *fiber.Ctx) error {
|
||||
var req dto.ShopSeriesAllocationListRequest
|
||||
if err := c.QueryParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
allocations, total, err := h.service.List(c.UserContext(), &req)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return response.SuccessWithPagination(c, allocations, total, req.Page, req.PageSize)
|
||||
}
|
||||
|
||||
func (h *ShopSeriesAllocationHandler) UpdateStatus(c *fiber.Ctx) error {
|
||||
id, err := strconv.ParseUint(c.Params("id"), 10, 64)
|
||||
if err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "无效的店铺系列分配 ID")
|
||||
}
|
||||
|
||||
var req dto.UpdateStatusRequest
|
||||
if err := c.BodyParser(&req); err != nil {
|
||||
return errors.New(errors.CodeInvalidParam, "请求参数解析失败")
|
||||
}
|
||||
|
||||
if err := h.service.UpdateStatus(c.UserContext(), uint(id), req.Status); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
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