package controllers import ( "encoding/json" "fmt" "hongze/hongze_clpt/models" "hongze/hongze_clpt/services" "hongze/hongze_clpt/utils" "strconv" "strings" "time" ) type ArticleController struct { BaseAuthController } type ArticleCommonController struct { BaseCommonController } // @Title 获取报告详情 // @Description 获取报告详情接口 // @Param ArticleId query int true "报告ID" // @Success 200 {object} models.ArticleDetailResp // @router /detail [get] func (this *ArticleController) Detail() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } resp := new(models.ArticleDetailResp) uid := user.UserId articleId, err := this.GetInt("ArticleId") if articleId <= 0 { br.Msg = "文章不存在" br.ErrMsg = "文章不存在,文章ID错误" return } detail := new(models.ArticleDetail) hasPermission := 0 hasFree := 0 var haveResearch bool //判断是否已经申请过 applyCount, err := models.GetApplyRecordCount(uid) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error() return } //resp := new(models.ArticleDetailResp) detail, err = models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } // 判断是否属于研选类型的报告 if strings.Contains(detail.CategoryName, utils.CHART_PERMISSION_NAME_YANXUAN) { resp.IsResearch = true } // 高毅资产的联系人,有权限的行业也不能查看报告详情页。提示无权限页面 if detail.ArticleTypeId == 0 && user.CompanyId == utils.GAO_YI_ZI_CHAN_COMPANY_ID { _, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error() return } resp.PopupMsg = popupMsg resp.HasPermission = 3 resp.SellerName = sellerName resp.SellerMobile = sellerMobile detail.Body = "" detail.Abstract = "" detail.Seller.SellerName = sellerName detail.Seller.SellerMobile = sellerMobile resp.Detail = detail br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp return } //是否属于专项调研报告 if detail.SubCategoryName == "专项调研" { detail.IsSpecialArticle = true havePower, err := services.GetSpecialArticleDetailUserPower(user, detail) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error() return } resp.IsSpecialArticle = true if !havePower { hasPermission, sellerName, sellerMobile, popupMsg, err := services.GetUserHasPermissionArticle(user) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error() return } resp.PopupMsg = popupMsg resp.HasPermission = hasPermission resp.SellerName = sellerName resp.SellerMobile = sellerMobile detail.Body = "" detail.Abstract = "" detail.Seller.SellerName = sellerName detail.Seller.SellerMobile = sellerMobile resp.Detail = detail br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp return } } //HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下(ficc),3:无该品类权限,已提交过申请,4:无该品类权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"` if user.CompanyId > 1 { companyPermission, err := models.GetCompanyPermission(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } //permissionNameArr := strings.Split(companyPermission, ",") //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称 mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid) if mfyxUserPermissionTotal == 1 { companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME //permissionNameArr = append(permissionNameArr, utils.CHART_PERMISSION_NAME_MF_YANXUAN) //permissionNameArr = append(permissionNameArr, utils.MAI_FANG_YAN_XUAN_NAME) } //如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验 if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) { companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME } detail, err = models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } detail.Body = services.GetReportContentTextArticleBody(detail.Body) detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract) if companyPermission == "" { if applyCount > 0 { hasPermission = 6 } else { hasPermission = 2 } hasFree = 2 goto Loop } else { hasPermission = 1 hasFree = 1 var articlePermissionName string var matchTypeName string //查研观向这边的匹配类型 if detail.CategoryId > 0 { articlePermission, err := models.GetArticlePermission(detail.CategoryId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if articlePermission == nil { br.Msg = "获取信息失败" br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } articlePermissionName = articlePermission.PermissionName matchTypeName = articlePermission.MatchTypeName } else { articlePermissionName = detail.CategoryName } if resp.IsResearch { detail.ChartPermissionName = utils.MAI_FANG_YAN_XUAN_NAME } else { detail.ChartPermissionName = articlePermissionName } var hasPersion bool slice := strings.Split(articlePermissionName, ",") for _, v := range slice { if strings.Contains(companyPermission, v) { //if utils.InArrayByStr(permissionNameArr, v) { hasPersion = true } } if articleId == 11223 { // 这是一篇非常特殊的文章,要单独处理 需求池 976 if strings.Contains(companyPermission, utils.YI_YAO_NAME) || strings.Contains(companyPermission, utils.XIAO_FEI_NAME) || strings.Contains(companyPermission, utils.KE_JI_NAME) || strings.Contains(companyPermission, utils.ZHI_ZAO_NAME) { hasPersion = true } } userType, _, err := services.GetUserType(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取用户信息失败,Err:" + err.Error() return } //永续客户,无法查看研选权限,但是下面的联系人,单独开通研选后,也可以查看研选内容 if userType == 1 && strings.Contains(detail.CategoryName, "研选") && mfyxUserPermissionTotal == 0 { hasPersion = false } //if detail.IsReport == 1 { // detailCategory, err := models.GetdetailByCategoryIdSando(detail.CategoryId) // if err != nil && err.Error() != utils.ErrNoRow() { // br.Msg = "获取信息失败" // br.ErrMsg = "获取信息失败,Err:" + err.Error() + "categoryID 不存在:" + strconv.Itoa(detail.CategoryId) // return // } // permissionStr, err := models.GetCompanyPermissionByUser(user.CompanyId) // if err != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取客户信息失败,Err:" + err.Error() // return // } // if detailCategory != nil { // if detailCategory.PermissionType == 1 { // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(主观)") { // hasPersion = false // } // } else if detailCategory.PermissionType == 2 { // if !strings.Contains(permissionStr, detailCategory.ChartPermissionName+"(客观)") { // hasPersion = false // } // } // } //} //大行业通过权限校验,再校验主客观权限。只有医药、消费、科技、智造,才会校验主客观权限,热点问答这个匹配类型下的所有报告,也不做主客观校验 if hasPersion && utils.InArrayByStr([]string{utils.YI_YAO_NAME, utils.XIAO_FEI_NAME, utils.KE_JI_NAME, utils.ZHI_ZAO_NAME}, articlePermissionName) && matchTypeName != "热点问答" { hasPersion = services.CheckArticlePermissionType(articleId, user) } if !hasPersion { if applyCount == 0 { hasPermission = 4 } else { hasPermission = 3 } } } collectCount, err := models.GetArticleCollectCount(uid, articleId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已收藏失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if collectCount > 0 { detail.IsCollect = true } interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if interviewApplyItem != nil && interviewApplyItem.InterviewApplyId > 0 { detail.IsInterviewApply = true detail.InterviewApplyStatus = interviewApplyItem.Status } //获取销售手机号 sellerItem, err := models.GetSellerByCompanyId(user.CompanyId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if sellerItem != nil { detail.Seller.SellerMobile = sellerItem.Mobile detail.Seller.SellerName = sellerItem.RealName } //作者头像 if detail.DepartmentId > 0 { departmentDetail, err := models.GetArticleDepartmentDateilById(detail.DepartmentId) if err == nil { detail.DepartmentDetail = departmentDetail } } } else { //潜在客户 if applyCount > 0 { hasPermission = 6 } else { hasPermission = 5 } } Loop: if hasPermission != 1 { detail.Body = "" } else { articleFollowdetail, err := models.GetArticleFollowDetail(articleId, uid) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取关注信息失败,Err:" + err.Error() return } detail.FollowNum = articleFollowdetail.DNum detail.CollectionNum = articleFollowdetail.AcNum detail.Disclaimers = utils.DISCLAIMERS if articleFollowdetail.MdNum > 0 { detail.IsFollow = true } haveResearch = true } if hasPermission == 2 || hasPermission == 4 { //获取销售手机号 sellerItem, err := models.GetSellerByCompanyId(user.CompanyId) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取销售数据失败2,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if sellerItem != nil { detail.Seller.SellerMobile = sellerItem.Mobile detail.Seller.SellerName = sellerItem.RealName } } if detail.ArticleId < utils.SummaryArticleId { if user.Mobile != "" { chartUserTokenByMobile, _ := services.GetUserTokenByMobile(user.Mobile) detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) + "?token=" + chartUserTokenByMobile } else { detail.HttpUrl = utils.StrategyPlatform + strconv.Itoa(articleId) } detail.IsNeedJump = true } //hasFree := 0 //var haveResearch bool fmt.Println(hasFree) fmt.Println(haveResearch) if hasPermission == 1 { go services.ArticleHistory(articleId, user) key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) if !utils.Rc.IsExist(key) { go services.ArticleUserRemind(user, detail, 1) utils.Rc.Put(key, 1, 30*time.Second) } } if detail.ArticleTypeId == 14 { detail.IsApplyAppointmentExpert = true //判断文章类型是否属于专家访谈 查研观向11.0 } if detail.SubCategoryName == "专项调研" { detail.IsSpecialArticle = true } detail.ShareImg = services.GetArticleShareImg(articleId) resp.HasPermission = hasPermission resp.IsSpecialArticle = detail.IsSpecialArticle resp.Detail = detail br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 收藏\取消收藏 // @Description 收藏\取消收藏 // @Param request body models.ArticleCollectReq true "type json string" // @Success 200 {object} models.ArticleCollectResp // @router /collect [post] func (this *ArticleController) ArticleCollect() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请重新登录" br.Ret = 408 return } uid := user.UserId var req models.ArticleCollectReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } articleId := req.ArticleId detail, err := models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } count, err := models.GetArticleCollectCount(uid, articleId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(models.ArticleCollectResp) if count <= 0 { item := new(models.CygxArticleCollect) item.ArticleId = req.ArticleId item.UserId = uid item.CreateTime = time.Now() item.Mobile = user.Mobile item.Email = user.Email item.CompanyId = user.CompanyId item.CompanyName = user.CompanyName item.RealName = user.RealName _, err = models.AddCygxArticleCollect(item) if err != nil { br.Msg = "收藏失败" br.ErrMsg = "收藏失败,Err:" + err.Error() return } br.Msg = "收藏成功" resp.Status = 1 // 文章收藏消息发送 go services.ArticleUserRemind(user, detail, 1) } else { err = models.RemoveArticleCollect(uid, articleId) if err != nil { br.Msg = "取消收藏失败" br.ErrMsg = "取消收藏失败,Err:" + err.Error() return } br.Msg = "已取消收藏" resp.Status = 2 } collectTotal, err := models.GetArticleCollectUsersCount(articleId) if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp.CollectCount = collectTotal br.Ret = 200 br.Success = true br.Data = resp } // @Title 访谈申请\取消访谈申请 // @Description 访谈申请\取消访谈申请 // @Param request body models.ArticleInterviewApplyReq true "type json string" // @Success 200 {object} models.FontsCollectResp // @router /interview/apply [post] func (this *ArticleController) InterviewApply() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请重新登录" br.Ret = 408 return } uid := user.UserId var req models.ArticleInterviewApplyReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } article, err := models.GetArticleDetailById(req.ArticleId) if err != nil { br.Msg = "获取纪要失败!" br.ErrMsg = "获取纪要失败,Err:" + err.Error() return } count, err := models.GetArticleInterviewApplyCount(uid, req.ArticleId) if err != nil { br.Msg = "获取数据失败!" br.ErrMsg = "获取数据失败,Err:" + err.Error() return } resp := new(models.ArticleInterviewApplyResp) if count <= 0 { item := new(models.CygxInterviewApply) item.ArticleId = req.ArticleId item.UserId = uid item.CompanyId = user.CompanyId item.Status = "待邀请" item.Sort = 1 item.ArticleTitle = article.Title item.CreateTime = time.Now() item.ModifyTime = time.Now() item.ArticleIdMd5 = article.ArticleIdMd5 _, err = models.AddCygxInterviewApply(item) if err != nil { br.Msg = "申请失败" br.ErrMsg = "申请失败,Err:" + err.Error() return } br.Msg = "申请成功" resp.Status = 1 //发送模板消息 if user.CompanyId > 1 { mobile := user.Mobile if mobile == "" { mobile = user.Email } sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId) if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" { openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile) if openIpItem != nil && openIpItem.OpenId != "" { go services.SendInterviewApplyTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem) } } } } else { err = models.RemoveArticleInterviewApply(uid, req.ArticleId) if err != nil { br.Msg = "取消申请失败" br.ErrMsg = "取消申请失败,Err:" + err.Error() return } br.Msg = "已取消申请" resp.Status = 2 if user.CompanyId > 1 { mobile := user.Mobile if mobile == "" { mobile = user.Email } sellerItem, _ := models.GetSellerByCompanyId(user.CompanyId) if sellerItem != nil && sellerItem.AdminId > 0 && user.Mobile != "" { openIpItem, _ := models.GetUserRecordByMobile(4, sellerItem.Mobile) if openIpItem != nil && openIpItem.OpenId != "" { go services.SendInterviewApplyCancelTemplateMsg(user.RealName, sellerItem.CompanyName, mobile, article.Title, openIpItem) } } } } br.Ret = 200 br.Success = true br.Data = resp } // @Title 文章带问 // @Description 新增文章带问接口 // @Param request body models.AddArticleAskRep true "type json string" // @Success Ret=200 新增成功 // @router /askAdd [post] func (this *ArticleController) AskAdd() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,SysUser Is Empty" br.Ret = 408 return } var req models.AddArticleAskRep err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } if req.Content == "" { br.Msg = "建议内容不可为空" return } content := req.Content //accessToken, err := models.GetWxAccessTokenByXzs() //itemToken, err := services.WxGetToken() //if err != nil { // br.Msg = "GetWxAccessToken Err:" + err.Error() // return //} //if accessToken == "" { // br.Msg = "accessToken is empty" // return //} //commerr, err := weapp.MSGSecCheck(accessToken, content) //if err != nil { // br.Msg = "内容校验失败!" // br.ErrMsg = "内容校验失败,Err:" + err.Error() // // return //} //fmt.Println(commerr) //if commerr.ErrCode != 0 { // br.Msg = "内容违规,请重新提交!" // br.ErrMsg = "颜文字内容违规,Err:" + commerr.ErrMSG // return //} articleId := req.ArticleId count, _ := models.GetArticleCountById(articleId) if count == 0 { br.Msg = "操作失败" br.ErrMsg = "文章ID错误,不存在 articleId:" + strconv.Itoa(articleId) return } companyDetail, err := models.GetCompanyDetailById(user.CompanyId) if err != nil { br.Msg = "提交失败!" br.ErrMsg = "获取客户详情失败,Err:" + err.Error() return } if companyDetail == nil { br.Msg = "提交失败!" br.ErrMsg = "客户不存在,uid:" + strconv.Itoa(user.UserId) return } item := new(models.CygxArticleAsk) item.UserId = user.UserId item.ArticleId = req.ArticleId item.CompanyId = user.CompanyId item.CompanyName = companyDetail.CompanyName item.CreateTime = time.Now() item.Mobile = user.Mobile item.Email = user.Email item.Content = content _, err = models.AddArticleAsk(item) if err != nil { br.Msg = "提交失败" br.ErrMsg = "提交失败,Err:" + err.Error() return } companyItem, err := models.GetSellerDetailAllByCompanyId(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取所属销售信息失败,Err:" + err.Error() return } var mobile string if utils.RunMode == "release" { //mobile = utils.WxMsgTemplateIdAskMsgMobileAll + "," + companyItem.Mobile mobile = utils.WxMsgTemplateIdAskMsgMobileAll } else { mobile = utils.WxMsgTemplateIdAskMsgMobile } openIdList, err := models.GetWxOpenIdByMobileList(mobile) if err != nil { br.Msg = "提交失败" br.ErrMsg = "提交失败,Err:" + err.Error() return } detail, err := models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } companyName := user.CompanyName + "-" + user.RealName + "(" + companyItem.SellerName + ")" go services.SendWxMsgWithAsk(companyName, time.Now().Format(utils.FormatDateTime), content, detail.Title, openIdList, req.ArticleId) br.Ret = 200 br.Success = true br.Msg = "提交成功" } // @Title 文章相关热门收藏 // @Description 文章相关热门收藏接口 // @Param ArticleId query int true "文章ID" // @Success 200 {object} models.ArticleCollectionLIstResp // @router /hotList [get] func (this *ArticleController) ArticleHotList() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请重新登录" br.Ret = 408 return } articleId, _ := this.GetInt("ArticleId") if articleId < 1 { br.Msg = "请输入分类ID" return } var condition string condition = ` AND a.article_id IN (SELECT article_id FROM cygx_industrial_article_group_management WHERE industrial_management_id IN (SELECT industrial_management_id FROM cygx_industrial_article_group_management WHERE article_id = ` + strconv.Itoa(articleId) + ` ) ) AND a.article_id != ` + strconv.Itoa(articleId) + ` AND a.category_name LIKE '%研选%' AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num DESC, publish_date DESC LIMIT 3 ` list, err := models.GetArticleCollectionList(condition, user.UserId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取品种信息失败,Err:" + err.Error() return } resp := new(models.ArticleCollectionLIstResp) if len(list) == 0 { list = make([]*models.ArticleCollectionResp, 0) } resp.List = list br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 上传文章阅读时间 // @Description 上传文章阅读时间接口 // @Param request body models.AddStopTimeRep true "type json string" // @Success 200 {object} models.ArticleDetailResp // @router /addStopTime [post] func (this *ArticleController) AddStopTime() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.AddStopTimeRep err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } uid := user.UserId articleId := req.ArticleId stopTime := req.StopTime outType := req.OutType //source := req.Source if articleId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } if stopTime == 0 { stopTime = 1 } if outType != 2 { outType = 1 } //source = "WEB" detail := new(models.ArticleDetail) hasPermission := 0 hasFree := 0 //判断是否已经申请过 applyCount, err := models.GetApplyRecordCount(uid) if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error() return } //`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"` if user.CompanyId > 1 { companyPermission, err := models.GetCompanyPermission(user.CompanyId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } detail, err = models.GetArticleDetailById(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if companyPermission == "" { if applyCount > 0 { hasPermission = 5 } else { hasPermission = 2 } hasFree = 2 goto Loop } else { hasFree = 1 var articlePermissionPermissionName string if detail.CategoryId > 0 { articlePermission, err := models.GetArticlePermission(detail.CategoryId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if articlePermission == nil { br.Msg = "获取信息失败" br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } articlePermissionPermissionName = articlePermission.PermissionName } else { articlePermissionPermissionName = detail.CategoryName } var hasPersion bool slice := strings.Split(articlePermissionPermissionName, ",") //判断用户是否开通了个人研选权限,如果有权限后缀拼接权限名称 mfyxUserPermissionTotal := services.GetMfyxUserPermissionTotal(uid) if mfyxUserPermissionTotal == 1 { companyPermission += "," + utils.CHART_PERMISSION_NAME_MF_YANXUAN companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME } //如果有研选订阅的权限,那么就拼接一个 买方研选的权限做校验 if strings.Contains(companyPermission, utils.CHART_PERMISSION_NAME_MF_YANXUAN) { companyPermission += "," + utils.MAI_FANG_YAN_XUAN_NAME } for _, v := range slice { if strings.Contains(companyPermission, v) { hasPersion = true } } if hasPersion { go services.ArticleHistoryStopTime(articleId, stopTime, outType, user) } else { //无该行业权限 hasPermission = 3 } } } else { //潜在客户 if applyCount > 0 { hasPermission = 5 } else { hasPermission = 4 } } Loop: resp := new(models.ArticleDetailAddStopTimeRep) resp.HasPermission = hasPermission resp.HasFree = hasFree br.Ret = 200 br.Success = true br.Msg = "操作成功" br.Data = resp } // @Title 约访专家 // @Description 约访专家接口 // @Param request body models.CygxArticleIdReq true "type json string" // @Success 200 {object} // @router /applyAppointmentExpert [post] func (this *ArticleController) ApplyAppointmentExpert() { br := new(models.BaseResponse).Init() defer func() { this.Data["json"] = br this.ServeJSON() }() user := this.User if user == nil { br.Msg = "请登录" br.ErrMsg = "请登录,用户信息为空" br.Ret = 408 return } var req models.CygxArticleIdReq err := json.Unmarshal(this.Ctx.Input.RequestBody, &req) if err != nil { br.Msg = "参数解析异常!" br.ErrMsg = "参数解析失败,Err:" + err.Error() return } articleId := req.ArticleId var condition string var pars []interface{} condition += ` AND article_id =? AND user_id = ? ` pars = append(pars, articleId, user.UserId) total, err := models.GetCygxArticleApplyAppointmentExpertCount(condition, pars) if err != nil { br.Msg = "约访专家失败" br.ErrMsg = "约访专家失败,Err:" + err.Error() return } if total > 0 { br.Msg = "您已提交申请,请勿重复提交。" return } err = services.AddArticleApplyAppointmentExpert(user, articleId) if err != nil { br.Msg = "约访专家失败" br.ErrMsg = "约访专家失败,Err:" + err.Error() return } services.SendArticleApplyAppointmentExpertTemplateMsg(user, articleId) br.Ret = 200 br.Success = true br.Msg = "操作成功" }