12345678910111213141516171819202122232425262728293031323334353637 |
- package orchard
- import (
- "active/constant"
- "fmt"
- "git.jiaxianghudong.com/webs/pkg/rds"
- "log"
- "strconv"
- "time"
- )
- type OrchardWatered struct {
- Number int `json:"number"`
- }
- var OrchardTime = ""
- func (this *OrchardWatered) GetData(tm string, userID string) {
- data := rds.Redis.HGet(fmt.Sprintf(constant.ORCHARWATERDAY, tm), userID).Val()
- if data != "" {
- this.Number, _ = strconv.Atoi(data)
- } else {
- this.Number = int(OrchardConf.WashList[3].WaterTimes)
- }
- }
- func (this *OrchardWatered) SetData(tm string, userID string) bool {
- rds.Redis.HSet(fmt.Sprintf(constant.ORCHARWATERDAY, tm), userID, this.Number)
- if OrchardTime == "" || OrchardTime != tm {
- end, _ := time.Parse("2006-01-02", tm)
- expireAt := end.Add(constant.ADVERTISETIMEOUT)
- log.Printf("---更新施肥数据过期时间: expireAt:%v \n", expireAt)
- rds.Redis.ExpireAt(fmt.Sprintf(constant.ORCHARWATERDAY, tm), expireAt)
- OrchardTime = tm
- }
- return true
- }
|