activity_voice.go 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_mfyx/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. BackgroundImg string `description:"封面图片"`
  18. ShareImg string `description:"分享图片"`
  19. }
  20. // ActivityVoice 活动语音表结构体
  21. type CygxActivityVoiceResp struct {
  22. ActivityVoiceId int `orm:"column(activity_voice_id);pk" description:"活动音频ID"`
  23. ActivityId int ` description:"活动ID"`
  24. VoiceUrl string `description:"音频地址"`
  25. VoiceName string `description:"音频名称"`
  26. VoicePlaySeconds string `description:"音频时长"`
  27. VoiceCounts int `description:"播放量"`
  28. ModifyTime string `description:"更新时间"`
  29. CreateTime string `description:"创建时间"`
  30. ChartPermissionId int `description:"权限id"`
  31. ChartPermissionName string `description:"行业名称"`
  32. ActivityTime string `description:"活动时间"`
  33. BackgroundImg string `description:"封面图片"`
  34. ShareImg string `description:"分享图片"`
  35. }
  36. // ActivityVoiceReq 音频数据
  37. type CygxActivityVoiceReq struct {
  38. ActivityId int ` description:"活动ID"`
  39. ActivityVoiceId int ` description:"音频ID"`
  40. Url string `description:"音频资源url地址"`
  41. Name string `description:"音频名称"`
  42. PlaySeconds int `description:"音频时长"`
  43. }
  44. // GetCygxActivityVoiceReqList 获取活动ID的音频
  45. func GetCygxActivityVoiceReqList(activityIds []int) (items []*CygxActivityVoiceReq, err error) {
  46. lenactivityIds := len(activityIds)
  47. if lenactivityIds == 0 {
  48. return
  49. }
  50. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  51. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  52. sql := `SELECT
  53. v.activity_id,
  54. v.activity_voice_id,
  55. v.voice_url AS url,
  56. v.voice_name AS name,
  57. v.voice_play_seconds AS play_seconds
  58. FROM
  59. cygx_activity_voice AS v
  60. INNER JOIN cygx_activity AS a ON a.activity_id = v.activity_id
  61. WHERE
  62. 1 = 1 AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
  63. o := orm.NewOrm()
  64. _, err = o.Raw(sql, activityIds).QueryRows(&items)
  65. return
  66. }
  67. func UpdateCygxActivityVoiceCounts(activityId int) (err error) {
  68. sql := `UPDATE cygx_activity_voice SET voice_counts = voice_counts+1 WHERE activity_id = ? `
  69. o := orm.NewOrm()
  70. _, err = o.Raw(sql, activityId).Exec()
  71. return
  72. }
  73. // GetCygxActivityVoiceById 主键获取活动音频
  74. func GetCygxActivityVoiceById(videoId int) (item *CygxActivityVoice, err error) {
  75. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id = ? LIMIT 1`
  76. err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item)
  77. return
  78. }
  79. // 获取数量
  80. func GetCygxActivityVoiceCount(activityId int) (count int, err error) {
  81. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_voice WHERE activity_id = ? `
  82. o := orm.NewOrm()
  83. err = o.Raw(sqlCount, activityId).QueryRow(&count)
  84. return
  85. }
  86. // 列表
  87. func GetActivityVoiceListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoListResp, err error) {
  88. o := orm.NewOrm()
  89. 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 `
  90. if condition != "" {
  91. sql += condition
  92. }
  93. sql += ` LIMIT ?,?`
  94. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  95. return
  96. }
  97. // GetCygxActivityVoiceByActivityId 主键获取活动音频
  98. func GetCygxActivityVoiceByActivityId(activityId int) (item *CygxActivityVoice, err error) {
  99. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id = ? LIMIT 1`
  100. err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
  101. return
  102. }
  103. // 列表
  104. func GetActivityVoiceList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVoiceResp, err error) {
  105. o := orm.NewOrm()
  106. sql := `SELECT
  107. v.*,art.chart_permission_id,art.activity_time
  108. FROM
  109. cygx_activity_voice AS v
  110. INNER JOIN cygx_activity as art ON art.activity_id = v.activity_id WHERE 1= 1 `
  111. if condition != "" {
  112. sql += condition
  113. }
  114. sql += ` LIMIT ?,?`
  115. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  116. return
  117. }
  118. // 获取所有活动音频ID
  119. func GetActivityVoiceActivityIds() (activityIds string, err error) {
  120. sql := `SELECT
  121. GROUP_CONCAT( DISTINCT a.activity_id SEPARATOR ',' ) AS activityids
  122. FROM
  123. cygx_activity_voice AS a `
  124. o := orm.NewOrm()
  125. err = o.Raw(sql).QueryRow(&activityIds)
  126. return
  127. }
  128. func UpdateActivityVoiceCommentNum(activityId int) (err error) {
  129. sql := `UPDATE cygx_activity_voice SET comment_num = comment_num+1 WHERE activity_id = ? `
  130. o := orm.NewOrm()
  131. _, err = o.Raw(sql, activityId).Exec()
  132. return
  133. }
  134. // 修改
  135. func UpdateCygxActivityVoice(item *CygxActivityVoice) (err error) {
  136. to := orm.NewOrm()
  137. updateParams := make(map[string]interface{})
  138. updateParams["BackgroundImg"] = item.BackgroundImg
  139. updateParams["ShareImg"] = item.ShareImg
  140. ptrStructOrTableName := "cygx_activity_voice"
  141. whereParam := map[string]interface{}{"activity_id": item.ActivityId}
  142. qs := to.QueryTable(ptrStructOrTableName)
  143. for expr, exprV := range whereParam {
  144. qs = qs.Filter(expr, exprV)
  145. }
  146. _, err = qs.Update(updateParams)
  147. return
  148. }