banner.go 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. package services
  2. import (
  3. "hongze/hongze_cygx/models"
  4. "hongze/hongze_cygx/utils"
  5. "strconv"
  6. "strings"
  7. "time"
  8. )
  9. // GetBannerUrlBody 处理banner的连接并做跳转处理
  10. func GetBannerUrlBody(url string) (itemResp *models.BannerUrlResp) {
  11. //2:文章详情 https://web.hzinsights.com/material/info/8436 小程序路径:/pageMy/reportDetail/reportDetail?id=
  12. //3:活动详情 https://web.hzinsights.com/activity/detail/2701 小程序路径:/activityPages/activityDetail/activityDetail?id=
  13. //4:产业详情 https://web.hzinsights.com/indepth/info/20/79 小程序路径:/reportPages/IndustryReport/IndustryReport?id=
  14. //5:关于我们 https://clpttest.hzinsights.com/about
  15. //6:产品内测 https://clpttest.hzinsights.com/internal/article/29 小程序路径:/reportPages/internalDetials/internalDetials?id=
  16. //7:本周研究汇总 https://clpttest.hzinsights.com/summary/2/152 小程序路径:/reportPages/reportSecretDetail/reportSecretDetail?type=2&id=
  17. //8:上周研究汇总 https://clpttest.hzinsights.com/summary/3/112 小程序路径:/reportPages/reportSecretDetail/reportSecretDetail?type=3&id=
  18. //9:专项调研活动 https://clpttest.hzinsights.com/activity/info/70 小程序路径:/activityPages/specialDetail/specialDetail?id=
  19. //10: 重点公司 https://clpttest.hzinsights.com/recent/67 小程序路径:/reportPages/keyCompany/keyCompany
  20. //11: 主题详情 https://clpttest.hzinsights.com/community/theme/117 小程序路径:/reportPages/researchTheme/researchTheme?id=
  21. //12: 作者详情 https://clpttest.hzinsights.com/community/author/78 小程序路径:/reportPages/authorPages/authorPages?id=
  22. mapPath := make(map[int]string)
  23. mapPath[2] = utils.WX_MSG_PATH_ARTICLE_DETAIL //文章详情
  24. mapPath[3] = utils.WX_MSG_PATH_ACTIVITY_DETAIL //活动详情
  25. mapPath[4] = utils.WX_MSG_PATH_INDUSTRY_DETAIL //产业详情
  26. mapPath[5] = utils.WX_MSG_PATH_ABOUT_US //关于我们视频
  27. mapPath[6] = utils.WX_MSG_PATH_PRODUCTINTERIOR_DETAIL //产品内测
  28. mapPath[7] = utils.WX_MSG_PATH_THIS_WEEK_DETAIL //本周研究汇总
  29. mapPath[8] = utils.WX_MSG_PATH_LAST_WEEK_DETAIL //上周研究汇总
  30. mapPath[9] = utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL //专项调研活动
  31. mapPath[10] = utils.WX_MSG_PATH_KEY_COMPANY_DETAIL //重点公司
  32. mapPath[11] = utils.WX_MSG_PATH_RESEARCHTHEME_DETAIL //主题详情
  33. mapPath[12] = utils.WX_MSG_PATH_AUTHOR_DETAIL //作者详情
  34. material := "material/info" //2:文章详情
  35. activity := "activity/detail" //3:活动详情
  36. activityVideo := "activity/video" //3:活动视频页,调活动详情
  37. indepth := "indepth/info" //4:产业详情
  38. indepthVideo := "indepth/video" //4:产业视频页,调详情
  39. about := "/about" //5:关于我们
  40. internal := "internal/article" //6:产品内测
  41. thisWeek := "summary/2/" //7:本周研究汇总
  42. lastWeek := "summary/3/" //8:上周研究汇总
  43. activitySpecial := "activity/info" //9:专项调研活动
  44. recent := "/recent/" //10:重点公司
  45. communityTheme := "/community/theme/" //11:主题详情
  46. communityAuthor := "/community/author/" //12:作者详情
  47. item := new(models.BannerUrlResp)
  48. item.Body = url
  49. urlSlice := strings.Split(url, "/")
  50. lenurlSlice := len(urlSlice)
  51. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  52. if strings.Contains(url, material) {
  53. item.Type = 2
  54. } else if strings.Contains(url, activity) {
  55. item.Type = 3
  56. } else if strings.Contains(url, activityVideo) {
  57. activityVideo, err := models.GetCygxActivityVideoById(sourceId)
  58. if err != nil {
  59. go utils.SendAlarmMsg("banner链接解析失败"+err.Error()+url, 2)
  60. }
  61. if activityVideo != nil {
  62. sourceId = activityVideo.ActivityId
  63. item.Type = 3
  64. }
  65. } else if strings.Contains(url, indepth) {
  66. if lenurlSlice >= 2 {
  67. chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
  68. item.ChartPermissionId = chartPermissionId
  69. }
  70. item.Type = 4
  71. } else if strings.Contains(url, indepthVideo) {
  72. if lenurlSlice >= 2 {
  73. sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
  74. }
  75. item.Type = 4
  76. } else if strings.Contains(url, about) {
  77. item.Type = 5
  78. sourceId = 1 // 强制设置为正数前端跳转使用
  79. } else if strings.Contains(url, internal) {
  80. item.Type = 6
  81. } else if strings.Contains(url, thisWeek) {
  82. item.Type = 7
  83. } else if strings.Contains(url, lastWeek) {
  84. item.Type = 8
  85. } else if strings.Contains(url, activitySpecial) {
  86. item.Type = 9
  87. } else if strings.Contains(url, recent) {
  88. item.Type = 10
  89. } else if strings.Contains(url, communityTheme) {
  90. item.Type = 11
  91. } else if strings.Contains(url, communityAuthor) {
  92. item.Type = 12
  93. } else {
  94. item.Type = 1
  95. }
  96. if mapPath[item.Type] != "" {
  97. item.Path = "/" + mapPath[item.Type]
  98. }
  99. item.SourceId = sourceId
  100. itemResp = item
  101. return
  102. }
  103. func AddCygxBannerHistory(user *models.WxUserItem, bannerId int) (err error) {
  104. if user.UserId == 0 {
  105. return
  106. }
  107. defer func() {
  108. if err != nil {
  109. go utils.SendAlarmMsg("banner点击信息记录失败"+err.Error()+"bannerId"+strconv.Itoa(bannerId)+"userId:"+strconv.Itoa(user.UserId), 2)
  110. }
  111. }()
  112. historyRecord := new(models.CygxBannerHistory)
  113. historyRecord.UserId = user.UserId
  114. historyRecord.BannerId = bannerId
  115. historyRecord.CreateTime = time.Now()
  116. historyRecord.Mobile = user.Mobile
  117. historyRecord.Email = user.Email
  118. historyRecord.CompanyId = user.CompanyId
  119. historyRecord.CompanyName = user.CompanyName
  120. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  121. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  122. if err != nil && err.Error() != utils.ErrNoRow() {
  123. return
  124. }
  125. historyRecord.RealName = user.RealName
  126. if sellerItem != nil {
  127. historyRecord.SellerName = sellerItem.RealName
  128. }
  129. _, err = models.AddCygxBannerHistory(historyRecord)
  130. return
  131. }