group_power_grade.go 1.39 KB
Newer Older
hujiebin's avatar
hujiebin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
package groupPower_c

import (
	"encoding/json"
	"git.hilo.cn/hilo-common/domain"
	"git.hilo.cn/hilo-common/resource/mysql"
	"hilo-group/_const/redis_key/groupPower_k"
	"time"
)

type GroupPowerGradeExp struct {
	GroupPowerId mysql.ID
	Exp          mysql.Num
	UserId       mysql.ID
	Remark       string
16
	Ts           int64
hujiebin's avatar
hujiebin committed
17 18 19 20 21 22 23 24 25 26
}

// redis队列缓冲GroupPowerGradeExp升级内容
func QueueGroupPowerGradeExp(model *domain.Model, groupPowerId mysql.ID, exp mysql.Num, userId mysql.ID, remark string) error {
	queue := groupPower_k.GetGroupPowerGradeExpQueue()
	data := GroupPowerGradeExp{
		GroupPowerId: groupPowerId,
		Exp:          exp,
		UserId:       userId,
		Remark:       remark,
27
		Ts:           time.Now().Unix(),
hujiebin's avatar
hujiebin committed
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
	}
	body, _ := json.Marshal(data)
	return model.Redis.RPush(model, queue, string(body)).Err()
}

// redis弹出GroupPowerGradeExp升级内容
func BLPopGroupPowerGradeExp(model *domain.Model) *GroupPowerGradeExp {
	var res *GroupPowerGradeExp
	queue := groupPower_k.GetGroupPowerGradeExpQueue()
	strs, err := model.Redis.BLPop(model, time.Second, queue).Result()
	if err != nil {
		model.Log.Errorf("BLPopGroupPowerGradeExp fail:%v", err)
		return nil
	}
	if len(strs) >= 2 {
		content := strs[1]
		res = new(GroupPowerGradeExp)
		if err := json.Unmarshal([]byte(content), res); err != nil {
			model.Log.Errorf("BLPopGroupPowerGradeExp json fail:%v", err)
			return nil
		}
		return res
	}
	return nil
}