activity_voice.go 4.4 KB

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