activity_voice.go 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_clpt/utils"
  5. "time"
  6. )
  7. // ActivityVoice 活动语音表结构体
  8. type CygxActivityVoice struct {
  9. ActivityVoiceId int `orm:"column(activity_voice_id);pk" description:"活动音频ID"`
  10. ActivityId int ` description:"活动ID"`
  11. VoiceUrl string `description:"音频地址"`
  12. VoiceName string `description:"音频名称"`
  13. VoicePlaySeconds string `description:"音频时长"`
  14. VoiceCounts int `description:"播放量"`
  15. ModifyTime string `description:"更新时间"`
  16. CreateTime time.Time `description:"创建时间"`
  17. }
  18. // ActivityVoice 活动语音表结构体
  19. type CygxActivityVoiceResp struct {
  20. ActivityVoiceId int `orm:"column(activity_voice_id);pk" description:"活动音频ID"`
  21. ActivityId int ` description:"活动ID"`
  22. VoiceUrl string `description:"音频地址"`
  23. VoiceName string `description:"音频名称"`
  24. VoicePlaySeconds string `description:"音频时长"`
  25. VoiceCounts int `description:"播放量"`
  26. ModifyTime string `description:"更新时间"`
  27. CreateTime string `description:"创建时间"`
  28. ChartPermissionId int `description:"权限id"`
  29. ChartPermissionName string `description:"行业名称"`
  30. }
  31. // ActivityVoiceReq 音频数据
  32. type CygxActivityVoiceReq struct {
  33. ActivityId int ` description:"活动ID"`
  34. Url string `description:"音频资源url地址"`
  35. Name string `description:"音频名称"`
  36. PlaySeconds int `description:"音频时长"`
  37. Type int `description:"类型: 1-音频; 2-活动视频; 3-产业视频 、 4-系列问答视频"`
  38. }
  39. // GetCygxActivityVoiceReqList 获取活动ID的音频
  40. func GetCygxActivityVoiceReqList(activityIds []int) (items []*CygxActivityVoiceReq, err error) {
  41. lenactivityIds := len(activityIds)
  42. if lenactivityIds == 0 {
  43. return
  44. }
  45. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  46. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  47. sql := `SELECT
  48. v.activity_id,
  49. v.voice_url AS url,
  50. v.voice_name AS name,
  51. v.voice_play_seconds AS play_seconds
  52. FROM
  53. cygx_activity_voice AS v
  54. INNER JOIN cygx_activity AS a ON a.activity_id = v.activity_id
  55. WHERE
  56. 1 = 1 AND v.is_hide = 0 AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
  57. o := orm.NewOrm()
  58. _, err = o.Raw(sql, activityIds).QueryRows(&items)
  59. return
  60. }
  61. func UpdateCygxActivityVoiceCounts(activityId int) (err error) {
  62. sql := `UPDATE cygx_activity_voice SET voice_counts = voice_counts+1 WHERE activity_id = ? `
  63. o := orm.NewOrm()
  64. _, err = o.Raw(sql, activityId).Exec()
  65. return
  66. }
  67. // GetCygxActivityVoiceById 主键获取活动音频
  68. func GetCygxActivityVoiceById(videoId int) (item *CygxActivityVoice, err error) {
  69. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id = ? LIMIT 1`
  70. err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item)
  71. return
  72. }
  73. // 列表
  74. func GetActivityVoiceListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoListResp, err error) {
  75. o := orm.NewOrm()
  76. sql := `SELECT art.* FROM cygx_activity as art INNER JOIN cygx_activity_voice AS v ON v.activity_id = art.activity_id WHERE 1= 1 `
  77. if condition != "" {
  78. sql += condition
  79. }
  80. sql += ` LIMIT ?,?`
  81. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  82. return
  83. }
  84. // 列表
  85. func GetActivityVoiceList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVoiceResp, err error) {
  86. o := orm.NewOrm()
  87. sql := `SELECT
  88. v.*,art.chart_permission_id,art.chart_permission_name
  89. FROM
  90. cygx_activity_voice AS v
  91. INNER JOIN cygx_activity as art ON art.activity_id = v.activity_id WHERE 1= 1 `
  92. if condition != "" {
  93. sql += condition
  94. }
  95. sql += ` LIMIT ?,?`
  96. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  97. return
  98. }
  99. // GetCygxActivityVoiceByActivityId 主键获取活动音频
  100. func GetCygxActivityVoiceByActivityId(activityId int) (item *CygxActivityVoice, err error) {
  101. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id = ? LIMIT 1`
  102. err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
  103. return
  104. }
  105. // 获取所有活动音频ID
  106. func GetActivityVoiceActivityIds() (activityIds string, err error) {
  107. sql := `SELECT
  108. GROUP_CONCAT( DISTINCT a.activity_id SEPARATOR ',' ) AS activityids
  109. FROM
  110. cygx_activity_voice AS a WHERE is_hide = 0 `
  111. o := orm.NewOrm()
  112. err = o.Raw(sql).QueryRow(&activityIds)
  113. return
  114. }
  115. func UpdateActivityVoiceCommentNum(activityId int) (err error) {
  116. sql := `UPDATE cygx_activity_voice SET comment_num = comment_num+1 WHERE activity_id = ? `
  117. o := orm.NewOrm()
  118. _, err = o.Raw(sql, activityId).Exec()
  119. return
  120. }