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.
30 lines
642 B
30 lines
642 B
package models
|
|
|
|
import (
|
|
"github.com/beego/beego/v2/client/orm"
|
|
"yixiang.co/yshop/dto"
|
|
)
|
|
|
|
type RolesMenus struct {
|
|
Id int64
|
|
MenuId *Menu `orm:"column(menu_id);rel(fk)"`
|
|
RoleId *Role `orm:"column(role_id);rel(fk)"`
|
|
}
|
|
|
|
func init() {
|
|
orm.RegisterModel(new(RolesMenus))
|
|
}
|
|
|
|
func BatchRoleMenuAdd(menu dto.RoleMenu) {
|
|
o := orm.NewOrm()
|
|
o.Raw("delete from roles_menus WHERE role_id = ?", menu.Id).Exec()
|
|
|
|
var roleMenus []RolesMenus
|
|
for _, val := range menu.Menus {
|
|
var menus = Menu{Id: val.Id}
|
|
var roles = Role{Id:menu.Id}
|
|
roleMenus = append(roleMenus,RolesMenus{MenuId: &menus,RoleId: &roles})
|
|
}
|
|
|
|
o.InsertMulti(100,roleMenus)
|
|
}
|
|
|