添加开始时间

This commit is contained in:
haomingming 2025-12-24 17:49:06 +08:00
parent 69d661c8ea
commit e96621f774
2 changed files with 49 additions and 0 deletions

View File

@ -295,6 +295,13 @@ func (r *Video) AddVideoVote(c *gin.Context) {
// 检测投票有效期
systemTimeService := service.SystemTimeService{}
isStartValid := systemTimeService.CheckVoteValidStartStatus()
if isStartValid == false {
responses.FailWithMessage("投票未开始", c)
return
}
// 检测投票有效期
isValid := systemTimeService.CheckVoteValidStatus()
if isValid == false {
responses.FailWithMessage("投票已结束", c)

View File

@ -51,3 +51,45 @@ func (r *SystemTimeService) CheckVoteValidStatus() bool {
return true
}
// CheckVoteValidStatus 检测投票有效期
// 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)
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
}