123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- package services
- import (
- "errors"
- "eta/eta_mini_bridge/models"
- "eta/eta_mini_bridge/utils"
- "strconv"
- )
- func CheckUserPermission(userId int) (status int, err error) {
- if userId > 0 {
- user, err := GetUserItemByUserId(userId)
- if err != nil {
- status = 40001
- if err.Error() == utils.ErrNoRow() {
- err = errors.New("用户信息不存在:userId:" + strconv.Itoa(userId))
- return status, err
- }
- err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId) + ";Err:" + err.Error())
- return status, err
- }
- if user == nil {
- status = 40001
- err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId))
- return status, err
- }
- } else {
- status = 40001
- err = errors.New("用户id错误")
- }
- return
- }
- // GetClassifyTree 递归获取分类目录树
- func GetClassifyTree(list []*models.ClassifyView, parentId int) []*models.ClassifyView {
- res := make([]*models.ClassifyView, 0)
- for _, v := range list {
- if v.ParentId == parentId {
- t := new(models.ClassifyView)
- t.Id = v.Id
- t.ClassifyName = v.ClassifyName
- t.CreateTime = v.CreateTime
- t.HasChild = v.HasChild
- t.Level = v.Level
- t.ModifyTime = v.ModifyTime
- t.ParentId = v.ParentId
- t.Sort = v.Sort
- t.Child = GetClassifyTree(list, v.Id)
- res = append(res, t)
- }
- }
- return res
- }
|