Browse Source

no message

xingzai 1 year ago
parent
commit
0ec420caaa

+ 3 - 47
controllers/article.go

@@ -686,7 +686,7 @@ func (this *ArticleController) AddStopTime() {
 	articleId := req.ArticleId
 	stopTime := req.StopTime
 	outType := req.OutType
-	source := req.Source
+	//source := req.Source
 	if articleId <= 0 {
 		br.Msg = "参数错误"
 		br.ErrMsg = "参数错误"
@@ -698,7 +698,7 @@ func (this *ArticleController) AddStopTime() {
 	if outType != 2 {
 		outType = 1
 	}
-	source = "WEB"
+	//source = "WEB"
 	detail := new(models.ArticleDetail)
 	hasPermission := 0
 	hasFree := 0
@@ -759,51 +759,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 > 4 {
-					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
 			}

+ 43 - 40
models/article_history_record_newpv.go

@@ -9,32 +9,34 @@ import (
 )
 
 type CygxArticleHistoryRecordNewpv struct {
-	Id          int `orm:"column(id);pk"`
-	ArticleId   int
-	UserId      int
-	CreateTime  time.Time
-	ModifyTime  time.Time
-	Mobile      string `description:"手机号"`
-	Email       string `description:"邮箱"`
-	CompanyId   int    `description:"公司id"`
-	CompanyName string `description:"公司名称"`
-	StopTime    int    `description:"停留时间"`
-	OutType     int    `description:"退出方式,1正常退出,2强制关闭"`
-	Source      string `description:"来源,MOBILE:手机端,PC:电脑端"`
+	Id               int `orm:"column(id);pk"`
+	ArticleId        int
+	UserId           int
+	CreateTime       time.Time
+	ModifyTime       time.Time
+	Mobile           string `description:"手机号"`
+	Email            string `description:"邮箱"`
+	CompanyId        int    `description:"公司id"`
+	CompanyName      string `description:"公司名称"`
+	StopTime         int    `description:"停留时间"`
+	OutType          int    `description:"退出方式,1正常退出,2强制关闭"`
+	Source           string `description:"来源,MOBILE:手机端,PC:电脑端"`
+	RegisterPlatform int    `description:"来源 1小程序,2:网页"`
 }
 
 type CygxArticleHistoryRecord struct {
-	Id          int `orm:"column(id);pk"`
-	ArticleId   int
-	UserId      int
-	CreateTime  time.Time
-	Mobile      string    `description:"手机号"`
-	Email       string    `description:"邮箱"`
-	CompanyId   int       `description:"公司id"`
-	CompanyName string    `description:"公司名称"`
-	ModifyTime  time.Time `description:"修改时间"`
-	StopTime    int       `description:"停留时间"`
-	OutType     int       `description:"退出方式,1正常退出,2强制关闭"`
+	Id               int `orm:"column(id);pk"`
+	ArticleId        int
+	UserId           int
+	CreateTime       time.Time
+	Mobile           string    `description:"手机号"`
+	Email            string    `description:"邮箱"`
+	CompanyId        int       `description:"公司id"`
+	CompanyName      string    `description:"公司名称"`
+	ModifyTime       time.Time `description:"修改时间"`
+	StopTime         int       `description:"停留时间"`
+	OutType          int       `description:"退出方式,1正常退出,2强制关闭"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
 }
 
 // 添加阅读记录信息
@@ -103,23 +105,24 @@ func AddCygxArticleViewRecordNewpv(item *CygxArticleHistoryRecordNewpv) (lastId
 }
 
 type CygxArticleHistoryRecordAll struct {
-	Id             int `orm:"column(id);pk"`
-	ArticleId      int
-	UserId         int
-	CreateTime     string
-	ModifyTime     time.Time
-	Mobile         string    `description:"手机号"`
-	Email          string    `description:"邮箱"`
-	CompanyId      int       `description:"公司id"`
-	CompanyName    string    `description:"公司名称"`
-	StopTime       int       `description:"停留时间"`
-	OutType        int       `description:"退出方式,1正常退出,2强制关闭"`
-	Source         string    `description:"来源,MOBILE:手机端,PC:电脑端"`
-	RealName       string    `description:"用户实际名称"`
-	CreateDateApi  time.Time `description:"同步创建时间"`
-	CelueHistoryId int       `description:"策略平台记录的ID"`
-	Platfor        int       `description:"PV阅读记录来源,1:查研观向,2:策略平台"`
-	IsDel          int       `description:"是否删除"`
+	Id               int `orm:"column(id);pk"`
+	ArticleId        int
+	UserId           int
+	CreateTime       string
+	ModifyTime       time.Time
+	Mobile           string    `description:"手机号"`
+	Email            string    `description:"邮箱"`
+	CompanyId        int       `description:"公司id"`
+	CompanyName      string    `description:"公司名称"`
+	StopTime         int       `description:"停留时间"`
+	OutType          int       `description:"退出方式,1正常退出,2强制关闭"`
+	Source           string    `description:"来源,MOBILE:手机端,PC:电脑端"`
+	RealName         string    `description:"用户实际名称"`
+	CreateDateApi    time.Time `description:"同步创建时间"`
+	CelueHistoryId   int       `description:"策略平台记录的ID"`
+	Platfor          int       `description:"PV阅读记录来源,1:查研观向,2:策略平台"`
+	IsDel            int       `description:"是否删除"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
 }
 
 type EsUserInteraction struct {

+ 25 - 0
models/article_view_record.go

@@ -0,0 +1,25 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxArticleViewRecord struct {
+	Id               int `orm:"column(id);pk"`
+	ArticleId        int
+	UserId           int
+	CreateTime       time.Time
+	Mobile           string `description:"手机号"`
+	Email            string `description:"邮箱"`
+	CompanyId        int    `description:"公司id"`
+	CompanyName      string `description:"公司名称"`
+	RegisterPlatform int    `description:"来源 1小程序,2:网页"`
+}
+
+// 添加收藏信息
+func AddCygxArticleViewRecord(item *CygxArticleViewRecord) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 1 - 0
models/db.go

@@ -57,6 +57,7 @@ func init() {
 		new(CygxPageHistoryRecord),
 		new(CygxArticleDepartmentFollow),
 		new(CygxArticleComment),
+		new(CygxArticleViewRecord),
 		new(CygxArticleHistoryRecordNewpv),
 		new(CygxArticleHistoryRecord),
 		new(CygxArticleHistoryRecordAll),

+ 89 - 0
services/article_history.go

@@ -0,0 +1,89 @@
+package services
+
+import (
+	"errors"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"strconv"
+	"time"
+)
+
+// 记录用户文章浏览记录
+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)
+	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)
+
+	return
+}

+ 0 - 37
services/article_red.go

@@ -107,43 +107,6 @@ func PushViewRecordNewRedisData(reportViewRecord *ReportViewRecord, companyId in
 	return false
 }
 
-// 记录用户文章浏览记录
-func ArticleHistory(articleId int, user *models.WxUserItem) (err error) {
-	defer func() {
-		if err != nil {
-			go utils.SendAlarmMsg("记录用户文章浏览记录,失败"+err.Error(), 2)
-		}
-	}()
-	uid := user.UserId
-	if uid == 0 {
-		return
-	}
-	record := new(models.CygxArticleHistoryRecordNewpv)
-	record.UserId = uid
-	record.ArticleId = articleId
-	record.CreateTime = time.Now()
-	record.ModifyTime = time.Now()
-	record.Mobile = user.Mobile
-	record.Email = user.Email
-	record.CompanyId = user.CompanyId
-	record.CompanyName = user.CompanyName
-	record.StopTime = 0
-	record.OutType = 1
-	record.Source = "WEB"
-
-	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)
-	_, err = models.AddCygxArticleViewRecordNewpv(record)
-	return
-}
-
 // GetUserArticleHistoryRecord 获取用户已经阅读的文章ID
 func GetUserArticleHistoryRecord(user *models.WxUserItem) (articleIdMap map[int]bool, err error) {
 	var condition string