- agent_recharge_dto.go: 创建/列表/详情请求响应 DTO - service.go: 权限验证(代理只能充自己店铺)、金额范围校验、查询 active 配置、创建订单、线下充值确认(乐观锁+审计日志)、回调幂等处理 - agent_recharge.go Handler: Create/List/Get/OfflinePay 共 4 个方法 - agent_recharge.go 路由: 注册到 /api/admin/agent-recharges/*,路由层拦截企业账号 Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-opencode) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
56 lines
1.9 KiB
Go
56 lines
1.9 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 registerAgentRechargeRoutes(router fiber.Router, handler *admin.AgentRechargeHandler, doc *openapi.Generator, basePath string) {
|
|
group := router.Group("/agent-recharges", func(c *fiber.Ctx) error {
|
|
userType := middleware.GetUserTypeFromContext(c.UserContext())
|
|
if userType == constants.UserTypeEnterprise {
|
|
return errors.New(errors.CodeForbidden, "企业账号无权访问代理充值功能")
|
|
}
|
|
return c.Next()
|
|
})
|
|
groupPath := basePath + "/agent-recharges"
|
|
|
|
Register(group, doc, groupPath, "POST", "", handler.Create, RouteSpec{
|
|
Summary: "创建代理充值订单",
|
|
Tags: []string{"代理预充值"},
|
|
Input: new(dto.CreateAgentRechargeRequest),
|
|
Output: new(dto.AgentRechargeResponse),
|
|
Auth: true,
|
|
})
|
|
|
|
Register(group, doc, groupPath, "GET", "", handler.List, RouteSpec{
|
|
Summary: "查询代理充值订单列表",
|
|
Tags: []string{"代理预充值"},
|
|
Input: new(dto.AgentRechargeListRequest),
|
|
Output: new(dto.AgentRechargeListResponse),
|
|
Auth: true,
|
|
})
|
|
|
|
Register(group, doc, groupPath, "GET", "/:id", handler.Get, RouteSpec{
|
|
Summary: "查询代理充值订单详情",
|
|
Tags: []string{"代理预充值"},
|
|
Input: new(dto.IDReq),
|
|
Output: new(dto.AgentRechargeResponse),
|
|
Auth: true,
|
|
})
|
|
|
|
Register(group, doc, groupPath, "POST", "/:id/offline-pay", handler.OfflinePay, RouteSpec{
|
|
Summary: "确认线下充值",
|
|
Tags: []string{"代理预充值"},
|
|
Input: new(dto.AgentOfflinePayRequest),
|
|
Output: new(dto.AgentRechargeResponse),
|
|
Auth: true,
|
|
})
|
|
}
|