新增了详情页排名计算
This commit is contained in:
parent
e83b15b03a
commit
3ac92da2db
@ -109,17 +109,32 @@ func (r *Article) GetArticle(c *gin.Context) {
|
||||
|
||||
article.ArticleAuthor = articleAuthors
|
||||
|
||||
// 获取排名
|
||||
rank, _ := articleDao.GetArticleRank(article.ArticleId)
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetArticleDto(article)
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadArticleAuthor(article.ArticleAuthor)
|
||||
// 获取排名开关限制
|
||||
systemConfigDao := dao.SystemConfigDao{}
|
||||
systemConfig, err := systemConfigDao.GetSystemConfigById(1)
|
||||
if err != nil {
|
||||
responses.OkWithData(nil, c)
|
||||
return
|
||||
}
|
||||
|
||||
if systemConfig.IsDisplayRank == 1 {
|
||||
// 获取大于某一投票数的文章
|
||||
maps := make(map[string]interface{})
|
||||
maps["article_status"] = 1
|
||||
articles, err := articleDao.GetArticleListGtVoteNum(maps, article.VoteNum)
|
||||
if err == nil {
|
||||
rank := len(articles) + 1
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadArticleAuthor(article.ArticleAuthor)
|
||||
|
||||
// 检测用户今日是否投票
|
||||
userId := c.GetInt64("UserId")
|
||||
|
||||
@ -109,17 +109,32 @@ func (r *Video) GetVideo(c *gin.Context) {
|
||||
|
||||
video.VideoAuthor = videoAuthors
|
||||
|
||||
// 获取排名
|
||||
rank, _ := videoDao.GetVideoRank(video.VideoId)
|
||||
|
||||
// 处理返回值
|
||||
g := dto.GetVideoDto(video)
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadVideoAuthor(video.VideoAuthor)
|
||||
// 获取排名开关限制
|
||||
systemConfigDao := dao.SystemConfigDao{}
|
||||
systemConfig, err := systemConfigDao.GetSystemConfigById(1)
|
||||
if err != nil {
|
||||
responses.OkWithData(nil, c)
|
||||
return
|
||||
}
|
||||
|
||||
if systemConfig.IsDisplayRank == 1 {
|
||||
// 获取大于某一投票数的文章
|
||||
maps := make(map[string]interface{})
|
||||
maps["article_status"] = 1
|
||||
videos, err := videoDao.GetVideoListGtVoteNum(maps, video.VoteNum)
|
||||
if err == nil {
|
||||
rank := len(videos) + 1
|
||||
|
||||
// 加载数据-作者排名
|
||||
g.LoadRank(rank)
|
||||
}
|
||||
}
|
||||
|
||||
// 加载数据-作者
|
||||
g.LoadVideoAuthor(video.VideoAuthor)
|
||||
|
||||
// 检测用户今日是否投票
|
||||
userId := c.GetInt64("UserId")
|
||||
|
||||
@ -210,6 +210,15 @@ func (r *ArticleDao) GetArticleRankList(maps interface{}, orderField string, lim
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleListGtVoteNum 获取大于某一投票数的文章列表
|
||||
func (r *ArticleDao) GetArticleListGtVoteNum(maps interface{}, voteNum uint) (m []*model.Article, err error) {
|
||||
err = global.Db.Where(maps).Where("vote_num > ?", voteNum).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetArticleRank 获取某一条数据的排名
|
||||
func (r *ArticleDao) GetArticleRank(articleID int64) (int, error) {
|
||||
var rank int
|
||||
|
||||
@ -210,6 +210,15 @@ func (r *VideoDao) GetVideoRankList(maps interface{}, orderField string, limit i
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoListGtVoteNum 获取大于某一投票数的视频列表
|
||||
func (r *VideoDao) GetVideoListGtVoteNum(maps interface{}, voteNum uint) (m []*model.Video, err error) {
|
||||
err = global.Db.Where(maps).Where("vote_num > ?", voteNum).Find(&m).Error
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
// GetVideoRank 获取某一条数据的排名
|
||||
func (r *VideoDao) GetVideoRank(videoID int64) (int, error) {
|
||||
var rank int
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user