community_video.go 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. package yb
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hz_crm_api/utils"
  5. "time"
  6. )
  7. // CommunityVideo 视频社区
  8. type CommunityVideo struct {
  9. CommunityVideoId int `orm:"column(community_video_id);pk" description:"问题ID"`
  10. Title string `description:"视频标题"`
  11. VarietyTagId int `description:"标签ID"`
  12. VarietyTagName string `description:"标签名称"`
  13. CoverImgUrl string `description:"封面图地址"`
  14. VideoUrl string `description:"视频地址"`
  15. VideoSeconds string `description:"视频时长,单位秒"`
  16. PublishState int `description:"发布状态:0-待发布 1-已发布"`
  17. SendThsState int `description:"客群消息推送状态:0-待推送 1-已推送"`
  18. SendTemplateState int `description:"模板消息推送状态:0-待推送 1-已推送"`
  19. IsDeleted int `description:"是否已删除 0-否 1-是"`
  20. PublishTime time.Time `description:"发布时间"`
  21. SendThsTime time.Time `description:"推送客群时间"`
  22. SendTemplateTime time.Time `description:"推送模板消息时间"`
  23. CreateTime time.Time `description:"提问时间"`
  24. ModifyTime time.Time `description:"修改时间"`
  25. DeleteTime time.Time `description:"删除时间"`
  26. }
  27. type CommunityVideoMore struct {
  28. CommunityVideo
  29. ClickNum int `description:"点击量"`
  30. }
  31. func (item *CommunityVideo) TableName() string {
  32. return "yb_community_video"
  33. }
  34. func (item *CommunityVideo) Add() (lastId int64, err error) {
  35. o := orm.NewOrm()
  36. lastId, err = o.Insert(item)
  37. if err != nil {
  38. return
  39. }
  40. item.CommunityVideoId = int(lastId)
  41. return
  42. }
  43. func (item *CommunityVideo) Update(cols []string) (err error) {
  44. o := orm.NewOrm()
  45. _, err = o.Update(item, cols...)
  46. return
  47. }
  48. // GetVideoById 主键获取视频
  49. func GetVideoById(videoId int) (item *CommunityVideo, err error) {
  50. o := orm.NewOrm()
  51. sql := `SELECT * FROM yb_community_video WHERE community_video_id = ? AND is_deleted = 0 LIMIT 1`
  52. err = o.Raw(sql, videoId).QueryRow(&item)
  53. return
  54. }
  55. // GetCommunityVideoList 获取视频列表
  56. func GetCommunityVideoList(condition string, pars []interface{}, order string, startSize, pageSize int) (total int, list []*CommunityVideoMore, err error) {
  57. o := orm.NewOrm()
  58. sql := `SELECT
  59. v.*,
  60. l.click_num
  61. FROM
  62. yb_community_video v
  63. LEFT JOIN ( SELECT count( * ) AS click_num, community_video_id FROM yb_community_video_play_log WHERE type=1 GROUP BY community_video_id ) AS l ON v.community_video_id = l.community_video_id
  64. WHERE
  65. v.is_deleted = 0 `
  66. sql += condition
  67. if order != "" {
  68. sql += order
  69. } else {
  70. sql += ` ORDER BY v.modify_time DESC`
  71. }
  72. totalSQl := `SELECT COUNT(1) total FROM (` + sql + `) z`
  73. if err = o.Raw(totalSQl, pars).QueryRow(&total); err != nil {
  74. return
  75. }
  76. sql += ` LIMIT ?,?`
  77. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&list)
  78. return
  79. }
  80. // DeleteVideo 删除视频
  81. func DeleteVideo(videoId int) (err error) {
  82. o := orm.NewOrm()
  83. sql := `UPDATE yb_community_video SET is_deleted = 1, delete_time = NOW() WHERE community_video_id = ? LIMIT 1`
  84. _, err = o.Raw(sql, videoId).Exec()
  85. return
  86. }
  87. // GetCommunityVideoListByIds 根据IDs获取视频列表
  88. func GetCommunityVideoListByIds(videoIds []int) (list []*CommunityVideo, err error) {
  89. arrLen := len(videoIds)
  90. if arrLen == 0 {
  91. return
  92. }
  93. o := orm.NewOrm()
  94. sql := `SELECT * FROM yb_community_video WHERE community_video_id IN (` + utils.GetOrmInReplace(arrLen) + `) AND is_deleted = 0`
  95. _, err = o.Raw(sql, videoIds).QueryRows(&list)
  96. return
  97. }