tiredness.go 1007 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package model
  2. import (
  3. "active/constant"
  4. "encoding/json"
  5. "fmt"
  6. "git.jiaxianghudong.com/go/logs"
  7. "git.jiaxianghudong.com/webs/pkg/rds"
  8. )
  9. //TiredNessData 累充数据
  10. type TiredNessData struct {
  11. Money int `json:"money"`
  12. Awards map[string]interface{} `json:"awards"`
  13. }
  14. //GetTiredNessData 获取累充用户存储数据
  15. func GetTiredNessData(UserID string, tm string) *TiredNessData {
  16. data := rds.Redis.HGet(fmt.Sprintf(constant.LCSHLDATA, tm), UserID).Val()
  17. tnd := new(TiredNessData)
  18. if data != "" {
  19. err := json.Unmarshal([]byte(data), &tnd)
  20. if err != nil {
  21. logs.Errorf("tiredness[%s] GetTiredNessData json err:%v", UserID, err)
  22. return tnd
  23. }
  24. }
  25. return tnd
  26. }
  27. //SetTiredNessData 设置用户存储
  28. func (t *TiredNessData) SetTiredNessData(UserID, tm string) bool {
  29. da, _ := json.Marshal(t)
  30. rds.Redis.Expire(fmt.Sprintf(constant.LCSHLDATA, tm), constant.LCSHLDATATIMEOUT)
  31. return rds.Redis.HSet(fmt.Sprintf(constant.LCSHLDATA, tm), UserID, string(da)).Val()
  32. }