wx_user.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. package services
  2. import (
  3. "errors"
  4. "fmt"
  5. "hongze/hongze_mfyx/models"
  6. "hongze/hongze_mfyx/utils"
  7. )
  8. // GetUserYxHasPermissionCode 获取用户申请权限状态码
  9. func GetUserYxHasPermissionCode(user *models.WxUserItem) (hasPermission int, err error) {
  10. defer func() {
  11. if err != nil {
  12. go utils.SendAlarmMsg(fmt.Sprint("线下调研活动报名给所属销售跟建会人员推送失败Err:", err.Error(), "活动ID:", "userId:", user.UserId), 2)
  13. }
  14. }()
  15. uid := user.UserId
  16. //判断是否已经申请过
  17. applyCount, e := models.GetApplyRecordCount(uid)
  18. if e != nil && e.Error() != utils.ErrNoRow() {
  19. err = errors.New("GetApplyRecordCount, Err: " + e.Error())
  20. return
  21. }
  22. if user.CompanyId > 1 {
  23. //查询研选的权限状态
  24. var condition string
  25. var pars []interface{}
  26. condition += " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id = ? ORDER BY company_report_permission_id DESC LIMIT 1 "
  27. pars = append(pars, user.CompanyId, utils.CHART_PERMISSION_ID_YANXUAN)
  28. companyReportPermissionDetail, e := models.GetCompanyReportPermissionDetailByCondition(condition, pars)
  29. if e != nil && e.Error() != utils.ErrNoRow() {
  30. err = errors.New("GetCompanyReportPermissionDetailByCondition, Err: " + e.Error())
  31. return
  32. }
  33. if companyReportPermissionDetail == nil {
  34. if applyCount > 0 {
  35. hasPermission = 5
  36. } else {
  37. hasPermission = 2
  38. }
  39. } else {
  40. hasPermission = 1
  41. }
  42. } else { //潜在客户
  43. if applyCount > 0 {
  44. hasPermission = 5
  45. } else {
  46. hasPermission = 4
  47. }
  48. }
  49. return
  50. }