Browse Source

Merge branch 'cygx_10.5.1' of http://8.136.199.33:3000/hongze/hongze_cygx into debug

xingzai 1 year ago
parent
commit
c567248d90
2 changed files with 87 additions and 85 deletions
  1. 2 85
      controllers/article.go
  2. 85 0
      services/article_history.go

+ 2 - 85
controllers/article.go

@@ -271,29 +271,7 @@ func (this *ArticleController) Detail() {
 				}
 			}
 			if hasPersion {
-				hasPermission = 1
-				historyRecord := new(models.CygxArticleHistoryRecord)
-				historyRecord.UserId = uid
-				historyRecord.ArticleId = articleId
-				historyRecord.CreateTime = time.Now()
-				historyRecord.Mobile = user.Mobile
-				historyRecord.Email = user.Email
-				historyRecord.CompanyId = user.CompanyId
-				historyRecord.CompanyName = user.CompanyName
-				recordCount, _ := models.GetNoAddStoptimeArticleCount(uid, articleId)
-				if recordCount == 0 {
-					go models.AddCygxArticleHistoryRecord(historyRecord)
-				} else {
-					detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
-					if err != nil {
-						br.Msg = "获取信息失败"
-						br.ErrMsg = "获取信息失败,Err:" + err.Error()
-						return
-					}
-					if detailNew.StopTime > 0 {
-						go models.AddCygxArticleHistoryRecord(historyRecord)
-					}
-				}
+				go services.ArticleHistory(articleId, user)
 				//30分钟之内阅读同一篇文章不错二次推送
 				key := "CYGX_ARTICLE_READ" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
 				if !utils.Rc.IsExist(key) {
@@ -308,23 +286,6 @@ func (this *ArticleController) Detail() {
 					hasPermission = 3
 				}
 			}
-			if hasPermission == 1 {
-				key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
-				if !utils.Rc.IsExist(key) {
-					//新增浏览记录
-					record := new(models.CygxArticleViewRecord)
-					record.UserId = uid
-					record.ArticleId = articleId
-					record.CreateTime = time.Now()
-					record.Mobile = user.Mobile
-					record.Email = user.Email
-					record.CompanyId = user.CompanyId
-					record.CompanyName = user.CompanyName
-					go models.AddCygxArticleViewRecord(record)
-					utils.Rc.Put(key, 1, 5*time.Second)
-					models.ModifyReportLastViewTime(uid)
-				}
-			}
 		}
 
 		interviewApplyItem, err := models.GetArticleInterviewApply(uid, articleId)
@@ -938,51 +899,7 @@ func (this *ArticleController) AddStopTime() {
 				}
 			}
 			if hasPersion {
-				detailNew, err := models.GetNewArticleHistoryRecord(uid, articleId)
-				if err == nil {
-					hasPermission = 1
-					historyRecord := new(models.AddStopTimeNewRep)
-					historyRecord.StopTime = detailNew.StopTime + stopTime
-					historyRecord.Id = detailNew.Id
-					historyRecord.OutType = outType
-					go models.UpdateArticleStopTime(historyRecord)
-				}
-
-				//不统计本公司的阅读记录、正常退出的不做时间差统计
-				if stopTime > 3 {
-					key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
-					record := new(models.CygxArticleHistoryRecordNewpv)
-					record.UserId = uid
-					record.ArticleId = articleId
-					record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
-					record.ModifyTime = time.Now()
-					record.Mobile = user.Mobile
-					record.Email = user.Email
-					record.CompanyId = user.CompanyId
-					record.CompanyName = user.CompanyName
-					record.StopTime = stopTime
-					record.OutType = outType
-					record.Source = source
-					if !utils.Rc.IsExist(key) || outType != 2 {
-						//新增浏览记录
-						go models.AddCygxArticleViewRecordNewpv(record)
-						recordRedis := new(services.ReportViewRecord)
-						recordRedis.UserId = user.UserId
-						recordRedis.ReportId = articleId
-						recordRedis.Mobile = user.Mobile
-						recordRedis.Email = user.Email
-						recordRedis.RealName = user.RealName
-						recordRedis.CompanyName = user.CompanyName
-						recordRedis.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
-						go services.PushViewRecordNewRedisData(recordRedis, user.CompanyId)
-						go services.ArticleHistoryUserLabelLogAdd(articleId, user.UserId)
-					} else {
-						go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
-					}
-					utils.Rc.Put(key, 1, 10*time.Minute)
-				}
-
-				models.ModifyReportLastViewTime(uid)
+				go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
 			} else { //无该行业权限
 				hasPermission = 3
 			}

+ 85 - 0
services/article_history.go

@@ -1,9 +1,12 @@
 package services
 
 import (
+	"errors"
 	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
+	"strconv"
+	"time"
 )
 
 func GetArticleHistoryByUser(articleIds []int, user *models.WxUserItem) (mapResp map[int]int) {
@@ -32,3 +35,85 @@ func GetArticleHistoryByUser(articleIds []int, user *models.WxUserItem) (mapResp
 	}
 	return
 }
+
+// 记录用户文章浏览记录
+func ArticleHistory(articleId int, user *models.WxUserItem) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("记录用户文章浏览记录,失败"+err.Error(), 2)
+		}
+	}()
+	recordRedis := new(ReportViewRecord)
+	recordRedis.UserId = user.UserId
+	recordRedis.ReportId = articleId
+	recordRedis.Mobile = user.Mobile
+	recordRedis.Email = user.Email
+	recordRedis.RealName = user.RealName
+	recordRedis.CompanyName = user.CompanyName
+	recordRedis.CreateTime = time.Now()
+	go PushViewRecordNewRedisData(recordRedis, user.CompanyId)
+	uid := user.UserId
+	key := "CYGX_ARTICLE_" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid)
+	if !utils.Rc.IsExist(key) {
+		//新增浏览记录
+		//这个表貌似没怎么用了,暂时保留记录
+		record := new(models.CygxArticleViewRecord)
+		record.UserId = uid
+		record.ArticleId = articleId
+		record.CreateTime = time.Now()
+		record.Mobile = user.Mobile
+		record.Email = user.Email
+		record.CompanyId = user.CompanyId
+		record.CompanyName = user.CompanyName
+		_, e := models.AddCygxArticleViewRecord(record)
+		if e != nil {
+			err = errors.New("AddCygxArticleViewRecord, Err: " + e.Error())
+			return
+		}
+
+		e = models.ModifyReportLastViewTime(uid)
+		if e != nil {
+			err = errors.New("ModifyReportLastViewTime, Err: " + e.Error())
+			return
+		}
+		utils.Rc.Put(key, 1, 2*time.Second)
+	}
+	return
+}
+
+// 记录用户文章浏览记录带时长
+func ArticleHistoryStopTime(articleId, stopTime, outType int, user *models.WxUserItem) (err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("记录用户文章浏览记录带时长,失败"+err.Error(), 2)
+		}
+	}()
+	if stopTime < 3 {
+		return
+	}
+	uid := user.UserId
+
+	key := "CYGX_ARTICLE_PV" + strconv.Itoa(articleId) + "_" + strconv.Itoa(uid) + "_" + strconv.Itoa(user.CompanyId) + "_" + strconv.Itoa(outType)
+	if !utils.Rc.IsExist(key) {
+		record := new(models.CygxArticleHistoryRecordNewpv)
+		record.UserId = uid
+		record.ArticleId = articleId
+		record.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
+		record.ModifyTime = time.Now()
+		record.Mobile = user.Mobile
+		record.Email = user.Email
+		record.CompanyId = user.CompanyId
+		record.CompanyName = user.CompanyName
+		record.StopTime = stopTime
+		record.OutType = outType
+		record.Source = "WEB"
+		_, e := models.AddCygxArticleViewRecordNewpv(record)
+		if e != nil {
+			err = errors.New("AddCygxArticleViewRecordNewpv, Err: " + e.Error())
+			return
+		}
+		utils.Rc.Put(key, 1, 2*time.Second)
+	}
+	go ArticleHistoryUserLabelLogAdd(articleId, uid)
+	return
+}