model.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. package yb_community_question_audio
  2. import (
  3. "hongze/hongze_yb/global"
  4. )
  5. func (item *YbCommunityQuestionAudio) Create() (err error) {
  6. err = global.DEFAULT_MYSQL.Create(item).Error
  7. return
  8. }
  9. func GetListByQuestrionIds(idArr []int) (list []*YbCommunityQuestionAudio, err error) {
  10. if len(idArr) == 0 {
  11. return
  12. }
  13. err = global.DEFAULT_MYSQL.
  14. Model(YbCommunityQuestionAudio{}).
  15. Select("community_question_audio_id, community_question_id, audio_url, audio_play_seconds, audio_size, sort").
  16. Where("community_question_id IN ?", idArr).
  17. Order("community_question_id ASC, sort ASC").
  18. Scan(&list).Error
  19. return
  20. }
  21. func GetListByQuestionId(questionId int) (list []*YbCommunityQuestionAudio, err error) {
  22. err = global.DEFAULT_MYSQL.
  23. Model(YbCommunityQuestionAudio{}).
  24. Select("community_question_audio_id, community_question_id, audio_url, audio_play_seconds, audio_size, sort").
  25. Where("community_question_id = ?", questionId).
  26. Order("sort ASC").
  27. Scan(&list).Error
  28. return
  29. }
  30. // GetByAudioId 根据问答音频ID, 查询音频详情
  31. func GetByAudioId(audioId int)(item *YbCommunityQuestionAudio, err error) {
  32. err = global.DEFAULT_MYSQL.
  33. Model(YbCommunityQuestionAudio{}).
  34. Select("community_question_audio_id, community_question_id, audio_url, audio_play_seconds, audio_size, sort").
  35. Where("community_question_audio_id = ?", audioId).
  36. First(&item).Error
  37. return
  38. }