diff --git a/api/controller/System.go b/api/controller/System.go index 03a3566..5d77fdc 100644 --- a/api/controller/System.go +++ b/api/controller/System.go @@ -90,27 +90,23 @@ func (b *System) PutSystemTime(c *gin.Context) { return } - t, err := time.ParseInLocation("2006-01-02 15:04:05", req.StartTime, location) + startTime, err := time.ParseInLocation("2006-01-02 15:04:05", req.StartTime, location) if err != nil { responses.FailWithMessage("修改失败", c) return } - startTime := model.LocalTime(t) - - if &startTime != systemTime.StartTime { + if model.LocalTime(startTime) != *systemTime.StartTime { systemTimeData["start_time"] = req.StartTime } - t, err = time.ParseInLocation("2006-01-02 15:04:05", req.EndTime, location) + endTime, err := time.ParseInLocation("2006-01-02 15:04:05", req.EndTime, location) if err != nil { responses.FailWithMessage("修改失败", c) return } - endTime := model.LocalTime(t) - - if &endTime != systemTime.EndTime { + if model.LocalTime(endTime) != *systemTime.EndTime { systemTimeData["end_time"] = req.EndTime } @@ -130,6 +126,26 @@ func (b *System) PutSystemTime(c *gin.Context) { return } + // 增加过期时间缓存 + redisKey := "VoteSystemTime" + // 当前时间 + now := time.Now() + + duration := endTime.Sub(now) + if duration < 0 { + tx.Rollback() + responses.FailWithMessage("结束时间错误", c) + return + } + + // 添加缓存 + _, err = global.Redis.Set(c, redisKey, "1", duration).Result() + if err != nil { + tx.Rollback() + responses.FailWithMessage("修改失败", c) + return + } + tx.Commit() }