xingzai 1 год назад
Родитель
Сommit
10d1a2bf5a

+ 3 - 1
controllers/research.go

@@ -123,18 +123,20 @@ func (this *MobileResearchController) ArticleNewList() {
 		br.ErrMsg = "GetArticleResearchCount,Err:" + err.Error()
 		return
 	}
-	list, err := models.GetArticleResearchList(condition, pars, startSize, pageSize, user.UserId, needYanxuanSpecial)
+	list, err := models.GetArticleResearchListYx(condition, pars, startSize, pageSize, user.UserId, needYanxuanSpecial)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
 		return
 	}
+
 	list, err = services.HandleArticleCategoryImg(list, user)
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "HandleArticleCategoryImg,Err:" + err.Error()
 		return
 	}
+
 	//处理对应的文章类型标签按钮
 	nameMap, styleMap, err := services.GetArticleTypeMap()
 	if err != nil {

+ 8 - 0
models/cygx_yanxuan_special_collect.go

@@ -48,3 +48,11 @@ func GetCygxYanxuanSpecialCollectCount(condition string, pars []interface{}) (co
 	err = o.Raw(sqlCount, pars).QueryRow(&count)
 	return
 }
+
+// GetCygxYanxuanSpecialCollectByUser 根据用户ID获取所有文章收藏
+func GetCygxYanxuanSpecialCollectByUser(userId int) (items []*CygxYanxuanSpecialCollect, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT * FROM cygx_yanxuan_special_collect  WHERE 1 =1  AND  user_id =?  `
+	_, err = o.Raw(sql, userId).QueryRows(&items)
+	return
+}

+ 57 - 0
models/report.go

@@ -936,6 +936,63 @@ func GetArticleResearchList(condition string, pars []interface{}, startSize, pag
 	return
 }
 
+func GetArticleResearchListYx(condition string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (items []*ArticleListResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			a.article_id,
+			a.title,
+			a.publish_date AS publish_time,
+			a.article_type_id,
+			d.nick_name,
+			d.department_id,
+			0 AS is_special,
+			0 as pv,
+			0 as collect_num,
+			0 AS special_type,
+			0 AS user_id,
+			'' AS company_tags, 
+			'' AS industry_tags
+		FROM
+			cygx_article AS a
+			INNER JOIN cygx_article_department AS d ON d.department_id = a.department_id 
+		WHERE
+			1 = 1  AND a.publish_status = 1
+		  `
+	if condition != "" {
+		sql += condition
+	}
+	sql += ` GROUP BY a.article_id  `
+	if needYanxuanSpecial {
+		sql += `UNION ALL
+	SELECT
+		a.id AS article_id,
+		a.title AS title,
+		a.publish_time AS publish_time,
+		-1 AS article_type_id,
+		b.nick_name AS nick_name,
+		a.user_id AS department_id,
+		1 AS is_special,
+		a.pv,
+		a.article_collect_num as collect_num,
+		a.type AS special_type,
+		a.user_id AS user_id,
+		a.company_tags AS company_tags, 
+		a.industry_tags AS industry_tags 
+	FROM
+	cygx_yanxuan_special AS a
+	JOIN cygx_yanxuan_special_author AS b ON a.user_id = b.user_id
+	WHERE
+	1 = 1  AND a.status = 3 `
+		sql += ` ORDER  BY publish_time DESC  LIMIT ?,? `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	} else {
+		sql += ` ORDER  BY publish_time DESC  LIMIT ?,? `
+		_, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
+	}
+
+	return
+}
+
 func GetArticleResearchAndYxSpecialList(condition, conditionYxSpecial string, pars []interface{}, startSize, pageSize, userId int, needYanxuanSpecial bool) (total int, items []*ArticleListResp, err error) {
 	o := orm.NewOrm()
 	sql := `SELECT

+ 3 - 1
services/article.go

@@ -206,7 +206,7 @@ func HandleArticleCategoryImg(list []*models.ArticleListResp, user *models.WxUse
 	articleMapPv := GetArticleHistoryByArticleId(articleIds)                       //文章Pv
 	articleCollectMap, _ := GetCygxArticleCollectMap(user.UserId)                  //用户收藏的文章
 	articleCollectNumMap, _ := GetCygxArticleCollectNumMapByArtcileIds(articleIds) //文章收藏的数量
-
+	articleCollectYanxuanSpecialMap, _ := GetYanxuanSpecialCollectMap(user.UserId) //用户收藏的研选专栏
 	for k, v := range list {
 		if len(industryMap[v.ArticleId]) > 0 {
 			list[k].List = industryMap[v.ArticleId]
@@ -220,6 +220,8 @@ func HandleArticleCategoryImg(list []*models.ArticleListResp, user *models.WxUse
 			list[k].Pv = articleMapPv[v.ArticleId]
 			list[k].IsCollect = articleCollectMap[v.ArticleId]
 			list[k].CollectNum = articleCollectNumMap[v.ArticleId]
+		} else {
+			v.IsCollect = articleCollectYanxuanSpecialMap[v.ArticleId]
 		}
 	}
 

+ 22 - 0
services/cygx_yanxuan_special.go

@@ -510,3 +510,25 @@ func UdpateYanxuanSpecialauthorArticleNum(authoruserId int) {
 	}
 	return
 }
+
+// GetYanxuanSpecialCollectMap 根据用户ID获取所有研选专栏的收藏
+func GetYanxuanSpecialCollectMap(userId int) (mapResp map[int]bool, err error) {
+	defer func() {
+		if err != nil {
+			go utils.SendAlarmMsg("GetYanxuanSpecialCollectMap 根据用户ID获取所有研选专栏的收藏失败 ErrMsg:"+err.Error(), 2)
+
+		}
+	}()
+	list, e := models.GetCygxYanxuanSpecialCollectByUser(userId)
+	if e != nil && e.Error() != utils.ErrNoRow() {
+		err = errors.New("根据用户ID获取所有文章收藏,GetCygxYanxuanSpecialCollectByUser " + e.Error())
+		return
+	}
+	mapResp = make(map[int]bool, 0)
+	if len(list) > 0 {
+		for _, v := range list {
+			mapResp[v.YanxuanSpecialId] = true
+		}
+	}
+	return
+}