package controllers import ( "fmt" "github.com/rdlucklib/rdluck_tools/paging" "hongze/hongze_cygx/models" "hongze/hongze_cygx/services" "hongze/hongze_cygx/utils" "html" "regexp" "strconv" "strings" "time" ) // 策略 type TacticsController struct { BaseAuthController } type TacticsCommonController struct { BaseCommonController } // @Title 策略、行业列表接口 // @Description 获取策略、行业 通用列表接口 // @Param PageSize query int true "每页数据条数" // @Param CurrentIndex query int true "当前页页码,从1开始" // @Param CategoryId query int true "分类ID" // @Success 200 {object} models.TacticsListResp // @router /list [get] func (this *TacticsController) List() { 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 pageSize, _ := this.GetInt("PageSize") currentIndex, _ := this.GetInt("CurrentIndex") categoryId, _ := this.GetInt("CategoryId") var startSize int if pageSize <= 0 { pageSize = utils.PageSize20 } if currentIndex <= 0 { currentIndex = 1 } startSize = paging.StartIndex(currentIndex, pageSize) var condition string var listTacticsSrt string var pars []interface{} var total int resp := new(models.TacticsListResp) page := paging.GetPaging(currentIndex, pageSize, total) //获取该产业下所对应的行业图片 detail, errCategory := models.GetdetailByCategoryIdOneByHangye(categoryId) if errCategory != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId) return } //对应行业的图片 detailChartPermissionUrl, err := models.GetConfigByCode("category_chart_permissionimg_url") if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "行业配置信息失败,Err:" + err.Error() return } chartPermissionUrlList := strings.Split(detailChartPermissionUrl.ConfigValue, "{|}") mapChartPermission := make(map[string]string) var permissionName string var imgUrlChartPermission string for _, v := range chartPermissionUrlList { vslice := strings.Split(v, "_") permissionName = vslice[0] imgUrlChartPermission = vslice[len(vslice)-1] mapChartPermission[permissionName] = imgUrlChartPermission } //对应分类的所图片 detailCategoryUrl, err := models.GetConfigByCode("category_map_img_url") if err != nil { br.Msg = "获取数据失败" br.ErrMsg = "行业配置信息失败,Err:" + err.Error() return } categoryUrlList := strings.Split(detailCategoryUrl.ConfigValue, "{|}") mapCategoryUrl := make(map[string]string) var categoryIdStr string var imgUrlChart string for _, v := range categoryUrlList { vslice := strings.Split(v, "_") categoryIdStr = vslice[0] imgUrlChart = vslice[len(vslice)-1] mapCategoryUrl[categoryIdStr] = imgUrlChart } if categoryId < 0 { listTactics, err := models.GetReportMappingStrategyAll() if err != nil && err.Error() != utils.ErrNoRow() { br.Msg = "获取信息失败" br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error() return } for _, v := range listTactics { listTacticsSrt = listTacticsSrt + strconv.Itoa(v.CategoryId) + `,` } listTacticsSrt = strings.TrimRight(listTacticsSrt, ",") condition = ` AND category_id IN(` + listTacticsSrt + `)` } else { //categoryIdSet, errCategory := models.GetdetailByCategoryIdSet(categoryId) //if errCategory != nil { // br.Msg = "获取信息失败" // br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId) // return //} //if categoryIdSet != "" { // condition = ` AND category_id IN(` + categoryIdSet + `)` //} else { // condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)` //} if detail.CeLueFieldId != "" { condition = ` AND ce_lue_field_id IN(` + detail.CeLueFieldId + `)` } else if detail.PolymerizationId != "" { condition = ` AND category_id IN(` + detail.PolymerizationId + `)` } else { condition = ` AND category_id IN(` + strconv.Itoa(categoryId) + `)` } } total, err = models.GetHomeCount(condition, pars) if err != nil { br.Msg = "获取信息失败" br.Msg = "获取帖子总数失败,Err:" + err.Error() return } page = paging.GetPaging(currentIndex, pageSize, total) list, err := models.GetReportTacticsList(condition, pars, uid, startSize, pageSize) if err != nil { br.Msg = "获取信息失败" br.Msg = "获取帖子数据失败,Err:" + err.Error() return } for k, v := range list { if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) { list[k].IsRed = true } list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId] } if categoryId > 0 { detail, errCategory := models.GetdetailByCategoryId(categoryId) if errCategory != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + errCategory.Error() + "categoryID 不存在:" + strconv.Itoa(categoryId) return } resp.MatchTypeName = detail.MatchTypeName } lenList := len(list) for i := 0; i < lenList; i++ { item := list[i] list[i].Body, _ = services.GetReportContentTextSub(item.Body) list[i].Abstract = html.UnescapeString(item.Abstract) //list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract) list[i].Annotation = strings.Replace(item.Annotation, "
", "", -1) //行业比较研究、资金流向,显示报告的摘要 if resp.MatchTypeName == "行业比较研究" || resp.MatchTypeName == "资金流向" { list[i].Annotation = list[i].Abstract } //if item.ArticleId == 6881 { // fmt.Println(list[i].Annotation) //} list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract) } resp.CategoryImgUrlPc = mapChartPermission[detail.ChartPermissionName] resp.List = list resp.Paging = page br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp } // @Title 获取报告详情 // @Description 获取报告详情接口 // @Param ArticleId query int true "报告ID" // @Success 200 {object} models.ArticleDetailResp // @router /detail [get] func (this *TacticsController) 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 } uid := user.UserId articleId, err := this.GetInt("ArticleId") if articleId <= 0 { br.Msg = "参数错误" br.ErrMsg = "参数错误" return } 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 } fmt.Println(user.CompanyId) //`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() return } fmt.Println(detail.Department) detail.Body = html.UnescapeString(detail.Body) //detail.Abstract = html.UnescapeString(detail.Abstract) detail.Abstract, _ = services.GetReportContentTextSub(detail.Abstract) 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 } if strings.Contains(companyPermission, articlePermissionPermissionName) { hasPermission = 1 historyRecord := new(models.CygxArticleHistoryRecord) historyRecord.UserId = uid historyRecord.ArticleId = articleId historyRecord.CreateTime = time.Now() historyRecord.Mobile = user.Mobile historyRecord.Email = user.Email historyRecord.CompanyId = user.CompanyId historyRecord.CompanyName = user.CompanyName recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId) if recordCount == 0 { go models.AddCygxArticleHistoryRecord(historyRecord) } else { detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取信息失败,Err:" + err.Error() return } if detailNew.StopTime > 0 { go models.AddCygxArticleHistoryRecord(historyRecord) } } } 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:" + err.Error() + 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 { br.Msg = "获取信息失败" br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if sellerItem != nil { detail.SellerMobile = sellerItem.Mobile detail.SellerName = sellerItem.RealName } sellerList, err := models.GetSellerList(articleId) if err != nil { br.Msg = "获取信息失败" br.ErrMsg = "获取销售数据失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId) return } if detail.ArticleId > 1000000 { var hrefRegexp = regexp.MustCompile("[0-9]\\d*") match := hrefRegexp.FindAllString(detail.SellerAndMobile, -1) if match != nil { for _, v := range match { sellerAndMobile := &models.SellerRep{ SellerMobile: v, SellerName: strings.Replace(detail.SellerAndMobile, v, "", -1), } sellerList = append(sellerList, sellerAndMobile) } } } detail.SellerList = sellerList } else { //潜在客户 if applyCount > 0 { hasPermission = 5 } else { hasPermission = 4 } } Loop: if hasPermission != 1 { detail.Body = "" detail.BodyText = "" } resp := new(models.ArticleDetailResp) resp.HasPermission = hasPermission resp.HasFree = hasFree resp.Detail = detail br.Ret = 200 br.Success = true br.Msg = "获取成功" br.Data = resp }