package model

import (
	"active/constant"
	"encoding/json"
	"fmt"

	"git.jiaxianghudong.com/go/logs"
	"git.jiaxianghudong.com/webs/pkg/rds"
)

//TiredNessData 累充数据
type TiredNessData struct {
	Money  int                    `json:"money"`
	Awards map[string]interface{} `json:"awards"`
}

//GetTiredNessData 获取累充用户存储数据
func GetTiredNessData(UserID string, tm string) *TiredNessData {

	data := rds.Redis.HGet(fmt.Sprintf(constant.LCSHLDATA, tm), UserID).Val()
	tnd := new(TiredNessData)
	if data != "" {
		err := json.Unmarshal([]byte(data), &tnd)
		if err != nil {
			logs.Errorf("tiredness[%s] GetTiredNessData json err:%v", UserID, err)
			return tnd
		}
	}

	return tnd
}

//SetTiredNessData 设置用户存储
func (t *TiredNessData) SetTiredNessData(UserID, tm string) bool {
	da, _ := json.Marshal(t)

	rds.Redis.Expire(fmt.Sprintf(constant.LCSHLDATA, tm), constant.LCSHLDATATIMEOUT)
	return rds.Redis.HSet(fmt.Sprintf(constant.LCSHLDATA, tm), UserID, string(da)).Val()
}
