172 lines
6.5 KiB
Go
172 lines
6.5 KiB
Go
package routes
|
||
|
||
import (
|
||
"github.com/gofiber/fiber/v2"
|
||
|
||
"github.com/break/junhong_cmp_fiber/internal/handler/admin"
|
||
"github.com/break/junhong_cmp_fiber/internal/model/dto"
|
||
"github.com/break/junhong_cmp_fiber/pkg/constants"
|
||
"github.com/break/junhong_cmp_fiber/pkg/errors"
|
||
"github.com/break/junhong_cmp_fiber/pkg/middleware"
|
||
"github.com/break/junhong_cmp_fiber/pkg/openapi"
|
||
)
|
||
|
||
func registerShopRoutes(router fiber.Router, handler *admin.ShopHandler, doc *openapi.Generator, basePath string) {
|
||
shops := router.Group("/shops")
|
||
groupPath := basePath + "/shops"
|
||
|
||
Register(shops, doc, groupPath, "GET", "", coreShopManagement(handler.List), RouteSpec{
|
||
Summary: "店铺列表",
|
||
Description: "仅超级管理员、平台账号和代理账号可访问,企业账号返回 403。分页默认第 1 页、每页 20 条;page 最小为 1,page_size 范围为 1 至 100。所有筛选条件在查询前统一校验。",
|
||
Tags: []string{"店铺管理"},
|
||
Input: new(dto.ShopListRequest),
|
||
Output: new(dto.ShopPageResult),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "POST", "", coreShopManagement(handler.Create), RouteSpec{
|
||
Summary: "创建店铺",
|
||
Description: "仅超级管理员、平台账号和代理账号可访问,企业账号返回 403。",
|
||
Tags: []string{"店铺管理"},
|
||
Input: new(dto.CreateShopRequest),
|
||
Output: new(dto.ShopResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "PUT", "/:id", coreShopManagement(handler.Update), RouteSpec{
|
||
Summary: "更新店铺",
|
||
Description: "仅超级管理员、平台账号和代理账号可访问,企业账号返回 403。",
|
||
Tags: []string{"店铺管理"},
|
||
Input: new(dto.UpdateShopParams),
|
||
Output: new(dto.ShopResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "DELETE", "/:id", coreShopManagement(handler.Delete), RouteSpec{
|
||
Summary: "删除店铺",
|
||
Description: "仅超级管理员、平台账号和代理账号可访问,企业账号返回 403。",
|
||
Tags: []string{"店铺管理"},
|
||
Input: new(dto.IDReq),
|
||
Output: nil,
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "GET", "/cascade", coreShopManagement(handler.Cascade), RouteSpec{
|
||
Summary: "店铺联级查询",
|
||
Description: "仅超级管理员、平台账号和代理账号可访问,企业账号返回 403。",
|
||
Tags: []string{"店铺管理"},
|
||
Input: new(dto.ShopCascadeRequest),
|
||
Output: new([]dto.ShopCascadeItem),
|
||
Auth: true,
|
||
})
|
||
}
|
||
|
||
func coreShopManagement(handler fiber.Handler) fiber.Handler {
|
||
return func(c *fiber.Ctx) error {
|
||
if middleware.GetUserTypeFromContext(c.UserContext()) == constants.UserTypeEnterprise {
|
||
return errors.New(errors.CodeForbidden, "无权限访问店铺管理功能")
|
||
}
|
||
return handler(c)
|
||
}
|
||
}
|
||
|
||
func registerShopRoleRoutes(router fiber.Router, handler *admin.ShopRoleHandler, doc *openapi.Generator, basePath string) {
|
||
shops := router.Group("/shops")
|
||
groupPath := basePath + "/shops"
|
||
|
||
Register(shops, doc, groupPath, "POST", "/:shop_id/roles", handler.AssignShopRoles, RouteSpec{
|
||
Summary: "分配店铺默认角色",
|
||
Tags: []string{"店铺管理"},
|
||
Input: new(dto.AssignShopRolesRequest),
|
||
Output: new(dto.ShopRolesResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "GET", "/:shop_id/roles", handler.GetShopRoles, RouteSpec{
|
||
Summary: "查询店铺默认角色",
|
||
Tags: []string{"店铺管理"},
|
||
Input: new(dto.GetShopRolesRequest),
|
||
Output: new(dto.ShopRolesResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "DELETE", "/:shop_id/roles/:role_id", handler.DeleteShopRole, RouteSpec{
|
||
Summary: "删除店铺默认角色",
|
||
Tags: []string{"店铺管理"},
|
||
Input: new(dto.DeleteShopRoleRequest),
|
||
Output: nil,
|
||
Auth: true,
|
||
})
|
||
}
|
||
|
||
func registerShopCommissionRoutes(router fiber.Router, handler *admin.ShopCommissionHandler, doc *openapi.Generator, basePath string) {
|
||
shops := router.Group("/shops")
|
||
groupPath := basePath + "/shops"
|
||
|
||
Register(shops, doc, groupPath, "GET", "/fund-summary", handler.ListFundSummary, RouteSpec{
|
||
Summary: "代理商资金概况",
|
||
Tags: []string{"代理商资金管理"},
|
||
Input: new(dto.ShopFundSummaryListReq),
|
||
Output: new(dto.ShopFundSummaryPageResult),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "GET", "/:shop_id/withdrawal-requests", handler.ListWithdrawalRequests, RouteSpec{
|
||
Summary: "代理商提现记录",
|
||
Tags: []string{"代理商资金管理"},
|
||
Input: new(dto.ShopWithdrawalRequestListReq),
|
||
Output: new(dto.ShopWithdrawalRequestPageResult),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "GET", "/:shop_id/commission-records", handler.ListCommissionRecords, RouteSpec{
|
||
Summary: "代理商佣金明细",
|
||
Tags: []string{"代理商资金管理"},
|
||
Input: new(dto.ShopCommissionRecordListReq),
|
||
Output: new(dto.ShopCommissionRecordPageResult),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "GET", "/:shop_id/main-wallet/transactions", handler.ListMainWalletTransactions, RouteSpec{
|
||
Summary: "代理商预充值钱包流水",
|
||
Tags: []string{"代理商资金管理"},
|
||
Input: new(dto.MainWalletTransactionListRequest),
|
||
Output: new(dto.MainWalletTransactionListResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "GET", "/:shop_id/commission-stats", handler.GetCommissionStats, RouteSpec{
|
||
Summary: "代理商佣金统计",
|
||
Tags: []string{"代理商资金管理"},
|
||
Input: new(dto.CommissionStatsRequest),
|
||
Output: new(dto.CommissionStatsResponse),
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "GET", "/:shop_id/commission-daily-stats", handler.GetCommissionDailyStats, RouteSpec{
|
||
Summary: "代理商每日佣金统计",
|
||
Tags: []string{"代理商资金管理"},
|
||
Input: new(dto.DailyCommissionStatsRequest),
|
||
Output: []dto.DailyCommissionStatsResponse{},
|
||
Auth: true,
|
||
})
|
||
|
||
Register(shops, doc, groupPath, "POST", "/:shop_id/withdrawal-requests", handler.CreateWithdrawal, RouteSpec{
|
||
Summary: "发起提现申请",
|
||
Tags: []string{"代理商资金管理"},
|
||
Input: new(dto.CreateMyWithdrawalReq),
|
||
Output: new(dto.CreateMyWithdrawalResp),
|
||
Auth: true,
|
||
})
|
||
|
||
commissionRecords := router.Group("/commission-records")
|
||
crPath := basePath + "/commission-records"
|
||
|
||
Register(commissionRecords, doc, crPath, "POST", "/:id/resolve", handler.ResolveCommissionRecord, RouteSpec{
|
||
Summary: "修正待审佣金记录",
|
||
Tags: []string{"代理商资金管理"},
|
||
Input: new(dto.CommissionRecordResolveRequest),
|
||
Auth: true,
|
||
})
|
||
}
|