activity_voice.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. // ActivityVoiceReq 音频数据
  19. type CygxActivityVoiceReq struct {
  20. ActivityId int ` description:"活动ID"`
  21. Url string `description:"音频资源url地址"`
  22. Name string `description:"音频名称"`
  23. PlaySeconds int `description:"音频时长"`
  24. }
  25. // GetCygxActivityVoiceReqList 获取活动ID的音频
  26. func GetCygxActivityVoiceReqList(activityIds []int) (items []*CygxActivityVoiceReq, err error) {
  27. lenactivityIds := len(activityIds)
  28. if lenactivityIds == 0 {
  29. return
  30. }
  31. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  32. endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  33. sql := `SELECT
  34. v.activity_id,
  35. v.voice_url AS url,
  36. v.voice_name AS name,
  37. v.voice_play_seconds AS play_seconds
  38. FROM
  39. cygx_activity_voice AS v
  40. INNER JOIN cygx_activity AS a ON a.activity_id = v.activity_id
  41. WHERE
  42. 1 = 1 AND a.activity_time > ? AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
  43. o := orm.NewOrm()
  44. _, err = o.Raw(sql, endTime, activityIds).QueryRows(&items)
  45. return
  46. }
  47. func UpdateCygxActivityVoiceCounts(activityId int) (err error) {
  48. sql := `UPDATE cygx_activity_voice SET voice_counts = voice_counts+1 WHERE activity_id = ? `
  49. o := orm.NewOrm()
  50. _, err = o.Raw(sql, activityId).Exec()
  51. return
  52. }