product_interior.go 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. package services
  2. import (
  3. "fmt"
  4. "hongze/hongze_clpt/models"
  5. "hongze/hongze_clpt/utils"
  6. "regexp"
  7. "strconv"
  8. "strings"
  9. "time"
  10. )
  11. // GetProductInteriorUrl 处理产品内测中的连接并做跳转处理
  12. func GetProductInteriorUrl(url string, urlMap map[string]string) (itemResp *models.ProductInteriorUrlResp) {
  13. //2:文章详情 https://web.hzinsights.com/material/info/8436
  14. //3:活动详情 https://web.hzinsights.com/activity/detail/2701
  15. //4:产业详情 https://web.hzinsights.com/indepth/info/20/79
  16. item := new(models.ProductInteriorUrlResp)
  17. item.Body = url
  18. if urlMap[url] == "" {
  19. item.Type = 1
  20. } else {
  21. urlSlice := strings.Split(url, "/")
  22. lenurlSlice := len(urlSlice)
  23. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  24. item.SourceId = sourceId
  25. if strings.Contains(url, "material/info") {
  26. item.Type = 2
  27. } else if strings.Contains(url, "activity/detail") {
  28. item.Type = 3
  29. } else if strings.Contains(url, "indepth/info") {
  30. if lenurlSlice >= 2 {
  31. chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
  32. item.ChartPermissionId = chartPermissionId
  33. }
  34. item.Type = 4
  35. }
  36. }
  37. itemResp = item
  38. return
  39. }
  40. // GetProductInteriorUrl 处理产品内测中的连接并做跳转处理
  41. func GetProductInteriorUrlBody(body string) (itemResp []*models.ProductInteriorUrlResp) {
  42. //2:文章详情 https://web.hzinsights.com/material/info/8436
  43. //3:活动详情 https://web.hzinsights.com/activity/detail/2701
  44. //4:产业详情 https://web.hzinsights.com/indepth/info/20/79
  45. material := "material/info"
  46. activity := "activity/detail"
  47. indepth := "indepth/info"
  48. var randStrStart = "start_cygx_{|}"
  49. var randStr = "start_cygx_{|}_end_cygx"
  50. urlMap := make(map[string]string)
  51. var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
  52. match := hrefRegexp.FindAllString(body, -1)
  53. if match != nil {
  54. for _, v := range match {
  55. //过滤不相干的超链接
  56. if !strings.Contains(v, material) && !strings.Contains(v, activity) && !strings.Contains(v, indepth) {
  57. continue
  58. }
  59. body = strings.Replace(body, fmt.Sprint("href=\"", v, "\""), "", -1)
  60. body = strings.Replace(body, fmt.Sprint("<a >"), "", -1)
  61. body = strings.Replace(body, fmt.Sprint("</a>"), "", -1)
  62. body = strings.Replace(body, v, randStrStart+v+randStr, -1)
  63. urlMap[v] = v
  64. }
  65. }
  66. sliceBody := strings.Split(body, randStr)
  67. var sliceBodyUrl []string
  68. for _, v := range sliceBody {
  69. sliceUrl := strings.Split(v, randStrStart)
  70. for _, url := range sliceUrl {
  71. if url == "" {
  72. continue
  73. }
  74. sliceBodyUrl = append(sliceBodyUrl, url)
  75. }
  76. }
  77. for _, url := range sliceBodyUrl {
  78. item := new(models.ProductInteriorUrlResp)
  79. item.Body = url
  80. if urlMap[url] == "" {
  81. item.Type = 1
  82. } else {
  83. urlSlice := strings.Split(url, "/")
  84. lenurlSlice := len(urlSlice)
  85. sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
  86. item.SourceId = sourceId
  87. if strings.Contains(url, material) {
  88. item.Type = 2
  89. } else if strings.Contains(url, activity) {
  90. item.Type = 3
  91. } else if strings.Contains(url, indepth) {
  92. if lenurlSlice >= 2 {
  93. chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
  94. item.ChartPermissionId = chartPermissionId
  95. }
  96. item.Type = 4
  97. }
  98. }
  99. itemResp = append(itemResp, item)
  100. }
  101. return
  102. }
  103. func AddCygxProductInteriorHistory(user *models.WxUserItem, articleId int) (err error) {
  104. defer func() {
  105. if err != nil {
  106. go utils.SendAlarmMsg("产品内测用户浏览信息记录失败"+err.Error(), 2)
  107. }
  108. }()
  109. historyRecord := new(models.CygxProductInteriorHistory)
  110. historyRecord.UserId = user.UserId
  111. historyRecord.ProductInteriorId = articleId
  112. historyRecord.CreateTime = time.Now()
  113. historyRecord.Mobile = user.Mobile
  114. historyRecord.Email = user.Email
  115. historyRecord.CompanyId = user.CompanyId
  116. historyRecord.CompanyName = user.CompanyName
  117. historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
  118. sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
  119. if err != nil && err.Error() != utils.ErrNoRow() {
  120. return
  121. }
  122. historyRecord.RealName = user.RealName
  123. if sellerItem != nil {
  124. historyRecord.SellerName = sellerItem.RealName
  125. }
  126. _, err = models.AddCygxProductInteriorHistory(historyRecord)
  127. return
  128. }
  129. // 获取产品内测的阅读数据
  130. func GetCygxProductInteriorHistoryListPvMap(productInteriorIs []int) (mapPv map[int]int) {
  131. var err error
  132. defer func() {
  133. if err != nil {
  134. fmt.Println(err)
  135. go utils.SendAlarmMsg("获取产品内测的阅读数据,信息失败,Err:"+err.Error(), 3)
  136. }
  137. }()
  138. lenproductInteriorIs := len(productInteriorIs)
  139. if lenproductInteriorIs == 0 {
  140. return
  141. }
  142. var condition string
  143. var pars []interface{}
  144. condition = ` AND product_interior_id IN (` + utils.GetOrmInReplace(lenproductInteriorIs) + `) `
  145. pars = append(pars, productInteriorIs)
  146. list, err := models.GetCygxProductInteriorHistoryList(condition, pars)
  147. if err != nil {
  148. return
  149. }
  150. mapPv = make(map[int]int, 0)
  151. for _, v := range list {
  152. mapPv[v.ProductInteriorId]++
  153. }
  154. return
  155. }