sear_inter.go 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. package service
  2. import (
  3. "go-common/app/admin/main/tv/model"
  4. bm "go-common/library/net/http/blademaster"
  5. )
  6. const (
  7. _isDeleted = 1
  8. )
  9. //SetSearInterRank set search intervene rank
  10. func (s *Service) SetSearInterRank(c *bm.Context, rank []*model.OutSearchInter) (err error) {
  11. err = s.dao.SetSearchInterv(c, rank)
  12. return
  13. }
  14. //GetSearInterRank get search intervene rank
  15. func (s *Service) GetSearInterRank(c *bm.Context) (rank []*model.OutSearchInter, err error) {
  16. rank, err = s.dao.GetSearchInterv(c)
  17. return
  18. }
  19. //GetSearInterList get search intervene list
  20. func (s *Service) GetSearInterList(c *bm.Context, pn, ps int) (items []*model.SearInter, total int, err error) {
  21. //rank, err = s.dao.GetSearchInterv(c)
  22. //return
  23. start := (pn - 1) * ps
  24. db := s.DB.Where("deleted!=?", _isDeleted).Order("rank ASC")
  25. if err = db.Model(&model.SearInter{}).Offset(start).Limit(ps).Find(&items).Error; err != nil {
  26. return
  27. }
  28. s.DB.Model(&model.SearInter{}).Where("deleted!=?", _isDeleted).Count(&total)
  29. return
  30. }
  31. //GetSearInterCount get search intervene count
  32. func (s *Service) GetSearInterCount(c *bm.Context) (total int, err error) {
  33. if err = s.DB.Model(&model.SearInter{}).Where("deleted!=?", _isDeleted).Count(&total).Error; err != nil {
  34. return
  35. }
  36. return
  37. }
  38. //AddSearInter add search intervene
  39. func (s *Service) AddSearInter(c *bm.Context, si *model.SearInter) (err error) {
  40. if err = s.DB.Create(si).Error; err != nil {
  41. return
  42. }
  43. return
  44. }
  45. //UpdateSearInter update search intervene
  46. func (s *Service) UpdateSearInter(c *bm.Context, id int64, searchword string) (err error) {
  47. if err = s.DB.Model(&model.SearInter{}).Where("id=?", id).Update("searchword", searchword).Error; err != nil {
  48. return
  49. }
  50. return
  51. }
  52. //DelSearInter delete search intervene
  53. func (s *Service) DelSearInter(c *bm.Context, id int64) (err error) {
  54. if err = s.DB.Model(&model.SearInter{}).Where("id=?", id).Update("deleted", 1).Error; err != nil {
  55. return
  56. }
  57. return
  58. }
  59. //RankSearInter set search intervene new rank
  60. func (s *Service) RankSearInter(c *bm.Context, idsArr []string) (err error) {
  61. tx := s.DB.Begin()
  62. for k, v := range idsArr {
  63. newRank := k + 1
  64. id := v
  65. if errDB := s.DB.Model(&model.SearInter{}).Where("id=?", id).Update("rank", newRank).Error; errDB != nil {
  66. err = errDB
  67. tx.Rollback()
  68. return
  69. }
  70. }
  71. tx.Commit()
  72. return
  73. }
  74. //GetSearInterPublish get search intervene publish status
  75. func (s *Service) GetSearInterPublish(c *bm.Context) (items []*model.SearInter, err error) {
  76. limit := s.c.Cfg.SearInterMax
  77. db := s.DB.Where("deleted!=?", _isDeleted).Order("rank ASC")
  78. if err = db.Model(&model.SearInter{}).Limit(limit).Find(&items).Error; err != nil {
  79. return
  80. }
  81. return
  82. }
  83. //GetMaxRank get search intervene max rank
  84. func (s *Service) GetMaxRank(c *bm.Context) (items model.SearInter, err error) {
  85. db := s.DB.Where("deleted!=?", _isDeleted).Order("rank DESC")
  86. if err = db.Model(&model.SearInter{}).Limit(1).Find(&items).Error; err != nil {
  87. return
  88. }
  89. return
  90. }
  91. //SetPublishState set publish status
  92. func (s *Service) SetPublishState(c *bm.Context, state *model.PublishStatus) (err error) {
  93. err = s.dao.SetPublishCache(c, state)
  94. return
  95. }
  96. //GetPublishState get publish status
  97. func (s *Service) GetPublishState(c *bm.Context) (state *model.PublishStatus, err error) {
  98. state, err = s.dao.GetPublishCache(c)
  99. return
  100. }