industry.go 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. package controllers
  2. import (
  3. "encoding/json"
  4. "hongze/hongze_cygx/models"
  5. "hongze/hongze_cygx/utils"
  6. "strconv"
  7. "time"
  8. )
  9. // 报告
  10. type IndustryController struct {
  11. BaseAuthController
  12. }
  13. // @Title 关注/取消关注产业
  14. // @Description 关注/取消关注 接口
  15. // @Param request body models.CygxIndustryFllowRep true "type json string"
  16. // @Success 200
  17. // @router /follow [post]
  18. func (this *IndustryController) Fllow() {
  19. br := new(models.BaseResponse).Init()
  20. defer func() {
  21. this.Data["json"] = br
  22. this.ServeJSON()
  23. }()
  24. user := this.User
  25. if user == nil {
  26. br.Msg = "请重新登录"
  27. br.Ret = 408
  28. return
  29. }
  30. uid := user.UserId
  31. var req models.IndustryFllowArryReq
  32. resp := new(models.CygxIndustryFllowResp)
  33. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  34. if err != nil {
  35. br.Msg = "参数解析异常!"
  36. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  37. return
  38. }
  39. sourceId := req.SourceId
  40. source := req.Source
  41. doType := req.DoType
  42. var status int
  43. var condition string
  44. var pars []interface{}
  45. var industrialIds []int
  46. if source == "article" {
  47. pars = make([]interface{}, 0)
  48. condition = ` AND article_id = ? `
  49. pars = append(pars, sourceId)
  50. industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
  51. if err != nil && err.Error() != utils.ErrNoRow() {
  52. br.Msg = "获取信息失败"
  53. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  54. return
  55. }
  56. if len(industrialList) > 0 {
  57. for _, v := range industrialList {
  58. industrialIds = append(industrialIds, v.IndustrialManagementId)
  59. }
  60. }
  61. } else if source == "activity" {
  62. //处理活动关联的产业
  63. industrialList, err := models.GetIndustrialActivityGroupManagementList(sourceId)
  64. if err != nil && err.Error() != utils.ErrNoRow() {
  65. br.Msg = "获取信息失败"
  66. br.ErrMsg = "获取活动关联的产业列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(sourceId)
  67. return
  68. }
  69. if len(industrialList) > 0 {
  70. for _, v := range industrialList {
  71. industrialIds = append(industrialIds, v.IndustrialManagementId)
  72. }
  73. }
  74. } else {
  75. br.Msg = "参数解析异常!"
  76. br.ErrMsg = "资源类型有误:" + source
  77. return
  78. }
  79. lenindustrialIds := len(industrialIds)
  80. if lenindustrialIds == 0 {
  81. br.Msg = "操作失败!"
  82. br.ErrMsg = "对应的产业不存在:" + source + "ID:" + strconv.Itoa(sourceId)
  83. return
  84. }
  85. //批量取关与关注
  86. if doType == "add" {
  87. status = 1
  88. var industryFllowItems []*models.CygxIndustryFllow
  89. for _, v := range industrialIds {
  90. item := new(models.CygxIndustryFllow)
  91. item.IndustrialManagementId = v
  92. item.UserId = uid
  93. item.Email = user.Email
  94. item.Mobile = user.Mobile
  95. item.RealName = user.RealName
  96. item.CompanyId = user.CompanyId
  97. item.CompanyName = user.CompanyName
  98. item.Type = 1
  99. item.CreateTime = time.Now()
  100. item.ModifyTime = time.Now()
  101. industryFllowItems = append(industryFllowItems, item)
  102. }
  103. err = models.AddCygxIndustryFllowMulti(industryFllowItems)
  104. } else if doType == "cancel" {
  105. status = 2
  106. pars = make([]interface{}, 0)
  107. condition = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenindustrialIds) + `)`
  108. pars = append(pars, industrialIds)
  109. err = models.RemoveCygxIndustryFllowArry(uid, condition, pars)
  110. } else {
  111. br.Msg = "参数解析异常!"
  112. br.ErrMsg = "操作方式有误:" + doType
  113. return
  114. }
  115. if err != nil {
  116. br.Msg = "操作失败"
  117. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  118. return
  119. }
  120. resp.Status = status
  121. //处理是否关注全部赛道字段
  122. //go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
  123. br.Msg = "操作成功"
  124. br.Ret = 200
  125. br.Success = true
  126. br.Data = resp
  127. }