Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
5dc1ce3a
Commit
5dc1ce3a
authored
Jun 09, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
check cp 麦位置
parent
c0aa4097
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
57 additions
and
41 deletions
+57
-41
mic.go
domain/model/group_m/mic.go
+1
-2
group_mic.go
domain/service/group_mic_s/group_mic.go
+54
-39
group_mic.go
route/group_r/group_mic.go
+2
-0
No files found.
domain/model/group_m/mic.go
View file @
5dc1ce3a
...
...
@@ -193,7 +193,7 @@ const micUpdateScript = "local flag = redis.call('EXISTS', '{prefixGroupUserMic}
//上麦(自己),
//规则:1:加锁了不能上麦 2:麦上有人,不能上麦
//cpUserId如果有
func
(
mic
*
Mic
)
In
(
userId
uint64
,
externalId
string
,
cpUserId
uint64
)
error
{
func
(
mic
*
Mic
)
In
(
userId
uint64
,
externalId
string
)
error
{
// 群是否被封禁, 呃,,,呃,,,呃,,,
banned
:=
GroupBanned
{
ImGroupId
:
mic
.
GroupUuid
}
if
err
:=
banned
.
Get
(
mic
.
model
);
err
!=
gorm
.
ErrRecordNotFound
{
...
...
@@ -218,7 +218,6 @@ func (mic *Mic) In(userId uint64, externalId string, cpUserId uint64) error {
I
:
mic
.
I
,
ExternalId
:
externalId
,
UserId
:
userId
,
CpUserId
:
cpUserId
,
Forbid
:
false
,
Timestamp
:
time
.
Now
()
.
Unix
(),
})
...
...
domain/service/group_mic_s/group_mic.go
View file @
5dc1ce3a
...
...
@@ -126,51 +126,14 @@ func redisLock(key string, sign string, expiration time.Duration, callBack func(
//加入麦位,锁两秒
func
(
s
*
GroupMicService
)
GroupMicIn
(
groupUuid
string
,
i
int
,
userId
uint64
,
externalId
string
)
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
{
return
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
,
cpUserId
)
return
mic
.
In
(
userId
,
externalId
)
})
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
.
Update
(
cpUserId
,
user
.
ExternalId
,
userId
)
})
}
return
nil
}
//离开麦位
...
...
@@ -367,3 +330,55 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u
}
return
nil
}
func
(
s
*
GroupMicService
)
CheckCpOnMic
(
groupUuid
string
)
{
model
:=
domain
.
CreateModelContext
(
s
.
svc
.
MyContext
)
// 填充cp麦位
micNumType
,
err
:=
group_m
.
GetMicNumType
(
model
,
groupUuid
)
if
err
!=
nil
{
return
}
_
,
micUsers
,
err
:=
group_m
.
GetAllMic
(
groupUuid
,
micNumType
)
if
err
!=
nil
{
return
}
// userId->micIndex
var
userMicIndex
=
make
(
map
[
uint64
]
int
)
var
userIds
[]
uint64
for
_
,
u
:=
range
micUsers
{
userMicIndex
[
u
.
UserId
]
=
u
.
I
userIds
=
append
(
userIds
,
u
.
UserId
)
}
cpPairs
,
err
:=
rpc
.
MGetUserCpPairs
(
model
,
userIds
)
// 更新麦上cp的信息
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"MGetUserCpPairs fail:%v"
,
err
)
return
}
users
,
err
:=
user_m
.
GetUserMapByIds
(
model
,
userIds
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetUserMapByIds fail:%v"
,
err
)
return
}
for
_
,
pairs
:=
range
cpPairs
{
userId
:=
pairs
[
0
]
cpUserId
:=
pairs
[
1
]
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
,
userMicIndex
[
userId
])
if
err
!=
nil
{
return
err
}
return
mic
.
Update
(
userId
,
users
[
userId
]
.
ExternalId
,
cpUserId
)
})
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
,
userMicIndex
[
cpUserId
])
if
err
!=
nil
{
return
err
}
return
mic
.
Update
(
cpUserId
,
users
[
cpUserId
]
.
ExternalId
,
userId
)
})
}
return
}
route/group_r/group_mic.go
View file @
5dc1ce3a
...
...
@@ -600,6 +600,8 @@ func GroupMicIn(c *gin.Context) (*mycontext.MyContext, error) {
}
else
{
resp
.
ResponseOk
(
c
,
nil
)
}
// check cp 麦位置
go
group_mic_s
.
NewGroupPowerService
(
myContext
)
.
CheckCpOnMic
(
groupUuid
)
return
myContext
,
nil
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment