|
@@ -8,6 +8,7 @@ import (
|
|
|
"github.com/spf13/cast"
|
|
|
"strconv"
|
|
|
"strings"
|
|
|
+ "time"
|
|
|
)
|
|
|
|
|
|
// HostService 接口定义
|
|
@@ -18,6 +19,8 @@ type HostService interface {
|
|
|
GetTcpLimitConfig(ctx context.Context, hostId int) (v1.TcpLimitRequest, error)
|
|
|
GetUdpLimitConfig(ctx context.Context, hostId int) (v1.UdpLimitRequest, error)
|
|
|
GetWebLimitConfig(ctx context.Context, hostId int) (v1.WebLimitRequest, error)
|
|
|
+ // 检查是否过期 到期false 未到期true
|
|
|
+ CheckExpired(ctx context.Context, uid int64, hostId int64) (bool, error)
|
|
|
}
|
|
|
|
|
|
func NewHostService(
|
|
@@ -299,3 +302,25 @@ func (s *hostService) GetWebLimitConfig(ctx context.Context, hostId int) (v1.Web
|
|
|
|
|
|
return data, nil
|
|
|
}
|
|
|
+
|
|
|
+// 检查是否过期 到期false 未到期true
|
|
|
+func (s *hostService) CheckExpired(ctx context.Context, uid int64, hostId int64) (bool, error) {
|
|
|
+ var expireTime string
|
|
|
+ expireTime, err := s.hostRepository.GetExpireTime(ctx, uid, hostId)
|
|
|
+ if err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+ if expireTime == "" {
|
|
|
+ return true, nil
|
|
|
+ }
|
|
|
+ unixTime, err := strconv.ParseInt(expireTime, 10, 64)
|
|
|
+ if err != nil {
|
|
|
+ return false, err
|
|
|
+ }
|
|
|
+ now := time.Now().Unix() // 当前时间戳(秒级)
|
|
|
+ if now > unixTime {
|
|
|
+ return false, nil
|
|
|
+ }
|
|
|
+
|
|
|
+ return true, nil
|
|
|
+}
|