community_video.go 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // CommunityVideo 视频社区
  7. type CommunityVideo struct {
  8. CommunityVideoId int `orm:"column(community_video_id);pk" description:"问题ID"`
  9. Title string `description:"视频标题"`
  10. VarietyTagId int `description:"标签ID"`
  11. VarietyTagName string `description:"标签名称"`
  12. CoverImgUrl string `description:"封面图地址"`
  13. VideoUrl string `description:"视频地址"`
  14. VideoSeconds string `description:"视频时长,单位秒"`
  15. PublishState int `description:"发布状态:0-待发布 1-已发布"`
  16. SendThsState int `description:"客群消息推送状态:0-待推送 1-已推送"`
  17. IsDeleted int `description:"是否已删除 0-否 1-是"`
  18. PublishTime time.Time `description:"发布时间"`
  19. SendThsTime time.Time `description:"推送客群时间"`
  20. CreateTime time.Time `description:"提问时间"`
  21. ModifyTime time.Time `description:"修改时间"`
  22. DeleteTime time.Time `description:"删除时间"`
  23. }
  24. func (item *CommunityVideo) TableName() string {
  25. return "yb_community_video"
  26. }
  27. func (item *CommunityVideo) Add() (lastId int64, err error) {
  28. o := orm.NewOrm()
  29. lastId, err = o.Insert(item)
  30. if err != nil {
  31. return
  32. }
  33. item.CommunityVideoId = int(lastId)
  34. return
  35. }
  36. func (item *CommunityVideo) Update(cols []string) (err error) {
  37. o := orm.NewOrm()
  38. _, err = o.Update(item, cols...)
  39. return
  40. }
  41. // GetVideoById 主键获取视频
  42. func GetVideoById(videoId int) (item *CommunityVideo, err error) {
  43. o := orm.NewOrm()
  44. sql := `SELECT * FROM yb_community_video WHERE community_video_id = ? AND is_deleted = 0 LIMIT 1`
  45. err = o.Raw(sql, videoId).QueryRow(&item)
  46. return
  47. }
  48. // GetCommunityVideoList 获取视频列表
  49. func GetCommunityVideoList(condition string, pars []interface{}, startSize, pageSize int) (total int, list []*CommunityVideo, err error) {
  50. o := orm.NewOrm()
  51. sql := `SELECT * FROM yb_community_video WHERE is_deleted = 0 `
  52. sql += condition
  53. sql += ` ORDER BY create_time DESC`
  54. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  55. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  56. return
  57. }
  58. sql += ` LIMIT ?,?`
  59. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  60. return
  61. }
  62. // DeleteVideo 删除视频
  63. func DeleteVideo(videoId int) (err error) {
  64. o := orm.NewOrm()
  65. sql := `UPDATE yb_community_video SET is_deleted = 1, delete_time = NOW() WHERE community_video_id = ? LIMIT 1`
  66. _, err = o.Raw(sql, videoId).Exec()
  67. return
  68. }