mirror of
https://github.com/bufanyun/hotgo.git
synced 2025-02-02 18:28:41 +08:00
commit
e67d6389b9
@ -8,11 +8,13 @@ package adminController
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/util/gconv"
|
||||||
|
|
||||||
"github.com/bufanyun/hotgo/app/com"
|
"github.com/bufanyun/hotgo/app/com"
|
||||||
"github.com/bufanyun/hotgo/app/form/adminForm"
|
"github.com/bufanyun/hotgo/app/form/adminForm"
|
||||||
"github.com/bufanyun/hotgo/app/form/input"
|
"github.com/bufanyun/hotgo/app/form/input"
|
||||||
"github.com/bufanyun/hotgo/app/service/adminService"
|
"github.com/bufanyun/hotgo/app/service/adminService"
|
||||||
"github.com/gogf/gf/v2/util/gconv"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 角色
|
// 角色
|
||||||
@ -94,3 +96,20 @@ func (controller *role) Dynamic(ctx context.Context, req *adminForm.RoleDynamicR
|
|||||||
}
|
}
|
||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// @Title 修改角色菜单权限
|
||||||
|
// @Description
|
||||||
|
// @Author Ms <133814250@qq.com>
|
||||||
|
// @Param ctx
|
||||||
|
// @Param req
|
||||||
|
// @Return res
|
||||||
|
// @Return err
|
||||||
|
//
|
||||||
|
func (controller *role) Edit(ctx context.Context, req *adminForm.RoleMenuEditReq) (res *adminForm.RoleMenuEditRes, err error) {
|
||||||
|
err = adminService.Role.EditRoleMenu(ctx, req)
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
return res, nil
|
||||||
|
}
|
||||||
|
@ -7,9 +7,10 @@
|
|||||||
package adminForm
|
package adminForm
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|
||||||
"github.com/bufanyun/hotgo/app/form"
|
"github.com/bufanyun/hotgo/app/form"
|
||||||
"github.com/bufanyun/hotgo/app/form/input"
|
"github.com/bufanyun/hotgo/app/form/input"
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// 查询列表
|
// 查询列表
|
||||||
@ -87,3 +88,11 @@ type RoleDynamicMenu struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type RoleDynamicRes []*RoleDynamicMenu
|
type RoleDynamicRes []*RoleDynamicMenu
|
||||||
|
|
||||||
|
type RoleMenuEditReq struct {
|
||||||
|
g.Meta `path:"/role/edit" method:"post" tags:"角色" summary:"编辑角色菜单权限"`
|
||||||
|
RoleId int64 `json:"id"`
|
||||||
|
MenuIds []int64 `json:"menuIds"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type RoleMenuEditRes struct{}
|
||||||
|
@ -8,13 +8,17 @@ package adminService
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
|
||||||
|
"github.com/gogf/gf/v2/database/gdb"
|
||||||
|
"github.com/gogf/gf/v2/errors/gerror"
|
||||||
|
"github.com/gogf/gf/v2/frame/g"
|
||||||
|
|
||||||
"github.com/bufanyun/hotgo/app/consts"
|
"github.com/bufanyun/hotgo/app/consts"
|
||||||
|
"github.com/bufanyun/hotgo/app/form/adminForm"
|
||||||
"github.com/bufanyun/hotgo/app/form/input"
|
"github.com/bufanyun/hotgo/app/form/input"
|
||||||
"github.com/bufanyun/hotgo/app/service/internal/dao"
|
"github.com/bufanyun/hotgo/app/service/internal/dao"
|
||||||
"github.com/bufanyun/hotgo/app/service/internal/dto"
|
"github.com/bufanyun/hotgo/app/service/internal/dto"
|
||||||
"github.com/bufanyun/hotgo/app/utils"
|
"github.com/bufanyun/hotgo/app/utils"
|
||||||
"github.com/gogf/gf/v2/errors/gerror"
|
|
||||||
"github.com/gogf/gf/v2/frame/g"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
var Role = new(role)
|
var Role = new(role)
|
||||||
@ -128,3 +132,34 @@ func (service *role) GetMemberList(ctx context.Context, RoleId int64) (list []*i
|
|||||||
|
|
||||||
return list, err
|
return list, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// @Title 更改角色菜单权限
|
||||||
|
// @Description
|
||||||
|
// @Author Ms <133814250@qq.com>
|
||||||
|
// @Param ctx
|
||||||
|
// @Param req
|
||||||
|
// @Return err
|
||||||
|
//
|
||||||
|
func (service *role) EditRoleMenu(ctx context.Context, reqInfo *adminForm.RoleMenuEditReq) error {
|
||||||
|
return dao.AdminRoleMenu.Transaction(ctx, func(ctx context.Context, tx *gdb.TX) (err error) {
|
||||||
|
_, err = dao.AdminRoleMenu.Ctx(ctx).Where("role_id", reqInfo.RoleId).Delete()
|
||||||
|
if err != nil {
|
||||||
|
err = gerror.Wrap(err, consts.ErrorORM)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
addMap := make(g.List, 0, len(reqInfo.MenuIds))
|
||||||
|
for _, v := range reqInfo.MenuIds {
|
||||||
|
addMap = append(addMap, g.Map{
|
||||||
|
"role_id": reqInfo.RoleId,
|
||||||
|
"menu_id": v,
|
||||||
|
})
|
||||||
|
}
|
||||||
|
_, err = dao.AdminRoleMenu.Ctx(ctx).Data(addMap).Insert()
|
||||||
|
if err != nil {
|
||||||
|
err = gerror.Wrap(err, consts.ErrorORM)
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
return nil
|
||||||
|
})
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user