This commit is contained in:
haomingming 2025-12-24 17:58:08 +08:00
parent e96621f774
commit 8042b10afe

View File

@ -52,44 +52,30 @@ func (r *SystemTimeService) CheckVoteValidStatus() bool {
return true return true
} }
// CheckVoteValidStatus 检测投票有效期 // CheckVoteValidStartStatus 检测投票有效期
// bool true:未结束 false:已结束 // bool true:已开始 false:未开始
func (r *SystemTimeService) CheckVoteValidStartStatus() bool { func (r *SystemTimeService) CheckVoteValidStartStatus() bool {
redisKey := "VoteSystemTime" // 获取配置-时间
res, _ := global.Redis.Get(context.Background(), redisKey).Result() systemTimeDao := dao.SystemTimeDao{}
if res == "" { systemTime, err := systemTimeDao.GetSystemTimeById(1)
// 获取配置-时间 if err != nil {
systemTimeDao := dao.SystemTimeDao{} return false
systemTime, err := systemTimeDao.GetSystemTimeById(1)
if err != nil {
return false
}
if systemTime.StartTime == nil {
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
}
} }
return true if systemTime.StartTime == nil {
return false
}
// 开始时间
startTime := time.Time(*systemTime.StartTime)
// 当前时间
now := time.Now()
// 如果当前时间在开始时间之后(或等于),说明已开始
if !now.Before(startTime) {
return true
}
return false
} }