channel_tab.go 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. package show
  2. import (
  3. "time"
  4. "go-common/app/admin/main/feed/model/common"
  5. "go-common/app/admin/main/feed/model/show"
  6. "go-common/library/log"
  7. )
  8. // ChannelTabAdd add channel tab
  9. func (d *Dao) ChannelTabAdd(param *show.ChannelTabAP) (err error) {
  10. if err = d.DB.Create(param).Error; err != nil {
  11. log.Error("dao.show.ChannelTabAdd error(%v)", err)
  12. return
  13. }
  14. return
  15. }
  16. // ChannelTabUpdate update channel tab
  17. func (d *Dao) ChannelTabUpdate(param *show.ChannelTabUP) (err error) {
  18. if err = d.DB.Model(&show.ChannelTabUP{}).Update(param).Error; err != nil {
  19. log.Error("dao.show.ChannelTabUpdate error(%v)", err)
  20. return
  21. }
  22. return
  23. }
  24. // ChannelTabDelete delete channel tab
  25. func (d *Dao) ChannelTabDelete(id int64) (err error) {
  26. up := map[string]interface{}{
  27. "is_delete": common.Deleted,
  28. }
  29. if err = d.DB.Model(&show.ChannelTab{}).Where("id = ?", id).Update(up).Error; err != nil {
  30. log.Error("dao.show.ChannelTabDelete error(%v)", err)
  31. return
  32. }
  33. return
  34. }
  35. // ChannelTabOffline offline channel tab
  36. func (d *Dao) ChannelTabOffline(id int64) (err error) {
  37. up := map[string]interface{}{
  38. "etime": time.Now().Unix(),
  39. }
  40. if err = d.DB.Model(&show.ChannelTab{}).Where("id = ?", id).Update(up).Error; err != nil {
  41. log.Error("dao.show.ChannelTabOffline error(%v)", err)
  42. return
  43. }
  44. return
  45. }
  46. // ChannelTabValid conflict check
  47. func (d *Dao) ChannelTabValid(id, tagID, sTime int64, eTime int64, priority int) (count int, err error) {
  48. w := map[string]interface{}{
  49. "is_delete": common.NotDeleted,
  50. "tag_id": tagID,
  51. }
  52. if priority != 0 {
  53. w["priority"] = priority
  54. }
  55. query := d.DB.Model(&show.ChannelTab{}).Where("stime < ?", eTime).Where("etime > ?", sTime)
  56. if id != 0 {
  57. query = query.Where("id != ?", id)
  58. }
  59. if err = query.Where(w).Count(&count).Error; err != nil {
  60. log.Error("dao.show.ChannelTabValid error(%v)", err)
  61. return
  62. }
  63. return
  64. }