|
@@ -0,0 +1,135 @@
|
|
|
+package services
|
|
|
+
|
|
|
+import (
|
|
|
+ "hongze/hongze_cygx/models"
|
|
|
+ "hongze/hongze_cygx/utils"
|
|
|
+ "strconv"
|
|
|
+ "strings"
|
|
|
+ "time"
|
|
|
+)
|
|
|
+
|
|
|
+
|
|
|
+func GetBannerUrlBody(url string) (itemResp *models.BannerUrlResp) {
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ mapPath := make(map[int]string)
|
|
|
+ mapPath[2] = utils.WX_MSG_PATH_ARTICLE_DETAIL
|
|
|
+ mapPath[3] = utils.WX_MSG_PATH_ACTIVITY_DETAIL
|
|
|
+ mapPath[4] = utils.WX_MSG_PATH_INDUSTRY_DETAIL
|
|
|
+ mapPath[6] = utils.WX_MSG_PATH_PRODUCTINTERIOR_DETAIL
|
|
|
+ mapPath[7] = utils.WX_MSG_PATH_THIS_WEEK_DETAIL
|
|
|
+ mapPath[8] = utils.WX_MSG_PATH_LAST_WEEK_DETAIL
|
|
|
+ mapPath[9] = utils.WX_MSG_PATH_ACTIVITY_SPECIAL_DETAIL
|
|
|
+ mapPath[10] = utils.WX_MSG_PATH_KEY_COMPANY_DETAIL
|
|
|
+ mapPath[11] = utils.WX_MSG_PATH_RESEARCHTHEME_DETAIL
|
|
|
+ mapPath[12] = utils.WX_MSG_PATH_AUTHOR_DETAIL
|
|
|
+
|
|
|
+ material := "material/info"
|
|
|
+ activity := "activity/detail"
|
|
|
+ activityVideo := "activity/video"
|
|
|
+ indepth := "indepth/info"
|
|
|
+ indepthVideo := "indepth/video"
|
|
|
+ about := "/about"
|
|
|
+ internal := "internal/article"
|
|
|
+ thisWeek := "summary/2/"
|
|
|
+ lastWeek := "summary/3/"
|
|
|
+ activitySpecial := "activity/info"
|
|
|
+ recent := "/recent/"
|
|
|
+ communityTheme := "/community/theme/"
|
|
|
+ communityAuthor := "/community/author/"
|
|
|
+ item := new(models.BannerUrlResp)
|
|
|
+ item.Body = url
|
|
|
+ urlSlice := strings.Split(url, "/")
|
|
|
+ lenurlSlice := len(urlSlice)
|
|
|
+ sourceId, _ := strconv.Atoi(urlSlice[lenurlSlice-1])
|
|
|
+
|
|
|
+ if strings.Contains(url, material) {
|
|
|
+ item.Type = 2
|
|
|
+ } else if strings.Contains(url, activity) {
|
|
|
+ item.Type = 3
|
|
|
+ } else if strings.Contains(url, activityVideo) {
|
|
|
+ activityVideo, err := models.GetCygxActivityVideoById(sourceId)
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg("banner链接解析失败"+err.Error()+url, 2)
|
|
|
+ }
|
|
|
+ if activityVideo != nil {
|
|
|
+ sourceId = activityVideo.ActivityId
|
|
|
+ item.Type = 3
|
|
|
+ }
|
|
|
+ } else if strings.Contains(url, indepth) {
|
|
|
+ if lenurlSlice >= 2 {
|
|
|
+ chartPermissionId, _ := strconv.Atoi(urlSlice[lenurlSlice-2])
|
|
|
+ item.ChartPermissionId = chartPermissionId
|
|
|
+ }
|
|
|
+ item.Type = 4
|
|
|
+ } else if strings.Contains(url, indepthVideo) {
|
|
|
+ if lenurlSlice >= 2 {
|
|
|
+ sourceId, _ = strconv.Atoi(urlSlice[lenurlSlice-2])
|
|
|
+ }
|
|
|
+ item.Type = 4
|
|
|
+ } else if strings.Contains(url, about) {
|
|
|
+ item.Type = 5
|
|
|
+ } else if strings.Contains(url, internal) {
|
|
|
+ item.Type = 6
|
|
|
+ } else if strings.Contains(url, thisWeek) {
|
|
|
+ item.Type = 7
|
|
|
+ } else if strings.Contains(url, lastWeek) {
|
|
|
+ item.Type = 8
|
|
|
+ } else if strings.Contains(url, activitySpecial) {
|
|
|
+ item.Type = 9
|
|
|
+ } else if strings.Contains(url, recent) {
|
|
|
+ item.Type = 10
|
|
|
+ } else if strings.Contains(url, communityTheme) {
|
|
|
+ item.Type = 11
|
|
|
+ } else if strings.Contains(url, communityAuthor) {
|
|
|
+ item.Type = 12
|
|
|
+ } else {
|
|
|
+ item.Type = 1
|
|
|
+ }
|
|
|
+ if mapPath[item.Type] != "" {
|
|
|
+ item.Path = "/" + mapPath[item.Type]
|
|
|
+ }
|
|
|
+ item.SourceId = sourceId
|
|
|
+ itemResp = item
|
|
|
+ return
|
|
|
+}
|
|
|
+
|
|
|
+func AddCygxBannerHistory(user *models.WxUserItem, bannerId int) (err error) {
|
|
|
+ if user.UserId == 0 {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ defer func() {
|
|
|
+ if err != nil {
|
|
|
+ go utils.SendAlarmMsg("banner点击信息记录失败"+err.Error()+"bannerId"+strconv.Itoa(bannerId)+"userId:"+strconv.Itoa(user.UserId), 2)
|
|
|
+ }
|
|
|
+ }()
|
|
|
+ historyRecord := new(models.CygxBannerHistory)
|
|
|
+ historyRecord.UserId = user.UserId
|
|
|
+ historyRecord.BannerId = bannerId
|
|
|
+ historyRecord.CreateTime = time.Now()
|
|
|
+ historyRecord.Mobile = user.Mobile
|
|
|
+ historyRecord.Email = user.Email
|
|
|
+ historyRecord.CompanyId = user.CompanyId
|
|
|
+ historyRecord.CompanyName = user.CompanyName
|
|
|
+ historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
|
|
|
+ sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
|
|
|
+ if err != nil && err.Error() != utils.ErrNoRow() {
|
|
|
+ return
|
|
|
+ }
|
|
|
+ historyRecord.RealName = user.RealName
|
|
|
+ if sellerItem != nil {
|
|
|
+ historyRecord.SellerName = sellerItem.RealName
|
|
|
+ }
|
|
|
+ _, err = models.AddCygxBannerHistory(historyRecord)
|
|
|
+ return
|
|
|
+}
|