Commit 8b63b8f3 authored by hujiebin's avatar hujiebin

feat:试下

parent ef4b6018
......@@ -124,8 +124,10 @@ type MicUser struct {
I int
//麦中的人
ExternalId string
//
//用户id
UserId uint64
//用户cpId
CpUserId uint64
//静音 true:静音,false:没有静音
Forbid bool
//上麦的的时间戳
......@@ -189,7 +191,8 @@ const micInScript = "local flag = redis.call('EXISTS', '{prefixGroupUserMic}') i
//上麦(自己),
//规则:1:加锁了不能上麦 2:麦上有人,不能上麦
func (mic *Mic) In(userId uint64, externalId string) error {
//cpUserId如果有
func (mic *Mic) In(userId uint64, externalId string, cpUserId uint64) error {
// 群是否被封禁, 呃,,,呃,,,呃,,,
banned := GroupBanned{ImGroupId: mic.GroupUuid}
if err := banned.Get(mic.model); err != gorm.ErrRecordNotFound {
......@@ -214,33 +217,13 @@ func (mic *Mic) In(userId uint64, externalId string) error {
I: mic.I,
ExternalId: externalId,
UserId: userId,
CpUserId: cpUserId,
Forbid: false,
Timestamp: time.Now().Unix(),
})
if err != nil {
return err
}
//让自己踢出去。
/* if str, err := redisCli.GetRedis().Get(context.Background(), redis_key.GetPrefixGroupUserInMic(externalId)).Result(); err != nil {
if err != redis2.Nil {
return myerr.WrapErr(err)
}
} else {
if userInMic, err := strToUserInMic(str); err != nil {
return err
} else {
if micUser, err := GetMicUser(mic.model, userInMic.GroupUuid, userInMic.I); err != nil {
return err
} else {
if micUser != nil {
if err := micUser.LeaveByUser(userId, externalId); err != nil {
return err
}
}
}
}
}*/
//加入到麦上可能有人的集合中。
groupMicHasIn(mic.model, mic.GroupUuid, userId)
......@@ -250,12 +233,15 @@ func (mic *Mic) In(userId uint64, externalId string) error {
if err != nil {
return err
}
//r, err := redis2.NewScript(micInScript).Run(context.Background(), redisCli.GetRedis(), []string{redis.GetPrefixGroupMicUser(mic.groupUuid), strconv.Itoa(mic.i), redis.GetPrefixGroupUserMic(), externalId}, micUserStr, groupUserStr).Result()
script := strings.Replace(strings.Replace(
strings.Replace(
strings.Replace(
strings.Replace(micInScript, "{micExpire}", strconv.Itoa(expireMinute), -1), "{prefixGroupMicUser}", redis_key.GetPrefixGroupMicUser(mic.GroupUuid, mic.I), -1), "{micUserStr}", micUserStr, -1), "{prefixGroupUserMic}", redis_key.GetPrefixGroupUserInMic(externalId), -1), "{groupUserStr}", groupUserStr, -1)
//redisCli.GetRedis().ScriptFlush(context.Background())
strings.Replace(micInScript,
"{micExpire}", strconv.Itoa(expireMinute), -1),
"{prefixGroupMicUser}", redis_key.GetPrefixGroupMicUser(mic.GroupUuid, mic.I), -1),
"{micUserStr}", micUserStr, -1),
"{prefixGroupUserMic}", redis_key.GetPrefixGroupUserInMic(externalId), -1),
"{groupUserStr}", groupUserStr, -1)
r, err := redis2.NewScript(script).Run(context.Background(), redisCli.GetRedis(), []string{}).Result()
mic.model.Log.Infof("micUser In micInScript:%v, result:%v", script, r)
d := r.(int64)
......
......@@ -42,6 +42,13 @@ type MicContent struct {
Timestamp int64 `json:"timestamp"`
//用户
User *MicUserData `json:"user"`
//cp特效
CpEffect *CpEffect `json:"cpEffect"`
}
type CpEffect struct {
Svga string `json:"svga"`
CpAvatar string `json:"cpAvatar"`
}
type MicUserData struct {
......
......@@ -6,12 +6,14 @@ import (
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/rpc"
uuid "github.com/satori/go.uuid"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key"
"hilo-group/domain/event/group_ev"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/signal_s"
"hilo-group/myerr"
"hilo-group/myerr/bizerr"
......@@ -124,14 +126,51 @@ func redisLock(key string, sign string, expiration time.Duration, callBack func(
//加入麦位,锁两秒
func (s *GroupMicService) GroupMicIn(groupUuid string, i int, userId uint64, externalId string) error {
return redisLock(redis_key.GetPrefixGroupMicUserInLock(userId), uuid.NewV4().String(), time.Second*2, func() error {
model := domain.CreateModelContext(s.svc.MyContext)
// 填充cp麦位
var cpUserId uint64
var cpI int
if cpRelation, _ := rpc.GetUserCpRelation(model, userId); cpRelation != nil {
micNumType, err := group_m.GetMicNumType(model, groupUuid)
if err != nil {
return err
}
_, micUsers, err := group_m.GetAllMic(groupUuid, micNumType)
if err != nil {
return err
}
for _, u := range micUsers {
if u.UserId == cpRelation.CpUserId {
cpUserId = u.UserId
cpI = u.I
break
}
}
}
err := redisLock(redis_key.GetPrefixGroupMicUserInLock(userId), uuid.NewV4().String(), time.Second*2, func() error {
model := domain.CreateModel(s.svc.CtxAndDb)
mic, err := group_m.GetMic(model, groupUuid, i)
if err != nil {
return err
}
return mic.In(userId, externalId)
return mic.In(userId, externalId, cpUserId)
})
if err != nil {
return err
}
// 更新麦上cp的信息
if cpUserId > 0 {
user, _ := user_m.GetUser(model, cpUserId)
return redisLock(redis_key.GetPrefixGroupMicUserInLock(cpUserId), uuid.NewV4().String(), time.Second*2, func() error {
model := domain.CreateModel(s.svc.CtxAndDb)
mic, err := group_m.GetMic(model, groupUuid, cpI)
if err != nil {
return err
}
return mic.In(cpUserId, user.ExternalId, userId)
})
}
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