Browse Source

no message

xingzai 1 year ago
parent
commit
65b4216f1a

+ 10 - 0
controllers/report.go

@@ -569,6 +569,16 @@ func (this *MobileReportController) List() {
 		br.ErrMsg = "获取报告封面图片失败, Err:" + err.Error()
 		return
 	}
+	var articleIds []int
+	for _, v := range listPublic {
+		if v.Resource == 1 {
+			articleIds = append(articleIds, v.ArticleId)
+		}
+	}
+
+	articleMapPv := services.GetArticleHistoryByArticleId(articleIds)                       //文章Pv
+	articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)                  //用户收藏的文章
+	articleCollectNumMap, _ := services.GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
 	listResp := make([]*models.HomeArticle, 0)
 	//listResp :=
 	for _, v := range listPublic {

+ 20 - 0
models/article_collect.go

@@ -79,6 +79,14 @@ func GetCygxArticleCollectList(condition string) (items []*CygxArticleCollect, e
 	return
 }
 
+// GetCygxArticleCollectByUser 根据用户ID获取所有文章收藏
+func GetCygxArticleCollectByUser(userId int) (items []*CygxArticleCollect, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_collect  WHERE 1 =1  AND article_id > 0 AND  user_id =?  `
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}
+
 func GetCygxArticleCollectListByUser(userId int) (items []*CygxArticleCollect, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT * FROM cygx_article_collect  WHERE 1 =1   AND article_id > 0 AND user_id = ? `
@@ -125,6 +133,18 @@ func GetUserArticleCollectList() (items []*CygxArticleCollectCountRep, err error
 	return
 }
 
+// GetArticleCollectNum 根据文章ID获取收藏数量的列表
+func GetArticleCollectListNum(articleIds []int) (items []*CygxArticleNum, err error) {
+	lenArr := len(articleIds)
+	if lenArr == 0 {
+		return
+	}
+	sql := `SELECT  COUNT(1) as collect_num , article_id  FROM cygx_article_collect  WHERE   article_id IN  (` + utils.GetOrmInReplace(lenArr) + `)   GROUP BY article_id `
+	o := orm.NewOrm()
+	_, err = o.Raw(sql, articleIds).QueryRows(&items)
+	return
+}
+
 // 修改文章收藏的数量
 func UpdateArticleCollectCountNum(num, articleId int) (err error) {
 	o := orm.NewOrm()

+ 11 - 0
models/article_history_record_newpv.go

@@ -194,3 +194,14 @@ func UpdateCygxArticleViewRecordNewpv(itemRep *CygxArticleHistoryRecordNewpv, st
 
 	return
 }
+
+// 列表
+func GetCygxArticleHistoryRecordNewpvList(condition string, pars []interface{}) (items []*CygxArticleHistoryRecordNewpv, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_article_history_record_newpv as art WHERE 1= 1  `
+	if condition != "" {
+		sql += condition
+	}
+	_, err = o.Raw(sql, pars).QueryRows(&items)
+	return
+}

+ 2 - 0
models/home.go

@@ -46,6 +46,8 @@ type HomeArticle struct {
 	Resource        int                  `description:"来源类型,1:文章、2:产品内测"`
 	MicroAudio      *MicroAudioUnionList `description:"微路演音频"`
 	List            []*IndustrialManagementIdInt
+	IsCollect       bool `description:"本人是否收藏"`
+	CollectNum      int  `description:"收藏人数"`
 }
 
 type ArticleListResp struct {

+ 28 - 0
services/article_history.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"hongze/hongze_clpt/models"
 	"hongze/hongze_clpt/utils"
 	"strconv"
@@ -92,3 +93,30 @@ func ArticleHistoryStopTime(articleId, stopTime, outType int, user *models.WxUse
 	go ArticleHistoryUserLabelLogAdd(articleId, uid)
 	return
 }
+
+func GetArticleHistoryByArticleId(articleIds []int) (mapResp map[int]int) {
+	var err error
+	defer func() {
+		if err != nil {
+			fmt.Println(err)
+			go utils.SendAlarmMsg("获取用户的阅读数据,信息失败,Err:"+err.Error(), 3)
+		}
+	}()
+	lenIds := len(articleIds)
+	if lenIds == 0 {
+		return
+	}
+	var condition string
+	var pars []interface{}
+	condition = ` AND article_id IN (` + utils.GetOrmInReplace(lenIds) + `) `
+	pars = append(pars, articleIds)
+	list, err := models.GetCygxArticleHistoryRecordNewpvList(condition, pars)
+	if err != nil {
+		return
+	}
+	mapResp = make(map[int]int, 0)
+	for _, v := range list {
+		mapResp[v.ArticleId]++
+	}
+	return
+}

+ 56 - 0
services/articlt_collect.go

@@ -0,0 +1,56 @@
+package services
+
+import (
+	"errors"
+	"fmt"
+	"hongze/hongze_clpt/models"
+	"hongze/hongze_clpt/utils"
+)
+
+//func init() {
+//	GetCygxArticleCollectMap(90)
+//}
+
+// GetCygxArticleCollectMap 根据用户ID获取所有文章收藏
+func GetCygxArticleCollectMap(userId int) (mapResp map[int]bool, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("根据用户ID获取所有文章收藏失败 ErrMsg:"+err.Error(), 2)
+
+		}
+	}()
+	list, e := models.GetCygxArticleCollectByUser(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("根据用户ID获取所有文章收藏,GetCygxArticleCollectByUser " + e.Error())
+		return
+	}
+	mapResp = make(map[int]bool, 0)
+	if len(list) > 0 {
+		for _, v := range list {
+			mapResp[v.ArticleId] = true
+		}
+	}
+	return
+}
+
+// GetCygxArticleCollectNumMapByArtcileIds 根据文章ID获取对应文章被收藏的数量
+func GetCygxArticleCollectNumMapByArtcileIds(articleIds []int) (mapResp map[int]int, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("根据文章ID获取对应文章被收藏的数量  GetCygxArticleCollectNumMapByArtcileIds ErrMsg:"+err.Error()+fmt.Sprint(articleIds), 2)
+
+		}
+	}()
+	list, e := models.GetArticleCollectListNum(articleIds)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("GetArticleCollectListNum " + e.Error())
+		return
+	}
+	mapResp = make(map[int]int, 0)
+	if len(list) > 0 {
+		for _, v := range list {
+			mapResp[v.ArticleId] = v.CollectNum
+		}
+	}
+	return
+}