123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191 |
- package controllers
- import (
- "github.com/rdlucklib/rdluck_tools/paging"
- "hongze/hongze_api/models"
- "hongze/hongze_api/utils"
- "time"
- )
- //视频
- type VideoController struct {
- BaseAuthController
- }
- // @Title 获取视频标签列表
- // @Description 获取视频标签列表接口
- // @Success 200 {object} video.VideoTagsListResp
- // @router /tags/list [get]
- func (this *VideoController) TagsList() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- list, err := models.GetVideoTagsList()
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- resp := new(models.VideoTagsListResp)
- resp.List = list
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
- // @Title 视频列表
- // @Description 视频列表接口
- // @Param PageSize query int true "每页数据条数"
- // @Param CurrentIndex query int true "当前页页码,从1开始"
- // @Param KeyWord query string true "搜索关键词"
- // @Param DateType query string true "时间筛选组合:1:近一个月,2:近三个月,3:近半年,4:全部"
- // @Param Tags query string true "标签名称"
- // @Success 200 {object} video.VideoListResp
- // @router /list [get]
- func (this *VideoController) List() {
- br := new(models.BaseResponse).Init()
- defer func() {
- this.Data["json"] = br
- this.ServeJSON()
- }()
- user := this.User
- if user == nil {
- br.Msg = "请登录"
- br.ErrMsg = "请登录,用户信息为空"
- br.Ret = 408
- return
- }
- status := 0
- companyProduct, err := models.GetCompanyById(user.CompanyId)
- if err != nil {
- if err.Error() != utils.ErrNoRow() {
- br.Msg = "获取报告详情失败"
- br.ErrMsg = "获取用户管理企业信息失败,Err:" + err.Error()
- return
- } else {
- status = 1
- }
- }
- if len(companyProduct) == 0 {
- status = 1
- } else {
- status = 1
- for _, v := range companyProduct {
- if v.Status == utils.COMPANY_STATUS_TRY_OUT ||
- v.Status == utils.COMPANY_STATUS_FORMAL ||
- v.Status == utils.COMPANY_STATUS_FOREVER {
- status = 0
- break
- }
- }
- for _, v := range companyProduct {
- //如果产品类型是 ficc ,且当前产品状态是禁用状态, 且是当前产品状态是禁用的,那么是没有权限访问的
- if v.ProductId == 1 && v.IsSuspend > 0 && v.Status == utils.COMPANY_STATUS_TRY_OUT {
- status = 1
- break
- }
- }
- }
- pageSize, _ := this.GetInt("PageSize")
- currentIndex, _ := this.GetInt("CurrentIndex")
- keyWord := this.GetString("KeyWord")
- dateType, _ := this.GetInt("DateType")
- tags := this.GetString("Tags")
- var startSize int
- if pageSize <= 0 {
- pageSize = utils.PageSize20
- }
- if currentIndex <= 0 {
- currentIndex = 1
- }
- startSize = paging.StartIndex(currentIndex, pageSize)
- resp := new(models.VideoListResp)
- var condition string
- var pars []interface{}
- if keyWord != "" {
- videoIdStr, err := models.GetVideoIdByKeyWord(keyWord)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if videoIdStr != "" {
- condition += ` AND (a.video_id IN (` + videoIdStr + `) OR a.title LIKE '%` + keyWord + `%' ) `
- } else {
- condition += ` AND (a.title LIKE '%` + keyWord + `%' ) `
- }
- }
- if tags != "" {
- videoIdStr, err := models.GetVideoIdByKeyWord(tags)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取失败,Err:" + err.Error()
- return
- }
- if videoIdStr != "" {
- condition += ` AND a.video_id IN (` + videoIdStr + `) `
- } else {
- list := make([]*models.VideoList, 0)
- resp.List = list
- resp.Status = status
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- return
- }
- }
- publishDate := ""
- if dateType == 1 {
- publishDate = time.Now().AddDate(0, -1, 0).Format(utils.FormatDate)
- } else if dateType == 2 {
- publishDate = time.Now().AddDate(0, -3, 0).Format(utils.FormatDate)
- } else if dateType == 3 {
- publishDate = time.Now().AddDate(0, -6, 0).Format(utils.FormatDate)
- } else if dateType == 4 {
- publishDate = time.Now().AddDate(-100, 0, 0).Format(utils.FormatDate)
- }
- if publishDate != "" {
- condition += ` AND a.publish_time >=? `
- pars = append(pars, publishDate)
- }
- if status == 0 {
- list, err := models.GetVideoList(condition, pars, startSize, pageSize)
- if err != nil {
- br.Msg = "获取失败"
- br.ErrMsg = "获取数据失败,Err:" + err.Error()
- return
- }
- if len(list) <= 0 {
- list := make([]*models.VideoList, 0)
- resp.List = list
- } else {
- resp.List = list
- }
- } else {
- list := make([]*models.VideoList, 0)
- resp.List = list
- }
- resp.Status = status
- br.Ret = 200
- br.Success = true
- br.Msg = "获取成功"
- br.Data = resp
- }
|