123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- package controllers
- import (
- "encoding/json"
- "hongze/hongze_mfyx/models"
- "hongze/hongze_mfyx/services"
- "hongze/hongze_mfyx/utils"
- "strconv"
- "time"
- )
- // 报告
- type IndustryController struct {
- BaseAuthController
- }
- // @Title 关注/取消关注产业
- // @Description 关注/取消关注 接口
- // @Param request body models.CygxIndustryFllowRep true "type json string"
- // @Success 200
- // @router /follow [post]
- func (this *IndustryController) Fllow() {
- 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.IndustryFllowArryReq
- resp := new(models.CygxIndustryFllowResp)
- err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
- if err != nil {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "参数解析失败,Err:" + err.Error()
- return
- }
- sourceId := req.SourceId
- source := req.Source
- doType := req.DoType
- var status int
- var condition string
- var pars []interface{}
- var industrialIds []int
- if source == "article" {
- articleDetail, err := models.GetArticleDetailById(sourceId)
- if err != nil {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- //判读是否属于策略的文章类型
- reportMappingMap, _ := services.GetReportMappingMap()
- if reportMappingMap[articleDetail.CategoryId] {
- chooseCategoryMap, _ := services.GetChooseCategoryMap(user)
- //判断用户是否关注策略对应分类
- if !chooseCategoryMap[articleDetail.CategoryId] {
- item := new(models.CygxXzsChooseCategory)
- item.CategoryId = articleDetail.CategoryId
- item.UserId = uid
- item.Email = user.Email
- item.Mobile = user.Mobile
- item.RealName = user.RealName
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- _, err = models.AddCygxCategoryFllow(item)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "操作失败,Err:" + err.Error()
- return
- }
- resp.Status = 1
- } else {
- err = models.RemoveCygxCategoryFllow(user.Mobile, articleDetail.CategoryId)
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "取消关注失败,Err:" + err.Error()
- return
- }
- resp.Status = 2
- }
- br.Msg = "操作成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- return
- } else {
- pars = make([]interface{}, 0)
- condition = ` AND article_id = ? `
- pars = append(pars, sourceId)
- industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取信息失败,Err:" + err.Error()
- return
- }
- if len(industrialList) > 0 {
- for _, v := range industrialList {
- industrialIds = append(industrialIds, v.IndustrialManagementId)
- }
- }
- }
- } else if source == "activity" {
- //处理活动关联的产业
- industrialList, err := models.GetIndustrialActivityGroupManagementList(sourceId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取活动关联的产业列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(sourceId)
- return
- }
- if len(industrialList) > 0 {
- for _, v := range industrialList {
- industrialIds = append(industrialIds, v.IndustrialManagementId)
- }
- }
- } else {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "资源类型有误:" + source
- return
- }
- lenindustrialIds := len(industrialIds)
- if lenindustrialIds == 0 {
- br.Msg = "操作失败!"
- br.ErrMsg = "对应的产业不存在:" + source + "ID:" + strconv.Itoa(sourceId)
- return
- }
- //批量取关与关注
- if doType == "add" {
- status = 1
- var industryFllowItems []*models.CygxIndustryFllow
- for _, v := range industrialIds {
- item := new(models.CygxIndustryFllow)
- item.IndustrialManagementId = v
- item.UserId = uid
- item.Email = user.Email
- item.Mobile = user.Mobile
- item.RealName = user.RealName
- item.CompanyId = user.CompanyId
- item.CompanyName = user.CompanyName
- item.Type = 1
- item.CreateTime = time.Now()
- item.ModifyTime = time.Now()
- industryFllowItems = append(industryFllowItems, item)
- }
- err = models.AddCygxIndustryFllowMulti(industryFllowItems)
- } else if doType == "cancel" {
- status = 2
- pars = make([]interface{}, 0)
- condition = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenindustrialIds) + `)`
- pars = append(pars, industrialIds)
- err = models.RemoveCygxIndustryFllowArry(uid, condition, pars)
- } else {
- br.Msg = "参数解析异常!"
- br.ErrMsg = "操作方式有误:" + doType
- return
- }
- if err != nil {
- br.Msg = "操作失败"
- br.ErrMsg = "取消关注失败,Err:" + err.Error()
- return
- }
- resp.Status = status
- //处理是否关注全部赛道字段
- //go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
- br.Msg = "操作成功"
- br.Ret = 200
- br.Success = true
- br.Data = resp
- }
|