watered.go 942 B

12345678910111213141516171819202122232425262728293031323334353637
  1. package orchard
  2. import (
  3. "active/constant"
  4. "fmt"
  5. "git.jiaxianghudong.com/webs/pkg/rds"
  6. "log"
  7. "strconv"
  8. "time"
  9. )
  10. type OrchardWatered struct {
  11. Number int `json:"number"`
  12. }
  13. var OrchardTime = ""
  14. func (this *OrchardWatered) GetData(tm string, userID string) {
  15. data := rds.Redis.HGet(fmt.Sprintf(constant.ORCHARWATERDAY, tm), userID).Val()
  16. if data != "" {
  17. this.Number, _ = strconv.Atoi(data)
  18. } else {
  19. this.Number = int(OrchardConf.WashList[3].WaterTimes)
  20. }
  21. }
  22. func (this *OrchardWatered) SetData(tm string, userID string) bool {
  23. rds.Redis.HSet(fmt.Sprintf(constant.ORCHARWATERDAY, tm), userID, this.Number)
  24. if OrchardTime == "" || OrchardTime != tm {
  25. end, _ := time.Parse("2006-01-02", tm)
  26. expireAt := end.Add(constant.ADVERTISETIMEOUT)
  27. log.Printf("---更新施肥数据过期时间: expireAt:%v \n", expireAt)
  28. rds.Redis.ExpireAt(fmt.Sprintf(constant.ORCHARWATERDAY, tm), expireAt)
  29. OrchardTime = tm
  30. }
  31. return true
  32. }