Commit 65c74be0 authored by hujiebin's avatar hujiebin

Merge branch 'feature/family-redis' into 'master'

Feature/family redis

See merge request !55
parents 9f9f87a3 b0a190e7
package groupPower_k
// groupPower等级
const (
GroupPowerGradeExpQueue = "group_power_grade_exp_queue"
)
func GetGroupPowerGradeExpQueue() string {
return GroupPowerGradeExpQueue
}
......@@ -16,5 +16,6 @@ func Init() {
mic_cron.OnMicCheck() // 检查上麦
group_cron.GroupPowerExpClear() // 清理家族经验/等级
group_cron.GroupPowerMonthRankAct()
group_cron.GroupInEventInit() // 进房事件
group_cron.GroupInEventInit() // 进房事件
group_cron.GroupPowerGradeExp() // 家族升级
}
package group_cron
import (
"git.hilo.cn/hilo-common/domain"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/model/groupPower_m"
)
func GroupPowerGradeExp() {
go func() {
for true {
model := domain.CreateModelNil()
if data := groupPower_c.BLPopGroupPowerGradeExp(model); data != nil {
if err := model.Transaction(func(model *domain.Model) error {
return groupPower_m.IncrGroupPowerExp(model, data.GroupPowerId, data.Exp, data.UserId, data.Remark)
}); err != nil {
model.Log.Errorf("IncrGroupPowerExp fail,data:%v-err:%v", data, err)
} else {
model.Log.Infof("IncrGroupPowerExp success,data:%v", data)
}
}
}
}()
}
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
}
// 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,
}
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
}
......@@ -8,6 +8,7 @@ import (
"gorm.io/gorm"
"gorm.io/gorm/clause"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/event/group_power_ev"
"time"
)
......@@ -230,7 +231,8 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID,
return err
}
// 每10分钟增加100点经验
if err := IncrGroupPowerExp(model, groupPowerId, 100, userId, "上麦10分钟"); err != nil {
//if err := IncrGroupPowerExp(model, groupPowerId, 100, userId, "上麦10分钟"); err != nil {
if err := groupPower_c.QueueGroupPowerGradeExp(model, groupPowerId, 100, userId, "上麦10分钟"); err != nil {
return err
}
}
......
......@@ -10,6 +10,7 @@ import (
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/_const/enum/task_e"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/cache/group_c"
"hilo-group/domain/event/gift_ev"
"hilo-group/domain/event/group_ev"
......@@ -488,9 +489,10 @@ func SendGift() {
}
if exist {
exp := sendGiftEvent.GiftN * mysql.Num(len(sendGiftEvent.ReceiveUserIds)) * sendGiftEvent.ResGift.DiamondNum
return model.Transaction(func(model *domain.Model) error {
return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp, sendGiftEvent.SendUserId, "送礼")
})
//return model.Transaction(func(model *domain.Model) error {
// return groupPower_m.IncrGroupPowerExp(model, groupPowerId, exp, sendGiftEvent.SendUserId, "送礼")
//})
return groupPower_c.QueueGroupPowerGradeExp(model, groupPowerId, exp, sendGiftEvent.SendUserId, "送礼")
}
return nil
})
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment