rdluck 4 年之前
父节点
当前提交
fc5e72086d
共有 3 个文件被更改,包括 54 次插入29 次删除
  1. 37 13
      controllers/video.go
  2. 6 4
      models/video.go
  3. 11 12
      utils/constants.go

+ 37 - 13
controllers/video.go

@@ -49,8 +49,8 @@ func (this *VideoController) TagsList() {
 // @Param   PageSize   query   int  true       "每页数据条数"
 // @Param   CurrentIndex   query   int  true       "当前页页码,从1开始"
 // @Param   KeyWord   query   string  true       "搜索关键词"
-// @Param   Tags   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() {
@@ -81,7 +81,9 @@ func (this *VideoController) List() {
 	if company == nil {
 		status = 1
 	} else {
-		if company.CompanyType == 3 || company.CompanyType == 4 {
+		if company.Status == utils.COMPANY_STATUS_FREEZE ||
+			company.Status == utils.COMPANY_STATUS_LOSE ||
+			company.Status == utils.COMPANY_STATUS_POTENTIAL {
 			status = 1
 		}
 	}
@@ -89,8 +91,8 @@ func (this *VideoController) List() {
 	pageSize, _ := this.GetInt("PageSize")
 	currentIndex, _ := this.GetInt("CurrentIndex")
 	keyWord := this.GetString("KeyWord")
-	tags := this.GetString("Tags")
 	dateType, _ := this.GetInt("DateType")
+	tags := this.GetString("Tags")
 
 	var startSize int
 	if pageSize <= 0 {
@@ -100,11 +102,13 @@ func (this *VideoController) List() {
 		currentIndex = 1
 	}
 	startSize = paging.StartIndex(currentIndex, pageSize)
-
+	total := 0
+	resp := new(models.VideoListResp)
+	page := paging.GetPaging(currentIndex, pageSize, total)
 	var condition string
 	var pars []interface{}
 
-	if tags != "" {
+	if keyWord != "" {
 		videoIdStr, err := models.GetVideoIdByKeyWord(keyWord)
 		if err != nil {
 			br.Msg = "获取失败"
@@ -112,14 +116,32 @@ func (this *VideoController) List() {
 			return
 		}
 		if videoIdStr != "" {
-			condition += ` AND a.video_id IN (` + videoIdStr + `) `
+			condition += ` AND (a.video_id IN (` + videoIdStr + `) OR a.title LIKE '%` + keyWord + `%' ) `
+		} else {
+			condition += ` AND (a.title LIKE '%` + keyWord + `%' ) `
 		}
 	}
 
-	if keyWord != "" {
-		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.Paging = page
+			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)
@@ -134,8 +156,6 @@ func (this *VideoController) List() {
 		condition += ` AND a.publish_time >=? `
 		pars = append(pars, publishDate)
 	}
-	total := 0
-	resp := new(models.VideoListResp)
 	if status == 0 {
 		total, err = models.GetVideoListCount(condition, pars)
 		if err != nil {
@@ -150,12 +170,16 @@ func (this *VideoController) List() {
 			br.ErrMsg = "获取数据失败,Err:" + err.Error()
 			return
 		}
-		resp.List = list
+		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
 	}
-	page := paging.GetPaging(currentIndex, pageSize, total)
 	resp.Paging = page
 	resp.Status = status
 	br.Ret = 200

+ 6 - 4
models/video.go

@@ -33,6 +33,7 @@ type VideoList struct {
 	PlaySeconds   uint32    `description:"视频播放时长"`
 	CreateTime    time.Time `description:"视频创建时间"`
 	ModifyTime    time.Time `description:"视频修改时间"`
+	TagsName     string    `description:"标签名称"`
 }
 
 func GetVideoIdByKeyWord(tagName string) (video_id string, err error) {
@@ -41,7 +42,7 @@ func GetVideoIdByKeyWord(tagName string) (video_id string, err error) {
 	sql := ` SELECT GROUP_CONCAT(DISTINCT a.video_id) AS video_id FROM video_tags AS a
              INNER JOIN tags AS b ON a.tags_id=b.tags_id
 			 WHERE b.tags_name=? `
-	err = o.Raw(sql,tagName).QueryRow(&video_id)
+	err = o.Raw(sql, tagName).QueryRow(&video_id)
 	return
 }
 
@@ -49,7 +50,7 @@ func GetVideoListCount(condition string, pars []interface{}) (count int, err err
 	o := orm.NewOrm()
 	o.Using("rddp")
 	sql := `SELECT COUNT(DISTINCT a.video_id) AS count
-			FROM video AS a  `
+			FROM video AS a  WHERE 1=1 `
 	if condition != "" {
 		sql += condition
 	}
@@ -62,7 +63,8 @@ func GetVideoList(condition string, pars []interface{}, startSize, pageSize int)
 	o.Using("rddp")
 	sql := `SELECT a.*,GROUP_CONCAT(c.tags_name SEPARATOR '/') AS tags_name FROM video AS a
 			INNER JOIN video_tags AS b ON a.video_id=b.video_id
-			INNER JOIN tags AS c ON b.tags_id=c.tags_id `
+			INNER JOIN tags AS c ON b.tags_id=c.tags_id 
+            WHERE 1=1 `
 	if condition != "" {
 		sql += condition
 	}
@@ -75,4 +77,4 @@ type VideoListResp struct {
 	Paging *paging.PagingItem
 	List   []*VideoList
 	Status int `description:"权限状态:0:有权限,1:无权限"`
-}
+}

+ 11 - 12
utils/constants.go

@@ -37,14 +37,13 @@ const (
 
 //聚合短信
 var (
-	JhGnTplId  = "65692"                            //聚合国内模板编码
-	JhGjTplId  = "10054"                            //聚合国内模板编码
+	JhGnTplId = "65692" //聚合国内模板编码
+	JhGjTplId = "10054" //聚合国内模板编码
 
 	JhGnAppKey = "4c8504c49dd335e99cfd7b6a3a9e2415" //聚合国内AppKey
 	JhGjAppKey = "3326ad2c1047a4cd92ace153e6044ca3"
 )
 
-
 //科大讯飞--语音合成
 const (
 	XfSTATUS_FIRST_FRAME    = 0 //第一帧标识
@@ -63,20 +62,20 @@ var (
 	Endpoint   string = "oss-cn-shanghai.aliyuncs.com"
 	Bucketname string = "hongze"
 
-	Imghost    string = "http://hongze.oss-cn-shanghai.aliyuncs.com/"
-	Upload_dir string = "static/images/"
+	Imghost          string = "http://hongze.oss-cn-shanghai.aliyuncs.com/"
+	Upload_dir       string = "static/images/"
 	Upload_Audio_Dir string = "static/audio/"
 
 	AccessKeyId     string = "LTAIFMZYQhS2BTvW"
 	AccessKeySecret string = "12kk1ptCHoGWedhBnKRVW5hRJzq9Fq"
 )
 
-
 //客户状态
 const (
-	COMPANY_STATUS_TRY_OUT       = "试用"
-	COMPANY_STATUS_FOREVER       = "永续"
-	COMPANY_STATUS_FREEZE        = "冻结"
-	COMPANY_STATUS_LOSE          = "流失"
-	COMPANY_STATUS_FORMAL        = "正式"
-)
+	COMPANY_STATUS_TRY_OUT   = "试用"
+	COMPANY_STATUS_FOREVER   = "永续"
+	COMPANY_STATUS_FREEZE    = "冻结"
+	COMPANY_STATUS_LOSE      = "流失"
+	COMPANY_STATUS_FORMAL    = "正式"
+	COMPANY_STATUS_POTENTIAL = "潜在"
+)