xingzai 1 سال پیش
والد
کامیت
d957432cac
5فایلهای تغییر یافته به همراه80 افزوده شده و 0 حذف شده
  1. 14 0
      controllers/report.go
  2. 4 0
      models/article.go
  3. 12 0
      models/article_collect.go
  4. 27 0
      services/article_history.go
  5. 23 0
      services/articlt_collect.go

+ 14 - 0
controllers/report.go

@@ -544,14 +544,22 @@ func (this *ReportController) List() {
 			imgUrlChart = vslice[len(vslice)-1]
 			mapCategoryUrl[categoryIdStr] = imgUrlChart
 		}
+		var articleIds []int
 		lenList := len(list)
 		for i := 0; i < lenList; i++ {
 			item := list[i]
 			list[i].Body, _ = services.GetReportContentTextSub(item.Body)
 			//list[i].Abstract = html.UnescapeString(item.Abstract)
 			list[i].Abstract, _ = services.GetReportContentTextSub(item.Abstract)
+
+			if item.Resource == 1 {
+				articleIds = append(articleIds, item.ArticleId)
+			}
 		}
 
+		articleMapPv := services.GetArticleHistoryByArticleId(articleIds)                       //文章Pv
+		articleCollectMap, _ := services.GetCygxArticleCollectMap(user.UserId)                  //用户收藏的文章
+		articleCollectNumMap, _ := services.GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
 		for k, v := range list {
 			if v.Readnum == 0 && user.CreatedTime.Before(utils.StrTimeToTime(v.PublishDate)) && utils.StrTimeToTime(utils.OnlineTime).Before(utils.StrTimeToTime(v.PublishDate)) {
 				list[k].IsRed = true
@@ -560,6 +568,12 @@ func (this *ReportController) List() {
 				list[k].IsHaveVideo = true
 			}
 			list[k].ImgUrlPc = mapCategoryUrl[v.CategoryId]
+
+			if v.Resource == 1 {
+				v.Pv = articleMapPv[v.ArticleId]
+				v.IsCollect = articleCollectMap[v.ArticleId]
+				v.CollectNum = articleCollectNumMap[v.ArticleId]
+			}
 			if v.Resource == 2 {
 				v.PublishDate = utils.TimeRemoveHms2(v.PublishDate)
 			}

+ 4 - 0
models/article.go

@@ -424,6 +424,10 @@ type ReportArticle struct {
 	CategoryId       string `description:"文章分类"`
 	Annotation       string `description:"核心观点"`
 	Resource         int    `description:"来源类型,1:文章、2:产品内测"`
+	MyCollectNum     int    `description:"本人是否收藏"`
+	IsCollect        bool   `description:"本人是否收藏"`
+	Pv               int    `description:"PV"`
+	CollectNum       int    `description:"收藏人数"`
 }
 
 type ReportMappingCategoryRep struct {

+ 12 - 0
models/article_collect.go

@@ -160,6 +160,18 @@ func GetArticleCollectNum(articleId []string, uid int) (items []*CygxArticleNum,
 	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
+}
+
 type MicroRoadshowCollectList struct {
 	AudioIds         string
 	VideoIds         string

+ 27 - 0
services/article_history.go

@@ -36,6 +36,33 @@ func GetArticleHistoryByUser(articleIds []int, user *models.WxUserItem) (mapResp
 	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
+}
+
 // 记录用户文章浏览记录
 func ArticleHistory(articleId int, user *models.WxUserItem) (err error) {
 	defer func() {

+ 23 - 0
services/articlt_collect.go

@@ -2,6 +2,7 @@ package services
 
 import (
 	"errors"
+	"fmt"
 	"hongze/hongze_cygx/models"
 	"hongze/hongze_cygx/utils"
 )
@@ -31,3 +32,25 @@ func GetCygxArticleCollectMap(userId int) (mapResp map[int]bool, err error) {
 	}
 	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
+}