123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- package controllers
- import (
- "hongze/hongze_clpt/models"
- "hongze/hongze_clpt/services"
- "hongze/hongze_clpt/utils"
- "time"
- )
- // 报告榜单
- type ReportBillboardController struct {
- BaseAuthController
- }
- type ReportBillboardCommonController struct {
- BaseCommonController
- }
- type MobileReportBillboardController struct {
- BaseAuthMobileController
- }
- // @Title 阅读飙升榜/报告收藏榜
- // @Description 获取阅读飙升榜/报告收藏榜接口
- // @Param ChartPermissionId query int false "分类ID"
- // @Param PageSize query int true "每页数据条数"
- // @Param Source query int true "来源 1:阅读飙升 ,2:报告收藏"
- // @Success 200 {object} models.ReportBillboardListResp
- // @router /list [get]
- func (this *MobileReportBillboardController) ReadList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请重新登录"
- br.Ret = 408
- return
- }
- chartPermissionId, _ := this.GetInt("ChartPermissionId")
- pageSize, _ := this.GetInt("PageSize")
- source, _ := this.GetInt("Source")
- sourceArr := []int{1, 2}
- if !utils.InArrayByInt(sourceArr, source) {
- br.Msg = "来源有误"
- return
- }
- var topNum int
- if pageSize == 0 {
- topNum = utils.PageSize15
- } else {
- topNum = pageSize
- }
- list := make([]*models.ArticleListResp, 0)
- // 阅读飙升榜
- if source == 1 {
- var topCond string
- var topPars []interface{}
- if chartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
- nowTime := time.Now().Local()
- startTime := nowTime.AddDate(0, -1, 0)
- endTime := nowTime.AddDate(0, 0, -1)
- topCond += ` AND l.create_time BETWEEN ? AND ? AND a.article_id > ? `
- topPars = append(topPars, startTime, endTime, utils.SummaryArticleId)
- topList, e := models.GetTopReadRecordArticleListByConditionYx(topNum, topCond, topPars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + e.Error()
- return
- }
- list = topList
- } else {
- if chartPermissionId > 0 {
- categoryId, err := models.GetCategoryId(chartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
- return
- }
- if categoryId != "" {
- topCond += ` AND a.category_id IN (` + categoryId + `)`
- }
- }
- topList, e := models.GetTopReadRecordArticleListByCondition(topNum, topCond, topPars)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + e.Error()
- return
- }
- list = topList
- }
- }
- // 报告收藏榜
- if source == 2 {
- var collectCond string
- var collectPars []interface{}
- // 根据关注时间一个月前至昨日的增量数据排序
- nowTime := time.Now().Local()
- startTime := nowTime.AddDate(0, -1, 0)
- endTime := nowTime.AddDate(0, 0, -1)
- collectCond += ` AND ac.create_time BETWEEN ? AND ?`
- collectPars = append(collectPars, startTime, endTime)
- if chartPermissionId == utils.CHART_PERMISSION_ID_YANXUAN {
- topList, e := models.GetReportCollectionBillboardListYx(topNum, collectPars, collectCond)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告阅读增量排行榜失败, Err:" + e.Error()
- return
- }
- list = topList
- } else {
- if chartPermissionId > 0 {
- categoryId, err := models.GetCategoryId(chartPermissionId)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取信息失败"
- br.ErrMsg = "获取分类权限信息失败,Err:" + err.Error()
- return
- }
- if categoryId != "" {
- collectCond += ` AND a.category_id IN (` + categoryId + `)`
- }
- }
- collectList, e := models.GetReportCollectionBillboardList(topNum, collectPars, collectCond)
- if e != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告收藏排行榜失败, Err:" + e.Error()
- return
- }
- list = collectList
- }
- }
- var err error
- resp := new(models.ReportBillboardListResp)
- resp.List, err = services.HandleArticleCategoryImg(list, user)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取报告封面图片失败, Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|