package controllers import ( "hongze/hongze_api/models" "hongze/hongze_api/services" "hongze/hongze_api/utils" "rdluck_tools/paging" "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(this.User.UserId) if err != nil { br.Msg = "获取失败" br.ErrMsg = "判断权限失败,判断权限失败:" + err.Error() return } if userPermission == 0 { hasPermission = true } } for i := 0; i < len(list); i++ { item := list[i] 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 }