123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186 |
- package controllers
- import (
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_api/models"
- "hongze/hongze_api/services"
- "hongze/hongze_api/utils"
- "time"
- )
- // @Title 首页专栏接口
- // @Description 首页专栏接口
- // @Success 200 {object} models.Classify
- // @router /pc/column/list [get]
- func (this *HomeCommonController) PcColumnList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- list, err := models.GetColumnList()
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取数据成功"
- br.Data = list
- }
- // @Title pc-首页列表接口
- // @Description pc-首页列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param ClassifyId query int true "分类id"
- // @Success 200 {object} models.PcListHomeResp
- // @router /pc/list [get]
- func (this *HomeCommonController) ListHome() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- var uid int
- if this.Token != "" && this.User != nil {
- uid = this.User.UserId
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- classifyId, _ := this.GetInt("ClassifyId")
- if classifyId <= 0 {
- br.Msg = "参数错误"
- br.ErrMsg = "参数错误"
- return
- }
- endDate := time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
- total, err := models.PcListHomeCount(classifyId, endDate)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据条数失败,Err:" + err.Error()
- return
- }
- list, err := models.PcListHome(classifyId, uid, startSize, pageSize, endDate)
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- var hasPermission bool
- if this.Token != "" && this.User != nil {
- userPermission, err := services.CheckUserPermission(uid)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "判断权限失败,判断权限失败:" + err.Error()
- return
- }
- if userPermission == 0 {
- hasPermission = true
- }
- }
- reportType := "rddp"
- reportPermissionList, err := models.GetReportVarietyListByUserIdExt(uid, reportType) //获取客户拥有权限的报告id
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取报告详情失败"
- br.ErrMsg = "获取客户信息失败,Err:" + err.Error()
- return
- } else {
- hasPermission = false
- }
- }
- if len(reportPermissionList) == 0 {
- hasPermission = false
- }
- permissionMap := make(map[int]int)
- for _, v := range reportPermissionList {
- if _, ok := permissionMap[v.ReportChapterTypeId]; !ok {
- permissionMap[v.ReportChapterTypeId] = v.ReportChapterTypeId
- }
- }
- for i := 0; i < len(list); i++ {
- item := list[i]
- if uid > 0 {
- count, err := models.GetReportPermission(uid, item.ClassifyNameSecond)
- if err != nil && err.Error() != utils.ErrNoRow() {
- br.Msg = "获取失败"
- br.ErrMsg = "判断报告是否拥有权限失败,Err:" + err.Error()
- return
- }
- if count <= 0 {
- list[i].VideoUrl = ""
- list[i].VideoName = ""
- list[i].VideoPlaySeconds = ""
- list[i].VideoSize = ""
- }
- }
- if item.ClassifyName == "权益研报" {
- list[i].TitleType = "权益"
- } else {
- list[i].TitleType = "FICC"
- }
- if !hasPermission {
- list[i].VideoUrl = ""
- list[i].VideoName = ""
- list[i].VideoPlaySeconds = ""
- list[i].VideoSize = ""
- }
- }
- if len(list) == 0 {
- list = make([]*models.PcHomeClassifyItem, 0)
- }
- page := paging.GetPaging(currentIndex, pageSize, total)
- resp := new(models.PcListHomeResp)
- resp.Paging = page
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取数据成功"
- br.Data = resp
- }
- // @Title 首页banner接口
- // @Description 首页banner接口
- // @Success 200 {object} models.Banner
- // @router /pc/banner [get]
- func (this *HomeCommonController) PcListBanner() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- list, err := models.GetHomeBannerList("pc")
- if err != nil {
- br.Msg = "获取数据失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- br.Ret = 200
- br.Success = true
- br.Msg = "获取数据成功"
- br.Data = list
- }
|