yxh 6 лет назад
Родитель
Сommit
1f2efb8027
2 измененных файлов с 45 добавлено и 1 удалено
  1. 24 1
      app/controller/admin/auth.go
  2. 21 0
      app/service/auth_service/auth_rule.go

+ 24 - 1
app/controller/admin/auth.go

@@ -102,5 +102,28 @@ func (c *Auth) DeleteMenu(r *ghttp.Request) {
 
 //添加用户组
 func (c *Auth) AddGroup(r *ghttp.Request) {
-	r.Response.Write("添加用户组")
+	//添加操作
+	if r.Method == "POST" {
+		res := r.GetFormMap()
+		response.SusJson(true, r, "添加成功", res)
+	}
+	//获取父级组
+	err, pList := auth_service.GetRoleList("")
+	if err != nil {
+		g.Log().Error(err)
+		response.FailJson(true, r, "获取父级数据失败")
+	}
+	pList = utils.ParentSonSort(pList, 0, 0, "parent_id", "id", "flg", "name")
+	//获取菜单信息
+	err, mList := auth_service.GetMenuList("")
+	if err != nil {
+		g.Log().Error(err)
+		response.FailJson(true, r, "获取菜单数据失败")
+	}
+	mList = utils.PushSonToParent(mList)
+	res := g.Map{
+		"parentList": pList,
+		"menuList":   mList,
+	}
+	response.SusJson(true, r, "成功", res)
 }

+ 21 - 0
app/service/auth_service/auth_rule.go

@@ -2,6 +2,7 @@ package auth_service
 
 import (
 	"gfast/app/model/auth_rule"
+	"gfast/app/model/role"
 	"github.com/gogf/gf/frame/g"
 	"github.com/gogf/gf/os/gtime"
 	"github.com/gogf/gf/util/gconv"
@@ -63,3 +64,23 @@ func EditMenu(req *MenuReq, id int) (err error, rows int64) {
 	rows, _ = res.RowsAffected()
 	return
 }
+
+//获取用户组列表
+func GetRoleList(where string, params ...interface{}) (err error, list g.List) {
+	var rl []*role.Entity
+	if where != "" {
+		rl, err = role.Model.Where(where, params).OrderBy("list_order asc,id asc").All()
+	} else {
+		rl, err = role.Model.OrderBy("list_order asc,id asc").All()
+	}
+	if err != nil {
+		g.Log().Error(err)
+		return err, nil
+	}
+	list = make(g.List, len(rl))
+	for k, v := range rl {
+		tMap := gconv.Map(v)
+		list[k] = tMap
+	}
+	return
+}