123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105 |
- package admin
- import (
- "zhiyuan/pkg/app"
- "zhiyuan/pkg/utils"
- "zhiyuan/services/form"
- "zhiyuan/services/role"
- "github.com/gin-gonic/gin"
- )
- func RoleInfo(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.ErrorMsg(c, "role id must be a number", nil)
- return
- }
- auth, err := role.GetInfoByID(id, nil, nil)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, auth)
- }
- func RoleList(c *gin.Context) {
- page := app.HandlePageNums(c)
- where := make(map[string]interface{})
- total, err := role.Count(where)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- type RoleList struct {
- ID int `json:"id"`
- Name string `json:"name"`
- CreatedAt string `json:"created_at"`
- AuthIds string `json:"auth_ids"`
- DataAuth int `json:"data_auth"`
- }
- var roleList []RoleList
- _, err = role.GetList(where, []string{"id", "name", "created_at", "auth_ids", "data_auth"}, page, &roleList)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- for k, v := range roleList {
- v.CreatedAt = utils.DateS(v.CreatedAt, "YYYY-MM-DD")
- roleList[k] = v
- }
- data := gin.H{
- "list": roleList,
- "total": total,
- "limit": page.PageSize,
- }
- app.Success(c, data)
- }
- func RoleAdd(c *gin.Context) {
- var form form.RoleAdd
- if app.Bind(c, &form) != nil {
- return
- }
- id, err := role.Add(form)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, gin.H{"id": id})
- }
- func RoleEdit(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.ErrorMsg(c, "auth id must be a number", nil)
- return
- }
- var form form.RoleAdd
- if app.Bind(c, &form) != nil {
- return
- }
- err := role.EditByID(form, id)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
- func RoleDel(c *gin.Context) {
- id := utils.StrTo(c.Param("id")).MustInt()
- if id <= 0 {
- app.ErrorMsg(c, "auth id must be a number", nil)
- return
- }
- err := role.DeleteByID(id)
- if err != nil {
- app.Error(c, err.Error())
- return
- }
- app.Success(c, nil)
- }
|