banner.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. package services
  2. import (
  3. "hongze/hongze_clpt/models"
  4. "hongze/hongze_clpt/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
  12. //3:活动详情 https://web.hzinsights.com/activity/detail/2701
  13. //4:产业详情 https://web.hzinsights.com/indepth/info/20/79
  14. //5:关于我们 https://clpttest.hzinsights.com/about
  15. //6:产品内测 https://clpttest.hzinsights.com/internal/article/29
  16. material := "material/info"
  17. activity := "activity/detail"
  18. indepth := "indepth/info"
  19. about := "/about"
  20. internal := "internal/article"
  21. item := new(models.BannerUrlResp)
  22. item.Body = url
  23. urlSlice := strings.Split(url, "/")
  24. lenurlSlice := len(urlSlice)
  25. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  26. item.SourceId = sourceId
  27. if strings.Contains(url, material) {
  28. item.Type = 2
  29. } else if strings.Contains(url, activity) {
  30. item.Type = 3
  31. } else if strings.Contains(url, indepth) {
  32. if lenurlSlice >= 2 {
  33. chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
  34. item.ChartPermissionId = chartPermissionId
  35. }
  36. item.Type = 4
  37. } else if strings.Contains(url, about) {
  38. item.Type = 5
  39. } else if strings.Contains(url, internal) {
  40. item.Type = 6
  41. } else {
  42. item.Type = 1
  43. }
  44. itemResp = item
  45. return
  46. }
  47. func AddCygxBannerHistory(user *models.WxUserItem, bannerId int) (err error) {
  48. defer func() {
  49. if err != nil {
  50. go utils.SendAlarmMsg("产品内测用户浏览信息记录失败"+err.Error(), 2)
  51. }
  52. }()
  53. historyRecord := new(models.CygxBannerHistory)
  54. historyRecord.UserId = user.UserId
  55. historyRecord.BannerId = bannerId
  56. historyRecord.CreateTime = time.Now()
  57. historyRecord.Mobile = user.Mobile
  58. historyRecord.Email = user.Email
  59. historyRecord.CompanyId = user.CompanyId
  60. historyRecord.CompanyName = user.CompanyName
  61. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  62. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  63. if err != nil && err.Error() != utils.ErrNoRow() {
  64. return
  65. }
  66. historyRecord.RealName = user.RealName
  67. if sellerItem != nil {
  68. historyRecord.SellerName = sellerItem.RealName
  69. }
  70. _, err = models.AddCygxBannerHistory(historyRecord)
  71. return
  72. }