chart_permission.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. package services
  2. import (
  3. "errors"
  4. "eta/eta_mini_bridge/models"
  5. "eta/eta_mini_bridge/utils"
  6. "strconv"
  7. )
  8. func CheckUserPermission(userId int) (status int, err error) {
  9. if userId > 0 {
  10. user, err := GetUserItemByUserId(userId)
  11. if err != nil {
  12. status = 40001
  13. if err.Error() == utils.ErrNoRow() {
  14. err = errors.New("用户信息不存在:userId:" + strconv.Itoa(userId))
  15. return status, err
  16. }
  17. err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId) + ";Err:" + err.Error())
  18. return status, err
  19. }
  20. if user == nil {
  21. status = 40001
  22. err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId))
  23. return status, err
  24. }
  25. } else {
  26. status = 40001
  27. err = errors.New("用户id错误")
  28. }
  29. return
  30. }
  31. // GetClassifyTree 递归获取分类目录树
  32. func GetClassifyTree(list []*models.ClassifyView, parentId int) []*models.ClassifyView {
  33. res := make([]*models.ClassifyView, 0)
  34. for _, v := range list {
  35. if v.ParentId == parentId {
  36. t := new(models.ClassifyView)
  37. t.Id = v.Id
  38. t.ClassifyName = v.ClassifyName
  39. t.CreateTime = v.CreateTime
  40. t.HasChild = v.HasChild
  41. t.Level = v.Level
  42. t.ModifyTime = v.ModifyTime
  43. t.ParentId = v.ParentId
  44. t.Sort = v.Sort
  45. t.Child = GetClassifyTree(list, v.Id)
  46. res = append(res, t)
  47. }
  48. }
  49. return res
  50. }