user_permission.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_api/models"
  5. "hongze/hongze_api/utils"
  6. "strconv"
  7. )
  8. func CheckUserPermission(userId int) (status int, err error) {
  9. if userId > 0 {
  10. wxUser, err := models.GetWxUserItemByUserId(userId)
  11. if err != nil {
  12. if err.Error() == utils.ErrNoRow() {
  13. status = 4001
  14. err = errors.New("用户信息不存在:userId:" + strconv.Itoa(userId))
  15. return status,err
  16. }
  17. status = 4001
  18. err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId) + ";Err:" + err.Error())
  19. return status, err
  20. }
  21. if wxUser == nil {
  22. status = 4001
  23. err = errors.New("获取用户信息失败:userId:" + strconv.Itoa(userId))
  24. return status, err
  25. }
  26. companyId := wxUser.CompanyId
  27. company, err := models.GetCompanyById(companyId)
  28. if err != nil {
  29. status = 4001
  30. err = errors.New("获取客户信息失败:userId:" + strconv.Itoa(userId) + ";Err:" + err.Error())
  31. return status, err
  32. }
  33. if company == nil {
  34. status = 4001
  35. err = errors.New("客户信息不存在:userId:" + strconv.Itoa(userId))
  36. return status, err
  37. }
  38. if company.IsFeeCustomer == 1 {
  39. status = 0
  40. } else {
  41. status = 40002
  42. err = errors.New("非付费用户" + strconv.Itoa(userId))
  43. }
  44. } else {
  45. status = 40001
  46. err = errors.New("用户id错误")
  47. }
  48. return
  49. }