banner.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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[6] = utils.WX_MSG_PATH_PRODUCTINTERIOR_DETAIL //产品内测
  27. mapPath[7] = utils.WX_MSG_PATH_THIS_WEEK_DETAIL //本周研究汇总
  28. mapPath[8] = utils.WX_MSG_PATH_LAST_WEEK_DETAIL //上周研究汇总
  29. mapPath[9] = utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL //专项调研活动
  30. mapPath[10] = utils.WX_MSG_PATH_KEY_COMPANY_DETAIL //重点公司
  31. mapPath[11] = utils.WX_MSG_PATH_RESEARCHTHEME_DETAIL //主题详情
  32. mapPath[12] = utils.WX_MSG_PATH_AUTHOR_DETAIL //作者详情
  33. material := "material/info" //2:文章详情
  34. activity := "activity/detail" //3:活动详情
  35. activityVideo := "activity/video" //3:活动视频页,调活动详情
  36. indepth := "indepth/info" //4:产业详情
  37. indepthVideo := "indepth/video" //4:产业视频页,调详情
  38. about := "/about" //5:关于我们
  39. internal := "internal/article" //6:产品内测
  40. thisWeek := "summary/2/" //7:本周研究汇总
  41. lastWeek := "summary/3/" //8:上周研究汇总
  42. activitySpecial := "activity/info" //9:专项调研活动
  43. recent := "/recent/" //10:重点公司
  44. communityTheme := "/community/theme/" //11:主题详情
  45. communityAuthor := "/community/author/" //12:作者详情
  46. item := new(models.BannerUrlResp)
  47. item.Body = url
  48. urlSlice := strings.Split(url, "/")
  49. lenurlSlice := len(urlSlice)
  50. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  51. if strings.Contains(url, material) {
  52. item.Type = 2
  53. } else if strings.Contains(url, activity) {
  54. item.Type = 3
  55. } else if strings.Contains(url, activityVideo) {
  56. activityVideo, err := models.GetCygxActivityVideoById(sourceId)
  57. if err != nil {
  58. go utils.SendAlarmMsg("banner链接解析失败"+err.Error()+url, 2)
  59. }
  60. if activityVideo != nil {
  61. sourceId = activityVideo.ActivityId
  62. item.Type = 3
  63. }
  64. } else if strings.Contains(url, indepth) {
  65. if lenurlSlice >= 2 {
  66. chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
  67. item.ChartPermissionId = chartPermissionId
  68. }
  69. item.Type = 4
  70. } else if strings.Contains(url, indepthVideo) {
  71. if lenurlSlice >= 2 {
  72. sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
  73. }
  74. item.Type = 4
  75. } else if strings.Contains(url, about) {
  76. item.Type = 5
  77. } else if strings.Contains(url, internal) {
  78. item.Type = 6
  79. } else if strings.Contains(url, thisWeek) {
  80. item.Type = 7
  81. } else if strings.Contains(url, lastWeek) {
  82. item.Type = 8
  83. } else if strings.Contains(url, activitySpecial) {
  84. item.Type = 9
  85. } else if strings.Contains(url, recent) {
  86. item.Type = 10
  87. } else if strings.Contains(url, communityTheme) {
  88. item.Type = 11
  89. } else if strings.Contains(url, communityAuthor) {
  90. item.Type = 12
  91. } else {
  92. item.Type = 1
  93. }
  94. if mapPath[item.Type] != "" {
  95. item.Path = "/" + mapPath[item.Type]
  96. }
  97. item.SourceId = sourceId
  98. itemResp = item
  99. return
  100. }
  101. func AddCygxBannerHistory(user *models.WxUserItem, bannerId int) (err error) {
  102. if user.UserId == 0 {
  103. return
  104. }
  105. defer func() {
  106. if err != nil {
  107. go utils.SendAlarmMsg("banner点击信息记录失败"+err.Error()+"bannerId"+strconv.Itoa(bannerId)+"userId:"+strconv.Itoa(user.UserId), 2)
  108. }
  109. }()
  110. historyRecord := new(models.CygxBannerHistory)
  111. historyRecord.UserId = user.UserId
  112. historyRecord.BannerId = bannerId
  113. historyRecord.CreateTime = time.Now()
  114. historyRecord.Mobile = user.Mobile
  115. historyRecord.Email = user.Email
  116. historyRecord.CompanyId = user.CompanyId
  117. historyRecord.CompanyName = user.CompanyName
  118. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  119. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  120. if err != nil && err.Error() != utils.ErrNoRow() {
  121. return
  122. }
  123. historyRecord.RealName = user.RealName
  124. if sellerItem != nil {
  125. historyRecord.SellerName = sellerItem.RealName
  126. }
  127. _, err = models.AddCygxBannerHistory(historyRecord)
  128. return
  129. }