video.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "time"
  5. )
  6. type VideoTagsItems struct {
  7. TagsId int `description:"标签id"`
  8. TagsName string `description:"标签名称"`
  9. }
  10. type VideoTagsListResp struct {
  11. List []*VideoTagsItems
  12. }
  13. func GetVideoTagsList() (items []*VideoTagsItems, err error) {
  14. o := orm.NewOrm()
  15. o.Using("rddp")
  16. sql := `SELECT * FROM tags WHERE tags_type=1 ORDER BY sort ASC `
  17. _, err = o.Raw(sql).QueryRows(&items)
  18. return
  19. }
  20. type VideoList struct {
  21. VideoId int `description:"视频id"`
  22. Title string `description:"视频标题"`
  23. VideoUrl string `description:"视频地址"`
  24. VideoCoverUrl string `description:"视频封面地址"`
  25. Status int `description:"视频状态:0:未发布,1:已发布"`
  26. PublishTime string `description:"视频发布时间"`
  27. PlaySeconds uint32 `description:"视频播放时长"`
  28. CreateTime time.Time `description:"视频创建时间"`
  29. ModifyTime time.Time `description:"视频修改时间"`
  30. TagsName string `description:"标签名称"`
  31. }
  32. func GetVideoIdByKeyWord(tagName string) (video_id string, err error) {
  33. o := orm.NewOrm()
  34. o.Using("rddp")
  35. sql := ` SELECT GROUP_CONCAT(DISTINCT a.video_id) AS video_id FROM video_tags AS a
  36. INNER JOIN tags AS b ON a.tags_id=b.tags_id
  37. WHERE b.tags_name=? `
  38. err = o.Raw(sql, tagName).QueryRow(&video_id)
  39. return
  40. }
  41. func GetVideoListCount(condition string, pars []interface{}) (count int, err error) {
  42. o := orm.NewOrm()
  43. o.Using("rddp")
  44. sql := `SELECT COUNT(DISTINCT a.video_id) AS count
  45. FROM video AS a WHERE 1=1 `
  46. if condition != "" {
  47. sql += condition
  48. }
  49. err = o.Raw(sql, pars).QueryRow(&count)
  50. return
  51. }
  52. func GetVideoList(condition string, pars []interface{}, startSize, pageSize int) (items []*VideoList, err error) {
  53. o := orm.NewOrm()
  54. o.Using("rddp")
  55. sql := `SELECT a.*,GROUP_CONCAT(c.tags_name SEPARATOR '/') AS tags_name FROM video AS a
  56. INNER JOIN video_tags AS b ON a.video_id=b.video_id
  57. INNER JOIN tags AS c ON b.tags_id=c.tags_id
  58. WHERE 1=1 AND status=1 `
  59. if condition != "" {
  60. sql += condition
  61. }
  62. sql += ` GROUP BY a.video_id ORDER BY a.modify_time DESC LIMIT ?,? `
  63. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  64. return
  65. }
  66. type VideoListResp struct {
  67. List []*VideoList
  68. Status int `description:"权限状态:0:有权限,1:无权限"`
  69. }