activity_voice.go 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. package cygx
  2. import (
  3. "github.com/beego/beego/v2/client/orm"
  4. "time"
  5. )
  6. // ActivityVoice 活动语音表结构体
  7. type CygxActivityVoice struct {
  8. ActivityVoiceId int `orm:"column(activity_voice_id);pk" description:"活动音频ID"`
  9. ActivityId int ` description:"活动ID"`
  10. VoiceUrl string `description:"音频地址"`
  11. VoiceName string `description:"音频名称"`
  12. VoicePlaySeconds string `description:"音频时长"`
  13. BackgroundImg string `description:"封面图片"`
  14. ShareImg string `description:"分享图片"`
  15. CreateTime time.Time `description:"创建时间"`
  16. }
  17. // ActivityVoiceReq 音频数据
  18. type CygxActivityVoiceReq struct {
  19. Url string `description:"音频资源url地址"`
  20. Name string `description:"音频名称"`
  21. PlaySeconds string `description:"音频时长"`
  22. ActivityVoiceId int `description:"活动音频ID"`
  23. BackgroundImg string `description:"封面图片"`
  24. ShareImg string `description:"分享图片"`
  25. }
  26. // 添加
  27. func AddCygxActivityVoice(item *CygxActivityVoice) (newId int64, err error) {
  28. o := orm.NewOrmUsingDB("hz_cygx")
  29. newId, err = o.Insert(item)
  30. return
  31. }
  32. // 修改
  33. func UpdateCygxActivityVoice(item *CygxActivityVoice) (err error) {
  34. to := orm.NewOrmUsingDB("hz_cygx")
  35. updateParams := make(map[string]interface{})
  36. updateParams["VoiceName"] = item.VoiceName
  37. updateParams["VoicePlaySeconds"] = item.VoicePlaySeconds
  38. updateParams["VoiceUrl"] = item.VoiceUrl
  39. updateParams["BackgroundImg"] = item.BackgroundImg
  40. updateParams["ShareImg"] = item.ShareImg
  41. ptrStructOrTableName := "cygx_activity_voice"
  42. whereParam := map[string]interface{}{"activity_id": item.ActivityId}
  43. qs := to.QueryTable(ptrStructOrTableName)
  44. for expr, exprV := range whereParam {
  45. qs = qs.Filter(expr, exprV)
  46. }
  47. _, err = qs.Update(updateParams)
  48. return
  49. }
  50. // 获取数量
  51. func GetCygxActivityVoiceCount(condition string, pars []interface{}) (count int, err error) {
  52. sqlCount := ` SELECT COUNT(1) AS count FROM cygx_activity_voice WHERE 1= 1 `
  53. if condition != "" {
  54. sqlCount += condition
  55. }
  56. o := orm.NewOrmUsingDB("hz_cygx")
  57. err = o.Raw(sqlCount, pars).QueryRow(&count)
  58. return
  59. }
  60. // 列表
  61. func GetCygxActivityVoiceReqList(activityId int) (items []*CygxActivityVoiceReq, err error) {
  62. o := orm.NewOrmUsingDB("hz_cygx")
  63. sql := `SELECT
  64. background_img,
  65. share_img,
  66. activity_voice_id,
  67. voice_url AS url,
  68. voice_name AS name,
  69. voice_play_seconds AS play_seconds FROM cygx_activity_voice WHERE activity_id= ? `
  70. _, err = o.Raw(sql, activityId).QueryRows(&items)
  71. return
  72. }
  73. // 列表
  74. func GetActivityVoiceList(condition string, pars []interface{}) (items []*CygxActivityVoice, err error) {
  75. o := orm.NewOrmUsingDB("hz_cygx")
  76. sql := ` SELECT * FROM cygx_activity_voice WHERE 1=1 `
  77. if condition != "" {
  78. sql += condition
  79. }
  80. _, err = o.Raw(sql, pars).QueryRows(&items)
  81. return
  82. }
  83. func GetCygxActivityVoiceReqDetail(activityId int) (item *CygxActivityVoice, err error) {
  84. o := orm.NewOrmUsingDB("hz_cygx")
  85. sql := `SELECT * FROM cygx_activity_voice WHERE activity_id= ? `
  86. err = o.Raw(sql, activityId).QueryRow(&item)
  87. return
  88. }
  89. // 删除数据
  90. func DeleteCygxActivityVoice(activityId int) (err error) {
  91. o := orm.NewOrmUsingDB("hz_cygx")
  92. sql := ` DELETE FROM cygx_activity_voice WHERE activity_id= ? `
  93. _, err = o.Raw(sql, activityId).Exec()
  94. return
  95. }