go-common/app/interface/main/account/service/vip/associate_limit.go
2019-04-22 18:49:16 +08:00

66 lines
1.5 KiB
Go

package vip
import (
"time"
"go-common/library/ecode"
"go-common/library/log"
)
// ActivityTimeLimit activity time limit.
func (s *Service) ActivityTimeLimit(mid int64) error {
if len(s.c.Vipproperty.AssociateWhiteMidMap) > 0 && mid != 0 {
for _, v := range s.c.Vipproperty.AssociateWhiteMidMap {
if v == mid {
return nil
}
}
}
now := time.Now().Unix()
if s.c.Vipproperty.ActStartTime > now {
return ecode.VipActivityNotStart
}
if s.c.Vipproperty.ActEndTime < now {
return ecode.VipActivityHadEnd
}
return nil
}
// ActivityWhiteIPLimit act ip limit.
func (s *Service) ActivityWhiteIPLimit(appkey string, ip string) error {
var (
whiteips []string
ok bool
)
if whiteips, ok = s.c.Vipproperty.AssociateWhiteIPMap[appkey]; !ok {
log.Error("act ip limit appkey(%s) ip(%s)", appkey, ip)
return ecode.VipWhiteIPListErr
}
for _, v := range whiteips {
if v == ip {
return nil
}
}
log.Error("act ip limit appkey(%s) ip(%s)", appkey, ip)
return ecode.VipWhiteIPListErr
}
// ActivityWhiteOutOpenIDLimit act out open id limit.
func (s *Service) ActivityWhiteOutOpenIDLimit(openid string) error {
if len(s.c.Vipproperty.AssociateWhiteOutOpenIDMap) > 0 && openid != "" {
for _, v := range s.c.Vipproperty.AssociateWhiteOutOpenIDMap {
if v == openid {
return nil
}
}
}
now := time.Now().Unix()
if s.c.Vipproperty.ActStartTime > now {
return ecode.VipActivityNotStart
}
if s.c.Vipproperty.ActEndTime < now {
return ecode.VipActivityHadEnd
}
return nil
}