activity_voice.go 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
  43. o := orm.NewOrm()
  44. _, err = o.Raw(sql, 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. }
  53. // GetCygxActivityVoiceById 主键获取活动音频
  54. func GetCygxActivityVoiceById(videoId int) (item *CygxActivityVoice, err error) {
  55. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id = ? LIMIT 1`
  56. err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item)
  57. return
  58. }
  59. //列表
  60. func GetActivityVoiceListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoListResp, err error) {
  61. o := orm.NewOrm()
  62. 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 `
  63. if condition != "" {
  64. sql += condition
  65. }
  66. sql += ` LIMIT ?,?`
  67. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  68. return
  69. }