Browse Source

Merge branch 'master' of http://8.136.199.33:3000/hongze/hongze_cygx into cygx_v6.3

xingzai 2 years ago
parent
commit
ed6257ca5d

+ 5 - 2
controllers/activity.go

@@ -3530,7 +3530,7 @@ func (this *ActivityCoAntroller) SpecialList() {
 		conditionOr += ` OR (1=1 AND art.customer_type_ids LIKE '%5%'	 ` + condition + `) `
 	}
 	if userType == 1 {
-		conditionOr += ` OR (` + condition + permissionSqlStr + `) `
+		conditionOr += ` OR ( 1=1` + condition + permissionSqlStr + `) `
 	}
 	if companyProduct != nil {
 		if companyProduct.Scale != "" {
@@ -3608,9 +3608,12 @@ func (this *ActivityCoAntroller) SpecialList() {
 		br.ErrMsg = "获取客户详情失败,Err:" + err.Error()
 		return
 	}
-	if count == 1 {
+	if count == 1 && user.UserId > 0 {
 		resp.IsFollow = true
 	}
+	if user.Mobile != "" {
+		resp.IsBindingMobile = true
+	}
 	resp.List = list
 	resp.Paging = page
 	br.Ret = 200

+ 4 - 3
models/activity.go

@@ -613,9 +613,10 @@ type CygxActivitySpecialDetail struct {
 }
 
 type GetCygxActivitySpecialDetailListResp struct {
-	IsFollow bool               `description:"是否关注新调研通知"`
-	Paging   *paging.PagingItem `description:"分页数据"`
-	List     []*CygxActivitySpecialDetail
+	IsFollow        bool               `description:"是否关注新调研通知"`
+	IsBindingMobile bool               `description:"是否绑定了手机号"`
+	Paging          *paging.PagingItem `description:"分页数据"`
+	List            []*CygxActivitySpecialDetail
 }
 
 type CygxActivitySpecialResp struct {

+ 96 - 3
models/article_history_record_newpv.go

@@ -1,7 +1,9 @@
 package models
 
 import (
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"hongze/hongze_cygx/utils"
 	"strconv"
 	"time"
 )
@@ -21,10 +23,49 @@ type CygxArticleHistoryRecordNewpv struct {
 	Source      string `description:"来源,MOBILE:手机端,PC:电脑端"`
 }
 
-//添加收藏信息
+//添加阅读记录信息
 func AddCygxArticleViewRecordNewpv(item *CygxArticleHistoryRecordNewpv) (lastId int64, err error) {
-	o := orm.NewOrm()
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		fmt.Println(err)
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
 	lastId, err = o.Insert(item)
+
+	//写入记录到总的统计表
+	record := new(CygxArticleHistoryRecordAll)
+	record.UserId = item.UserId
+	record.ArticleId = item.ArticleId
+	record.CreateTime = time.Now().Format(utils.FormatDateTime)
+	record.ModifyTime = item.ModifyTime
+	record.Mobile = item.Mobile
+	record.Email = item.Email
+	record.CompanyId = item.CompanyId
+	record.CompanyName = item.CompanyName
+	record.StopTime = item.StopTime
+	record.OutType = item.OutType
+	record.Source = item.Source
+	record.Platfor = 1
+	lastId, err = o.Insert(record)
+
+	// 软删除当天策略平台的文章阅读记录
+	if item.Mobile != "" {
+		sql := `UPDATE cygx_article_history_record_all 
+			SET is_del = 1 
+			WHERE
+			article_id = ? 
+			AND mobile = ?
+			AND platfor = 2
+			AND create_time >= date(NOW()) `
+		_, err = o.Raw(sql, record.ArticleId, record.Mobile).Exec()
+	}
 	return
 }
 
@@ -38,7 +79,18 @@ func GetNewArticleHistoryRecordNewpv(uid, articleId int, modifytime string) (ite
 
 //把十分钟之内的阅读记录进行累加
 func UpdateCygxArticleViewRecordNewpv(itemRep *CygxArticleHistoryRecordNewpv, stopTime int) (err error) {
-	o := orm.NewOrm()
+	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
@@ -48,6 +100,16 @@ func UpdateCygxArticleViewRecordNewpv(itemRep *CygxArticleHistoryRecordNewpv, st
 			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
 }
 
@@ -65,3 +127,34 @@ func UpdateCygxArticleViewRecordNewpvList(itemRep *CygxArticleHistoryRecordNewpv
 
 	return
 }
+
+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:"是否删除"`
+}
+
+//获取当天总表的阅读记录
+func GetArticleHistoryRecordAllList() (items []*CygxArticleHistoryRecordNewpv, err error) {
+	o := orm.NewOrm()
+	sql := ` SELECT * FROM cygx_article_history_record_all WHERE create_time >= date(NOW()) 
+			AND mobile <> '' 
+			AND platfor = 1
+			GROUP BY mobile,article_id `
+	_, err = o.Raw(sql).QueryRows(&items)
+	return
+}

+ 32 - 2
models/celue_article_history_record.go

@@ -1,7 +1,9 @@
 package models
 
 import (
+	"fmt"
 	"github.com/beego/beego/v2/client/orm"
+	"strconv"
 	"time"
 )
 
@@ -48,8 +50,36 @@ type CygxCelueArticleHistoryRecord struct {
 }
 
 //新增
-func AddCeLueArticle(item *CygxCelueArticleHistoryRecord) (lastId int64, err error) {
-	o := orm.NewOrm()
+func AddCeLueArticle(item *CygxCelueArticleHistoryRecord, mapMobileArticleId map[string]int) (lastId int64, err error) {
+	o, err := orm.NewOrm().Begin()
+	if err != nil {
+		return
+	}
+	defer func() {
+		if err == nil {
+			o.Commit()
+		} else {
+			o.Rollback()
+		}
+	}()
 	lastId, err = o.Insert(item)
+
+	//写入记录到总的统计表
+	record := new(CygxArticleHistoryRecordAll)
+	articleId, _ := strconv.Atoi(item.ArticleId)
+	record.ArticleId = articleId
+	record.CelueHistoryId = item.CelueHistoryId
+	record.CreateTime = item.CreateTime
+	record.ModifyTime = time.Now()
+	record.CreateDateApi = time.Now()
+	record.Mobile = item.Mobile
+	record.CompanyName = item.CompanyName
+	record.RealName = item.RealName
+	record.Platfor = 2
+	record.Source = "CELUE"
+	if mapMobileArticleId[fmt.Sprint(item.Mobile, "_", item.ArticleId)] == articleId {
+		record.IsDel = 1
+	}
+	lastId, err = o.Insert(record)
 	return
 }

+ 1 - 0
models/db.go

@@ -103,6 +103,7 @@ func init() {
 		new(CygxChartCollect),
 		new(CygxChartTop),
 		new(CygxCelueArticleHistoryRecord),
+		new(CygxArticleHistoryRecordAll),
 	)
 	// 记录ORM查询日志
 	orm.Debug = true

+ 13 - 2
services/article.go

@@ -916,7 +916,18 @@ func GetCeLueArticlePv(cont context.Context) (err error) {
 		fmt.Println(err)
 		return err
 	}
-
+	mapMobileArticleId := make(map[string]int)
+	//获取当天阅读记录
+	listPv, err := models.GetArticleHistoryRecordAllList()
+	if err != nil && err.Error() != utils.ErrNoRow() {
+		fmt.Println("获取当天阅读记录失败", err)
+		return err
+	}
+	if len(listPv) > 0 {
+		for _, v := range listPv {
+			mapMobileArticleId[fmt.Sprint(v.Mobile, "_", v.ArticleId)] = v.ArticleId
+		}
+	}
 	for _, v := range chartResult.Data {
 		//fmt.Println(v.ArticleId)
 		item := new(models.CygxCelueArticleHistoryRecord)
@@ -936,7 +947,7 @@ func GetCeLueArticlePv(cont context.Context) (err error) {
 			return err
 		}
 		if count == 0 {
-			_, err := models.AddCeLueArticle(item)
+			_, err := models.AddCeLueArticle(item, mapMobileArticleId)
 			if err != nil {
 				fmt.Println(err)
 				return err

+ 3 - 3
services/task.go

@@ -22,9 +22,6 @@ func Task() {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */5 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章
 		task.AddTask("getArticleListByApi", getArticleListByApi)
 
-		getCeLueArticlePv := task.NewTask("getCeLueArticlePv", "0 */10 * * * *", GetCeLueArticlePv) //通过三方接口获取策略平台上的阅读记录
-		task.AddTask("getCeLueArticlePv", getCeLueArticlePv)
-
 		//会议提醒模板消息推送
 		sendActivityBeginMsg := task.NewTask("sendActivityBeginMsg", "0 */10 8-22 * * *", SendActivityBeginMsg) //会议前60分钟的提醒
 		task.AddTask("sendActivityBeginMsg", sendActivityBeginMsg)
@@ -71,6 +68,9 @@ func Task() {
 
 		updateWxUserLabel := task.NewTask("updateWxUserLabel", "0 50 3 * * *", UpdateWxUserLabel) //更新用户的标签
 		task.AddTask("updateWxUserLabel", updateWxUserLabel)
+
+		getCeLueArticlePv := task.NewTask("getCeLueArticlePv", "0 */10 * * * *", GetCeLueArticlePv) //通过三方接口获取策略平台上的阅读记录
+		task.AddTask("getCeLueArticlePv", getCeLueArticlePv)
 	}
 	if utils.RunMode != "release" {
 		getArticleListByApi := task.NewTask("getArticleListByApi", "0 */60 * * * *", GetArticleListByApi) //通过三方接口获取策略平台上的文章