package services import ( "errors" "fmt" "hongze/hongze_mfyx/models" "hongze/hongze_mfyx/utils" ) // GetUserYxHasPermissionCode 获取用户申请权限状态码 func GetUserYxHasPermissionCode(user *models.WxUserItem) (hasPermission int, err error) { defer func() { if err != nil { go utils.SendAlarmMsg(fmt.Sprint("线下调研活动报名给所属销售跟建会人员推送失败Err:", err.Error(), "活动ID:", "userId:", user.UserId), 2) } }() uid := user.UserId //判断是否已经申请过 applyCount, e := models.GetApplyRecordCount(uid) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetApplyRecordCount, Err: " + e.Error()) return } if user.CompanyId > 1 { //查询研选的权限状态 var condition string var pars []interface{} condition += " AND company_id = ? AND status IN ('正式','试用') AND chart_permission_id = ? ORDER BY company_report_permission_id DESC LIMIT 1 " pars = append(pars, user.CompanyId, utils.CHART_PERMISSION_ID_YANXUAN) companyReportPermissionDetail, e := models.GetCompanyReportPermissionDetailByCondition(condition, pars) if e != nil && e.Error() != utils.ErrNoRow() { err = errors.New("GetCompanyReportPermissionDetailByCondition, Err: " + e.Error()) return } if companyReportPermissionDetail == nil { if applyCount > 0 { hasPermission = 5 } else { hasPermission = 2 } } else { hasPermission = 1 } } else { //潜在客户 if applyCount > 0 { hasPermission = 5 } else { hasPermission = 4 } } return }