activity_voice.go 1.9 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. sql := `SELECT
  32. activity_id ,
  33. voice_url AS url,
  34. voice_name AS name,
  35. voice_play_seconds AS play_seconds FROM cygx_activity_voice WHERE activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
  36. o := orm.NewOrm()
  37. _, err = o.Raw(sql, activityIds).QueryRows(&items)
  38. return
  39. }
  40. func UpdateCygxActivityVoiceCounts(activityId int) (err error) {
  41. sql := `UPDATE cygx_activity_voice SET voice_counts = voice_counts+1 WHERE activity_id = ? `
  42. o := orm.NewOrm()
  43. _, err = o.Raw(sql, activityId).Exec()
  44. return
  45. }
  46. // GetCygxActivityVoiceById 主键获取活动音频
  47. func GetCygxActivityVoiceById(videoId int) (item *CygxActivityVoice, err error) {
  48. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id = ? LIMIT 1`
  49. err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item)
  50. return
  51. }