access.go 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. package view
  2. import (
  3. "context"
  4. "go-common/app/interface/main/tv/dao/account"
  5. "go-common/app/service/main/archive/model/archive"
  6. "go-common/library/ecode"
  7. "go-common/library/log"
  8. )
  9. // checkAceess check user Aceess
  10. func (s *Service) checkAceess(c context.Context, mid, aid int64, state, access int, ak, ip string) (err error) {
  11. if state >= 0 && access == 0 {
  12. return
  13. }
  14. if state < 0 {
  15. if state == archive.StateForbidFixed {
  16. log.Warn("archive(%d) is fixed", aid)
  17. } else if state == archive.StateForbidUpDelete {
  18. log.Warn("archive(%d) is deleted", aid)
  19. } else {
  20. log.Warn("mid(%d) have not access view not pass archive(%d) ", mid, aid)
  21. }
  22. err = ecode.NothingFound
  23. return
  24. }
  25. if mid == 0 {
  26. log.Warn("not login can not view(%d) state(%d) access(%d) mid(%d)", aid, state, access, mid)
  27. err = ecode.AccessDenied
  28. s.prom.Incr("no_login_access")
  29. return
  30. }
  31. card, err := s.accDao.Card3(c, mid)
  32. if err != nil {
  33. log.Warn("s.accDao.Info failed can not view(%d) state(%d) access(%d)", aid, state, access)
  34. s.prom.Incr("err_login_access")
  35. return
  36. }
  37. if access > 0 && int(card.Rank) < access && !account.IsVip(card) {
  38. err = ecode.AccessDenied
  39. log.Warn("mid(%d) rank(%d) vip(tp:%d,status:%d) have not access(%d) view archive(%d) ", mid, card.Rank, card.Vip.Type, card.Vip.Status, access, aid)
  40. s.prom.Incr("login_access")
  41. }
  42. return
  43. }