industry.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
  33. if err != nil {
  34. br.Msg = "参数解析异常!"
  35. br.ErrMsg = "参数解析失败,Err:" + err.Error()
  36. return
  37. }
  38. sourceId := req.SourceId
  39. source := req.Source
  40. doType := req.DoType
  41. var condition string
  42. var pars []interface{}
  43. var industrialIds []int
  44. if source == "article" {
  45. pars = make([]interface{}, 0)
  46. condition = ` AND article_id = ? `
  47. pars = append(pars, sourceId)
  48. industrialList, err := models.GetIndustrialArticleGroupManagementList(condition, pars)
  49. if err != nil && err.Error() != utils.ErrNoRow() {
  50. br.Msg = "获取信息失败"
  51. br.ErrMsg = "获取信息失败,Err:" + err.Error()
  52. return
  53. }
  54. if len(industrialList) > 0 {
  55. for _, v := range industrialList {
  56. industrialIds = append(industrialIds, v.IndustrialManagementId)
  57. }
  58. }
  59. } else if source == "activity" {
  60. //处理活动关联的产业
  61. industrialList, err := models.GetIndustrialActivityGroupManagementList(sourceId)
  62. if err != nil && err.Error() != utils.ErrNoRow() {
  63. br.Msg = "获取信息失败"
  64. br.ErrMsg = "获取活动关联的产业列表信息失败,Err:" + err.Error() + "activityId:" + strconv.Itoa(sourceId)
  65. return
  66. }
  67. if len(industrialList) > 0 {
  68. for _, v := range industrialList {
  69. industrialIds = append(industrialIds, v.IndustrialManagementId)
  70. }
  71. }
  72. } else {
  73. br.Msg = "参数解析异常!"
  74. br.ErrMsg = "资源类型有误:" + source
  75. return
  76. }
  77. lenindustrialIds := len(industrialIds)
  78. if lenindustrialIds == 0 {
  79. br.Msg = "操作失败!"
  80. br.ErrMsg = "对应的产业不存在:" + source + "ID:" + strconv.Itoa(sourceId)
  81. return
  82. }
  83. //批量取关与关注
  84. if doType == "add" {
  85. var industryFllowItems []*models.CygxIndustryFllow
  86. for _, v := range industrialIds {
  87. item := new(models.CygxIndustryFllow)
  88. item.IndustrialManagementId = v
  89. item.UserId = uid
  90. item.Email = user.Email
  91. item.Mobile = user.Mobile
  92. item.RealName = user.RealName
  93. item.CompanyId = user.CompanyId
  94. item.CompanyName = user.CompanyName
  95. item.Type = 1
  96. item.CreateTime = time.Now()
  97. item.ModifyTime = time.Now()
  98. industryFllowItems = append(industryFllowItems, item)
  99. }
  100. err = models.AddCygxIndustryFllowMulti(industryFllowItems)
  101. } else if doType == "cancel" {
  102. pars = make([]interface{}, 0)
  103. condition = ` AND industrial_management_id IN (` + utils.GetOrmInReplace(lenindustrialIds) + `)`
  104. pars = append(pars, industrialIds)
  105. err = models.RemoveCygxIndustryFllowArry(uid, condition, pars)
  106. } else {
  107. br.Msg = "参数解析异常!"
  108. br.ErrMsg = "操作方式有误:" + doType
  109. return
  110. }
  111. if err != nil {
  112. br.Msg = "操作失败"
  113. br.ErrMsg = "取消关注失败,Err:" + err.Error()
  114. return
  115. }
  116. //处理是否关注全部赛道字段
  117. //go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
  118. br.Msg = "操作成功"
  119. br.Ret = 200
  120. br.Success = true
  121. //br.Data = resp
  122. }