|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740 |
- package hdl
-
- import (
- "applet/app/e"
- "applet/app/enum"
- "applet/app/lib/validate"
- "applet/app/md"
- "applet/app/svc"
- "applet/app/utils"
- db "code.fnuoos.com/zhimeng/model.git/src"
- "code.fnuoos.com/zhimeng/model.git/src/implement"
- "code.fnuoos.com/zhimeng/model.git/src/model"
- implement2 "code.fnuoos.com/zhimeng/model.git/src/super/implement"
- "github.com/gin-gonic/gin"
- "time"
- )
-
- // PermissionGroupList
- // @Summary 权限组列表
- // @Tags 权限管理
- // @Description 权限管理-权限组列表
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @param adm_id query string true "管理员id"
- // @Success 200 {string} "具体看返回内容"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /role/permissionGroupList [GET]
- func PermissionGroupList(c *gin.Context) {
- roleId := c.DefaultQuery("role_id", "")
- engine := db.DBs[svc.GetMasterId(c)]
- qrcodeWithBatchRecordsDb := implement.NewPermissionGroupDb(engine)
- groupList, err := qrcodeWithBatchRecordsDb.FindPermissionGroup()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- roleDb := implement.NewRoleDb(engine, utils.StrToInt(roleId))
- list, _, err := roleDb.FindPermissionGroupByRole(utils.StrToInt(roleId))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- var isHasPermissionGroupId []string
- for _, v := range list {
- isHasPermissionGroupId = append(isHasPermissionGroupId, utils.IntToStr(v.PermissionGroup.Id))
- }
-
- var tempRespMap = map[string]*md.PermissionGroupListResp{}
- var tempRespMapKeys []string
- for _, v := range *groupList {
- isCheck := false
- if utils.InArr(utils.IntToStr(v.Id), isHasPermissionGroupId) {
- isCheck = true
- }
- tempRespMap[utils.IntToStr(v.Id)] = &md.PermissionGroupListResp{
- Id: v.Id,
- Name: v.Name,
- Key: v.Key,
- State: v.State,
- ParentId: v.ParentId,
- CreateAt: v.CreateAt,
- UpdateAt: v.UpdateAt,
- IsCheck: isCheck,
- }
- tempRespMapKeys = append(tempRespMapKeys, utils.IntToStr(v.Id))
- }
- for _, v := range tempRespMap {
- if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId != 0 {
- tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
- }
- }
- for _, v := range tempRespMap {
- if v.ParentId != 0 && tempRespMap[utils.IntToStr(v.ParentId)].ParentId == 0 {
- tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList = append(tempRespMap[utils.IntToStr(v.ParentId)].SubPermissionGroupList, *v)
- }
- }
-
- var resp []*md.PermissionGroupListResp
- for _, v := range tempRespMapKeys {
- if tempRespMap[v].ParentId == 0 {
- resp = append(resp, tempRespMap[v])
- }
- }
-
- e.OutSuc(c, map[string]interface{}{
- "list": resp,
- "state": []map[string]interface{}{
- {
- "name": enum.PermissionGroupState(enum.PermissionGroupStateForNormal).String(),
- "value": enum.PermissionGroupStateForNormal,
- },
- {
- "name": enum.PermissionGroupState(enum.PermissionGroupStateForDiscard).String(),
- "value": enum.PermissionGroupStateForDiscard,
- },
- },
- }, nil)
- return
- }
-
- // RoleList
- // @Summary 角色列表
- // @Tags 权限管理
- // @Description 权限管理-角色列表
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Success 200 {string} "具体看返回内容"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/roleList [GET]
- func RoleList(c *gin.Context) {
- engine := db.DBs[svc.GetMasterId(c)]
- roleDb := implement.NewRoleDb(engine, 0)
- roleList, err := roleDb.FindRole()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- adminRoleDb := implement.NewAdminRoleDb(engine)
- adminDb := implement.NewAdminDb(engine)
- var result []*md.RoleListResp
- for _, v := range *roleList {
- var temp md.RoleListResp
- temp.Data = v
- adminRoles, err1 := adminRoleDb.FindAdminRoleByRoleId(v.Id)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- for _, adminRole := range *adminRoles {
- admin, err2 := adminDb.GetAdmin(adminRole.AdmId)
- if err2 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err2.Error())
- return
- }
- temp.AdminList = append(temp.AdminList, struct {
- Name string `json:"name"`
- }{
- Name: admin.Username,
- })
- }
- result = append(result, &temp)
- }
- e.OutSuc(c, map[string]interface{}{
- "list": result,
- "state": []map[string]interface{}{
- {
- "name": enum.RoleState(enum.RoleStateForNormal).String(),
- "value": enum.RoleStateForNormal,
- },
- {
- "name": enum.RoleState(enum.RoleStateForFreeze).String(),
- "value": enum.RoleStateForFreeze,
- },
- },
- }, nil)
- return
- }
-
- // AddRole
- // @Summary 添加角色
- // @Tags 权限管理
- // @Description 权限管理-添加角色
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.AddRoleReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/addRole [POST]
- func AddRole(c *gin.Context) {
- var req md.AddRoleReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := db.DBs[svc.GetMasterId(c)]
- roleDb := implement.NewRoleDb(engine, 0)
- now := time.Now()
- _, err = roleDb.RoleInsert(&model.Role{
- Name: req.Name,
- State: enum.RoleStateForNormal,
- Memo: req.Memo,
- Logo: req.Logo,
- Label: req.Label,
- SeoLogo: req.SeoLogo,
- SeoTitle: req.SeoTitle,
- CreateAt: now.Format("2006-01-02 15:04:05"),
- UpdateAt: now.Format("2006-01-02 15:04:05"),
- })
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UpdateRole
- // @Summary 修改角色
- // @Tags 权限管理
- // @Description 权限管理-修改角色
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.UpdateRoleReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/updateRole [POST]
- func UpdateRole(c *gin.Context) {
- var req md.UpdateRoleReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := db.DBs[svc.GetMasterId(c)]
- roleDb := implement.NewRoleDb(engine, req.RoleId)
- role, err := roleDb.GetRole()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if role == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
- return
- }
- role.Name = req.Name
- role.Memo = req.Memo
- role.Logo = req.Logo
- role.Label = req.Label
- role.SeoLogo = req.SeoLogo
- role.SeoTitle = req.SeoTitle
- _, err = roleDb.UpdateRole(role, "name", "memo", "logo", "label", "seo_logo", "seo_title")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // RoleBindPermissionGroup
- // @Summary 角色绑定权限组
- // @Tags 权限管理
- // @Description 权限管理-角色绑定权限组
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.RoleBindPermissionGroupReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/roleBindPermissionGroup [POST]
- func RoleBindPermissionGroup(c *gin.Context) {
- var req md.RoleBindPermissionGroupReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- err = svc.RoleBindPermissionGroup(c, req)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UpdateRoleState
- // @Summary 修改角色状态
- // @Tags 权限管理
- // @Description 权限管理-修改角色状态
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.UpdateRoleStateReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/updateRoleState [POST]
- func UpdateRoleState(c *gin.Context) {
- var req md.UpdateRoleStateReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := db.DBs[svc.GetMasterId(c)]
- roleDb := implement.NewRoleDb(engine, req.RoleId)
- role, err := roleDb.GetRole()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if role == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
- return
- }
- role.State = req.State
- _, err = roleDb.UpdateRole(role, "state")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // DeleteRole
- // @Summary 删除角色
- // @Tags 权限管理
- // @Description 权限管理-删除角色
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.UpdateRoleStateReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/deleteRole/{$id} [DELETE]
- func DeleteRole(c *gin.Context) {
- id := c.Param("id")
- engine := db.DBs[svc.GetMasterId(c)]
- roleDb := implement.NewRoleDb(engine, utils.StrToInt(id))
- role, err := roleDb.GetRole()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if role == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
- return
- }
-
- err = svc.DeleteRole(c, utils.StrToInt(id))
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
-
- e.OutSuc(c, "success", nil)
- return
- }
-
- // AdminList
- // @Summary 管理员列表
- // @Tags 权限管理
- // @Description 权限管理-管理员列表
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.AdminListReq true "请求参数"
- // @Success 200 {string} "具体看返回内容"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/adminList [POST]
- func AdminList(c *gin.Context) {
- var req md.AdminListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- if req.Limit == 0 {
- req.Limit = 10
- }
- if req.Page == 0 {
- req.Page = 10
- }
- engine := db.DBs[svc.GetMasterId(c)]
- adminDb := implement.NewAdminDb(engine)
- adminList, total, err := adminDb.FindAdmin(req.UserName, req.State, req.Page, req.Limit)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- var result []md.AdminListResp
- for _, v := range adminList {
- permissionGroupList, _, err1 := adminDb.FindAdminRolePermissionGroup(v.AdmId)
- if err1 != nil {
- e.OutErr(c, e.ERR_DB_ORM, err1.Error())
- return
- }
- var roleList []string
- for _, v1 := range permissionGroupList {
- roleList = append(roleList, v1.Role.Name)
- }
-
- result = append(result, md.AdminListResp{
- AdmId: v.AdmId,
- Username: v.Username,
- State: v.State,
- IsSuperAdministrator: v.IsSuperAdministrator,
- Memo: v.Memo,
- CreateAt: v.CreateAt,
- UpdateAt: v.UpdateAt,
- RoleList: roleList,
- })
- }
-
- e.OutSuc(c, map[string]interface{}{
- "list": result,
- "total": total,
- "state": []map[string]interface{}{
- {
- "name": enum.RoleState(enum.RoleStateForNormal).String(),
- "value": enum.RoleStateForNormal,
- },
- {
- "name": enum.RoleState(enum.RoleStateForFreeze).String(),
- "value": enum.RoleStateForFreeze,
- },
- },
- }, nil)
- return
- }
-
- // UpdateAdminState
- // @Summary 修改管理员状态
- // @Tags 权限管理
- // @Description 权限管理-修改管理员状态
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.UpdateAdminStateReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/updateAdminState [POST]
- func UpdateAdminState(c *gin.Context) {
- var req md.UpdateAdminStateReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
-
- engine := db.DBs[svc.GetMasterId(c)]
- admDb := implement.NewAdminDb(engine)
- admin, err := admDb.GetAdmin(req.AdmId)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if admin == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
- return
- }
- admin.State = req.State
- _, err = admDb.UpdateAdmin(admin, "state")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // UpdateAdmin
- // @Summary 修改管理员信息
- // @Tags 权限管理
- // @Description 权限管理-修改管理员信息
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.UpdateAdminReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/updateAdmin [POST]
- func UpdateAdmin(c *gin.Context) {
- var req md.UpdateAdminReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := db.DBs[svc.GetMasterId(c)]
- admDb := implement.NewAdminDb(engine)
- admin, err := admDb.GetAdmin(req.AdmId)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if admin == nil {
- e.OutErr(c, e.ERR_NO_DATA, "未查询到相应记录")
- return
- }
- admin.Username = req.Username
- admin.Memo = req.Memo
- admin.Password = utils.Md5(req.Password)
- _, err = admDb.UpdateAdmin(admin, "username", "memo", "password")
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // AddAdmin
- // @Summary 新增管理员
- // @Tags 权限管理
- // @Description 权限管理-新增管理员
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.AddAdminReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/addAdmin [POST]
- func AddAdmin(c *gin.Context) {
- var req md.AddAdminReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := db.DBs[svc.GetMasterId(c)]
- admDb := implement.NewAdminDb(engine)
- isHasAdmin, err := admDb.GetAdminByUserName(req.Username)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- if isHasAdmin != nil {
- e.OutErr(c, e.ERR, "当前用户名已存在,请勿重复添加")
- return
- }
-
- admId, err := admDb.CreateAdminId()
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- admin := model.Admin{
- AdmId: admId,
- Username: req.Username,
- Password: utils.Md5(req.Password),
- State: enum.AdminStateForNormal,
- IsSuperAdministrator: 0,
- Memo: req.Memo,
- CreateAt: time.Now().Format("2006-01-02 15:04:05"),
- UpdateAt: time.Now().Format("2006-01-02 15:04:05"),
- }
- _, err = admDb.AdminInsert(&admin)
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // DeleteAdmin
- // @Summary 删除管理员
- // @Tags 权限管理
- // @Description 权限管理-删除管理员
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/deleteAdmin/{$adm_id} [DELETE]
- func DeleteAdmin(c *gin.Context) {
- admId := c.Param("adm_id")
- err := svc.AdminDelete(c, []int{utils.StrToInt(admId)})
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // BindAdminRole
- // @Summary 管理员绑定角色
- // @Tags 权限管理
- // @Description 权限管理-管理员绑定角色
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @Param args body md.BindAdminRoleReq true "请求参数"
- // @Success 200 {string} "success"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/bindAdminRole/ [POST]
- func BindAdminRole(c *gin.Context) {
- var req md.BindAdminRoleReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- err = svc.BindAdminRole(c, req)
- if err != nil {
- e.OutErr(c, e.ERR, err.Error())
- return
- }
- e.OutSuc(c, "success", nil)
- return
- }
-
- // AdminInfo
- // @Summary 管理员信息
- // @Tags 权限管理
- // @Description 权限管理-管理员信息
- // @param Authorization header string true "验证参数Bearer和token空格拼接"
- // @Accept json
- // @Produce json
- // @param adm_id query string true "管理员id"
- // @Success 200 {string} "具体看返回内容"
- // @Failure 400 {object} md.Response "具体错误"
- // @Router /api/role/adminInfo [GET]
- func AdminInfo(c *gin.Context) {
- admId := c.DefaultQuery("adm_id", "")
- engine := db.DBs[svc.GetMasterId(c)]
- admDb := implement.NewAdminDb(engine)
- admin, err := admDb.GetAdmin(utils.StrToInt(admId))
- if err != nil {
- e.OutErr(c, e.ERR_DB_ORM, err.Error())
- return
- }
- admin.Password = ""
- e.OutSuc(c, map[string]interface{}{
- "info": admin,
- "state": []map[string]interface{}{
- {
- "name": enum.RoleState(enum.RoleStateForNormal).String(),
- "value": enum.RoleStateForNormal,
- },
- {
- "name": enum.RoleState(enum.RoleStateForFreeze).String(),
- "value": enum.RoleStateForFreeze,
- },
- },
- }, nil)
- return
- }
- func RoleMediumList(c *gin.Context) {
- var req md.AdminBindMediumListReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- engine := svc.MasterDb(c)
- NewMediumDb := implement.NewMediumDb(engine)
- appId := svc.GetMediumIdStr(c, 0, req.Name, req.Account)
- list, total, _ := NewMediumDb.FindSuperAdminByMediumId(appId, utils.StrToInt(req.Page), utils.StrToInt(req.Limit))
- data := make([]md.AdminBindMediumListData, 0)
- if len(list) > 0 {
- for _, v := range list {
- var tmp = md.AdminBindMediumListData{
- MediumId: utils.IntToStr(v.MediumId),
- Name: v.Memo,
- IsBind: "0",
- Account: v.Username,
- }
- NewMediumListDb := implement2.NewMediumListDb(db.Db)
- GetMediumList, _ := NewMediumListDb.GetMediumList(v.MediumId)
- if GetMediumList != nil {
- tmp.Name = GetMediumList.CompanyName
- if GetMediumList.CompanyAbbreviation != "" {
- tmp.Name = GetMediumList.CompanyAbbreviation
- }
- }
- count, _ := engine.Where("medium_id=? and admin_id=?", v.MediumId, req.AdminId).Count(&model.AdminBindMedium{})
- if count > 0 {
- tmp.IsBind = "1"
- }
- data = append(data, tmp)
- }
- }
- res := md.AdminBindMediumListRes{
- List: data,
- Total: total,
- }
- e.OutSuc(c, res, nil)
- return
- }
- func RoleBindMedium(c *gin.Context) {
- var req md.AdminBindMediumListSaveReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- NewAdminBindMediumDb := implement.NewAdminBindMediumDb(svc.MasterDb(c))
- data := NewAdminBindMediumDb.GetAdminByMediumId(utils.StrToInt(req.AdminId), utils.StrToInt(req.MediumId))
- if data != nil {
- e.OutErr(c, 400, e.NewErr(400, "已绑定该媒体"))
- return
- }
- tmp := model.AdminBindMedium{
- AdminId: utils.StrToInt(req.AdminId),
- MediumId: utils.StrToInt(req.MediumId),
- CreateAt: time.Now(),
- UpdateAt: time.Now(),
- }
- svc.MasterDb(c).Insert(&tmp)
- e.OutSuc(c, "success", nil)
- return
- }
- func RoleDelMedium(c *gin.Context) {
- var req md.AdminBindMediumListSaveReq
- err := c.ShouldBindJSON(&req)
- if err != nil {
- err = validate.HandleValidateErr(err)
- err1 := err.(e.E)
- e.OutErr(c, err1.Code, err1.Error())
- return
- }
- svc.MasterDb(c).Where("medium_id=? and admin_id=?", req.MediumId, req.AdminId).Delete(&model.AdminBindMedium{})
- e.OutSuc(c, "success", nil)
- return
- }
|