activity_voice.go 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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. }
  31. // ActivityVoiceReq 音频数据
  32. type CygxActivityVoiceReq struct {
  33. ActivityId int ` description:"活动ID"`
  34. ActivityVoiceId int ` description:"音频ID"`
  35. Url string `description:"音频资源url地址"`
  36. Name string `description:"音频名称"`
  37. PlaySeconds int `description:"音频时长"`
  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.activity_voice_id,
  50. v.voice_url AS url,
  51. v.voice_name AS name,
  52. v.voice_play_seconds AS play_seconds
  53. FROM
  54. cygx_activity_voice AS v
  55. INNER JOIN cygx_activity AS a ON a.activity_id = v.activity_id
  56. WHERE
  57. 1 = 1 AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
  58. o := orm.NewOrm()
  59. _, err = o.Raw(sql, activityIds).QueryRows(&items)
  60. return
  61. }
  62. func UpdateCygxActivityVoiceCounts(activityId int) (err error) {
  63. sql := `UPDATE cygx_activity_voice SET voice_counts = voice_counts+1 WHERE activity_id = ? `
  64. o := orm.NewOrm()
  65. _, err = o.Raw(sql, activityId).Exec()
  66. return
  67. }
  68. // GetCygxActivityVoiceById 主键获取活动音频
  69. func GetCygxActivityVoiceById(videoId int) (item *CygxActivityVoice, err error) {
  70. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id = ? LIMIT 1`
  71. err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item)
  72. return
  73. }
  74. //列表
  75. func GetActivityVoiceListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoListResp, err error) {
  76. o := orm.NewOrm()
  77. 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 `
  78. if condition != "" {
  79. sql += condition
  80. }
  81. sql += ` LIMIT ?,?`
  82. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  83. return
  84. }
  85. // GetCygxActivityVoiceByActivityId 主键获取活动音频
  86. func GetCygxActivityVoiceByActivityId(activityId int) (item *CygxActivityVoice, err error) {
  87. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id = ? LIMIT 1`
  88. err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
  89. return
  90. }
  91. //列表
  92. func GetActivityVoiceList(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVoiceResp, err error) {
  93. o := orm.NewOrm()
  94. sql := `SELECT
  95. v.*,art.chart_permission_id
  96. FROM
  97. cygx_activity_voice AS v
  98. INNER JOIN cygx_activity as art ON art.activity_id = v.activity_id WHERE 1= 1 `
  99. if condition != "" {
  100. sql += condition
  101. }
  102. sql += ` LIMIT ?,?`
  103. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  104. return
  105. }