tag.go 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. package services
  2. import (
  3. "errors"
  4. "hongze/hongze_mfyx/models"
  5. "hongze/hongze_mfyx/utils"
  6. "strconv"
  7. "time"
  8. )
  9. func AddCygxTagHistory(user *models.WxUserItem, tagId int) (err error) {
  10. if user.UserId == 0 {
  11. return
  12. }
  13. defer func() {
  14. if err != nil {
  15. go utils.SendAlarmMsg("tag点击信息记录失败"+err.Error()+"tagId"+strconv.Itoa(tagId)+"userId:"+strconv.Itoa(user.UserId), 2)
  16. }
  17. }()
  18. historyRecord := new(models.CygxTagHistory)
  19. historyRecord.UserId = user.UserId
  20. historyRecord.TagId = tagId
  21. historyRecord.CreateTime = time.Now()
  22. historyRecord.Mobile = user.Mobile
  23. historyRecord.Email = user.Email
  24. historyRecord.CompanyId = user.CompanyId
  25. historyRecord.CompanyName = user.CompanyName
  26. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  27. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  28. if err != nil && err.Error() != utils.ErrNoRow() {
  29. return
  30. }
  31. historyRecord.RealName = user.RealName
  32. if sellerItem != nil {
  33. historyRecord.SellerName = sellerItem.RealName
  34. }
  35. _, err = models.AddCygxTagHistory(historyRecord)
  36. return
  37. }
  38. //func init() {
  39. // conditionInit, err := GetConditionInitByTagIds("20,21,26")
  40. // fmt.Println(err)
  41. // fmt.Println()
  42. // fmt.Println(conditionInit)
  43. //}
  44. //const (
  45. // LABEL_L1_1 string = "全部活动" // 全部活动
  46. // LABEL_L1_2 string = "买方交流" // 买方交流
  47. // LABEL_L1_3 string = "专家调研" // 专家调研
  48. // LABEL_L1_4 string = "上市公司小范围" // 上市公司小范围
  49. // LABEL_L2_1 string = "全部报告" // 全部报告
  50. // LABEL_L2_2 string = "专栏" // 专栏
  51. // LABEL_L2_3 string = "纪要" // 纪要
  52. // LABEL_L2_4 string = "买方沙龙" // 买方沙龙
  53. // LABEL_L3_1 string = "主题a" // 主题a
  54. // LABEL_L3_2 string = "主题b" // 主题b
  55. // LABEL_L3_3 string = "主题c" // 主题c
  56. //)
  57. func GetConditionInitByTagIds(user *models.WxUserItem, labelKeyword string) (yanxuanActivityIdsResp, yanxuanArticleIdsResp []int, conditionresp string, err error) {
  58. var yanxuanActivityIds []int
  59. var yanxuanArticleIds []int
  60. var condition string
  61. var pars []interface{}
  62. switch labelKeyword {
  63. case utils.LABEL_L1_1: // 全部活动
  64. yanxuanActivityIds = GetYanxuanActivityIds(user, "1,2") // 获取所有的研选活动ID
  65. case "买方交流": // 买方交流 ->买方线下交流
  66. condition = ` AND chart_permission_id = ? AND yidong_activity_id = '' AND activity_type_id = 8 AND active_state IN (1,2) `
  67. pars = append(pars, utils.CHART_PERMISSION_ID_YANXUAN)
  68. list, e := models.GetCygxActivityIdList(condition, pars)
  69. if e != nil {
  70. err = errors.New("GetCygxActivityIdList, Err: " + e.Error())
  71. return
  72. }
  73. for _, v := range list {
  74. yanxuanActivityIds = append(yanxuanActivityIds, v.ActivityId)
  75. }
  76. case "专家调研": // 专家调研->专家电话会+专家线下沙龙
  77. condition = ` AND chart_permission_id = ? AND yidong_activity_id = '' AND activity_type_id IN (1,5) AND active_state IN (1,2) `
  78. pars = append(pars, utils.CHART_PERMISSION_ID_YANXUAN)
  79. list, e := models.GetCygxActivityIdList(condition, pars)
  80. if e != nil {
  81. err = errors.New("GetCygxActivityIdList, Err: " + e.Error())
  82. return
  83. }
  84. for _, v := range list {
  85. yanxuanActivityIds = append(yanxuanActivityIds, v.ActivityId)
  86. }
  87. case "上市公司小范围": // 上市公司小范围->公司调研电话会
  88. condition = ` AND chart_permission_id = ? AND yidong_activity_id = '' AND activity_type_id = 3 AND active_state IN (1,2) `
  89. pars = append(pars, utils.CHART_PERMISSION_ID_YANXUAN)
  90. list, e := models.GetCygxActivityIdList(condition, pars)
  91. if e != nil {
  92. err = errors.New("GetCygxActivityIdList, Err: " + e.Error())
  93. return
  94. }
  95. for _, v := range list {
  96. yanxuanActivityIds = append(yanxuanActivityIds, v.ActivityId)
  97. }
  98. case "全部报告": // 全部报告
  99. yanxuanArticleIds = GetYanxuanArticleIds() //获取所有研选文章ID
  100. conditionresp = ` AND source IN ('article','yanxuanspecial') `
  101. case "专栏": //专栏
  102. conditionresp = ` AND source IN ('yanxuanspecial') `
  103. case "纪要": //纪要
  104. conditionresp = ` AND source IN ('article') `
  105. condition = ` AND article_type_id > 0 `
  106. list, e := models.GetCygxCygxArticleIdList(condition, pars)
  107. if e != nil {
  108. err = errors.New("GetCygxCygxArticleIdList, Err: " + e.Error())
  109. return
  110. }
  111. for _, v := range list {
  112. yanxuanArticleIds = append(yanxuanArticleIds, v.ArticleId)
  113. }
  114. //case "买方沙龙": // 买方沙龙
  115. // condition = ` AND article_type_id = 12 `
  116. // list, e := models.GetCygxCygxArticleIdList(condition, pars)
  117. // if e != nil {
  118. // err = errors.New("GetCygxCygxArticleIdList, Err: " + e.Error())
  119. // return
  120. // }
  121. // for _, v := range list {
  122. // yanxuanArticleIds = append(yanxuanArticleIds, v.ArticleId)
  123. // }
  124. }
  125. yanxuanActivityIdsPerssion := GetYanxuanActivityIds(user, "1,2") // 获取所有有权限的研选活动ID
  126. mapyanxuanActivityIds := make(map[int]bool)
  127. for _, v := range yanxuanActivityIdsPerssion {
  128. mapyanxuanActivityIds[v] = true
  129. }
  130. for _, v := range yanxuanActivityIds {
  131. if mapyanxuanActivityIds[v] {
  132. yanxuanActivityIdsResp = append(yanxuanActivityIdsResp, v)
  133. }
  134. }
  135. yanxuanArticleIdsResp = yanxuanArticleIds
  136. return
  137. }