|
@@ -1,8 +1,10 @@
|
|
|
package services
|
|
|
|
|
|
import (
|
|
|
+ "fmt"
|
|
|
"hongze/hongze_cygx/models"
|
|
|
"hongze/hongze_cygx/utils"
|
|
|
+ "regexp"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
"time"
|
|
@@ -38,6 +40,72 @@ func GetProductInteriorUrl(url string, urlMap map[string]string) (itemResp *mode
|
|
|
return
|
|
|
}
|
|
|
|
|
|
+// GetProductInteriorUrl 处理产品内测中的连接并做跳转处理
|
|
|
+func GetProductInteriorUrlBody(body string) (itemResp []*models.ProductInteriorUrlResp) {
|
|
|
+ //2:文章详情 https://web.hzinsights.com/material/info/8436
|
|
|
+ //3:活动详情 https://web.hzinsights.com/activity/detail/2701
|
|
|
+ //4:产业详情 https://web.hzinsights.com/indepth/info/20/79
|
|
|
+ material := "material/info"
|
|
|
+ activity := "activity/detail"
|
|
|
+ indepth := "indepth/info"
|
|
|
+
|
|
|
+ var randStrStart = "start_cygx_{|}"
|
|
|
+ var randStr = "start_cygx_{|}_end_cygx"
|
|
|
+ urlMap := make(map[string]string)
|
|
|
+ var hrefRegexp = regexp.MustCompile(utils.RegularUrl)
|
|
|
+ match := hrefRegexp.FindAllString(body, -1)
|
|
|
+ if match != nil {
|
|
|
+ for _, v := range match {
|
|
|
+ //过滤不相干的超链接
|
|
|
+ if !strings.Contains(v, material) && !strings.Contains(v, activity) && strings.Contains(v, indepth) {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ body = strings.Replace(body, fmt.Sprint("href=\"", v, "\""), "", -1)
|
|
|
+ body = strings.Replace(body, fmt.Sprint("<a >"), "", -1)
|
|
|
+ body = strings.Replace(body, fmt.Sprint("</a>"), "", -1)
|
|
|
+ body = strings.Replace(body, v, randStrStart+v+randStr, -1)
|
|
|
+ urlMap[v] = v
|
|
|
+ }
|
|
|
+ }
|
|
|
+ sliceBody := strings.Split(body, randStr)
|
|
|
+ var sliceBodyUrl []string
|
|
|
+ for _, v := range sliceBody {
|
|
|
+ sliceUrl := strings.Split(v, randStrStart)
|
|
|
+ for _, url := range sliceUrl {
|
|
|
+ if url == "" {
|
|
|
+ continue
|
|
|
+ }
|
|
|
+ sliceBodyUrl = append(sliceBodyUrl, url)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ for _, url := range sliceBodyUrl {
|
|
|
+ item := new(models.ProductInteriorUrlResp)
|
|
|
+ item.Body = url
|
|
|
+ if urlMap[url] == "" {
|
|
|
+ item.Type = 1
|
|
|
+ } else {
|
|
|
+ urlSlice := strings.Split(url, "/")
|
|
|
+ lenurlSlice := len(urlSlice)
|
|
|
+ sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
|
|
|
+ item.SourceId = sourceId
|
|
|
+ if strings.Contains(url, material) {
|
|
|
+ item.Type = 2
|
|
|
+ } else if strings.Contains(url, activity) {
|
|
|
+ item.Type = 3
|
|
|
+ } else if strings.Contains(url, indepth) {
|
|
|
+ if lenurlSlice >= 2 {
|
|
|
+ chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
|
|
|
+ item.ChartPermissionId = chartPermissionId
|
|
|
+ }
|
|
|
+ item.Type = 4
|
|
|
+ }
|
|
|
+ }
|
|
|
+ itemResp = append(itemResp, item)
|
|
|
+ }
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
func AddCygxProductInteriorHistory(user *models.WxUserItem, articleId int) (err error) {
|
|
|
defer func() {
|
|
|
if err != nil {
|