code.go 809 B

123456789101112131415161718192021222324252627282930313233343536
  1. package goldbrick
  2. import (
  3. "active/constant"
  4. "fmt"
  5. "git.jiaxianghudong.com/webs/pkg/rds"
  6. "log"
  7. "strconv"
  8. "time"
  9. )
  10. var recordTime = ""
  11. func GetGoldData(userId string, tm string) int {
  12. data := rds.Redis.HGet(fmt.Sprintf(constant.GoldBrick, tm), userId).Val()
  13. if data == "" {
  14. return 0
  15. } else {
  16. number, err := strconv.Atoi(data)
  17. if err != nil {
  18. return 0
  19. }
  20. return number
  21. }
  22. }
  23. func SetGoldData(userId string, tm string, data int) bool {
  24. rds.Redis.HSet(fmt.Sprintf(constant.GoldBrick, tm), userId, fmt.Sprintf("%v", data))
  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.GoldBrick, tm), expireAt)
  29. recordTime = tm
  30. return true
  31. }