Browse Source

no message

xingzai 2 years ago
parent
commit
7f71ea781a
2 changed files with 51 additions and 6 deletions
  1. 15 6
      controllers/research.go
  2. 36 0
      models/report.go

+ 15 - 6
controllers/research.go

@@ -8,6 +8,7 @@ import (
 	"hongze/hongze_cygx/utils"
 	"strconv"
 	"strings"
+	"time"
 )
 
 // 研选
@@ -95,24 +96,32 @@ func (this *ResearchController) CollectionList() {
 		return
 	}
 
+	pageSize, _ := this.GetInt("PageSize", 15)
 	var condition string
+	var pars []interface{}
 	articleTypeIds, err := services.GetYanXuanArticleTypeIds()
 	if err != nil {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "GetYanXuanArticleTypeIds,Err:" + err.Error()
 		return
 	}
-	if articleTypeIds == "" {
+	if articleTypeIds != "" {
+		condition = ` AND a.article_type_id IN (` + articleTypeIds + `)  `
+	} else {
 		br.Msg = "获取信息失败"
 		br.ErrMsg = "研选分类ID不能为空"
 		return
 	}
-	condition = ` AND a.article_type_id IN (` + articleTypeIds + `)  `
-	condition += `  AND publish_status = 1 GROUP BY a.article_id ORDER BY collect_num_order DESC, publish_date DESC LIMIT 15 `
-	list, err := models.GetArticleCollectionList(condition, user.UserId)
+	// 根据关注时间一个月前至昨日的增量数据排序
+	nowTime := time.Now().Local()
+	startTime := nowTime.AddDate(0, -1, 0)
+	endTime := nowTime.AddDate(0, 0, -1)
+	condition += ` AND ac.create_time BETWEEN ? AND ? `
+	pars = append(pars, startTime, endTime)
+	list, err := models.GetReportCollectionBillboardListYx(pageSize, pars, condition)
 	if err != nil {
-		br.Msg = "获取信息失败"
-		br.ErrMsg = "获取品种信息失败,Err:" + err.Error()
+		br.Msg = "获取失败"
+		br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + err.Error()
 		return
 	}
 	for k, v := range list {

+ 36 - 0
models/report.go

@@ -389,6 +389,42 @@ type ArticleCollectionLIstResp struct {
 	List []*ArticleCollectionResp
 }
 
+// 研选报告收藏榜单列表
+func GetReportCollectionBillboardListYx(limit int, pars []interface{}, condition string) (items []*ArticleCollectionResp, err error) {
+	o := orm.NewOrm()
+	sql := `SELECT
+			ac.id,
+			a.category_id,
+			a.article_id,
+			a.title,
+			a.body,
+			a.annotation,
+			a.abstract,
+			a.publish_date,
+			a.article_type_id,
+			d.nick_name,
+			d.department_id,
+			( SELECT count( 1 ) FROM cygx_article_history_record_newpv AS h WHERE h.article_id = a.article_id ) AS pv,
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac  INNER JOIN wx_user as u ON  u.user_id = ac.user_id  WHERE ac.article_id = a.article_id  ) AS collect_num, 
+			( SELECT count( 1 ) FROM cygx_article_collect AS ac  INNER JOIN wx_user as u ON  u.user_id = ac.user_id  WHERE ac.article_id = a.article_id AND DATE_SUB( CURDATE(), INTERVAL 30 DAY ) <= date( ac.create_time )  ) AS collection_num
+		FROM
+			cygx_article AS a
+			INNER JOIN cygx_article_collect AS ac ON ac.article_id = a.article_id 
+			INNER JOIN cygx_industrial_article_group_management AS mg ON mg.article_id = a.article_id
+			INNER JOIN cygx_industrial_management AS m ON m.industrial_management_id = mg.industrial_management_id
+			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 ORDER BY collection_num DESC,  a.publish_date DESC`
+	sql += ` LIMIT ?`
+	_, err = o.Raw(sql, pars, limit).QueryRows(&items)
+	return
+}
+
 // 列表
 func GetArticleCollectionList(condition string, userId int) (items []*ArticleCollectionResp, err error) {
 	o := orm.NewOrm()