video.go 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package models
  2. import (
  3. "rdluck_tools/orm"
  4. "rdluck_tools/paging"
  5. "time"
  6. )
  7. type VideoTagsItems struct {
  8. TagsId int `description:"标签id"`
  9. TagsName string `description:"标签名称"`
  10. }
  11. type VideoTagsListResp struct {
  12. List []*VideoTagsItems
  13. }
  14. func GetVideoTagsList() (items []*VideoTagsItems, err error) {
  15. o := orm.NewOrm()
  16. o.Using("rddp")
  17. sql := `SELECT * FROM tags WHERE tags_type=1 ORDER BY sort ASC `
  18. _, err = o.Raw(sql).QueryRows(&items)
  19. return
  20. }
  21. type VideoList struct {
  22. VideoId int `description:"视频id"`
  23. Title string `description:"视频标题"`
  24. VideoUrl string `description:"视频地址"`
  25. VideoCoverUrl string `description:"视频封面地址"`
  26. Status int `description:"视频状态:0:未发布,1:已发布"`
  27. PublishTime time.Time `description:"视频发布时间"`
  28. PlaySeconds uint32 `description:"视频播放时长"`
  29. CreateTime time.Time `description:"视频创建时间"`
  30. ModifyTime time.Time `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 `
  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. if condition != "" {
  59. sql += condition
  60. }
  61. sql += ` GROUP BY a.video_id ORDER BY a.modify_time DESC LIMIT ?,? `
  62. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  63. return
  64. }
  65. type VideoListResp struct {
  66. Paging *paging.PagingItem
  67. List []*VideoList
  68. Status int `description:"权限状态:0:有权限,1:无权限"`
  69. }