package model import ( "active/constant" "encoding/json" "fmt" "time" "git.jiaxianghudong.com/go/logs" "git.jiaxianghudong.com/webs/pkg/rds" ) //UserDrawData 用户抽奖数据 type UserDrawData struct { Special int `yaml:"special" json:"special"` // 1小王 2大王 3 双王 Indexs []int `yaml:"indexs" json:"indexs"` //位置集合 PropInfo []OpenCardsInfo `yaml:"propinfo" json:"propinfo"` } //OpenCardsInfo 翻牌结果 type OpenCardsInfo struct { Index int `json:"index"` PropID int `json:"propid"` //道具ID Num int `json:"num"` //数量 Special int `json:"special"` // 特殊 1 小王 2 大王 Status int `json:"status"` //0 剩余没翻开 1 翻开 } //RollData 轮播数据 type RollData struct { NickName string `json:"nickname"` UserID uint32 `json:"userid"` PropID int `json:"propid"` Num int `json:"num"` //数量 Special int `json:"special"` // 特殊 1 小王 2 大王 3 s双王 Time string `json:"time"` } //GetUserDrawData 获取用户翻牌数据 func GetUserDrawData(UserID string) *UserDrawData { data := rds.Redis.HGet(fmt.Sprintf(constant.DrawUserData, time.Now().Format("20060102")), UserID).Val() ud := &UserDrawData{} if data != "" { err := json.Unmarshal([]byte(data), &ud) if err != nil { logs.Errorf("draw[%s] GetUserDrawData json err:%v", UserID, err) return ud } } return ud } //SetUserDrawData 设置用户存储 func (t *UserDrawData) SetUserDrawData(UserID string) error { da, _ := json.Marshal(t) rds.Redis.HSet(fmt.Sprintf(constant.DrawUserData, time.Now().Format("20060102")), UserID, string(da)) rds.Redis.Expire(fmt.Sprintf(constant.DrawUserData, time.Now().Format("20060102")), constant.ExpireAtTime) return nil } //GetRollData 获取轮播数据 func GetRollData() []*RollData { rdm := []*RollData{} data := rds.Redis.Get(constant.DrawROLL).Val() if data != "" { err := json.Unmarshal([]byte(data), &rdm) if err != nil { logs.Errorf("rolldata get json err:%v", err) return rdm } } return rdm } //AddRollData 添加滚动数据 func AddRollData(rd *RollData) { rdm := GetRollData() if len(rdm) < 50 { rdm = append(rdm, rd) } else { rdm = append(rdm, rd) rdm = rdm[len(rdm)-50:] } data, err := json.Marshal(rdm) if err != nil { logs.Errorf("rolldata add json err:%v", err) } rds.Redis.Set(constant.DrawROLL, string(data), 0) }