activity_voice.go 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. ActivityVoiceId int ` description:"音频ID"`
  22. Url string `description:"音频资源url地址"`
  23. Name string `description:"音频名称"`
  24. PlaySeconds int `description:"音频时长"`
  25. }
  26. // GetCygxActivityVoiceReqList 获取活动ID的音频
  27. func GetCygxActivityVoiceReqList(activityIds []int) (items []*CygxActivityVoiceReq, err error) {
  28. lenactivityIds := len(activityIds)
  29. if lenactivityIds == 0 {
  30. return
  31. }
  32. //活动音频,设置有效时间为30天,失效后该活动就不再支持音频回放。有效期起始时间为活动的开始时间
  33. //endTime := time.Now().AddDate(0, 0, -30).Format("2006-01-02 15:04:05")
  34. sql := `SELECT
  35. v.activity_id,
  36. v.activity_voice_id,
  37. v.voice_url AS url,
  38. v.voice_name AS name,
  39. v.voice_play_seconds AS play_seconds
  40. FROM
  41. cygx_activity_voice AS v
  42. INNER JOIN cygx_activity AS a ON a.activity_id = v.activity_id
  43. WHERE
  44. 1 = 1 AND v.activity_id IN (` + utils.GetOrmInReplace(lenactivityIds) + `) `
  45. o := orm.NewOrm()
  46. _, err = o.Raw(sql, activityIds).QueryRows(&items)
  47. return
  48. }
  49. func UpdateCygxActivityVoiceCounts(activityId int) (err error) {
  50. sql := `UPDATE cygx_activity_voice SET voice_counts = voice_counts+1 WHERE activity_id = ? `
  51. o := orm.NewOrm()
  52. _, err = o.Raw(sql, activityId).Exec()
  53. return
  54. }
  55. // GetCygxActivityVoiceById 主键获取活动音频
  56. func GetCygxActivityVoiceById(videoId int) (item *CygxActivityVoice, err error) {
  57. sql := `SELECT * FROM cygx_activity_voice WHERE activity_voice_id = ? LIMIT 1`
  58. err = orm.NewOrm().Raw(sql, videoId).QueryRow(&item)
  59. return
  60. }
  61. //列表
  62. func GetActivityVoiceListAll(condition string, pars []interface{}, startSize, pageSize int) (items []*CygxActivityVideoListResp, err error) {
  63. o := orm.NewOrm()
  64. 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 `
  65. if condition != "" {
  66. sql += condition
  67. }
  68. sql += ` LIMIT ?,?`
  69. _, err = o.Raw(sql, pars, startSize, pageSize).QueryRows(&items)
  70. return
  71. }
  72. // GetCygxActivityVoiceByActivityId 主键获取活动音频
  73. func GetCygxActivityVoiceByActivityId(activityId int) (item *CygxActivityVoice, err error) {
  74. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id = ? LIMIT 1`
  75. err = orm.NewOrm().Raw(sql, activityId).QueryRow(&item)
  76. return
  77. }