|
@@ -0,0 +1,131 @@
|
|
|
+package controllers
|
|
|
+
|
|
|
+import (
|
|
|
+ "encoding/json"
|
|
|
+ "hongze/hongze_cygx/models"
|
|
|
+ "hongze/hongze_cygx/utils"
|
|
|
+ "strconv"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+// 报告
|
|
|
+type IndustryController struct {
|
|
|
+ BaseAuthController
|
|
|
+}
|
|
|
+
|
|
|
+// @Title 关注/取消关注产业
|
|
|
+// @Description 关注/取消关注 接口
|
|
|
+// @Param request body models.CygxIndustryFllowRep true "type json string"
|
|
|
+// @Success 200
|
|
|
+// @router /fllow [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
|
|
|
+ }
|
|
|
+ //type IndustryFllowArryReq struct {
|
|
|
+ // SourceId int `description:"资源ID"`
|
|
|
+ // Source string `description:"资源类型 报告 :article 、活动 :activity"`
|
|
|
+ // DoType string `description:"操作方式 关注 :add 、取消关注 :cancel"`
|
|
|
+ //}
|
|
|
+ uid := user.UserId
|
|
|
+ var req models.IndustryFllowArryReq
|
|
|
+
|
|
|
+ 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 condition string
|
|
|
+ var pars []interface{}
|
|
|
+ var industrialIds []int
|
|
|
+ if source == "article" {
|
|
|
+ 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" {
|
|
|
+ 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" {
|
|
|
+ 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
|
|
|
+ }
|
|
|
+ //处理是否关注全部赛道字段
|
|
|
+ //go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
|
|
|
+ br.Msg = "操作成功"
|
|
|
+ br.Ret = 200
|
|
|
+ br.Success = true
|
|
|
+ //br.Data = resp
|
|
|
+}
|