添加开始时间
This commit is contained in:
parent
69d661c8ea
commit
e96621f774
@ -295,6 +295,13 @@ func (r *Video) AddVideoVote(c *gin.Context) {
|
|||||||
|
|
||||||
// 检测投票有效期
|
// 检测投票有效期
|
||||||
systemTimeService := service.SystemTimeService{}
|
systemTimeService := service.SystemTimeService{}
|
||||||
|
isStartValid := systemTimeService.CheckVoteValidStartStatus()
|
||||||
|
if isStartValid == false {
|
||||||
|
responses.FailWithMessage("投票未开始", c)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// 检测投票有效期
|
||||||
isValid := systemTimeService.CheckVoteValidStatus()
|
isValid := systemTimeService.CheckVoteValidStatus()
|
||||||
if isValid == false {
|
if isValid == false {
|
||||||
responses.FailWithMessage("投票已结束", c)
|
responses.FailWithMessage("投票已结束", c)
|
||||||
|
|||||||
@ -51,3 +51,45 @@ func (r *SystemTimeService) CheckVoteValidStatus() bool {
|
|||||||
|
|
||||||
return true
|
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
|
||||||
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user