uplist_plus.go 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. package wxbroadcastv2
  2. import (
  3. "encoding/json"
  4. "fmt"
  5. "git.jiaxianghudong.com/webs/pkg/rds"
  6. "time"
  7. )
  8. type UpListConf struct {
  9. UpawardList []UpAward `json:"upaward_list" yaml:"upaward_list"`
  10. }
  11. type UpAward struct {
  12. Index int64 `json:"index" yaml:"index"`
  13. Number int64 `json:"number" yaml:"number"`
  14. Bean int64 `json:"bean" yaml:"bean"`
  15. IsTreasure int `json:"is_treasure" yaml:"is_treasure"`
  16. Rate []int `json:"-" yaml:"rate"`
  17. BeanList [][]int `json:"-" yaml:"bean_list"`
  18. Status int `json:"status" yaml:"status"`
  19. }
  20. type UpListAward struct {
  21. UserId int64 `json:"-"`
  22. Tm time.Time `json:"-"`
  23. Up map[int]bool `json:"up"`
  24. Receive map[int]bool `json:"receive"`
  25. }
  26. func (this *UpListAward) Store() error {
  27. marshal, _ := json.Marshal(this)
  28. err := rds.Redis.HSet(fmt.Sprintf(WXBROADCASTUP, this.Tm.Format("2006-01-02")), fmt.Sprintf("%v", this.UserId), string(marshal)).Err()
  29. rds.Redis.Expire(fmt.Sprintf(WXBROADCASTUP, this.Tm.Format("2006-01-02")), 25*time.Hour)
  30. return err
  31. }
  32. func (this *UpListAward) Load() error {
  33. val := rds.Redis.HGet(fmt.Sprintf(WXBROADCASTUP, this.Tm.Format("2006-01-02")), fmt.Sprintf("%v", this.UserId)).Val()
  34. if val != "" {
  35. json.Unmarshal([]byte(val), this)
  36. }
  37. if this.Up == nil {
  38. this.Up = make(map[int]bool)
  39. }
  40. if this.Receive == nil {
  41. this.Receive = make(map[int]bool)
  42. }
  43. return nil
  44. }