match_detail.go 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. package service
  2. import (
  3. "context"
  4. "go-common/app/admin/main/esports/model"
  5. "go-common/library/ecode"
  6. "go-common/library/log"
  7. )
  8. // AddDetail .
  9. func (s *Service) AddDetail(c context.Context, param *model.MatchDetail) (err error) {
  10. if err = s.dao.DB.Model(&model.MatchDetail{}).Create(param).Error; err != nil {
  11. log.Error("AddDetail MatchDetail db.Model Create error(%v)", err)
  12. }
  13. return
  14. }
  15. // EditDetail .
  16. func (s *Service) EditDetail(c context.Context, param *model.MatchDetail) (err error) {
  17. upFields := map[string]interface{}{"ma_id": param.MaID, "game_type": param.GameType, "stime": param.Stime,
  18. "etime": param.Etime, "game_stage": param.GameStage, "knockout_type": param.KnockoutType,
  19. "winner_type": param.WinnerType, "ScoreID": param.ScoreID, "status": param.Status, "online": param.Online}
  20. if err = s.dao.DB.Model(&model.MatchDetail{}).Where("id=?", param.ID).Update(upFields).Error; err != nil {
  21. log.Error("EditDetail MatchDetail db.Model Update error(%v)", err)
  22. }
  23. return
  24. }
  25. // ForbidDetail .
  26. func (s *Service) ForbidDetail(c context.Context, id int64, state int) (err error) {
  27. if err = s.dao.DB.Model(&model.MatchDetail{}).Where("id=?", id).Updates(map[string]interface{}{"status": state}).Error; err != nil {
  28. log.Error("ForbidDetail MatchDetail db.Model Updates(%d) error(%v)", id, err)
  29. }
  30. return
  31. }
  32. // UpOnline .
  33. func (s *Service) UpOnline(c context.Context, id int64, onLine int64) (err error) {
  34. if onLine == _online {
  35. var count int64
  36. treeDB := s.dao.DB.Model(&model.Tree{}).Where("mad_id=?", id).Where("is_deleted=0")
  37. if err = treeDB.Error; err != nil {
  38. log.Error("upOnline treeDB Error (%v)", err)
  39. return
  40. }
  41. treeDB.Count(&count)
  42. if count == 0 {
  43. err = ecode.EsportsTreeEmptyErr
  44. return
  45. }
  46. }
  47. if err = s.dao.DB.Model(&model.MatchDetail{}).Where("id=?", id).Updates(map[string]interface{}{"online": onLine}).Error; err != nil {
  48. log.Error("UpOnline s.dao.DB.Model Updates(%+v) error(%v)", id, err)
  49. }
  50. return
  51. }
  52. // ListDetail .
  53. func (s *Service) ListDetail(c context.Context, maID, pn, ps int64) (rs []*model.MatchDetail, count int64, err error) {
  54. db := s.dao.DB.Model(&model.MatchDetail{}).Offset((pn-1)*ps).Where("ma_id=?", maID).Order("id ASC").Limit(ps).Find(&rs)
  55. if err = db.Error; err != nil {
  56. log.Error("ListDetail MatchDetail db.Model Find error(%v)", err)
  57. }
  58. db.Count(&count)
  59. return
  60. }