瀏覽代碼

no message

xingzai 1 年之前
父節點
當前提交
0f9113250f

+ 167 - 0
controllers/article.go

@@ -656,3 +656,170 @@ 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 {
+				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)
+					} else {
+						go models.UpdateCygxArticleViewRecordNewpv(record, stopTime)
+					}
+					utils.Rc.Put(key, 1, 10*time.Minute)
+				}
+
+				models.ModifyReportLastViewTime(uid)
+			} 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
+}

+ 2 - 2
controllers/report.go

@@ -1778,7 +1778,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 +1886,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:未付费(没有任何品类权限)"`
+}

+ 37 - 0
models/article_history_record_newpv.go

@@ -4,6 +4,7 @@ import (
 	"fmt"
 	"github.com/beego/beego/v2/client/orm"
 	"hongze/hongze_clpt/utils"
+	"strconv"
 	"time"
 )
 
@@ -154,3 +155,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
+}

+ 1 - 0
models/db.go

@@ -68,6 +68,7 @@ func init() {
 		new(CygxProductInteriorHistory),
 		new(CygxAboutUsVideoHistory),
 		new(CygxTacticsTimeLineHistory),
+		new(CygxReportHistoryRecordLog),
 	)
 	// 记录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:上周纪要汇总"`
+}

+ 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",
@@ -673,6 +682,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",

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