activity_video.go 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "github.com/rdlucklib/rdluck_tools/paging"
  5. )
  6. type CygxActivityVideo struct {
  7. VideoId int `orm:"column(video_id);pk"description:"视频id"`
  8. VideoName string `description:"视频名称"`
  9. ActivityId int ` description:"活动ID"`
  10. ModifyDate string `description:"更新时间"`
  11. VideoDuration string `description:"视频时长"`
  12. VideoCounts int `description:"播放量"`
  13. VideoUrl string `description:"视频地址"`
  14. CreateTime string `description:"创建时间"`
  15. BackgroundImg string `description:"封面图片"`
  16. ShareImg string `description:"分享图片"`
  17. }
  18. type CygxActivityVideoResp struct {
  19. VideoId int `orm:"column(video_id);pk"description:"视频id"`
  20. ChartPermissionId int `description:"权限id"`
  21. VideoName string `description:"视频名称"`
  22. ActivityId int ` description:"活动ID"`
  23. ModifyDate string `description:"更新时间"`
  24. VideoDuration string `description:"视频时长"`
  25. VideoCounts int `description:"播放量"`
  26. VideoUrl string `description:"视频地址"`
  27. CreateTime string `description:"创建时间"`
  28. BackgroundImg string `description:"封面图片"`
  29. ShareImg string `description:"分享图片"`
  30. }
  31. type CygxActivityVideoReq struct {
  32. VideoName string `description:"视频名称"`
  33. VideoDuration string `description:"视频时长"`
  34. VideoUrl string `description:"视频地址"`
  35. ActivityId int ` description:"活动ID"`
  36. }
  37. // string `orm:"column(label)";description:"主题"`
  38. // 活动详情
  39. type CygxActivityVideoListResp struct {
  40. ActivityId int `description:"活动ID 等于0新增活动,大于0修改活动"`
  41. Id int `orm:"column(video_id)";description:"视频id"`
  42. Title string `orm:"column(video_name)";description:"视频名称"`
  43. ResourceUrl string `orm:"column(video_url)";description:"视频地址"`
  44. VideoDuration string `description:"视频时长"`
  45. ActivityTime string `description:"活动时间"`
  46. }
  47. type CygxActivityVideoListRep struct {
  48. Paging *paging.PagingItem `description:"分页数据"`
  49. List []*CygxActivityVideoListResp
  50. }
  51. // 列表
  52. func GetActivityVideoListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoListResp, err error) {
  53. o := orm.NewOrm()
  54. sql := `SELECT art.*,v.video_id,v.video_name,v.video_url,video_duration FROM cygx_activity as art INNER JOIN cygx_activity_video AS v ON v.activity_id = art.activity_id WHERE 1= 1 AND v.is_hide = 0 `
  55. if condition != "" {
  56. sql += condition
  57. }
  58. sql += ` LIMIT ?,?`
  59. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  60. return
  61. }
  62. func UpdateActivityVideoCounts(activityId int) (err error) {
  63. sql := `UPDATE cygx_activity_video SET video_counts = video_counts+1 WHERE activity_id = ? `
  64. o := orm.NewOrm()
  65. _, err = o.Raw(sql, activityId).Exec()
  66. return
  67. }
  68. // GetCygxActivityVideoByActivityId 获取活动视频
  69. func GetCygxActivityVideoByActivityId(activityId int) (item *CygxActivityVideo, err error) {
  70. sql := `SELECT * FROM cygx_activity_video WHERE activity_id = ? LIMIT 1 `
  71. err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
  72. return
  73. }
  74. // 获取数量
  75. func GetCygxActivityVideoCount(activityId int) (count int, err error) {
  76. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_video WHERE activity_id = ? `
  77. o := orm.NewOrm()
  78. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  79. return
  80. }
  81. // GetCygxActivityVideoReqByActivityId 获取活动视频
  82. func GetCygxActivityVideoReqByActivityId(activityId int) (item *CygxActivityVideoReq, err error) {
  83. sql := `SELECT * FROM cygx_activity_video WHERE video_id = ? LIMIT 1 `
  84. err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
  85. return
  86. }
  87. // GetCygxActivityVideoById 获取活动视频
  88. func GetCygxActivityVideoById(videoId int) (item *CygxActivityVideo, err error) {
  89. sql := `SELECT * FROM cygx_activity_video WHERE video_id = ? LIMIT 1 `
  90. err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item)
  91. return
  92. }
  93. // 列表
  94. func GetActivityVideoList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoResp, err error) {
  95. o := orm.NewOrm()
  96. sql := `SELECT
  97. v.*,art.chart_permission_id
  98. FROM
  99. cygx_activity_video AS v
  100. INNER JOIN cygx_activity as art ON art.activity_id = v.activity_id WHERE 1= 1 `
  101. if condition != "" {
  102. sql += condition
  103. }
  104. sql += ` LIMIT ?,?`
  105. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  106. return
  107. }
  108. // 获取所有活动视频ID
  109. func GetActivityVideoActivityIds() (activityIds string, err error) {
  110. sql := `SELECT
  111. GROUP_CONCAT( DISTINCT a.activity_id SEPARATOR ',' ) AS activityids
  112. FROM
  113. cygx_activity_video AS a WHERE is_hide = 0 `
  114. o := orm.NewOrm()
  115. err = o.Raw(sql).QueryRow(&activityIds)
  116. return
  117. }
  118. type CygxActivityVideoDetailResp struct {
  119. ActivityId int ` description:"活动ID"`
  120. Id int `description:"视频ID"`
  121. Title string `description:"标题"`
  122. ResourceUrl string `description:"链接"`
  123. BackgroundImg string `description:"背景图"`
  124. PlaySeconds int `description:"音视频时长"`
  125. ChartPermissionId int `description:"行业ID"`
  126. ChartPermissionName string `description:"行业名称"`
  127. Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频 、 4-系列问答视频"`
  128. }
  129. // GetCygxActivityVideoById 获取活动视频
  130. func GetCygxActivityVideoByActivityIdInfo(activityId int) (item *CygxActivityVideoDetailResp, err error) {
  131. sql := `SELECT
  132. v.video_id AS id,
  133. v.video_name AS title,
  134. v.video_url AS resource_url,
  135. v.video_duration AS play_seconds,
  136. v.activity_id,
  137. a.chart_permission_id,
  138. a.chart_permission_name
  139. FROM
  140. cygx_activity_video AS v
  141. INNER JOIN cygx_activity AS a ON v.activity_id = a.activity_id
  142. WHERE
  143. v.activity_id = ?
  144. LIMIT 1 `
  145. err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
  146. return
  147. }
  148. func UpdateActivityVideoCommentNum(activityId int) (err error) {
  149. sql := `UPDATE cygx_activity_video SET comment_num = comment_num+1 WHERE activity_id = ? `
  150. o := orm.NewOrm()
  151. _, err = o.Raw(sql, activityId).Exec()
  152. return
  153. }
  154. // 修改
  155. func UpdateCygxActivityVideo(item *CygxActivityVideo) (err error) {
  156. to := orm.NewOrm()
  157. updateParams := make(map[string]interface{})
  158. updateParams["BackgroundImg"] = item.BackgroundImg
  159. updateParams["ShareImg"] = item.ShareImg
  160. ptrStructOrTableName := "cygx_activity_video"
  161. whereParam := map[string]interface{}{"activity_id": item.ActivityId}
  162. qs := to.QueryTable(ptrStructOrTableName)
  163. for expr, exprV := range whereParam {
  164. qs = qs.Filter(expr, exprV)
  165. }
  166. _, err = qs.Update(updateParams)
  167. return
  168. }