user_permission.go 1.5 KB

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