12
This commit is contained in:
parent
e96621f774
commit
8042b10afe
@ -52,12 +52,9 @@ func (r *SystemTimeService) CheckVoteValidStatus() bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// CheckVoteValidStatus 检测投票有效期
|
||||
// bool true:未结束 false:已结束
|
||||
// CheckVoteValidStartStatus 检测投票有效期
|
||||
// bool true:已开始 false:未开始
|
||||
func (r *SystemTimeService) CheckVoteValidStartStatus() bool {
|
||||
redisKey := "VoteSystemTime"
|
||||
res, _ := global.Redis.Get(context.Background(), redisKey).Result()
|
||||
if res == "" {
|
||||
// 获取配置-时间
|
||||
systemTimeDao := dao.SystemTimeDao{}
|
||||
systemTime, err := systemTimeDao.GetSystemTimeById(1)
|
||||
@ -69,27 +66,16 @@ func (r *SystemTimeService) CheckVoteValidStartStatus() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
// 结束时间
|
||||
// 开始时间
|
||||
startTime := time.Time(*systemTime.StartTime)
|
||||
|
||||
// 当前时间
|
||||
now := time.Now()
|
||||
|
||||
duration := startTime.Sub(now)
|
||||
if duration > 0 {
|
||||
return false
|
||||
}
|
||||
|
||||
if duration > 5*time.Minute {
|
||||
duration = 5 * time.Minute
|
||||
}
|
||||
|
||||
// 添加缓存
|
||||
_, err = global.Redis.Set(context.Background(), redisKey, "1", duration).Result()
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// 如果当前时间在开始时间之后(或等于),说明已开始
|
||||
if !now.Before(startTime) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user