Browse Source

Merge branch 'cygx_10.5.1' of http://8.136.199.33:3000/cxzhang/hongze_clpt

xingzai 1 năm trước cách đây
mục cha
commit
9514a8442a

+ 124 - 0
controllers/article.go

@@ -669,3 +669,127 @@ func (this *ArticleController) ArticleHotList() {
 	br.Msg = "获取成功"
 	br.Data = resp
 }
+
+// @Title 上传文章阅读时间
+// @Description 上传文章阅读时间接口
+// @Param  request	body models.AddStopTimeRep true "type json string"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /addStopTime [post]
+func (this *ArticleController) AddStopTime() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	var req models.AddStopTimeRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	uid := user.UserId
+	articleId := req.ArticleId
+	stopTime := req.StopTime
+	outType := req.OutType
+	//source := req.Source
+	if articleId <= 0 {
+		br.Msg = "参数错误"
+		br.ErrMsg = "参数错误"
+		return
+	}
+	if stopTime == 0 {
+		stopTime = 1
+	}
+	if outType != 2 {
+		outType = 1
+	}
+	//source = "WEB"
+	detail := new(models.ArticleDetail)
+	hasPermission := 0
+	hasFree := 0
+
+	//判断是否已经申请过
+	applyCount, err := models.GetApplyRecordCount(uid)
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "判断是否已申请过试用失败,Err:" + err.Error()
+		return
+	}
+	//`description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,4:潜在客户,未提交过申请,5:潜在客户,已提交过申请"`
+	if user.CompanyId > 1 {
+		companyPermission, err := models.GetCompanyPermission(user.CompanyId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "判断是否已申请访谈失败,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		detail, err = models.GetArticleDetailById(articleId)
+		if err != nil {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取文章信息失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+			return
+		}
+		if companyPermission == "" {
+			if applyCount > 0 {
+				hasPermission = 5
+			} else {
+				hasPermission = 2
+			}
+			hasFree = 2
+			goto Loop
+		} else {
+			hasFree = 1
+			var articlePermissionPermissionName string
+			if detail.CategoryId > 0 {
+				articlePermission, err := models.GetArticlePermission(detail.CategoryId)
+				if err != nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "获取报告权限失败,Err:" + err.Error() + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+					return
+				}
+				if articlePermission == nil {
+					br.Msg = "获取信息失败"
+					br.ErrMsg = "报告权限不存在,Err:" + strconv.Itoa(uid) + ";articleId" + strconv.Itoa(articleId)
+					return
+				}
+				articlePermissionPermissionName = articlePermission.PermissionName
+			} else {
+				articlePermissionPermissionName = detail.CategoryName
+			}
+			var hasPersion bool
+			slice := strings.Split(articlePermissionPermissionName, ",")
+			for _, v := range slice {
+				if strings.Contains(companyPermission, v) {
+					hasPersion = true
+				}
+			}
+			if hasPersion {
+				go services.ArticleHistoryStopTime(articleId, stopTime, outType, user)
+			} else { //无该行业权限
+				hasPermission = 3
+			}
+		}
+	} else { //潜在客户
+		if applyCount > 0 {
+			hasPermission = 5
+		} else {
+			hasPermission = 4
+		}
+	}
+Loop:
+	resp := new(models.ArticleDetailAddStopTimeRep)
+	resp.HasPermission = hasPermission
+	resp.HasFree = hasFree
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+	br.Data = resp
+}

+ 4 - 2
controllers/report.go

@@ -801,6 +801,7 @@ func (this *ReportController) IndustrialFllow() {
 	}
 	//处理是否关注全部赛道字段
 	go services.IndustryFllowWithTrack(industrialManagementId, count, uid)
+	go services.IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid) //处理用户标签
 	br.Ret = 200
 	br.Success = true
 	br.Data = resp
@@ -897,6 +898,7 @@ func (this *ReportController) CategoryFllow() {
 		resp.Status = 2
 		br.Msg = "已取消关注"
 	}
+	go services.CategoryFllowUserLabelLogAdd(categoryId, count, uid) //处理用户标签
 	br.Ret = 200
 	br.Success = true
 	br.Data = resp
@@ -1778,7 +1780,7 @@ func (this *ReportController) ResearchDetail() {
 			listFirst[k].IcoLink = "https://hongze.oss-cn-shanghai.aliyuncs.com/static/images/202111/20211104/QbTGTNhD9MxYp24cJ7V5WpCN0oNl.png"
 		}
 	}
-	go services.AddCygxReportHistoryRecord(user, articleId, "bzyjhz")
+	//go services.AddCygxReportHistoryRecord(user, articleId, "bzyjhz")
 	resp.List = listFirst
 	resp.Detail = detail
 	br.Ret = 200
@@ -1886,7 +1888,7 @@ func (this *ReportController) MinutesDetail() {
 		}
 	}
 
-	go services.AddCygxReportHistoryRecord(user, articleId, "szjyhz")
+	//go services.AddCygxReportHistoryRecord(user, articleId, "szjyhz")
 	resp.List = listFirst
 	resp.Detail = detail
 	br.Ret = 200

+ 76 - 1
controllers/report_selection.go

@@ -170,7 +170,7 @@ func (this *ReportSelectionController) Detail() {
 	//if sellerItem != nil {
 	//	historyRecord.SellerName = sellerItem.RealName
 	//}
-	go services.AddCygxReportHistoryRecord(user, articleId, "bgjx")
+	//go services.AddCygxReportHistoryRecord(user, articleId, "bgjx")
 	resp.List = items
 	resp.ListPermissionSubject = itemsSubject
 	resp.Detail = detail
@@ -235,3 +235,78 @@ func (this *ReportSelectionController) ClickHistory() {
 	br.Success = true
 	br.Msg = "记录成功"
 }
+
+// @Title 上传文章阅读时间
+// @Description 上传文章阅读时间接口
+// @Param  request	body models.AddStopTimeRep true "type json string"
+// @Success 200 {object} models.ArticleDetailResp
+// @router /addStopTime [post]
+func (this *ReportSelectionController) AddStopTime() {
+	br := new(models.BaseResponse).Init()
+	defer func() {
+		this.Data["json"] = br
+		this.ServeJSON()
+	}()
+	user := this.User
+	if user == nil {
+		br.Msg = "请登录"
+		br.ErrMsg = "请登录,用户信息为空"
+		br.Ret = 408
+		return
+	}
+	var req models.AddReportSelectionStopTimeRep
+	err := json.Unmarshal(this.Ctx.Input.RequestBody, &req)
+	if err != nil {
+		br.Msg = "参数解析异常!"
+		br.ErrMsg = "参数解析失败,Err:" + err.Error()
+		return
+	}
+	uid := user.UserId
+	articleId := req.ArticleId
+	stopTime := req.StopTime
+	outType := req.OutType
+	source := req.Source
+	var reportType string
+	if source == 1 {
+		reportType = "bgjx"
+	} else if source == 2 {
+		reportType = "bzyjhz"
+	} else if source == 3 {
+		reportType = "szjyhz"
+	}
+	hasPermission, err := services.GetUserhasPermission(user)
+	if err != nil {
+		br.Msg = "获取信息失败"
+		br.ErrMsg = "获取用户权限信息失败,Err:" + err.Error()
+	}
+
+	if hasPermission == 1 {
+		historyRecord := new(models.CygxReportHistoryRecord)
+		historyRecord.UserId = uid
+		historyRecord.ArticleId = articleId
+		historyRecord.CreateTime = time.Now().Add(-time.Second * time.Duration(stopTime))
+		historyRecord.Mobile = user.Mobile
+		historyRecord.Email = user.Email
+		historyRecord.CompanyId = user.CompanyId
+		historyRecord.CompanyName = user.CompanyName
+		historyRecord.StopTime = stopTime
+		historyRecord.OutType = outType
+		historyRecord.ReportType = reportType
+		historyRecord.RegisterPlatform = utils.REGISTER_PLATFORM
+		sellerItem, err := models.GetSellerByCompanyIdCheckFicc(user.CompanyId, 2)
+		if err != nil && err.Error() != utils.ErrNoRow() {
+			br.Msg = "获取信息失败"
+			br.ErrMsg = "获取销售信息失败,Err:" + err.Error()
+			return
+		}
+		historyRecord.RealName = user.RealName
+		if sellerItem != nil {
+			historyRecord.SellerName = sellerItem.RealName
+		}
+		go services.AddCygxReportHistoryRecord(historyRecord)
+	}
+
+	br.Ret = 200
+	br.Success = true
+	br.Msg = "操作成功"
+}

+ 14 - 2
models/article_history_record.go

@@ -24,7 +24,7 @@ type ArticleTopHistoryRecord struct {
 	CreateTime        time.Time `description:"创建时间"`
 }
 
-//获取用户阅读记录
+// 获取用户阅读记录
 func GetUserToArticleCount(uid, articleId int) (count int, err error) {
 	sqlCount := `SELECT COUNT(1) AS count FROM cygx_article_history_record WHERE user_id=? AND article_id=? `
 	o := orm.NewOrm()
@@ -32,7 +32,7 @@ func GetUserToArticleCount(uid, articleId int) (count int, err error) {
 	return
 }
 
-//获取用户阅读记录
+// 获取用户阅读记录
 func GetUserToArticleHistory(uid int, articleIdArr []int) (items []*CygxArticleHistoryResp, err error) {
 	arrLen := len(articleIdArr)
 	if arrLen == 0 {
@@ -96,3 +96,15 @@ WHERE
 	_, err = orm.NewOrm().Raw(sql, pars, limit).QueryRows(&list)
 	return
 }
+
+type AddStopTimeRep struct {
+	ArticleId int    `description:"文章ID"`
+	StopTime  int    `description:"停留时间"`
+	OutType   int    `description:"退出方式,1正常退出,2强制关闭"`
+	Source    string `description:"来源,MOBILE:手机端,PC:电脑端"`
+}
+
+type ArticleDetailAddStopTimeRep struct {
+	HasPermission int `description:"1:有该行业权限,正常展示,2:无该行业权限,不存在权益客户下,3:无该品类权限,已提交过申请,4:无该行业权限,未提交过申请,5:潜在客户,未提交过申请,6:潜在客户,已提交过申请"`
+	HasFree       int `description:"1:已付费(至少包含一个品类的权限),2:未付费(没有任何品类权限)"`
+}

+ 80 - 40
models/article_history_record_newpv.go

@@ -4,36 +4,39 @@ import (
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"hongze/hongze_clpt/utils"
+	"strconv"
 	"time"
 )
 
 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:网页"`
 }
 
 // 添加阅读记录信息
@@ -102,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 {
@@ -154,3 +158,39 @@ func GetArticleHistoryRecord(condition string, pars []interface{}) (item []*Cygx
 	_, err = o.Raw(sql, pars).QueryRows(&item)
 	return
 }
+
+// 把十分钟之内的阅读记录进行累加
+func UpdateCygxArticleViewRecordNewpv(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
+	sql := `UPDATE cygx_article_history_record_newpv 
+			SET modify_time = NOW(), stop_time = stop_time + ` + strconv.Itoa(stopTime) + `
+			WHERE
+			article_id = ? 
+			AND user_id = ?
+			AND out_type = 2
+			AND timestampdiff(MINUTE,modify_time,NOW()) < 10`
+	_, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId).Exec()
+
+	// 修改总表的停留时间
+	sql = `UPDATE cygx_article_history_record_all 
+			SET modify_time = NOW(), stop_time = stop_time + ` + strconv.Itoa(stopTime) + `
+			WHERE
+			article_id = ? 
+			AND user_id = ?
+			AND out_type = 2
+			AND timestampdiff(MINUTE,modify_time,NOW()) < 10`
+	_, err = o.Raw(sql, itemRep.ArticleId, itemRep.UserId).Exec()
+
+	return
+}

+ 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
+}

+ 3 - 0
models/db.go

@@ -57,6 +57,7 @@ func init() {
 		new(CygxPageHistoryRecord),
 		new(CygxArticleDepartmentFollow),
 		new(CygxArticleComment),
+		new(CygxArticleViewRecord),
 		new(CygxArticleHistoryRecordNewpv),
 		new(CygxArticleHistoryRecord),
 		new(CygxArticleHistoryRecordAll),
@@ -69,6 +70,8 @@ func init() {
 		new(CygxAboutUsVideoHistory),
 		new(CygxTacticsTimeLineHistory),
 		new(CygxBannerHistory),
+		new(CygxReportHistoryRecordLog),
+		new(CygxUserLabel),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 50 - 0
models/report_history_record.go

@@ -18,6 +18,26 @@ type CygxReportHistoryRecord struct {
 	ReportType       string    `description:"报告类型,bgjx:报告精选、bzyjhz:本周研究汇总、szjyhz:上周纪要汇总"`
 	RealName         string    `description:"用户实际名称"`
 	SellerName       string    `description:"所属销售"`
+	StopTime         int       `description:"停留时间"`
+	OutType          int       `description:"退出方式,1正常退出,2强制关闭"`
+	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
+}
+
+type CygxReportHistoryRecordLog 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:"修改时间"`
+	ReportType       string    `description:"报告类型,bgjx:报告精选、bzyjhz:本周研究汇总、szjyhz:上周纪要汇总"`
+	RealName         string    `description:"用户实际名称"`
+	SellerName       string    `description:"所属销售"`
+	StopTime         int       `description:"停留时间"`
+	OutType          int       `description:"退出方式,1正常退出,2强制关闭"`
 	RegisterPlatform int       `description:"来源 1小程序,2:网页"`
 }
 
@@ -28,3 +48,33 @@ func AddCygxReportHistoryRecord(item *CygxReportHistoryRecord) (lastId int64, er
 	lastId, err = o.Insert(item)
 	return
 }
+
+// 添加历史信息
+func AddCygxReportHistoryRecordLog(item *CygxReportHistoryRecordLog) (lastId int64, err error) {
+	o := orm.NewOrm()
+	item.ModifyTime = time.Now()
+	lastId, err = o.Insert(item)
+	return
+}
+
+type AddStopTimeNewRep struct {
+	Id        int `description:"ID"`
+	ArticleId int `description:"文章ID"`
+	StopTime  int `description:"停留时间"`
+	OutType   int `description:"退出方式,1正常退出,2强制关闭"`
+}
+
+func UpdateArticleStopTime(item *AddStopTimeNewRep) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_article_history_record SET stop_time = ?,out_type = ? WHERE id =?`
+	_, err = o.Raw(sql, item.StopTime, item.OutType, item.Id).Exec()
+	return
+}
+
+// 获取最新的一条阅读记录
+func GetNewArticleHistoryRecord(uid, articleId int) (item *AddStopTimeNewRep, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM  cygx_article_history_record WHERE user_id = ? AND article_id = ? ORDER BY id DESC LIMIT 1;`
+	err = o.Raw(sql, uid, articleId).QueryRow(&item)
+	return
+}

+ 7 - 0
models/report_selection.go

@@ -189,3 +189,10 @@ func GetIndustrialByIds(industrialManagementIds string) (items []*IndustriaRepor
 	_, err = o.Raw(sql).QueryRows(&items)
 	return
 }
+
+type AddReportSelectionStopTimeRep struct {
+	ArticleId int `description:"文章ID"`
+	StopTime  int `description:"停留时间"`
+	OutType   int `description:"退出方式,1正常退出,2强制关闭"`
+	Source    int `description:"来源,1:深度研究、2:本周研究汇总、3:上周纪要汇总"`
+}

+ 75 - 0
models/user_label.go

@@ -0,0 +1,75 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelLogRedis struct {
+	UserId     int       `description:"用户ID"`
+	SourceId   int       `description:"资源ID"`
+	SourceType int       `description:"1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。"`
+	IsFllow    int       `description:"1关注、0取消关注"`
+	CreateTime time.Time `description:"创建时间"`
+}
+
+type CygxUserLabel struct {
+	Id         int       `orm:"column(id);pk"`
+	UserId     int       `description:"用户ID"`
+	CompanyId  int       `description:"公司id"`
+	RealName   string    `description:"用户实际名称"`
+	Mobile     string    `description:"手机号"`
+	Email      string    `description:"邮箱"`
+	Label      string    `description:"标签内容"`
+	Weight     int       `description:"权重"`
+	SourceId   int       `description:"来源ID(产业ID,系列ID)"`
+	Source     int       `description:"来源1:产业、2:系列"`
+	IsFollow   int       `description:"是否关注,1是,0否"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+// 获取数量
+func GetCygxUserLabelCount(condition string, pars []interface{}) (count int, err error) {
+	sqlCount := ` SELECT COUNT(1) AS count  FROM cygx_user_label as art WHERE 1= 1   AND modify_time > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)  `
+	if condition != "" {
+		sqlCount += condition
+	}
+	o := orm.NewOrm()
+	err = o.Raw(sqlCount, pars).QueryRow(&count)
+	return
+}
+
+// 添加
+func AddCygxUserLabel(item *CygxUserLabel) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}
+
+// 修改是否关注
+func UpdateCygxUserLabelIsFollow(isFollow, sourceId, source, userId int, label string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_user_label SET is_follow=?,label = ? , modify_time=NOW()  WHERE source_id=? AND source = ? AND user_id = ? `
+	_, err = o.Raw(sql, isFollow, label, sourceId, source, userId).Exec()
+	return
+}
+
+// 修改对应标签权重+1
+func UpdateCygxUserLabelWeight(sourceId, source, userId int, label string) (err error) {
+	o := orm.NewOrm()
+	sql := `UPDATE cygx_user_label SET weight = weight +1 ,label = ? , modify_time=NOW()  WHERE source_id=? AND source = ? AND  user_id = ? `
+	_, err = o.Raw(sql, label, sourceId, source, userId).Exec()
+	return
+}
+
+// 列表
+func GetCygxUserLabelList(condition string, pars []interface{}) (items []*CygxUserLabel, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_user_label as art WHERE 1= 1   AND modify_time > DATE_SUB(CURDATE(), INTERVAL 3 MONTH)	`
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 28 - 0
models/user_label_article.go

@@ -0,0 +1,28 @@
+package models
+
+import (
+	"github.com/beego/beego/v2/client/orm"
+	"time"
+)
+
+type CygxUserLabelArticle struct {
+	Id         int       `orm:"column(id);pk"`
+	UserId     int       `description:"用户ID"`
+	CompanyId  int       `description:"公司id"`
+	RealName   string    `description:"用户实际名称"`
+	Mobile     string    `description:"手机号"`
+	Email      string    `description:"邮箱"`
+	Label      string    `description:"标签内容"`
+	ArticleId  int       `description:"文章ID"`
+	SourceId   int       `description:"来源ID(产业ID,系列ID)"`
+	Source     int       `description:"来源1:产业、2:系列"`
+	CreateTime time.Time `description:"创建时间"`
+	ModifyTime time.Time `description:"更新时间"`
+}
+
+// 添加
+func AddCygxUserLabelArticle(item *CygxUserLabelArticle) (lastId int64, err error) {
+	o := orm.NewOrm()
+	lastId, err = o.Insert(item)
+	return
+}

+ 7 - 0
models/wx_user.go

@@ -200,3 +200,10 @@ func GetUserRemind(uid int) (count int, err error) {
 	err = orm.NewOrm().Raw(sql, uid).QueryRow(&count)
 	return
 }
+
+func ModifyReportLastViewTime(uid int) (err error) {
+	sql := ` UPDATE wx_user SET report_last_view_time=NOW()
+			WHERE user_id=? `
+	_, err = orm.NewOrm().Raw(sql, uid).Exec()
+	return
+}

+ 18 - 0
routers/commentsRouter.go

@@ -187,6 +187,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ArticleController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ArticleController"],
+        beego.ControllerComments{
+            Method: "AddStopTime",
+            Router: `/addStopTime`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ArticleController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ArticleController"],
         beego.ControllerComments{
             Method: "AskAdd",
@@ -718,6 +727,15 @@ func init() {
             Filters: nil,
             Params: nil})
 
+    beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ReportSelectionController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ReportSelectionController"],
+        beego.ControllerComments{
+            Method: "AddStopTime",
+            Router: `/addStopTime`,
+            AllowHTTPMethods: []string{"post"},
+            MethodParams: param.Make(),
+            Filters: nil,
+            Params: nil})
+
     beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ReportSelectionController"] = append(beego.GlobalControllerRouter["hongze/hongze_clpt/controllers:ReportSelectionController"],
         beego.ControllerComments{
             Method: "ClickHistory",

+ 91 - 0
services/article_history.go

@@ -0,0 +1,91 @@
+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)
+	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
+}

+ 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

+ 28 - 22
services/report_history_record.go

@@ -3,33 +3,39 @@ package services
 import (
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/utils"
-	"time"
+	"strconv"
 )
 
-func AddCygxReportHistoryRecord(user *models.WxUserItem, articleId int, reportType string) (err error) {
-	defer func() {
+// 添加历史信息
+func AddCygxReportHistoryRecord(item *models.CygxReportHistoryRecord) (err error) {
+	//defer func() {
+	//	if err != nil {
+	//		go utils.SendAlarmMsg("产品内测用户浏览信息记录失败"+err.Error(), 2)
+	//	}
+	//}()
+	if item.StopTime >= 5 {
+		_, err = models.AddCygxReportHistoryRecord(item)
 		if err != nil {
-			go utils.SendAlarmMsg("研究汇总用户浏览信息记录失败"+err.Error(), 2)
+			go utils.SendAlarmMsg("报告精选用户浏览信息记录失败"+err.Error()+"报告类型"+item.ReportType+"报告ID:"+strconv.Itoa(item.ArticleId), 2)
 		}
-	}()
-	historyRecord := new(models.CygxReportHistoryRecord)
-	historyRecord.UserId = user.UserId
-	historyRecord.ArticleId = articleId
-	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
-	historyRecord.ReportType = reportType
-	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
+
+	historyRecordLog := new(models.CygxReportHistoryRecordLog)
+	historyRecordLog.UserId = item.UserId
+	historyRecordLog.ArticleId = historyRecordLog.ArticleId
+	historyRecordLog.CreateTime = historyRecordLog.CreateTime
+	historyRecordLog.Mobile = historyRecordLog.Mobile
+	historyRecordLog.Email = historyRecordLog.Email
+	historyRecordLog.CompanyId = historyRecordLog.CompanyId
+	historyRecordLog.CompanyName = historyRecordLog.CompanyName
+	historyRecordLog.StopTime = historyRecordLog.StopTime
+	historyRecordLog.OutType = historyRecordLog.OutType
+	historyRecordLog.ReportType = historyRecordLog.ReportType
+	historyRecordLog.RegisterPlatform = historyRecordLog.RegisterPlatform
+
+	_, err = models.AddCygxReportHistoryRecordLog(historyRecordLog)
+	if err != nil {
+		go utils.SendAlarmMsg("报告精选用户浏览信息日志记录失败"+err.Error()+"报告类型"+item.ReportType+"报告ID:"+strconv.Itoa(item.ArticleId), 2)
 	}
-	_, err = models.AddCygxReportHistoryRecord(historyRecord)
 	return
 }

+ 78 - 0
services/user_label.go

@@ -0,0 +1,78 @@
+package services
+
+import (
+	"fmt"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+	"time"
+)
+
+// 添加用户阅读标签到Redis
+func ArticleHistoryUserLabelLogAdd(articleId, uid int) (err error) {
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("articleId:", articleId, "userId:", uid)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	// SourceType 1:文章阅读、 2产业关注、3:活动到会、4系列关注、5专项调研活动到会。
+	log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: articleId, SourceType: 1, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+		if err != nil {
+			fmt.Println("CygxUserLabelLogRedis LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
+// 添加用户2产业关注标签到Redis
+func IndustryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
+	var isFllow int
+	if count == 0 {
+		isFllow = 1
+	} else {
+		isFllow = 0
+	}
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 2, IsFllow: isFllow, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+		if err != nil {
+			fmt.Println("RecordNewLogs LPush Err:" + err.Error())
+		}
+	}
+	return
+}
+
+// 添加用户4系列关注标签到Redis
+func CategoryFllowUserLabelLogAdd(industrialManagementId, count, uid int) (err error) {
+	var isFllow int
+	if count == 0 {
+		isFllow = 1
+	} else {
+		isFllow = 0
+	}
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			msg := fmt.Sprint("industrialManagementId:", industrialManagementId, "isFllow:", isFllow, "userId:", uid)
+			go utils.SendAlarmMsg("用户关注产业更新相关标签,写入Redis队列消息失败:"+err.Error()+msg, 2)
+		}
+	}()
+	log := &models.CygxUserLabelLogRedis{UserId: uid, SourceId: industrialManagementId, SourceType: 4, IsFllow: isFllow, CreateTime: time.Now()}
+	if utils.Re == nil {
+		err := utils.Rc.LPush(utils.CYGX_USER_KEY_LABEL, log)
+		if err != nil {
+			fmt.Println("RecordNewLogs LPush Err:" + err.Error())
+		}
+	}
+	return
+}

+ 2 - 1
utils/constants.go

@@ -140,7 +140,8 @@ const (
 	YAN_XUAN_TAB_KEY = "yanxuan_header_tab"
 )
 const (
-	YD_TOKEN = "yidong_token"
+	YD_TOKEN            = "yidong_token"
+	CYGX_USER_KEY_LABEL = "CYGX_USER_KEY_LABEL" //查研观向用户标签
 )
 
 const (