You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

160 lines
5.2 KiB

package sys
import (
"bkb-seller/global"
"bkb-seller/model"
"bkb-seller/model/request"
"bkb-seller/model/response"
"bkb-seller/service"
"bkb-seller/utils"
"fmt"
"github.com/gin-gonic/gin"
"go.uber.org/zap"
)
// @Tags sysSeller
// @Summary 获取菜单接口树
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} []model.SysMenuApi "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sub/menuApiTree [get]
func GetMenuApiTree(c *gin.Context) {
if err, menus := service.GetMenuApiTree(GetUserAppid(c), GetUserType(c)); err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
} else {
response.OkWithData(menus, c)
}
}
// @Tags sysSeller
// @Summary 获取角色api权限列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} []model.SysMenuApi "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sub/authority [get]
func GetAuthority(c *gin.Context) {
if err, menus := service.GetAuthority(GetUserAppid(c), GetUserType(c)); err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
} else {
response.OkWithData(menus, c)
}
}
// @Tags sysSeller
// @Summary 获取子账号列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Success 200 {object} []model.SysMenuApi "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sub/accountList [get]
func GetSubAccountList(c *gin.Context) {
if err, menus := service.GetSubAccountList(GetUserAppid(c), GetUserType(c)); err != nil {
response.FailWithMessage(fmt.Sprintf("获取失败,%v", err), c)
} else {
response.OkWithData(menus, c)
}
}
// @Tags sysSeller
// @Summary 分页获取角色列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PageInfo true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sub/authorityList [post]
func GetSubAuthorityList(c *gin.Context) {
var pageInfo request.PageInfo
_ = c.ShouldBindJSON(&pageInfo)
if err := utils.Verify(pageInfo, utils.PageInfoVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err, list, total := service.GetAuthorityInfoList(pageInfo, GetUserAppid(c)); err != nil {
global.MG_LOG.Error("获取失败!", zap.Any("err", err))
response.FailWithMessage("获取失败"+err.Error(), c)
} else {
response.OkWithDetailed(response.PageResult{
List: list,
Total: total,
Page: pageInfo.Page,
PageSize: pageInfo.PageSize,
}, "获取成功", c)
}
}
// @Tags sysSeller
// @Summary 修改角色菜单api权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.UpdateAuthorityRole true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sub/authority [put]
func UpdateAuthorityRole(c *gin.Context) {
var role request.UpdateAuthorityRole
_ = c.ShouldBindJSON(&role)
if err := service.UpdateAuthorityRole(&role, GetUserAppid(c), "seller"); err != nil {
response.FailWithMessage(fmt.Sprintf("更新失败,%v", err), c)
return
}
response.OkWithMessage("更新成功", c)
}
// @Tags sysSeller
// @Summary 创建角色菜单api权限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.AddAuthorityRole true "页码, 每页大小"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /sub/authority [post]
func AddAuthorityRole(c *gin.Context) {
var role request.AddAuthorityRole
_ = c.ShouldBindJSON(&role)
if err := service.AddAuthorityRole(&role, GetUserAppid(c), "seller"); err != nil {
response.FailWithMessage(fmt.Sprintf("添加失败,%v", err), c)
return
}
response.OkWithMessage("添加成功", c)
}
// @Tags sysSeller
// @Summary 删除角色
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body model.SysAuthority true "删除角色"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /sub/authority [post]
func DeleteAuthorityRole(c *gin.Context) {
var authority model.SysAuthority
_ = c.ShouldBindJSON(&authority)
if err := utils.Verify(authority, utils.AuthorityIdVerify); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
if err := service.DeleteAuthority(&authority); err != nil { // 删除角色之前需要判断是否有用户正在使用此角色
global.MG_LOG.Error("删除失败!", zap.Any("err", err))
response.FailWithMessage("删除失败"+err.Error(), c)
} else {
response.OkWithMessage("删除成功", c)
}
}
func AddSubAccount(c *gin.Context) {
var subAccount request.AddSubAccount
_ = c.ShouldBindJSON(&subAccount)
// if err := utils.Verify(subAccount, utils.SubAccountVerify); err != nil {
// response.FailWithMessage(err.Error(), c)
// return
// }
if err := service.AddSubAccount(&subAccount, GetUserAppid(c), "seller"); err != nil {
response.FailWithMessage(err.Error(), c)
return
}
response.OkWithMessage("添加成功", c)
}