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
dbaf767b
Commit
dbaf767b
authored
Aug 25, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
group support
parent
b3eb9655
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
199 additions
and
96 deletions
+199
-96
support.go
domain/model/group_m/support.go
+14
-14
group_support.go
domain/service/group_s/group_support.go
+171
-76
group_support.go
route/group_r/group_support.go
+14
-6
No files found.
domain/model/group_m/support.go
View file @
dbaf767b
...
@@ -102,14 +102,14 @@ func (gsa *GroupSupportAwardMgr) Get(db *gorm.DB) ([]GroupSupportAwardMgr, error
...
@@ -102,14 +102,14 @@ func (gsa *GroupSupportAwardMgr) Get(db *gorm.DB) ([]GroupSupportAwardMgr, error
}
}
//添加记录
//添加记录
func
AddGroupSupportAward
(
model
*
domain
.
Model
,
groupUid
string
,
issuerUserId
mysql
.
ID
,
res
GroupSupportId
mysql
.
ID
,
userIds
[]
mysql
.
ID
,
period
string
)
(
*
GroupSupportAwardAdmin
,
[]
GroupSupportAwardMgr
,
error
)
{
func
AddGroupSupportAward
(
model
*
domain
.
Model
,
groupUid
string
,
issuerUserId
mysql
.
ID
,
res
Support
*
res_m
.
ResGroupSupport
,
userIds
[]
mysql
.
ID
,
period
string
)
(
*
GroupSupportAwardAdmin
,
[]
GroupSupportAwardMgr
,
error
)
{
//资源获取
//
//
资源获取
resGroupSupport
,
err
:=
res_m
.
GetResGroupSupportById
(
model
,
resGroupSupportId
)
//
resGroupSupport, err := res_m.GetResGroupSupportById(model, resGroupSupportId)
if
err
!=
nil
{
//
if err != nil {
return
nil
,
nil
,
err
//
return nil, nil, err
}
//
}
if
int
(
res
Group
Support
.
MgrNum
)
<
len
(
userIds
)
{
if
int
(
resSupport
.
MgrNum
)
<
len
(
userIds
)
{
return
nil
,
nil
,
myerr
.
NewSysErrorF
(
"AddGroupSupportAward mgrNum:%v 同 len(userIds)=%v 不一致"
,
res
Group
Support
.
MgrNum
,
len
(
userIds
))
return
nil
,
nil
,
myerr
.
NewSysErrorF
(
"AddGroupSupportAward mgrNum:%v 同 len(userIds)=%v 不一致"
,
resSupport
.
MgrNum
,
len
(
userIds
))
}
}
//增加群主奖励
//增加群主奖励
...
@@ -118,9 +118,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
...
@@ -118,9 +118,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
GroupUid
:
groupUid
,
GroupUid
:
groupUid
,
IssuerUserId
:
issuerUserId
,
IssuerUserId
:
issuerUserId
,
UserId
:
issuerUserId
,
UserId
:
issuerUserId
,
DiamondNum
:
res
Group
Support
.
AdminAward
,
DiamondNum
:
resSupport
.
AdminAward
,
Grade
:
res
Group
Support
.
Grade
,
Grade
:
resSupport
.
Grade
,
ResGroupSupportId
:
res
Group
Support
.
ID
,
ResGroupSupportId
:
resSupport
.
ID
,
Period
:
period
,
Period
:
period
,
}
}
...
@@ -133,9 +133,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
...
@@ -133,9 +133,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
GroupUid
:
groupUid
,
GroupUid
:
groupUid
,
IssuerUserId
:
issuerUserId
,
IssuerUserId
:
issuerUserId
,
UserId
:
userIds
[
i
],
UserId
:
userIds
[
i
],
DiamondNum
:
res
Group
Support
.
MgrAward
,
DiamondNum
:
resSupport
.
MgrAward
,
Grade
:
res
Group
Support
.
Grade
,
Grade
:
resSupport
.
Grade
,
ResGroupSupportId
:
res
Group
Support
.
ID
,
ResGroupSupportId
:
resSupport
.
ID
,
Period
:
period
,
Period
:
period
,
})
})
}
}
...
...
domain/service/group_s/group_support.go
View file @
dbaf767b
...
@@ -15,13 +15,12 @@ import (
...
@@ -15,13 +15,12 @@ import (
"hilo-group/domain/model/msg_m"
"hilo-group/domain/model/msg_m"
"hilo-group/domain/model/res_m"
"hilo-group/domain/model/res_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/model/user_m"
"hilo-group/myerr/bizerr"
"strconv"
"strconv"
"time"
"time"
)
)
// 群组支持名单过滤
// 群组支持名单过滤
func
(
s
*
GroupService
)
GroupSupportList
(
groupId
string
,
uids
[]
uint64
)
([]
uint64
,
[]
uint64
,
error
)
{
func
(
s
*
GroupService
)
GroupSupportList
(
groupId
string
,
uids
[]
uint64
,
supportLevel
uint32
)
([]
uint64
,
[]
uint64
,
error
)
{
if
len
(
uids
)
<=
0
{
if
len
(
uids
)
<=
0
{
return
uids
,
nil
,
nil
return
uids
,
nil
,
nil
}
}
...
@@ -29,86 +28,157 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
...
@@ -29,86 +28,157 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
result
:=
make
([]
uint64
,
0
)
result
:=
make
([]
uint64
,
0
)
out
:=
make
([]
uint64
,
0
)
out
:=
make
([]
uint64
,
0
)
err
:=
s
.
svc
.
Transactional
(
func
()
error
{
model
:=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
model
:=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
// 1. 去掉非群管理者
// 1. 去掉非群管理者
roles
,
_
,
err
:=
group_m
.
GetRolesInGroup
(
model
,
groupId
)
roles
,
_
,
err
:=
group_m
.
GetRolesInGroup
(
model
,
groupId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
model
.
Log
.
Errorf
(
"GroupSupportList groupId:%v, uids:%v, err:%v"
,
groupId
,
uids
,
err
)
}
return
nil
,
nil
,
err
userIds
:=
make
([]
uint64
,
0
)
}
for
_
,
i
:=
range
uids
{
userIds
:=
make
([]
uint64
,
0
)
if
_
,
ok
:=
roles
[
i
];
ok
{
for
_
,
i
:=
range
uids
{
userIds
=
append
(
userIds
,
i
)
if
_
,
ok
:=
roles
[
i
];
ok
{
}
else
{
userIds
=
append
(
userIds
,
i
)
out
=
append
(
out
,
i
)
}
else
{
model
.
Log
.
Infof
(
"GroupSupportList: rule out %d, no role"
,
i
)
out
=
append
(
out
,
i
)
}
model
.
Log
.
Infof
(
"GroupSupportList: rule out %d, no role"
,
i
)
}
}
}
// TODO: 去掉非群成员
// TODO: 去掉非群成员
//(4)1个账户只能做1个群组的管理员(5)1个设备下只允许领取1个管理奖励
_
,
_
,
period
:=
group_m
.
GetLastSupportPeriod
(
time
.
Now
())
gsa
:=
group_m
.
GroupSupportAwardMgr
{
Period
:
period
}
rows
,
err
:=
gsa
.
Get
(
model
.
Db
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GroupSupportList groupId:%v, uids:%v, err:%v"
,
groupId
,
uids
,
err
)
return
nil
,
nil
,
err
}
awards
:=
make
(
map
[
uint64
]
struct
{},
0
)
for
_
,
i
:=
range
rows
{
awards
[
i
.
UserId
]
=
struct
{}{}
}
//(4)1个账户只能做1个群组的管理员(5)1个设备下只允许领取1个管理奖励
uids
=
userIds
_
,
_
,
period
:=
group_m
.
GetLastSupportPeriod
(
time
.
Now
())
userIds
=
make
([]
uint64
,
0
)
gsa
:=
group_m
.
GroupSupportAwardMgr
{
Period
:
period
}
m
:=
make
(
map
[
uint64
]
uint64
)
rows
,
err
:=
gsa
.
Get
(
model
.
Db
)
for
_
,
u
:=
range
uids
{
m
,
err
:=
user_m
.
GetSameImeiMap
(
model
,
u
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
model
.
Log
.
Errorf
(
"GroupSupportList groupId:%v, uids:%v, err:%v"
,
groupId
,
uids
,
err
)
return
nil
,
nil
,
err
}
}
awards
:=
make
(
map
[
uint64
]
struct
{},
0
)
for
_
,
i
:=
range
rows
{
awards
[
i
.
UserId
]
=
struct
{}{}
}
uids
=
userIds
userIds
=
make
([]
uint64
,
0
)
m
:=
make
(
map
[
uint64
]
uint64
)
for
_
,
u
:=
range
uids
{
m
,
err
:=
user_m
.
GetSameImeiMap
(
model
,
u
)
if
err
!=
nil
{
return
err
}
passed
:=
true
passed
:=
true
for
_
,
i
:=
range
m
{
for
_
,
i
:=
range
m
{
if
_
,
ok
:=
awards
[
i
];
ok
{
if
_
,
ok
:=
awards
[
i
];
ok
{
if
i
==
u
{
if
i
==
u
{
passed
=
false
passed
=
false
model
.
Log
.
Infof
(
"GroupSupportList: rule out %d, already awarded"
,
i
)
model
.
Log
.
Infof
(
"GroupSupportList: rule out %d, already awarded"
,
i
)
}
else
{
}
else
{
passed
=
false
passed
=
false
model
.
Log
.
Infof
(
"GroupSupportList: rule out %d, imei awarded"
,
i
)
model
.
Log
.
Infof
(
"GroupSupportList: rule out %d, imei awarded"
,
i
)
}
}
}
}
}
if
passed
==
true
{
userIds
=
append
(
userIds
,
u
)
}
else
{
out
=
append
(
out
,
u
)
}
}
model
.
Log
.
Infof
(
"GroupSupportList: uids %v, map %v"
,
uids
,
m
)
_
,
supportLevel
,
err
:=
s
.
GetSupportLevel
(
groupId
)
if
err
!=
nil
{
return
err
}
}
if
passed
==
true
{
if
uint32
(
len
(
userIds
))
>
supportLevel
{
userIds
=
append
(
userIds
,
u
)
model
.
Log
.
Infof
(
"GroupSupportList: rule out %v, limit exeeded"
,
userIds
[
supportLevel
:
])
}
else
{
out
=
append
(
out
,
userIds
[
supportLevel
:
]
...
)
out
=
append
(
out
,
u
)
userIds
=
userIds
[
0
:
supportLevel
]
}
}
result
=
userIds
}
return
nil
model
.
Log
.
Infof
(
"GroupSupportList: uids %v, map %v"
,
uids
,
m
)
})
if
err
==
ni
l
{
if
uint32
(
len
(
userIds
))
>
supportLeve
l
{
return
result
,
out
,
nil
model
.
Log
.
Infof
(
"GroupSupportList: rule out %v, limit exeeded"
,
userIds
[
supportLevel
:
])
}
else
{
out
=
append
(
out
,
userIds
[
supportLevel
:
]
...
)
return
nil
,
nil
,
err
userIds
=
userIds
[
0
:
supportLevel
]
}
}
result
=
userIds
return
result
,
out
,
nil
//err := s.svc.Transactional(func() error {
// model := domain.CreateModel(s.svc.CtxAndDb)
//
// // 1. 去掉非群管理者
// roles, _, err := group_m.GetRolesInGroup(model, groupId)
// if err != nil {
// return err
// }
// userIds := make([]uint64, 0)
// for _, i := range uids {
// if _, ok := roles[i]; ok {
// userIds = append(userIds, i)
// } else {
// out = append(out, i)
// model.Log.Infof("GroupSupportList: rule out %d, no role", i)
// }
// }
//
// // TODO: 去掉非群成员
//
// //(4)1个账户只能做1个群组的管理员(5)1个设备下只允许领取1个管理奖励
// _, _, period := group_m.GetLastSupportPeriod(time.Now())
// gsa := group_m.GroupSupportAwardMgr{Period: period}
// rows, err := gsa.Get(model.Db)
// if err != nil {
// return err
// }
// awards := make(map[uint64]struct{}, 0)
// for _, i := range rows {
// awards[i.UserId] = struct{}{}
// }
//
// uids = userIds
// userIds = make([]uint64, 0)
// m := make(map[uint64]uint64)
// for _, u := range uids {
// m, err := user_m.GetSameImeiMap(model, u)
// if err != nil {
// return err
// }
//
// passed := true
// for _, i := range m {
// if _, ok := awards[i]; ok {
// if i == u {
// passed = false
// model.Log.Infof("GroupSupportList: rule out %d, already awarded", i)
// } else {
// passed = false
// model.Log.Infof("GroupSupportList: rule out %d, imei awarded", i)
// }
// }
// }
// if passed == true {
// userIds = append(userIds, u)
// } else {
// out = append(out, u)
// }
// }
// model.Log.Infof("GroupSupportList: uids %v, map %v", uids, m)
//
// _, supportLevel, err := s.GetSupportLevel(groupId)
// if err != nil {
// return err
// }
//
// if uint32(len(userIds)) > supportLevel {
// model.Log.Infof("GroupSupportList: rule out %v, limit exeeded", userIds[supportLevel:])
// out = append(out, userIds[supportLevel:]...)
// userIds = userIds[0:supportLevel]
// }
// result = userIds
// return nil
//})
//
//if err == nil {
// return result, out, nil
//} else {
// return nil, nil, err
//}
}
}
func
(
s
*
GroupService
)
GetSupportLevel
(
groupId
string
)
(
uint64
,
uint32
,
error
)
{
func
(
s
*
GroupService
)
GetSupportLevel
(
groupId
string
)
(
uint64
,
uint32
,
error
)
{
...
@@ -132,17 +202,42 @@ func (s *GroupService) GetSupportLevel(groupId string) (uint64, uint32, error) {
...
@@ -132,17 +202,42 @@ func (s *GroupService) GetSupportLevel(groupId string) (uint64, uint32, error) {
return
0
,
0
,
nil
return
0
,
0
,
nil
}
}
func
(
s
*
GroupService
)
GetSupportLevelByRedis
(
groupId
string
)
(
*
res_m
.
ResGroupSupport
,
uint32
,
error
)
{
model
:=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
_
,
_
,
period
:=
group_m
.
GetLastSupportPeriod
(
time
.
Now
())
// 流水
keyDiamond
:=
rediskey
.
GetGroupSupportConsumeSummary
(
period
)
consume
,
err
:=
model
.
RedisCluster
.
ZScore
(
context
.
Background
(),
keyDiamond
,
groupId
)
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetSupportLevelByRedis key:%v, groupId:%v, err:%v"
,
keyDiamond
,
groupId
,
err
)
return
nil
,
0
,
err
}
// 支持者数量
keySupportNum
:=
rediskey
.
GetGroupSupportCountSupporter
(
period
,
groupId
)
count
,
err
:=
model
.
RedisCluster
.
SCard
(
context
.
Background
(),
keySupportNum
)
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetSupportLevelByRedis key:%v, groupId:%v, err:%v"
,
keySupportNum
,
groupId
,
err
)
return
nil
,
0
,
err
}
rec
,
err
:=
res_m
.
GetResGroupSupportBy
(
model
,
uint32
(
count
),
uint64
(
consume
))
if
err
!=
nil
{
return
nil
,
0
,
err
}
if
rec
!=
nil
{
return
rec
,
rec
.
MgrNum
,
nil
}
return
rec
,
0
,
nil
}
//群组支持奖励
//群组支持奖励
func
(
s
*
GroupService
)
GroupSupportAward
(
groupId
string
,
profitAllocator
uint64
,
userIds
[]
uint64
,
resId
uint64
,
period
string
)
error
{
func
(
s
*
GroupService
)
GroupSupportAward
(
groupId
string
,
profitAllocator
uint64
,
userIds
[]
uint64
,
resSupport
*
res_m
.
ResGroupSupport
,
period
string
,
groupInfo
*
group_m
.
GroupInfo
)
error
{
return
s
.
svc
.
Transactional
(
func
()
error
{
return
s
.
svc
.
Transactional
(
func
()
error
{
model
:=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
model
:=
domain
.
CreateModel
(
s
.
svc
.
CtxAndDb
)
//
groupInfo
,
err
:=
group_m
.
GetGroupInfo
(
model
,
groupId
)
if
groupInfo
==
nil
{
return
bizerr
.
GroupNotFound
}
//发放奖励
//发放奖励
groupSupportAwardAdmin
,
groupSupportAwardMgrs
,
err
:=
group_m
.
AddGroupSupportAward
(
model
,
groupId
,
profitAllocator
,
res
Id
,
userIds
,
period
)
groupSupportAwardAdmin
,
groupSupportAwardMgrs
,
err
:=
group_m
.
AddGroupSupportAward
(
model
,
groupId
,
profitAllocator
,
res
Support
,
userIds
,
period
)
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
...
...
route/group_r/group_support.go
View file @
dbaf767b
...
@@ -335,20 +335,24 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -335,20 +335,24 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
return
myContext
,
bizerr
.
GroupAlreadyAwarded
return
myContext
,
bizerr
.
GroupAlreadyAwarded
}
}
userIds
,
outUserIds
,
err
:=
group_s
.
NewGroupService
(
myContext
)
.
GroupSupportList
(
groupId
,
userIds
)
model
.
Log
.
Infof
(
"TakeSupportAward: %v, %v"
,
userIds
,
outUserIds
)
model
=
domain
.
CreateModelContext
(
myContext
)
model
=
domain
.
CreateModelContext
(
myContext
)
resSupport
Id
,
_
,
err
:=
group_s
.
NewGroupService
(
myContext
)
.
GetSupportLevel
(
groupId
)
resSupport
,
supportLevel
,
err
:=
group_s
.
NewGroupService
(
myContext
)
.
GetSupportLevelByRedis
(
groupId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
myContext
,
err
return
myContext
,
err
}
}
if
resSupport
Id
<=
0
{
if
resSupport
.
ID
<=
0
{
return
myContext
,
bizerr
.
NotQualified
return
myContext
,
bizerr
.
NotQualified
}
}
userIds
,
outUserIds
,
err
:=
group_s
.
NewGroupService
(
myContext
)
.
GroupSupportList
(
groupId
,
userIds
,
supportLevel
)
model
.
Log
.
Infof
(
"TakeSupportAward: %v, %v"
,
userIds
,
outUserIds
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"TakeSupportAward groupId:%v, userId:%v err:%v"
,
groupId
,
userId
,
err
)
return
myContext
,
err
}
// 检查userIds的ip限制
// 检查userIds的ip限制
userIp
,
err
:=
user_m
.
GetUserIpMap
(
model
.
Db
,
userIds
)
userIp
,
err
:=
user_m
.
GetUserIpMap
(
model
.
Db
,
userIds
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -382,8 +386,12 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -382,8 +386,12 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
}
}
}
}
groupInfo
,
err
:=
group_m
.
GetGroupInfo
(
model
,
groupId
)
if
groupInfo
==
nil
||
groupInfo
.
Id
<=
0
{
return
myContext
,
bizerr
.
GroupNotFound
}
// 真正地放奖励
// 真正地放奖励
err
=
group_s
.
NewGroupService
(
myContext
)
.
GroupSupportAward
(
groupId
,
pa
,
userIds
,
resSupport
Id
,
period
)
err
=
group_s
.
NewGroupService
(
myContext
)
.
GroupSupportAward
(
groupId
,
pa
,
userIds
,
resSupport
,
period
,
groupInfo
)
if
err
!=
nil
{
if
err
!=
nil
{
return
myContext
,
err
return
myContext
,
err
}
}
...
...
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