activity_voice.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. package models
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "hongze/hongze_cygx/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. ActivityTime string `description:"活动时间"`
  31. }
  32. // ActivityVoiceReq 音频数据
  33. type CygxActivityVoiceReq struct {
  34. ActivityId int ` description:"活动ID"`
  35. ActivityVoiceId int ` description:"音频ID"`
  36. Url string `description:"音频资源url地址"`
  37. Name string `description:"音频名称"`
  38. PlaySeconds int `description:"音频时长"`
  39. }
  40. // GetCygxActivityVoiceReqList 获取活动ID的音频
  41. func GetCygxActivityVoiceReqList(activityIds []int) (items []*CygxActivityVoiceReq, err error) {
  42. lenactivityIds := len(activityIds)
  43. if lenactivityIds == 0 {
  44. return
  45. }
  46. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  47. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  48. sql := `SELECT
  49. v.activity_id,
  50. v.activity_voice_id,
  51. v.voice_url AS url,
  52. v.voice_name AS name,
  53. v.voice_play_seconds AS play_seconds
  54. FROM
  55. cygx_activity_voice AS v
  56. INNER JOIN cygx_activity AS a ON a.activity_id = v.activity_id
  57. WHERE
  58. 1 = 1 AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
  59. o := orm.NewOrm()
  60. _, err = o.Raw(sql, activityIds).QueryRows(&items)
  61. return
  62. }
  63. func UpdateCygxActivityVoiceCounts(activityId int) (err error) {
  64. sql := `UPDATE cygx_activity_voice SET voice_counts = voice_counts+1 WHERE activity_id = ? `
  65. o := orm.NewOrm()
  66. _, err = o.Raw(sql, activityId).Exec()
  67. return
  68. }
  69. // GetCygxActivityVoiceById 主键获取活动音频
  70. func GetCygxActivityVoiceById(videoId int) (item *CygxActivityVoice, err error) {
  71. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id = ? LIMIT 1`
  72. err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item)
  73. return
  74. }
  75. // 列表
  76. func GetActivityVoiceListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoListResp, err error) {
  77. o := orm.NewOrm()
  78. 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 `
  79. if condition != "" {
  80. sql += condition
  81. }
  82. sql += ` LIMIT ?,?`
  83. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  84. return
  85. }
  86. // GetCygxActivityVoiceByActivityId 主键获取活动音频
  87. func GetCygxActivityVoiceByActivityId(activityId int) (item *CygxActivityVoice, err error) {
  88. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id = ? LIMIT 1`
  89. err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
  90. return
  91. }
  92. // 列表
  93. func GetActivityVoiceList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVoiceResp, err error) {
  94. o := orm.NewOrm()
  95. sql := `SELECT
  96. v.*,art.chart_permission_id,art.activity_time
  97. FROM
  98. cygx_activity_voice AS v
  99. INNER JOIN cygx_activity as art ON art.activity_id = v.activity_id WHERE 1= 1 `
  100. if condition != "" {
  101. sql += condition
  102. }
  103. sql += ` LIMIT ?,?`
  104. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  105. return
  106. }
  107. // 获取所有活动音频ID
  108. func GetActivityVoiceActivityIds() (activityIds string, err error) {
  109. sql := `SELECT
  110. GROUP_CONCAT( DISTINCT a.activity_id SEPARATOR ',' ) AS activityids
  111. FROM
  112. cygx_activity_voice AS a `
  113. o := orm.NewOrm()
  114. err = o.Raw(sql).QueryRow(&activityIds)
  115. return
  116. }