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
3702a0f9
Commit
3702a0f9
authored
Aug 25, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix/group_support' into 'master'
Fix/group support See merge request
!67
parents
8aed32d6
202b83a7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
330 additions
and
216 deletions
+330
-216
cron.go
cron/cron.go
+1
-1
group_support.go
cron/group_cron/group_support.go
+73
-78
gift.go
domain/model/gift_m/gift.go
+33
-33
support.go
domain/model/group_m/support.go
+14
-14
group_support.go
domain/service/group_s/group_support.go
+179
-76
group_support.go
route/group_r/group_support.go
+30
-14
No files found.
cron/cron.go
View file @
3702a0f9
...
...
@@ -21,5 +21,5 @@ func Init() {
//group_cron.GroupInEventInit() // 进房事件
group_cron
.
CreateGroup
()
//
group_cron
.
CalcGroupSupport
()
// 群组扶持计算
group_cron
.
CalcGroupSupport_OldData
()
//
group_cron.CalcGroupSupport_OldData()
}
cron/group_cron/group_support.go
View file @
3702a0f9
package
group_cron
import
(
"context"
"encoding/json"
"git.hilo.cn/hilo-common/_const/rediskey"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"git.hilo.cn/hilo-common/utils"
"github.com/robfig/cron"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/group_e"
"hilo-group/domain/model/gift_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_s"
"time"
...
...
@@ -92,76 +87,76 @@ func sendGroupSupportH5(model *domain.Model) error {
}
// 群组扶持计算-旧数据
func
CalcGroupSupport_OldData
()
{
if
!
config
.
IsMaster
()
{
return
}
c
:=
cron
.
New
()
spec
:=
"0 20 11 25 8 ?"
_
=
c
.
AddFunc
(
spec
,
func
()
{
defer
utils
.
CheckGoPanic
()
var
model
=
domain
.
CreateModelNil
()
//开始
model
.
Log
.
Infof
(
"CalcGroupSupport_OldData start"
)
beginTime
,
endTime
,
period
:=
group_m
.
GetSupportLevelTime
(
time
.
Now
()
.
AddDate
(
0
,
0
,
-
group_e
.
SUPPORT_LEVEL_PERIOD_DAY
))
//beginTime, _, period := group_m.GetSupportLevelTime(time.Now())
//endTime := time.Unix(1692843600, 0)
g
:=
gift_m
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
,
Model
:
model
}
records
,
err
:=
g
.
BatchGetConsumeByRange
(
beginTime
,
endTime
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v"
,
beginTime
,
endTime
,
err
)
return
}
// 流水写入redis
keyDiamond
:=
rediskey
.
GetGroupSupportConsumeSummary
(
period
)
for
_
,
r
:=
range
records
{
if
r
.
SceneUid
==
""
||
r
.
Consume
<=
0
{
continue
}
_
,
err
=
model
.
RedisCluster
.
ZIncrBy
(
context
.
Background
(),
keyDiamond
,
float64
(
r
.
Consume
),
r
.
SceneUid
)
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v"
,
keyDiamond
,
r
.
Consume
,
r
.
SceneUid
,
err
)
}
}
err
=
redisCli
.
SetExpire
(
model
.
RedisCluster
,
keyDiamond
,
time
.
Hour
*
24
*
14
)
// 保留两周
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData groupSupport key:%s, err:%v"
,
keyDiamond
,
err
)
return
}
// 支持者写入redis
for
_
,
r
:=
range
records
{
if
r
.
SceneUid
==
""
||
r
.
C
<=
0
{
continue
}
// 支持者列表
support
:=
gift_m
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
,
SceneUid
:
r
.
SceneUid
,
Model
:
model
}
uids
,
err
:=
support
.
BatchGetSupportList
(
beginTime
,
endTime
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v"
,
beginTime
,
endTime
,
r
.
SceneUid
,
err
)
continue
}
if
len
(
uids
)
<=
0
{
continue
}
// 支持者数量
keySupportNum
:=
rediskey
.
GetGroupSupportCountSupporter
(
period
,
r
.
SceneUid
)
for
_
,
uid
:=
range
uids
{
err
=
model
.
RedisCluster
.
SAdd
(
context
.
Background
(),
keySupportNum
,
uid
)
.
Err
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData groupSupport key:%s, UserId:%d, err:%v"
,
keySupportNum
,
uid
,
err
)
}
}
err
=
redisCli
.
SetExpire
(
model
.
RedisCluster
,
keySupportNum
,
time
.
Hour
*
24
*
14
)
// 保留两周
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddSendGiftEventAsync groupSupport key:%s, err:%v"
,
keySupportNum
,
err
)
}
}
model
.
Log
.
Infof
(
"CalcGroupSupport_OldData end"
)
})
c
.
Start
()
}
//
func CalcGroupSupport_OldData() {
//
if !config.IsMaster() {
//
return
//
}
//
c := cron.New()
//
spec := "0 20 11 25 8 ?"
//
_ = c.AddFunc(spec, func() {
//
defer utils.CheckGoPanic()
//
var model = domain.CreateModelNil()
//
//开始
//
model.Log.Infof("CalcGroupSupport_OldData start")
//
//
beginTime, endTime, period := group_m.GetSupportLevelTime(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
//
//beginTime, _, period := group_m.GetSupportLevelTime(time.Now())
//
//endTime := time.Unix(1692843600, 0)
//
//
g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, Model: model}
//
records, err := g.BatchGetConsumeByRange(beginTime, endTime)
//
if err != nil {
//
model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err)
//
return
//
}
//
// 流水写入redis
//
keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
//
for _, r := range records {
//
if r.SceneUid == "" || r.Consume <= 0 {
//
continue
//
}
//
_, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result()
//
if err != nil {
//
model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v",
//
keyDiamond, r.Consume, r.SceneUid, err)
//
}
//
}
//
err = redisCli.SetExpire(model.RedisCluster, keyDiamond, time.Hour*24*14) // 保留两周
//
if err != nil {
//
model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err)
//
return
//
}
//
// 支持者写入redis
//
for _, r := range records {
//
if r.SceneUid == "" || r.C <= 0 {
//
continue
//
}
//
// 支持者列表
//
support := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: r.SceneUid, Model: model}
//
uids, err := support.BatchGetSupportList(beginTime, endTime)
//
if err != nil {
//
model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err)
//
continue
//
}
//
if len(uids) <= 0 {
//
continue
//
}
//
// 支持者数量
//
keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid)
//
for _, uid := range uids {
//
err = model.RedisCluster.SAdd(context.Background(), keySupportNum, uid).Err()
//
if err != nil {
//
model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, UserId:%d, err:%v", keySupportNum, uid, err)
//
}
//
}
//
err = redisCli.SetExpire(model.RedisCluster, keySupportNum, time.Hour*24*14) // 保留两周
//
if err != nil {
//
model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, err:%v", keySupportNum, err)
//
}
//
}
//
//
model.Log.Infof("CalcGroupSupport_OldData end")
//
})
//
//
c.Start()
//
}
domain/model/gift_m/gift.go
View file @
3702a0f9
...
...
@@ -128,39 +128,39 @@ func (g *GiftOperate) GetConsumeByRange(beginTime, endTime time.Time) (uint32, u
return
0
,
0
,
nil
}
if
beginTime
.
Unix
()
>=
1691337600
&&
beginTime
.
Unix
()
<
1691942400
{
// 因为这周水果机被部分人刷币,所以这里做了特殊的处理
reduceMap
:=
map
[
string
]
uint64
{
"HTGS#a63226380"
:
20000000
,
//"HTGS#a42641278": 10000000,
"@TGS#3ZZ5GZLHA"
:
27141539
,
"HTGS#a81630128"
:
8955410
,
"HTGS#a42300598"
:
50211301
,
"HTGS#a40088696"
:
10000000
,
"HTGS#a21700997"
:
14352310
,
"HTGS#a83608384"
:
49644203
,
"@TGS#33GDXTSIH"
:
50000000
,
"HTGS#a50538513"
:
15000000
,
"HTGS#a77282385"
:
15000000
,
"HTGS#a59437326"
:
10000000
,
"HTGS#a16909405"
:
10000000
,
"HTGS#a44104431"
:
16861206
,
"HTGS#a56794634"
:
59591313
,
"HTGS#a11286025"
:
31232311
,
"HTGS#a17238550"
:
52309338
,
"HTGS#a83592361"
:
79545067
,
"HTGS#a39882521"
:
10255093
,
}
if
reduceNum
,
ok
:=
reduceMap
[
g
.
SceneUid
];
ok
{
if
g
.
Log
!=
nil
{
g
.
Log
.
Infof
(
"fruit diamond reduceMap,groupId:%v,reduceNum:%v"
,
g
.
SceneUid
,
reduceNum
)
}
if
rows
[
0
]
.
Consume
>=
reduceNum
{
rows
[
0
]
.
Consume
-=
reduceNum
}
else
{
rows
[
0
]
.
Consume
=
0
}
}
}
//
if beginTime.Unix() >= 1691337600 && beginTime.Unix() < 1691942400 { // 因为这周水果机被部分人刷币,所以这里做了特殊的处理
//
reduceMap := map[string]uint64{
//
"HTGS#a63226380": 20000000,
//
//"HTGS#a42641278": 10000000,
//
"@TGS#3ZZ5GZLHA": 27141539,
//
"HTGS#a81630128": 8955410,
//
"HTGS#a42300598": 50211301,
//
"HTGS#a40088696": 10000000,
//
"HTGS#a21700997": 14352310,
//
"HTGS#a83608384": 49644203,
//
"@TGS#33GDXTSIH": 50000000,
//
"HTGS#a50538513": 15000000,
//
"HTGS#a77282385": 15000000,
//
"HTGS#a59437326": 10000000,
//
"HTGS#a16909405": 10000000,
//
"HTGS#a44104431": 16861206,
//
"HTGS#a56794634": 59591313,
//
"HTGS#a11286025": 31232311,
//
"HTGS#a17238550": 52309338,
//
"HTGS#a83592361": 79545067,
//
"HTGS#a39882521": 10255093,
//
}
//
if reduceNum, ok := reduceMap[g.SceneUid]; ok {
//
if g.Log != nil {
//
g.Log.Infof("fruit diamond reduceMap,groupId:%v,reduceNum:%v", g.SceneUid, reduceNum)
//
}
//
if rows[0].Consume >= reduceNum {
//
rows[0].Consume -= reduceNum
//
} else {
//
rows[0].Consume = 0
//
}
//
}
//
}
return
rows
[
0
]
.
C
,
rows
[
0
]
.
Consume
,
nil
}
...
...
domain/model/group_m/support.go
View file @
3702a0f9
...
...
@@ -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
)
{
//资源获取
resGroupSupport
,
err
:=
res_m
.
GetResGroupSupportById
(
model
,
resGroupSupportId
)
if
err
!=
nil
{
return
nil
,
nil
,
err
}
if
int
(
res
Group
Support
.
MgrNum
)
<
len
(
userIds
)
{
return
nil
,
nil
,
myerr
.
NewSysErrorF
(
"AddGroupSupportAward mgrNum:%v 同 len(userIds)=%v 不一致"
,
res
Group
Support
.
MgrNum
,
len
(
userIds
))
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)
//
if err != nil {
//
return nil, nil, err
//
}
if
int
(
resSupport
.
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
GroupUid
:
groupUid
,
IssuerUserId
:
issuerUserId
,
UserId
:
issuerUserId
,
DiamondNum
:
res
Group
Support
.
AdminAward
,
Grade
:
res
Group
Support
.
Grade
,
ResGroupSupportId
:
res
Group
Support
.
ID
,
DiamondNum
:
resSupport
.
AdminAward
,
Grade
:
resSupport
.
Grade
,
ResGroupSupportId
:
resSupport
.
ID
,
Period
:
period
,
}
...
...
@@ -133,9 +133,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
GroupUid
:
groupUid
,
IssuerUserId
:
issuerUserId
,
UserId
:
userIds
[
i
],
DiamondNum
:
res
Group
Support
.
MgrAward
,
Grade
:
res
Group
Support
.
Grade
,
ResGroupSupportId
:
res
Group
Support
.
ID
,
DiamondNum
:
resSupport
.
MgrAward
,
Grade
:
resSupport
.
Grade
,
ResGroupSupportId
:
resSupport
.
ID
,
Period
:
period
,
})
}
...
...
domain/service/group_s/group_support.go
View file @
3702a0f9
...
...
@@ -15,13 +15,12 @@ import (
"hilo-group/domain/model/msg_m"
"hilo-group/domain/model/res_m"
"hilo-group/domain/model/user_m"
"hilo-group/myerr/bizerr"
"strconv"
"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
{
return
uids
,
nil
,
nil
}
...
...
@@ -29,13 +28,13 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
result
:=
make
([]
uint64
,
0
)
out
:=
make
([]
uint64
,
0
)
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
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
{
...
...
@@ -48,13 +47,13 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
}
// 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
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
{
...
...
@@ -67,7 +66,8 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
for
_
,
u
:=
range
uids
{
m
,
err
:=
user_m
.
GetSameImeiMap
(
model
,
u
)
if
err
!=
nil
{
return
err
model
.
Log
.
Errorf
(
"GroupSupportList groupId:%v, uids:%v, err:%v"
,
groupId
,
uids
,
err
)
return
nil
,
nil
,
err
}
passed
:=
true
...
...
@@ -90,25 +90,95 @@ func (s *GroupService) GroupSupportList(groupId string, uids []uint64) ([]uint64
}
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
}
//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
)
{
...
...
@@ -132,17 +202,50 @@ func (s *GroupService) GetSupportLevel(groupId string) (uint64, uint32, error) {
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
())
consume
,
count
,
err
:=
GetGroupConsumeCount
(
model
,
groupId
,
period
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
rec
,
err
:=
res_m
.
GetResGroupSupportBy
(
model
,
count
,
consume
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
if
rec
!=
nil
{
return
rec
,
rec
.
MgrNum
,
nil
}
return
rec
,
0
,
nil
}
func
GetGroupConsumeCount
(
model
*
domain
.
Model
,
imGroupId
,
period
string
)
(
uint64
,
uint32
,
error
)
{
// 流水
keyDiamond
:=
rediskey
.
GetGroupSupportConsumeSummary
(
period
)
consume
,
err
:=
model
.
RedisCluster
.
ZScore
(
context
.
Background
(),
keyDiamond
,
imGroupId
)
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetSupportLevelByRedis key:%v, groupId:%v, err:%v"
,
keyDiamond
,
imGroupId
,
err
)
return
0
,
0
,
err
}
// 支持者数量
keySupportNum
:=
rediskey
.
GetGroupSupportCountSupporter
(
period
,
imGroupId
)
count
,
err
:=
model
.
RedisCluster
.
SCard
(
context
.
Background
(),
keySupportNum
)
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetSupportLevelByRedis key:%v, groupId:%v, err:%v"
,
keySupportNum
,
imGroupId
,
err
)
return
0
,
0
,
err
}
return
uint64
(
consume
),
uint32
(
count
),
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
{
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
{
return
err
}
...
...
route/group_r/group_support.go
View file @
3702a0f9
...
...
@@ -6,13 +6,11 @@ import (
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/cv/group_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/cache/group_c"
"hilo-group/domain/model/gift_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/res_m"
"hilo-group/domain/model/user_m"
...
...
@@ -111,18 +109,28 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) {
result
:=
group_cv
.
SupportPageDetail
{
GroupId
:
txGroupId
}
now
:=
time
.
Now
()
beginTime
,
endTime
,
_
:=
group_m
.
GetSupportLevelTime
(
now
)
_
,
endTime
,
period
:=
group_m
.
GetSupportLevelTime
(
now
)
result
.
RemainSecond
=
endTime
.
Unix
()
-
now
.
Unix
()
g
:=
gift_m
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
,
SceneUid
:
groupId
,
Model
:
model
}
result
.
CurrentCount
,
result
.
CurrentConsume
,
err
=
g
.
GetConsumeByRange
(
beginTime
,
endTime
)
//g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: groupId, Model: model}
//result.CurrentCount, result.CurrentConsume, err = g.GetConsumeByRange(beginTime, endTime)
//if err != nil {
// return myContext, err
//}
result
.
CurrentConsume
,
result
.
CurrentCount
,
err
=
group_s
.
GetGroupConsumeCount
(
model
,
groupId
,
period
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetSupportDetail groupId:%s, err:%v"
,
groupId
,
err
)
return
myContext
,
err
}
beginTime
,
endTime
,
_
=
group_m
.
GetSupportLevelTime
(
now
.
AddDate
(
0
,
0
,
-
group_e
.
SUPPORT_LEVEL_PERIOD_DAY
))
result
.
LastCount
,
result
.
LastConsume
,
err
=
g
.
GetConsumeByRange
(
beginTime
,
endTime
)
_
,
_
,
periodLast
:=
group_m
.
GetSupportLevelTime
(
now
.
AddDate
(
0
,
0
,
-
group_e
.
SUPPORT_LEVEL_PERIOD_DAY
))
//result.LastCount, result.LastConsume, err = g.GetConsumeByRange(beginTimeLast, endTimeLast)
//if err != nil {
// return myContext, err
//}
result
.
LastConsume
,
result
.
LastCount
,
err
=
group_s
.
GetGroupConsumeCount
(
model
,
groupId
,
periodLast
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetSupportDetail groupId:%s, err:%v"
,
groupId
,
err
)
return
myContext
,
err
}
...
...
@@ -152,7 +160,7 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) {
}
// 判断这个周期这个群的奖金是否已经发过
_
,
_
,
period
:
=
group_m
.
GetLastSupportPeriod
(
now
)
_
,
_
,
period
=
group_m
.
GetLastSupportPeriod
(
now
)
gsaa
:=
group_m
.
GroupSupportAwardAdmin
{
Period
:
period
,
GroupUid
:
groupId
}
rows
,
err
:=
gsaa
.
Get
(
model
.
Db
)
if
err
!=
nil
{
...
...
@@ -335,20 +343,24 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
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
)
resSupport
Id
,
_
,
err
:=
group_s
.
NewGroupService
(
myContext
)
.
GetSupportLevel
(
groupId
)
resSupport
,
supportLevel
,
err
:=
group_s
.
NewGroupService
(
myContext
)
.
GetSupportLevelByRedis
(
groupId
)
if
err
!=
nil
{
return
myContext
,
err
}
if
resSupport
Id
<=
0
{
if
resSupport
.
ID
<=
0
{
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限制
userIp
,
err
:=
user_m
.
GetUserIpMap
(
model
.
Db
,
userIds
)
if
err
!=
nil
{
...
...
@@ -382,8 +394,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
{
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