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
Compare Revisions
feature/onMic...master
Source
master
Select Git revision
...
Target
feature/onMic
Select Git revision
Compare
Commits (101)
f3d1cdca
Feature/on mic
Aug 24, 2023
031187b7
Merge branch 'feature/onMic' into 'master'
Aug 24, 2023
1c13f8e5
feat:去掉增加上麦时长
Aug 24, 2023
f4eeba74
feat:4个进程处理
Aug 24, 2023
43e1f9a9
feat:增加耗时打点
Aug 24, 2023
d60ea0ca
group support
Aug 25, 2023
8aed32d6
Merge branch 'fix/group_support_old_data' into 'master'
Aug 25, 2023
202b83a7
Fix/group support
Aug 25, 2023
3702a0f9
Merge branch 'fix/group_support' into 'master'
Aug 25, 2023
fe866622
Fix/group support
Aug 25, 2023
cdf3f6d7
Merge branch 'fix/group_support' into 'master'
Aug 25, 2023
9ce21c0d
feat:改到30秒执行观察大波浪
Aug 25, 2023
b1a5481e
用户上麦 还是得静态数据
Aug 25, 2023
c1cf069e
feat:去掉无用的大key
Aug 26, 2023
a29fdf93
hgetall 改成mget
Aug 26, 2023
d41ec14f
过滤游戏房
Aug 26, 2023
04b986e8
feat:1分钟统一60秒
Aug 26, 2023
128d01b1
增加用户上麦时长Redis
Aug 26, 2023
8a88c123
feat:去掉打点
Aug 26, 2023
fc40c181
feat:redis版本家族榜单
Aug 27, 2023
0429a5c0
Merge branch 'feature/power-redis' into 'master'
Aug 27, 2023
92d400a0
feat:去掉一次型脚本
Aug 27, 2023
c3d53ba5
临时处理
Aug 27, 2023
6410a1b0
Update cron.go
Aug 27, 2023
9ab90200
feat:更换redis队列
Aug 27, 2023
f25299ec
去掉最近访问的人 todo
Aug 27, 2023
bf30a995
Update event_init.go
Aug 27, 2023
0500449b
1
Aug 27, 2023
5a04f6b5
Revert "1"
Aug 27, 2023
cc89d144
Update room.go
Aug 27, 2023
416d58ad
ZAddUserEnterRoom 补回去
Aug 27, 2023
1c15a89a
BatchGetAllMicUser
Aug 27, 2023
9c3da418
Update user.go
Aug 27, 2023
155ad046
MGetRoomVisitCount:也先去掉
Aug 27, 2023
e8b2157d
Revert "Update room.go"
Aug 28, 2023
ee0e634d
Revert "MGetRoomVisitCount:也先去掉"
Aug 28, 2023
c7278791
Revert "BatchGetAllMicUser"
Aug 28, 2023
81c74802
Revert "去掉最近访问的人 todo"
Aug 28, 2023
80137d5c
Revert "临时处理"
Aug 28, 2023
b28ebb47
去掉查询,redis性能
Aug 28, 2023
32c52c48
feat:去掉家族月之星
Aug 28, 2023
ec2ad090
feat:临时兼容
Aug 28, 2023
9eaa60e5
Update user.go
Aug 28, 2023
718a71fa
Fix/group country
Aug 28, 2023
3f4af9eb
Merge branch 'fix/group_country' into 'master'
Aug 28, 2023
9d7d5fe1
群组优化
Aug 28, 2023
9e768f4f
feat:家族房间,去掉micUser
Aug 28, 2023
d2147624
Fix/group country
Aug 28, 2023
01ee2e7a
Merge branch 'fix/group_country' into 'master'
Aug 28, 2023
59f72c41
feat:最近加入的群组,只给10个
Aug 28, 2023
cb4a4fad
30个才行
Aug 28, 2023
016a61f5
Fix/group country
Aug 28, 2023
572b5f28
Merge branch 'fix/group_country' into 'master'
Aug 28, 2023
81534485
Fix/group country
Aug 28, 2023
bb94872b
Merge branch 'fix/group_country' into 'master'
Aug 28, 2023
439687d9
online_status迁移到redis-cluster
Aug 28, 2023
1845196b
Merge branch 'master' of
http://47.107.153.111:8081/gitlab/hujiebin/hilo-group
Aug 28, 2023
4fd91f6e
fix: recent
Aug 28, 2023
24b5fa82
Feature/mic hget
Aug 28, 2023
d8d76b8a
Merge branch 'feature/mic-hget' into 'master'
Aug 28, 2023
ea19ee5c
群组扶持旧数据
Aug 29, 2023
2d0ca0c4
Merge branch 'fix/group_country' into 'master'
Aug 29, 2023
aef54de6
lru批量获取房间访问人数
Aug 29, 2023
278179d6
Merge branch 'feature/room-visit-count' into 'master'
Aug 29, 2023
fb210a72
热门banner:10351麻烦加上版本控制
Aug 29, 2023
97801bdd
群组bannerid:1621
Aug 29, 2023
b6f697a4
zset同步存一份到redis集群
Aug 29, 2023
ba802a38
用redisCluster中的zset代替,只是取出大于100的
Aug 30, 2023
55ac5ee5
feat:测服搞成0
Aug 30, 2023
75948b6a
feat:国旗,国家位置
Aug 30, 2023
d6bed3fb
feat:user redis cluster
Aug 30, 2023
9961fb08
注释不用调用
Aug 30, 2023
63842f2c
feat: 前面30个群
Aug 30, 2023
ecdec591
Revert "feat: 前面30个群"
Aug 30, 2023
a23a0a0c
fix:之前是用错了revrange
Aug 30, 2023
0d54c5ee
feat:group-consume更换到集群
Aug 31, 2023
ceda79f5
Feature/room visitor up
Aug 31, 2023
5b2e24f8
Merge branch 'feature/room-visitor-up' into 'master'
Aug 31, 2023
f370d32f
fix;漏了group by
Aug 31, 2023
cd5586a5
feat:切!
Aug 31, 2023
01de3f5e
for循环获取 userTiny
Aug 31, 2023
82b87ac2
feat:有问题
Aug 31, 2023
9abe6c52
GetGroupVisitorsV2:用批量看看
Aug 31, 2023
5899b86f
feat:再来一遍
Aug 31, 2023
96b54e85
feat:去掉无用的打点
Aug 31, 2023
8b61f804
medal lru
Aug 31, 2023
77a0e197
Update gift_event.go
Sep 01, 2023
0601ede0
Merge branch 'feature/redis-queue' into 'master'
Sep 01, 2023
aa8bf199
群等级lru
Sep 01, 2023
47ef3686
feat:groupInfo的优化
Sep 01, 2023
dad9dda9
feat:roomVisitCount退休
Sep 01, 2023
769a19b0
feat:替换group_in_user_duration_
Sep 01, 2023
9264dfbf
Merge branch 'feature/group_in_user_duration' into 'master'
Sep 01, 2023
d481605f
feat:不再 写enter_room这个key
Sep 01, 2023
6830ffe8
feature/mic_change_redis
Sep 02, 2023
8013f67e
Merge branch 'feature/mic_change_redis' into 'master'
Sep 02, 2023
5bbb19d9
Feature/group room living
Sep 03, 2023
1d17d692
Merge branch 'feature/group_room_living' into 'master'
Sep 03, 2023
cd3386b3
feat:去掉一个黑名单
Sep 04, 2023
80afaac2
feat:优化MGetRoomVisittCnt LRU
Sep 05, 2023
1 additional commits have been omitted to prevent performance issues.
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
57 changed files
with
2134 additions
and
890 deletions
+2134
-890
group_power_grade.go
_const/redis_key/groupPower_k/group_power_grade.go
+0
-10
group_power_star.go
_const/redis_key/groupPower_k/group_power_star.go
+17
-0
keys.go
_const/redis_key/mic_k/keys.go
+24
-0
redisPrefix.go
_const/redis_key/redisPrefix.go
+12
-0
cron.go
cron/cron.go
+6
-3
send_gift_redis.go
cron/gift_cron/send_gift_redis.go
+7
-10
group_list.go
cron/group_cron/group_list.go
+32
-0
group_power_grade.go
cron/group_cron/group_power_grade.go
+0
-24
group_support.go
cron/group_cron/group_support.go
+79
-73
on_mic.go
cron/mic_cron/on_mic.go
+31
-18
svip_vip_noble.go
cron/user_cron/svip_vip_noble.go
+20
-0
group.go
cv/group_cv/group.go
+200
-20
user.go
cv/user_cv/user.go
+110
-4
gift_event.go
domain/cache/gift_c/gift_event.go
+1
-1
group_power_grade.go
domain/cache/groupPower_c/group_power_grade.go
+0
-55
group_power_star.go
domain/cache/groupPower_c/group_power_star.go
+110
-0
enter_room.go
domain/cache/group_c/enter_room.go
+13
-5
group.go
domain/cache/group_c/group.go
+3
-3
queue.go
domain/cache/mic_c/queue.go
+2
-2
modelRedis.go
domain/cache/modelRedis.go
+7
-7
country.go
domain/cache/res_c/country.go
+36
-20
userRoomVisit.go
domain/cache/room_c/userRoomVisit.go
+66
-52
svip_vip_noble.go
domain/cache/user_c/svip_vip_noble.go
+95
-0
user.go
domain/cache/user_c/user.go
+34
-4
cache_medal.go
domain/model/common/cache_medal.go
+11
-60
gift.go
domain/model/gift_m/gift.go
+35
-35
group_grade.go
domain/model/groupPower_m/group_grade.go
+16
-166
group_rank.go
domain/model/groupPower_m/group_rank.go
+1
-2
group_star.go
domain/model/groupPower_m/group_star.go
+3
-22
factory.go
domain/model/group_m/factory.go
+15
-0
groupBanned.go
domain/model/group_m/groupBanned.go
+1
-2
mic.go
domain/model/group_m/mic.go
+52
-7
micData.go
domain/model/group_m/micData.go
+7
-7
room.go
domain/model/group_m/room.go
+18
-30
support.go
domain/model/group_m/support.go
+32
-14
banner.go
domain/model/mgr_m/banner.go
+1
-1
mic.go
domain/model/mic_m/mic.go
+40
-0
country.go
domain/model/res_m/country.go
+7
-0
user.go
domain/model/tim_m/user.go
+2
-2
medal.go
domain/model/user_m/medal.go
+2
-2
user.go
domain/model/user_m/user.go
+36
-0
group_mic.go
domain/service/group_mic_s/group_mic.go
+7
-7
group_power.go
domain/service/group_power_s/group_power.go
+7
-1
group.go
domain/service/group_s/group.go
+43
-43
group_list.go
domain/service/group_s/group_list.go
+244
-0
group_support.go
domain/service/group_s/group_support.go
+179
-76
local.ini
local.ini
+2
-0
group_power.go
route/group_power_r/group_power.go
+2
-1
group_rank.go
route/group_power_r/group_rank.go
+2
-1
inner.go
route/group_power_r/inner.go
+68
-0
group_info.go
route/group_r/group_info.go
+19
-15
group_list.go
route/group_r/group_list.go
+326
-66
group_op.go
route/group_r/group_op.go
+3
-3
group_support.go
route/group_r/group_support.go
+30
-14
router.go
route/router.go
+3
-2
group_power_test.go
test/group_power_test.go
+13
-0
local.ini
test/local.ini
+2
-0
No files found.
_const/redis_key/groupPower_k/group_power_grade.go
deleted
100644 → 0
View file @
cc2946f0
package
groupPower_k
// groupPower等级
const
(
GroupPowerGradeExpQueue
=
"group_power_grade_exp_queue"
)
func
GetGroupPowerGradeExpQueue
()
string
{
return
GroupPowerGradeExpQueue
}
_const/redis_key/groupPower_k/group_power_star.go
0 → 100644
View file @
577a8fef
package
groupPower_k
import
(
"fmt"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/redis_key"
)
// 家族之星榜单
// type: 1:送礼 2:活跃 3:收礼
// date:天/周/月的开始时间
const
GroupPowerStarPrefix
=
"groupPowerStar:${type}:${period}:${groupPowerId}:${date}"
// zset member:userId score:分数
func
GetGroupPowerStarRankKey
(
_type
groupPower_e
.
GroupPowerStarType
,
period
string
,
groupPowerId
uint64
,
date
string
)
string
{
return
redis_key
.
ReplaceKey
(
GroupPowerStarPrefix
,
fmt
.
Sprintf
(
"%d"
,
_type
),
period
,
fmt
.
Sprintf
(
"%d"
,
groupPowerId
),
date
)
}
_const/redis_key/mic_k/keys.go
View file @
577a8fef
...
@@ -10,9 +10,33 @@ import (
...
@@ -10,9 +10,33 @@ import (
const
(
const
(
MicPrefix
=
"mic:"
MicPrefix
=
"mic:"
MicDayInvite
=
MicPrefix
+
"day:invite:${userId}:${date}"
// string 自动被邀请上麦,1天一次,TTL:24H
MicDayInvite
=
MicPrefix
+
"day:invite:${userId}:${date}"
// string 自动被邀请上麦,1天一次,TTL:24H
MicGroupPowerOnMic
=
MicPrefix
+
"groupPower:${userId}:${date}"
// 家族内群上麦分钟数
MicUserOnMic
=
MicPrefix
+
"user:onMic:${tz}:${userId}:${date}"
MicGroupOnMic
=
MicPrefix
+
"group:onMic:${groupId}"
// 在群组麦位上的人 hset field:micIndex member:userId
)
)
func
GetUserMicDayInvite
(
userId
mysql
.
ID
)
string
{
func
GetUserMicDayInvite
(
userId
mysql
.
ID
)
string
{
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
return
redis_key
.
ReplaceKey
(
MicDayInvite
,
fmt
.
Sprintf
(
"%d"
,
userId
),
date
)
return
redis_key
.
ReplaceKey
(
MicDayInvite
,
fmt
.
Sprintf
(
"%d"
,
userId
),
date
)
}
}
// 家族内群上麦分钟数
func
GetMicGroupPowerOnMic
(
userId
uint64
)
string
{
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
return
redis_key
.
ReplaceKey
(
MicGroupPowerOnMic
,
fmt
.
Sprintf
(
"%d"
,
userId
),
date
)
}
// 获取用户上麦时间
// 北京、沙特时间
func
GetUserOnMicKey
(
userId
uint64
,
tz
,
date
string
)
string
{
return
redis_key
.
ReplaceKey
(
MicUserOnMic
,
tz
,
fmt
.
Sprintf
(
"%d"
,
userId
),
date
)
}
// 获取群组麦位上的人
// 可能会有数据不一致,已原来麦位的key为准
// 这里用户快速获取群上麦位的人用,代替大量mget命令慢查询
func
GetGroupOnMicUser
(
groupId
string
)
string
{
return
redis_key
.
ReplaceKey
(
MicGroupOnMic
,
groupId
)
}
_const/redis_key/redisPrefix.go
View file @
577a8fef
...
@@ -249,6 +249,9 @@ const groupInUserDuration = "group_in_user_duration_{groupUuid}"
...
@@ -249,6 +249,9 @@ const groupInUserDuration = "group_in_user_duration_{groupUuid}"
// 15天内进入房间的人数
// 15天内进入房间的人数
const
roomVisitCount
=
"room_visit_count"
const
roomVisitCount
=
"room_visit_count"
// 15天内进入房间的人数 member groupId score 麦位有人的数量
const
roomVisitCountZSet
=
"room_visit_count_zset"
// 用户进入过的房间及时间
// 用户进入过的房间及时间
const
userEnterRoom
=
"enter_room_{userId}"
const
userEnterRoom
=
"enter_room_{userId}"
...
@@ -757,18 +760,27 @@ func GetPrefixGroupMicNumType(groupUuid string) string {
...
@@ -757,18 +760,27 @@ func GetPrefixGroupMicNumType(groupUuid string) string {
return
strings
.
Replace
(
groupMicNumType
,
"{groupUuid}"
,
groupUuid
,
-
1
)
return
strings
.
Replace
(
groupMicNumType
,
"{groupUuid}"
,
groupUuid
,
-
1
)
}
}
// Deprecated: 用户进房时间
// 用 uer:g:${group_id}代替
func
GetPrefixGroupInUserDuration
(
groupUuid
string
)
string
{
func
GetPrefixGroupInUserDuration
(
groupUuid
string
)
string
{
return
strings
.
Replace
(
groupInUserDuration
,
"{groupUuid}"
,
groupUuid
,
-
1
)
return
strings
.
Replace
(
groupInUserDuration
,
"{groupUuid}"
,
groupUuid
,
-
1
)
}
}
// Deprecated: 用户进房时间
// 可用 uer:u:${user_id}代替
func
GetUserEnterRoomKey
(
userId
uint64
)
string
{
func
GetUserEnterRoomKey
(
userId
uint64
)
string
{
return
strings
.
Replace
(
userEnterRoom
,
"{userId}"
,
strconv
.
FormatUint
(
userId
,
10
),
-
1
)
return
strings
.
Replace
(
userEnterRoom
,
"{userId}"
,
strconv
.
FormatUint
(
userId
,
10
),
-
1
)
}
}
// Deprecated: 用redis集群中的zset代替
func
GetPrefixRoomVisitCount
()
string
{
func
GetPrefixRoomVisitCount
()
string
{
return
roomVisitCount
return
roomVisitCount
}
}
func
GetPrefixRoomVisitCountZset
()
string
{
return
roomVisitCountZSet
}
func
GetPrefixSupportLevel
(
date
string
)
string
{
func
GetPrefixSupportLevel
(
date
string
)
string
{
return
strings
.
Replace
(
supportLevel
,
"{date}"
,
date
,
-
1
)
return
strings
.
Replace
(
supportLevel
,
"{date}"
,
date
,
-
1
)
}
}
...
...
cron/cron.go
View file @
577a8fef
...
@@ -5,9 +5,11 @@ import (
...
@@ -5,9 +5,11 @@ import (
"hilo-group/cron/gift_cron"
"hilo-group/cron/gift_cron"
"hilo-group/cron/group_cron"
"hilo-group/cron/group_cron"
"hilo-group/cron/mic_cron"
"hilo-group/cron/mic_cron"
"hilo-group/cron/user_cron"
)
)
func
Init
()
{
func
Init
()
{
user_cron
.
LoadSvipVipNoble
()
// 加载用户特权
if
!
config
.
IsMaster
()
{
if
!
config
.
IsMaster
()
{
return
return
}
}
...
@@ -19,7 +21,8 @@ func Init() {
...
@@ -19,7 +21,8 @@ func Init() {
group_cron
.
GroupPowerExpClear
()
// 清理家族经验/等级
group_cron
.
GroupPowerExpClear
()
// 清理家族经验/等级
group_cron
.
GroupPowerMonthRankAct
()
group_cron
.
GroupPowerMonthRankAct
()
//group_cron.GroupInEventInit() // 进房事件
//group_cron.GroupInEventInit() // 进房事件
group_cron
.
GroupPowerGradeExp
()
// 家族升级(上麦事件会用到) todo 待优化
//group_cron.CreateGroup() //
group_cron
.
CreateGroup
()
//
group_cron
.
CalcGroupSupport
()
// 群组扶持计算
group_cron
.
CalcGroupSupport
()
// 群组扶持计算
//group_cron.CalcGroupSupport_OldData()
group_cron
.
GroupCountryListSort
()
}
}
cron/gift_cron/send_gift_redis.go
View file @
577a8fef
...
@@ -9,6 +9,7 @@ import (
...
@@ -9,6 +9,7 @@ import (
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/domain/cache/gift_c"
"hilo-group/domain/cache/gift_c"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/event/gift_ev"
"hilo-group/domain/event/gift_ev"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/group_m"
...
@@ -74,10 +75,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
...
@@ -74,10 +75,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
// 送礼加分
// 送礼加分
if
data
,
ok
:=
groupPowers
[
sendGiftEvent
.
SendUserId
];
ok
{
if
data
,
ok
:=
groupPowers
[
sendGiftEvent
.
SendUserId
];
ok
{
diamonds
:=
sendGiftEvent
.
GiftN
*
sendGiftEvent
.
ResGift
.
DiamondNum
*
mysql
.
Num
(
len
(
sendGiftEvent
.
ReceiveUserIds
))
diamonds
:=
sendGiftEvent
.
GiftN
*
sendGiftEvent
.
ResGift
.
DiamondNum
*
mysql
.
Num
(
len
(
sendGiftEvent
.
ReceiveUserIds
))
if
err
:=
groupPower_m
.
IncrGroupPowerMonthStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeFamous
,
diamonds
,
0
);
err
!=
nil
{
if
err
:=
groupPower_c
.
IncrGroupPowerDayStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore famous fail:%v"
,
err
)
groupPower_e
.
GroupPowerStarTypeFamous
,
diamonds
);
err
!=
nil
{
}
if
err
:=
groupPower_m
.
IncrGroupPowerDayStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeFamous
,
diamonds
,
0
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerDayStarScore famous fail:%v"
,
err
)
model
.
Log
.
Errorf
(
"IncrGroupPowerDayStarScore famous fail:%v"
,
err
)
}
}
}
}
...
@@ -85,10 +84,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
...
@@ -85,10 +84,8 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
for
_
,
userId
:=
range
sendGiftEvent
.
ReceiveUserIds
{
for
_
,
userId
:=
range
sendGiftEvent
.
ReceiveUserIds
{
if
data
,
ok
:=
groupPowers
[
userId
];
ok
{
if
data
,
ok
:=
groupPowers
[
userId
];
ok
{
diamonds
:=
sendGiftEvent
.
GiftN
*
sendGiftEvent
.
ResGift
.
DiamondNum
diamonds
:=
sendGiftEvent
.
GiftN
*
sendGiftEvent
.
ResGift
.
DiamondNum
if
err
:=
groupPower_m
.
IncrGroupPowerMonthStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
diamonds
,
0
);
err
!=
nil
{
if
err
:=
groupPower_c
.
IncrGroupPowerDayStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore charm fail:%v"
,
err
)
groupPower_e
.
GroupPowerStarTypeCharm
,
diamonds
);
err
!=
nil
{
}
if
err
:=
groupPower_m
.
IncrGroupPowerDayStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
diamonds
,
0
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerDayStarScore charm fail:%v"
,
err
)
model
.
Log
.
Errorf
(
"IncrGroupPowerDayStarScore charm fail:%v"
,
err
)
}
}
}
}
...
@@ -98,7 +95,7 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
...
@@ -98,7 +95,7 @@ func groupPowerStar(model *domain.Model, sendGiftEvent *gift_ev.SendGiftEvent) {
// 群组扶持增加流水数据
// 群组扶持增加流水数据
func
groupSupportAddConsume
(
model
*
domain
.
Model
,
sendGiftEvent
*
gift_ev
.
SendGiftEvent
)
{
func
groupSupportAddConsume
(
model
*
domain
.
Model
,
sendGiftEvent
*
gift_ev
.
SendGiftEvent
)
{
if
time
.
Now
()
.
Unix
()
<=
169
28436
00
{
if
time
.
Now
()
.
Unix
()
<=
169
32759
00
{
return
return
}
}
model
.
Log
.
Infof
(
"groupSupportAddConsume UserId:%d, sendGiftEvent:%+v"
,
sendGiftEvent
.
SendUserId
,
sendGiftEvent
)
model
.
Log
.
Infof
(
"groupSupportAddConsume UserId:%d, sendGiftEvent:%+v"
,
sendGiftEvent
.
SendUserId
,
sendGiftEvent
)
...
@@ -108,7 +105,7 @@ func groupSupportAddConsume(model *domain.Model, sendGiftEvent *gift_ev.SendGift
...
@@ -108,7 +105,7 @@ func groupSupportAddConsume(model *domain.Model, sendGiftEvent *gift_ev.SendGift
}
}
_
,
_
,
period
:=
group_m
.
GetSupportLevelTime
(
time
.
Now
())
_
,
_
,
period
:=
group_m
.
GetSupportLevelTime
(
time
.
Now
())
// 钻石数
// 钻石数
diamond
:=
sendGiftEvent
.
GiftN
*
sendGiftEvent
.
ResGift
.
DiamondNum
diamond
:=
sendGiftEvent
.
GiftN
*
sendGiftEvent
.
ResGift
.
DiamondNum
*
mysql
.
Num
(
len
(
sendGiftEvent
.
ReceiveUserIds
))
keyDiamond
:=
rediskey
.
GetGroupSupportConsumeSummary
(
period
)
keyDiamond
:=
rediskey
.
GetGroupSupportConsumeSummary
(
period
)
_
,
err
:=
model
.
RedisCluster
.
ZIncrBy
(
context
.
Background
(),
keyDiamond
,
float64
(
diamond
),
sendGiftEvent
.
SceneUid
)
.
Result
()
_
,
err
:=
model
.
RedisCluster
.
ZIncrBy
(
context
.
Background
(),
keyDiamond
,
float64
(
diamond
),
sendGiftEvent
.
SceneUid
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
...
...
cron/group_cron/group_list.go
0 → 100644
View file @
577a8fef
package
group_cron
import
(
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-group/domain/service/group_s"
)
// 清理家族经验和等级
func
GroupCountryListSort
()
{
// 常用国家-每15分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口
spec
:=
"0 */15 * * * ?"
c
:=
cron
.
New
()
_
=
c
.
AddFunc
(
spec
,
func
()
{
var
model
=
domain
.
CreateModelNil
()
model
.
Log
.
Infof
(
"GroupCountryListSort Common start"
)
group_s
.
SortGroupCommonCountryList
(
model
)
model
.
Log
.
Infof
(
"GroupCountryListSort Common end"
)
})
// 非常用国家-每60分钟计算国家房间列表排序 /v1/imGroup/country [get] 接口
spec2
:=
"0 59 * * * ?"
_
=
c
.
AddFunc
(
spec2
,
func
()
{
var
model
=
domain
.
CreateModelNil
()
model
.
Log
.
Infof
(
"GroupCountryListSort not Common start"
)
group_s
.
SortGroupNotCommonCountryList
(
model
)
model
.
Log
.
Infof
(
"GroupCountryListSort not Common end"
)
})
c
.
Start
()
}
cron/group_cron/group_power_grade.go
deleted
100644 → 0
View file @
cc2946f0
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
)
}
}
}
}()
}
cron/group_cron/group_support.go
View file @
577a8fef
package
group_cron
package
group_cron
import
(
import
(
"context"
"encoding/json"
"encoding/json"
"git.hilo.cn/hilo-common/_const/rediskey"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/config"
"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/sdk/tencentyun"
"git.hilo.cn/hilo-common/utils"
"git.hilo.cn/hilo-common/utils"
"github.com/robfig/cron"
"github.com/robfig/cron"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/group_e"
"hilo-group/domain/model/gift_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_s"
"hilo-group/domain/service/group_s"
"time"
"time"
...
@@ -86,76 +91,77 @@ func sendGroupSupportH5(model *domain.Model) error {
...
@@ -86,76 +91,77 @@ func sendGroupSupportH5(model *domain.Model) error {
return
nil
return
nil
}
}
// 群组扶持计算-本周旧数据
// 群组扶持计算-旧数据
//func CalcGroupSupport_OldData() {
func
CalcGroupSupport_OldData
()
{
// if !config.IsMaster() {
if
!
config
.
IsMaster
()
{
// return
return
// }
}
// c := cron.New()
c
:=
cron
.
New
()
// spec := "0 30 10 24 8 ?"
spec
:=
"0 27 10 29 8 ?"
// _ = c.AddFunc(spec, func() {
_
=
c
.
AddFunc
(
spec
,
func
()
{
// defer utils.CheckGoPanic()
defer
utils
.
CheckGoPanic
()
// var model = domain.CreateModelNil()
var
model
=
domain
.
CreateModelNil
()
// //开始
//开始
// model.Log.Infof("CalcGroupSupport_OldData start")
model
.
Log
.
Infof
(
"CalcGroupSupport_OldData start"
)
//
// beginTime, _, period := group_m.GetSupportLevelTime(time.Now())
//beginTime, endTime, period := group_m.GetSupportLevelTime(time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
// endTime := time.Unix(1692843600, 0)
beginTime
,
_
,
period
:=
group_m
.
GetSupportLevelTime
(
time
.
Now
())
//
endTime
:=
time
.
Unix
(
1693275900
,
0
)
// g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, Model: model}
// records, err := g.BatchGetConsumeByRange(beginTime, endTime)
g
:=
gift_m
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
,
Model
:
model
}
// if err != nil {
records
,
err
:=
g
.
BatchGetConsumeByRange
(
beginTime
,
endTime
)
// model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v", beginTime, endTime, err)
if
err
!=
nil
{
// return
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData beginTime:%v, endTime:%v, err:%v"
,
beginTime
,
endTime
,
err
)
// }
return
// // 流水写入redis
}
// keyDiamond := rediskey.GetGroupSupportConsumeSummary(period)
// 流水写入redis
// for _, r := range records {
keyDiamond
:=
rediskey
.
GetGroupSupportConsumeSummary
(
period
)
// if r.SceneUid == "" || r.Consume <= 0 {
for
_
,
r
:=
range
records
{
// continue
if
r
.
SceneUid
==
""
||
r
.
Consume
<=
0
{
// }
continue
// _, err = model.RedisCluster.ZIncrBy(context.Background(), keyDiamond, float64(r.Consume), r.SceneUid).Result()
}
// if err != nil {
_
,
err
=
model
.
RedisCluster
.
ZIncrBy
(
context
.
Background
(),
keyDiamond
,
float64
(
r
.
Consume
),
r
.
SceneUid
)
.
Result
()
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, val:%d, member:%s, err:%v",
if
err
!=
nil
{
// keyDiamond, r.Consume, r.SceneUid, err)
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 {
err
=
redisCli
.
SetExpire
(
model
.
RedisCluster
,
keyDiamond
,
time
.
Hour
*
24
*
14
)
// 保留两周
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, err:%v", keyDiamond, err)
if
err
!=
nil
{
// return
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData groupSupport key:%s, err:%v"
,
keyDiamond
,
err
)
// }
return
// // 支持者写入redis
}
// for _, r := range records {
// 支持者写入redis
// if r.SceneUid == "" || r.C <= 0 {
for
_
,
r
:=
range
records
{
// continue
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)
support
:=
gift_m
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
,
SceneUid
:
r
.
SceneUid
,
Model
:
model
}
// if err != nil {
uids
,
err
:=
support
.
BatchGetSupportList
(
model
,
beginTime
,
endTime
)
// model.Log.Errorf("CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v", beginTime, endTime, r.SceneUid, err)
if
err
!=
nil
{
// continue
model
.
Log
.
Errorf
(
"CalcGroupSupport_OldData beginTime:%v, endTime:%v, imGroupId:%v, err:%v"
,
beginTime
,
endTime
,
r
.
SceneUid
,
err
)
// }
continue
// if len(uids) <= 0 {
}
// continue
if
len
(
uids
)
<=
0
{
// }
continue
// // 支持者数量
}
// keySupportNum := rediskey.GetGroupSupportCountSupporter(period, r.SceneUid)
// 支持者数量
// for _, uid := range uids {
keySupportNum
:=
rediskey
.
GetGroupSupportCountSupporter
(
period
,
r
.
SceneUid
)
// err = model.RedisCluster.SAdd(context.Background(), keySupportNum, uid).Err()
for
_
,
uid
:=
range
uids
{
// if err != nil {
err
=
model
.
RedisCluster
.
SAdd
(
context
.
Background
(),
keySupportNum
,
uid
)
.
Err
()
// model.Log.Errorf("CalcGroupSupport_OldData groupSupport key:%s, UserId:%d, err:%v", 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 {
err
=
redisCli
.
SetExpire
(
model
.
RedisCluster
,
keySupportNum
,
time
.
Hour
*
24
*
14
)
// 保留两周
// model.Log.Errorf("AddSendGiftEventAsync groupSupport key:%s, err:%v", keySupportNum, err)
if
err
!=
nil
{
// }
model
.
Log
.
Errorf
(
"AddSendGiftEventAsync groupSupport key:%s, err:%v"
,
keySupportNum
,
err
)
// }
}
//
}
// model.Log.Infof("CalcGroupSupport_OldData end")
// })
model
.
Log
.
Infof
(
"CalcGroupSupport_OldData end"
)
//
})
// c.Start()
//}
c
.
Start
()
}
cron/mic_cron/on_mic.go
View file @
577a8fef
package
mic_cron
package
mic_cron
import
(
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"github.com/robfig/cron"
"hilo-group/_const/redis_key/mic_k"
"hilo-group/domain/cache/mic_c"
"hilo-group/domain/cache/mic_c"
"hilo-group/domain/event/mic_ev"
"hilo-group/domain/event/mic_ev"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/mic_m"
"hilo-group/domain/model/mic_m"
"hilo-group/domain/service/group_mic_s"
"hilo-group/domain/service/group_mic_s"
"time"
)
)
func
OnMicCheck
()
{
func
OnMicCheck
()
{
c
:=
cron
.
New
()
c
:=
cron
.
New
()
//一分钟执行一次
//一分钟执行一次
spec
:=
"0 */1 * * * ?"
spec
:=
"
3
0 */1 * * * ?"
_
=
c
.
AddFunc
(
spec
,
func
()
{
_
=
c
.
AddFunc
(
spec
,
func
()
{
//获取麦上的所有人
//获取麦上的所有人
var
model
=
domain
.
CreateModelNil
()
var
model
=
domain
.
CreateModelNil
()
...
@@ -23,6 +26,7 @@ func OnMicCheck() {
...
@@ -23,6 +26,7 @@ func OnMicCheck() {
return
return
}
}
for
_
,
groupId
:=
range
groupIds
{
for
_
,
groupId
:=
range
groupIds
{
onGroupMicKey
:=
mic_k
.
GetGroupOnMicUser
(
groupId
)
// 同步在mic上的人
//遍历每个麦位
//遍历每个麦位
for
i
:=
1
;
i
<=
group_m
.
MaxMicNum
;
i
++
{
for
i
:=
1
;
i
<=
group_m
.
MaxMicNum
;
i
++
{
micUser
,
err
:=
group_m
.
GetMicUser
(
model
,
groupId
,
i
)
micUser
,
err
:=
group_m
.
GetMicUser
(
model
,
groupId
,
i
)
...
@@ -40,6 +44,11 @@ func OnMicCheck() {
...
@@ -40,6 +44,11 @@ func OnMicCheck() {
});
err
!=
nil
{
});
err
!=
nil
{
model
.
Log
.
Errorf
(
"QueueOnMic fail:%v"
,
err
)
model
.
Log
.
Errorf
(
"QueueOnMic fail:%v"
,
err
)
}
}
// 设置mic上的人
model
.
Redis
.
HSet
(
model
,
onGroupMicKey
,
i
,
micUser
.
UserId
)
}
else
{
// 删除mic上的人
model
.
Redis
.
HDel
(
model
,
onGroupMicKey
,
fmt
.
Sprintf
(
"%d"
,
i
))
}
}
}
}
}
}
...
@@ -48,24 +57,28 @@ func OnMicCheck() {
...
@@ -48,24 +57,28 @@ func OnMicCheck() {
}
}
func
OnMicQueue
()
{
func
OnMicQueue
()
{
go
func
()
{
for
i
:=
0
;
i
<
4
;
i
++
{
for
true
{
go
func
()
{
model
:=
domain
.
CreateModelNil
()
for
true
{
if
onMic
:=
mic_c
.
BLPopQueueOnMic
(
model
);
onMic
!=
nil
{
model
:=
domain
.
CreateModelNil
()
// 群组上麦经验
if
onMic
:=
mic_c
.
BLPopQueueOnMic
(
model
);
onMic
!=
nil
{
if
err
:=
group_mic_s
.
NewGroupPowerService
(
model
.
MyContext
)
.
IncrGroupPowerOnMicExpAndTime
(
onMic
.
GroupUuid
,
onMic
.
UserId
,
onMic
.
Timestamp
);
err
!=
nil
{
start
:=
time
.
Now
()
model
.
Log
.
Errorf
(
"cron micIn GroupPowerOnMicExp err:%v"
,
err
)
// 群组上麦经验
}
else
{
if
err
:=
group_mic_s
.
NewGroupPowerService
(
model
.
MyContext
)
.
IncrGroupPowerOnMicExpAndTime
(
onMic
.
GroupUuid
,
onMic
.
UserId
,
onMic
.
Timestamp
);
err
!=
nil
{
model
.
Log
.
Infof
(
"cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v"
,
onMic
.
GroupUuid
,
onMic
.
UserId
)
model
.
Log
.
Errorf
(
"cron micIn GroupPowerOnMicExp err:%v"
,
err
)
}
}
else
{
model
.
Log
.
Infof
(
"cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v,cost:%vs"
,
onMic
.
GroupUuid
,
onMic
.
UserId
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
}
// 用户上麦
// 用户上麦
if
err
:=
mic_m
.
IncrUserOnMic
(
model
,
onMic
.
UserId
,
onMic
.
Timestamp
);
err
!=
nil
{
//if err := mic_m.IncrUserOnMic(model, onMic.UserId, onMic.Timestamp); err != nil {
model
.
Log
.
Errorf
(
"cron micIn IncrUserOnMic err:%v"
,
err
)
//if err := mic_m.IncrUserOnMicV2(model, onMic.UserId); err != nil {
}
else
{
if
err
:=
mic_m
.
IncrUserOnMicV3
(
model
,
onMic
.
UserId
);
err
!=
nil
{
model
.
Log
.
Infof
(
"cron micIn IncrUserOnMic success,userId:%v"
,
onMic
.
UserId
)
model
.
Log
.
Errorf
(
"cron micIn IncrUserOnMic err:%v"
,
err
)
}
else
{
}
}
}
}
}
}
}
()
}
()
}
}
}
cron/user_cron/svip_vip_noble.go
0 → 100644
View file @
577a8fef
package
user_cron
import
(
"git.hilo.cn/hilo-common/domain"
"github.com/robfig/cron"
"hilo-group/domain/cache/user_c"
)
// 加载数据到lru
func
LoadSvipVipNoble
()
{
go
user_c
.
LoadAllSvipVipNoble
(
domain
.
CreateModelNil
())
// 启动先执行一次
c
:=
cron
.
New
()
spec
:=
"0 */30 * * * ?"
_
=
c
.
AddFunc
(
spec
,
func
()
{
model
:=
domain
.
CreateModelNil
()
user_c
.
LoadAllSvipVipNoble
(
model
)
})
c
.
Start
()
}
cv/group_cv/group.go
View file @
577a8fef
...
@@ -445,40 +445,220 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGrou
...
@@ -445,40 +445,220 @@ func BuildJoinedGroupInfo(myService *domain.Service, myUserId uint64, originGrou
return
result
,
len
(
groupInfo
),
nil
return
result
,
len
(
groupInfo
),
nil
}
}
func
BuildPopularGroupInfo
(
model
*
domain
.
Model
,
myUserId
uint64
,
groupInfo
[]
*
group_m
.
GroupInfo
)
([]
*
PopularGroupInfo
,
error
)
{
// 填充用户最近进房
groupIds
:=
make
([]
string
,
0
,
len
(
groupInfo
))
func
BuildRecentGroupInfo
(
myService
*
domain
.
Service
,
myUserId
uint64
,
originGroupIds
[]
string
,
roomEnterTime
map
[
string
]
int64
)
([]
JoinedGroupInfo
,
int
,
error
)
{
for
_
,
v
:=
range
groupInfo
{
model
:=
domain
.
CreateModel
(
myService
.
CtxAndDb
)
groupIds
=
append
(
groupIds
,
v
.
ImGroupId
)
groupInfo
,
err
:=
group_m
.
BatchGetGroupInfo
(
model
,
originGroupIds
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
var
groupIds
[]
string
for
_
,
groupId
:=
range
originGroupIds
{
if
group
,
ok
:=
groupInfo
[
groupId
];
ok
{
if
group
.
IsGameRoom
==
0
{
groupIds
=
append
(
groupIds
,
groupId
)
}
}
}
if
len
(
groupIds
)
<=
0
{
return
nil
,
0
,
nil
}
}
//
roomMicUserMap不影响排序
//
获取群组中上麦用户
roomMicUserMap
,
err
:=
group_m
.
BatchGetAllMicUser
(
model
,
groupIds
)
roomMicUserMap
,
err
:=
group_m
.
BatchGetAllMicUser
(
model
,
groupIds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
0
,
err
}
}
uids
:=
make
([]
uint64
,
0
)
uids
:=
make
([]
uint64
,
0
)
micUsersMap
:=
make
(
map
[
string
][]
uint64
,
0
)
micUsersMap
:=
make
(
map
[
string
][]
uint64
,
0
)
for
_
,
v
:=
range
groupInfo
{
for
_
,
i
:=
range
groupInfo
{
micUsersMap
[
v
.
ImGroupId
]
=
make
([]
uint64
,
0
)
micUsersMap
[
i
.
ImGroupId
]
=
make
([]
uint64
,
0
)
if
len
(
v
.
Password
)
<=
0
{
if
len
(
i
.
Password
)
<=
0
{
// 密码群不显示麦上头像
// 密码群不显示麦上头像
u
:=
roomMicUserMap
[
v
.
ImGroupId
]
u
:=
roomMicUserMap
[
i
.
ImGroupId
]
if
len
(
u
)
>=
4
{
if
len
(
u
)
>=
4
{
micUsersMap
[
v
.
ImGroupId
]
=
u
[
0
:
4
]
micUsersMap
[
i
.
ImGroupId
]
=
u
[
0
:
4
]
}
else
if
len
(
u
)
>
0
{
}
else
if
len
(
u
)
>
0
{
micUsersMap
[
v
.
ImGroupId
]
=
u
micUsersMap
[
i
.
ImGroupId
]
=
u
}
}
uids
=
append
(
uids
,
micUsersMap
[
v
.
ImGroupId
]
...
)
uids
=
append
(
uids
,
micUsersMap
[
i
.
ImGroupId
]
...
)
}
}
}
}
uids
=
utils
.
UniqueSliceUInt64
(
uids
)
uids
=
utils
.
UniqueSliceUInt64
(
uids
)
userTiny
,
err
:=
user_cv
.
GetUserTinyMap
(
uids
)
userTiny
,
err
:=
user_cv
.
GetUserTinyMap
(
uids
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
0
,
err
}
}
roomCount
,
err
:=
group_m
.
BatchGetRoomCount
(
model
,
groupIds
)
roomCount
,
err
:=
group_m
.
BatchGetRoomCount
(
model
,
groupIds
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
countryInfo
,
err
:=
res_c
.
GetCountryIconMap
(
model
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
supportLevels
,
err
:=
group_s
.
NewGroupService
(
model
.
MyContext
)
.
GetWeekMaxSupportLevelMap
()
if
err
!=
nil
{
return
nil
,
0
,
err
}
visitCount
,
err
:=
group_m
.
BatchGetRoomVisitCount
(
model
.
Log
,
groupIds
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
// 排序优先级V8.0版本
sort
.
Slice
(
groupIds
,
func
(
i
,
j
int
)
bool
{
gi
:=
groupIds
[
i
]
gj
:=
groupIds
[
j
]
return
roomEnterTime
[
gi
]
>
roomEnterTime
[
gj
]
||
roomEnterTime
[
gi
]
==
roomEnterTime
[
gj
]
&&
visitCount
[
gj
]
>
visitCount
[
gj
]
||
roomEnterTime
[
gi
]
==
roomEnterTime
[
gj
]
&&
visitCount
[
gj
]
==
visitCount
[
gj
]
&&
i
>=
j
})
result
:=
make
([]
JoinedGroupInfo
,
0
)
owners
:=
make
([]
uint64
,
0
)
for
_
,
i
:=
range
groupIds
{
owners
=
append
(
owners
,
groupInfo
[
i
]
.
Owner
)
}
powerIds
,
powerNames
,
powerNameplates
,
powerGrades
,
err
:=
group_power_cv
.
BatchGetGroupPower
(
model
.
Db
,
owners
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
groupMedals
,
err
:=
group_m
.
BatchGetMedals
(
model
.
Db
,
groupIds
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
resMedal
,
err
:=
res_m
.
MedalGetAllMap
(
model
.
Db
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
rr
:=
rocket_m
.
RocketResult
{}
maxStageMap
,
err
:=
rr
.
GetMaxStage
(
model
.
Db
,
groupIds
)
if
err
!=
nil
{
return
nil
,
0
,
err
}
// 正在进行的游戏
games
:=
game_m
.
GetNotEndGamesMap
(
model
)
for
_
,
i
:=
range
groupIds
{
g
:=
groupInfo
[
i
]
micUsers
:=
make
([]
user_cv
.
CvUserTiny
,
0
)
for
_
,
j
:=
range
micUsersMap
[
i
]
{
micUsers
=
append
(
micUsers
,
userTiny
[
j
])
}
var
maxStage
*
uint16
=
nil
if
s
,
ok
:=
maxStageMap
[
i
];
ok
{
maxStage
=
&
s
}
medals
:=
make
([]
medal_cv
.
PicElement
,
0
)
// 补上房间流水勋章
var
pe
*
medal_cv
.
PicElement
_
,
pe
,
err
=
medal_cv
.
GetGroupConsumeMedal
(
model
,
i
)
if
err
!=
nil
{
model
.
Log
.
Infof
(
"BuildJoinedGroupInfo: GetGroupConsumeMedal: %s"
,
err
.
Error
())
}
else
if
pe
!=
nil
{
medals
=
append
(
medals
,
medal_cv
.
PicElement
{
PicUrl
:
pe
.
PicUrl
})
}
// res_medal
if
m
,
ok
:=
groupMedals
[
i
];
ok
{
for
_
,
j
:=
range
m
{
mId
:=
uint32
(
j
)
if
e
,
ok
:=
resMedal
[
mId
];
ok
{
medals
=
append
(
medals
,
medal_cv
.
PicElement
{
PicUrl
:
e
.
PicUrl
,
})
}
}
}
var
password
*
string
=
nil
if
len
(
g
.
Password
)
>
0
&&
g
.
Owner
!=
myUserId
{
emptyStr
:=
""
password
=
&
emptyStr
}
result
=
append
(
result
,
JoinedGroupInfo
{
PopularGroupInfo
:
PopularGroupInfo
{
GroupInfo
:
GroupInfo
{
GroupBasicInfo
:
GroupBasicInfo
{
GroupId
:
g
.
TxGroupId
,
Name
:
g
.
Name
,
Notification
:
g
.
Notification
,
Introduction
:
g
.
Introduction
,
FaceUrl
:
g
.
FaceUrl
,
Code
:
g
.
Code
,
CountryIcon
:
countryInfo
[
g
.
Country
],
Password
:
password
,
SupportLevel
:
supportLevels
[
i
],
GroupInUserDuration
:
visitCount
[
i
],
MicNumType
:
int
(
g
.
MicNumType
),
GroupMedals
:
medals
,
},
HasOnMic
:
len
(
micUsers
)
>
0
,
GroupPowerId
:
powerIds
[
g
.
Owner
],
GroupPowerName
:
powerNames
[
g
.
Owner
],
GroupPowerNameplate
:
powerNameplates
[
g
.
Owner
],
GroupPower
:
GroupPower
{
Id
:
powerIds
[
g
.
Owner
],
Name
:
powerNames
[
g
.
Owner
],
Nameplate
:
powerNameplates
[
g
.
Owner
],
Grade
:
powerGrades
[
g
.
Owner
],
},
},
MicUsers
:
micUsers
,
RoomUserCount
:
uint
(
roomCount
[
i
]),
MaxStage
:
maxStage
,
GameTypes
:
games
[
g
.
TxGroupId
],
},
LastEnterTime
:
roomEnterTime
[
i
],
})
}
return
result
,
len
(
groupInfo
),
nil
}
func
BuildPopularGroupInfo
(
model
*
domain
.
Model
,
myUserId
uint64
,
groupInfo
[]
*
group_m
.
GroupInfo
)
([]
*
PopularGroupInfo
,
error
)
{
groupIds
:=
make
([]
string
,
0
,
len
(
groupInfo
))
for
_
,
v
:=
range
groupInfo
{
groupIds
=
append
(
groupIds
,
v
.
ImGroupId
)
}
// roomMicUserMap不影响排序
//roomMicUserMap, err := group_m.BatchGetAllMicUser(model, groupIds)
//if err != nil {
// return nil, err
//}
//uids := make([]uint64, 0)
//micUsersMap := make(map[string][]uint64, 0)
//for _, v := range groupInfo {
// micUsersMap[v.ImGroupId] = make([]uint64, 0)
//
// if len(v.Password) <= 0 {
// // 密码群不显示麦上头像
// u := roomMicUserMap[v.ImGroupId]
// if len(u) >= 4 {
// micUsersMap[v.ImGroupId] = u[0:4]
// } else if len(u) > 0 {
// micUsersMap[v.ImGroupId] = u
// }
// uids = append(uids, micUsersMap[v.ImGroupId]...)
// }
//}
//uids = utils.UniqueSliceUInt64(uids)
//userTiny, err := user_cv.GetUserTinyMap(uids)
//if err != nil {
// return nil, err
//}
roomCount
,
err
:=
group_m
.
BatchGetRoomCount
(
model
,
groupIds
)
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
@@ -546,10 +726,10 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
...
@@ -546,10 +726,10 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
for
_
,
v
:=
range
groupInfo
{
for
_
,
v
:=
range
groupInfo
{
g
:=
v
g
:=
v
i
:=
v
.
ImGroupId
i
:=
v
.
ImGroupId
micUsers
:=
make
([]
user_cv
.
CvUserTiny
,
0
)
//
micUsers := make([]user_cv.CvUserTiny, 0)
for
_
,
j
:=
range
micUsersMap
[
i
]
{
//
for _, j := range micUsersMap[i] {
micUsers
=
append
(
micUsers
,
userTiny
[
j
])
//
micUsers = append(micUsers, userTiny[j])
}
//
}
var
maxStage
*
uint16
=
nil
var
maxStage
*
uint16
=
nil
if
s
,
ok
:=
maxStageMap
[
i
];
ok
{
if
s
,
ok
:=
maxStageMap
[
i
];
ok
{
...
@@ -598,7 +778,7 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
...
@@ -598,7 +778,7 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
MicNumType
:
int
(
g
.
MicNumType
),
MicNumType
:
int
(
g
.
MicNumType
),
GroupMedals
:
medals
,
GroupMedals
:
medals
,
},
},
HasOnMic
:
len
(
micUsers
)
>
0
,
//
HasOnMic: len(micUsers) > 0,
GroupPowerId
:
powerIds
[
g
.
Owner
],
GroupPowerId
:
powerIds
[
g
.
Owner
],
GroupPowerName
:
powerNames
[
g
.
Owner
],
GroupPowerName
:
powerNames
[
g
.
Owner
],
GroupPowerNameplate
:
powerNameplates
[
g
.
Owner
],
GroupPowerNameplate
:
powerNameplates
[
g
.
Owner
],
...
@@ -609,7 +789,7 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
...
@@ -609,7 +789,7 @@ func BuildPopularGroupInfo(model *domain.Model, myUserId uint64, groupInfo []*gr
Grade
:
powerGrades
[
g
.
Owner
],
Grade
:
powerGrades
[
g
.
Owner
],
},
},
},
},
MicUsers
:
micUsers
,
//
MicUsers: micUsers,
RoomUserCount
:
uint
(
roomCount
[
i
]),
RoomUserCount
:
uint
(
roomCount
[
i
]),
MaxStage
:
maxStage
,
MaxStage
:
maxStage
,
GameTypes
:
games
[
g
.
TxGroupId
],
GameTypes
:
games
[
g
.
TxGroupId
],
...
...
cv/user_cv/user.go
View file @
577a8fef
...
@@ -908,16 +908,122 @@ func GetUserDetail(model *domain.Model, userId mysql.ID, myUserId mysql.ID) (*Cv
...
@@ -908,16 +908,122 @@ func GetUserDetail(model *domain.Model, userId mysql.ID, myUserId mysql.ID) (*Cv
noble
,
superManagerMap
[
userId
],
myGroups
,
phoneInfo
,
thirdList
,
cvCountryManager
)
noble
,
superManagerMap
[
userId
],
myGroups
,
phoneInfo
,
thirdList
,
cvCountryManager
)
}
}
//群主信息
func
GetRoomInfoOwner
(
model
*
domain
.
Model
,
userId
mysql
.
ID
,
myUserId
mysql
.
ID
)
(
*
CvUserDetail
,
error
)
{
model
.
Log
.
Infof
(
"GetUserDetail %d begin"
,
userId
)
var
user
user_m
.
User
var
err
error
if
err
=
mysql
.
Db
.
First
(
&
user
,
userId
)
.
Error
;
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
var
wealthUserScore
user_m
.
MatchWealthUserScore
if
err
:=
mysql
.
Db
.
Model
(
&
user_m
.
MatchWealthUserScore
{})
.
Where
(
&
user_m
.
MatchWealthUserScore
{
UserId
:
userId
})
.
First
(
&
wealthUserScore
)
.
Error
;
err
!=
nil
{
if
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
wealthUserScore
=
user_m
.
MatchWealthUserScore
{
UserId
:
userId
,
Score
:
0
,
Grade
:
0
,
}
}
else
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
}
var
charmUserScore
user_m
.
MatchCharmUserScore
if
err
:=
mysql
.
Db
.
Model
(
&
user_m
.
MatchCharmUserScore
{})
.
Where
(
&
user_m
.
MatchCharmUserScore
{
UserId
:
userId
,
})
.
First
(
&
charmUserScore
)
.
Error
;
err
!=
nil
{
if
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
charmUserScore
=
user_m
.
MatchCharmUserScore
{
UserId
:
userId
,
Score
:
0
,
Grade
:
0
,
}
}
else
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
}
isVip
,
expireTime
,
err
:=
user_m
.
IsVip
(
userId
)
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
svip
,
err
:=
rpc
.
GetUserSvip
(
model
,
userId
)
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
medals
:=
make
(
map
[
uint64
][]
uint32
,
0
)
medals
[
userId
],
err
=
user_m
.
GetUserMedalMerge
(
model
.
Log
,
mysql
.
Db
,
userId
)
if
err
!=
nil
{
return
nil
,
err
}
medals
,
medalInfo
,
err
:=
medal_cv
.
GetMedalInfoMap
(
mysql
.
Db
,
medals
)
if
err
!=
nil
{
return
nil
,
err
}
groupPowerId
,
groupPowerName
,
err
:=
groupPower_m
.
GetUserGroupPower
(
model
,
userId
)
if
err
!=
nil
{
return
nil
,
err
}
powers
:=
map
[
mysql
.
ID
]
uint64
{
userId
:
groupPowerId
}
powerNames
:=
map
[
mysql
.
ID
]
string
{
userId
:
groupPowerName
}
groupPowerInfos
,
err
:=
groupPower_m
.
MGetGroupPowerInfoMap
(
model
,
[]
mysql
.
ID
{
groupPowerId
})
groupPowerGrades
,
err
:=
groupPower_m
.
MGetGroupPowerGrade
(
model
,
[]
mysql
.
ID
{
groupPowerId
})
groupPowerUsers
,
err
:=
groupPower_m
.
MGetGroupPowerUsers
(
model
,
[]
mysql
.
ID
{
groupPowerId
})
var
memberMax
int
grade
:=
groupPowerGrades
[
groupPowerId
]
.
Grade
if
grade
>=
groupPower_e
.
GroupPowerGrade0
&&
grade
<=
groupPower_e
.
GroupPowerGradeMax
{
if
grade
==
groupPower_e
.
GroupPowerGrade0
{
memberMax
=
300
}
if
grade
==
groupPower_e
.
GroupPowerGrade1
{
memberMax
=
500
}
if
grade
==
groupPower_e
.
GroupPowerGrade2
{
memberMax
=
800
}
if
grade
==
groupPower_e
.
GroupPowerGrade3
{
memberMax
=
1200
}
}
memberNum
:=
len
(
groupPowerUsers
[
groupPowerId
])
if
memberNum
>
memberMax
{
memberMax
=
memberNum
}
groupPowerMembers
:=
[
2
]
int
{
memberNum
,
memberMax
}
// 0->memberNum 1->memberLimit
noble
,
err
:=
noble_m
.
FindActiveNoble
(
mysql
.
Db
,
userId
)
if
err
!=
nil
{
return
nil
,
err
}
return
userToDetailOne
(
model
,
&
user
,
myUserId
,
nil
,
false
,
false
,
map
[
mysql
.
ID
]
Relation
{},
isVip
,
expireTime
,
svip
,
nil
,
property_cv
.
CvProperty
{},
wealthUserScore
.
Grade
,
charmUserScore
.
Grade
,
0
,
medals
[
userId
],
medalInfo
[
userId
],
""
,
powers
[
userId
],
powerNames
[
userId
],
groupPowerInfos
[
groupPowerId
],
groupPowerGrades
[
groupPowerId
],
groupPowerMembers
,
noble
,
false
,
nil
,
nil
,
nil
,
nil
)
}
// 单用户版,简化参数
// 单用户版,简化参数
func
userToDetailOne
(
model
*
domain
.
Model
,
user
*
user_m
.
User
,
myUserId
mysql
.
ID
,
userTradeUnion
*
user_m
.
UserTradeUnion
,
isLike
bool
,
likeMe
bool
,
hvMap
map
[
mysql
.
ID
]
Relation
,
func
userToDetailOne
(
model
*
domain
.
Model
,
user
*
user_m
.
User
,
myUserId
mysql
.
ID
,
userTradeUnion
*
user_m
.
UserTradeUnion
,
isLike
bool
,
likeMe
bool
,
hvMap
map
[
mysql
.
ID
]
Relation
,
isVip
bool
,
vipExpireTime
*
int64
,
svip
rpc
.
CvSvip
,
headwear
*
headwear_cv
.
CvHeadwear
,
ride
property_cv
.
CvProperty
,
wealthGrade
uint32
,
charmGrade
uint32
,
activityGrade
uint32
,
isVip
bool
,
vipExpireTime
*
int64
,
svip
rpc
.
CvSvip
,
headwear
*
headwear_cv
.
CvHeadwear
,
ride
property_cv
.
CvProperty
,
wealthGrade
uint32
,
charmGrade
uint32
,
activityGrade
uint32
,
medals
[]
uint32
,
medalInfo
[]
medal_cv
.
CvMedal
,
room
string
,
power
uint64
,
powerName
string
,
powerInfo
groupPower_m
.
GroupPowerInfo
,
grade
groupPower_m
.
GroupPowerGrade
,
members
[
2
]
int
,
noble
*
noble_m
.
UserNoble
,
isOfficialStaff
bool
,
medals
[]
uint32
,
medalInfo
[]
medal_cv
.
CvMedal
,
room
string
,
power
uint64
,
powerName
string
,
powerInfo
groupPower_m
.
GroupPowerInfo
,
grade
groupPower_m
.
GroupPowerGrade
,
members
[
2
]
int
,
noble
*
noble_m
.
UserNoble
,
isOfficialStaff
bool
,
myGroups
[]
group_m
.
GroupInfo
,
phoneInfo
*
user_m
.
UserPhoneInfo
,
thirdList
[]
int8
,
countryManager
*
country_cv
.
CVCountryManager
)
(
*
CvUserDetail
,
error
)
{
myGroups
[]
group_m
.
GroupInfo
,
phoneInfo
*
user_m
.
UserPhoneInfo
,
thirdList
[]
int8
,
countryManager
*
country_cv
.
CVCountryManager
)
(
*
CvUserDetail
,
error
)
{
room
,
err
:=
group_m
.
ToTxGroupId
(
model
,
room
)
if
len
(
room
)
>
0
{
if
err
!=
nil
{
var
err
error
model
.
Log
.
Warnf
(
"ToTxGroupId failed for %s, err:%v"
,
room
,
err
)
room
,
err
=
group_m
.
ToTxGroupId
(
model
,
room
)
room
=
""
if
err
!=
nil
{
model
.
Log
.
Warnf
(
"ToTxGroupId failed for %s, err:%v"
,
room
,
err
)
room
=
""
}
}
}
cvUserDetail
:=
&
CvUserDetail
{
cvUserDetail
:=
&
CvUserDetail
{
...
...
domain/cache/gift_c/gift_event.go
View file @
577a8fef
...
@@ -14,7 +14,7 @@ const EventSendGiftHiloGroupQueue = "send:gift:queue:hilo_group"
...
@@ -14,7 +14,7 @@ const EventSendGiftHiloGroupQueue = "send:gift:queue:hilo_group"
func
BLPopQueueSendGift
(
model
*
domain
.
Model
)
*
gift_ev
.
SendGiftEvent
{
func
BLPopQueueSendGift
(
model
*
domain
.
Model
)
*
gift_ev
.
SendGiftEvent
{
var
res
*
gift_ev
.
SendGiftEvent
var
res
*
gift_ev
.
SendGiftEvent
queue
:=
EventSendGiftHiloGroupQueue
queue
:=
EventSendGiftHiloGroupQueue
strs
,
err
:=
model
.
Redis
.
BLPop
(
model
,
time
.
Second
,
queue
)
.
Result
()
strs
,
err
:=
model
.
Redis
Cluster
.
BLPop
(
model
,
time
.
Second
,
queue
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
if
err
!=
redis
.
Nil
{
if
err
!=
redis
.
Nil
{
model
.
Log
.
Errorf
(
"BLPopQueueSendGift fail:%v"
,
err
)
model
.
Log
.
Errorf
(
"BLPopQueueSendGift fail:%v"
,
err
)
...
...
domain/cache/groupPower_c/group_power_grade.go
deleted
100644 → 0
View file @
cc2946f0
package
groupPower_c
import
(
"encoding/json"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/go-redis/redis/v8"
"hilo-group/_const/redis_key/groupPower_k"
"time"
)
type
GroupPowerGradeExp
struct
{
GroupPowerId
mysql
.
ID
Exp
mysql
.
Num
UserId
mysql
.
ID
Remark
string
Ts
int64
}
// 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
,
Ts
:
time
.
Now
()
.
Unix
(),
}
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
{
if
err
!=
redis
.
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
}
domain/cache/groupPower_c/group_power_star.go
0 → 100644
View file @
577a8fef
package
groupPower_c
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/go-redis/redis/v8"
"github.com/jinzhu/now"
"github.com/pkg/errors"
"github.com/spf13/cast"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/redis_key/groupPower_k"
"time"
)
// 家族之星-排名
type
GroupPowerStarRank
struct
{
Period
string
GroupPowerId
mysql
.
ID
UserId
mysql
.
ID
Type
groupPower_e
.
GroupPowerStarType
Score
mysql
.
Num
}
// 增加家族之星分数
func
IncrGroupPowerDayStarScore
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
score
mysql
.
Num
)
error
{
ttl
:=
map
[
string
]
time
.
Duration
{
"day"
:
time
.
Hour
*
24
*
7
,
"week"
:
time
.
Hour
*
24
*
7
*
30
,
"month"
:
time
.
Hour
*
24
*
7
*
30
*
2
,
}
for
_
,
period
:=
range
[]
string
{
"day"
,
"week"
,
"month"
}
{
date
:=
""
switch
period
{
case
"day"
:
date
=
time
.
Now
()
.
Format
(
"2006-01-02"
)
case
"week"
:
date
=
now
.
BeginningOfWeek
()
.
Format
(
"2006-01-02"
)
case
"month"
:
date
=
now
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
)
}
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
_type
,
period
,
groupPowerId
,
date
)
model
.
RedisCluster
.
ZIncrBy
(
model
,
key
,
float64
(
score
),
fmt
.
Sprintf
(
"%d"
,
userId
))
model
.
RedisCluster
.
Expire
(
model
,
key
,
ttl
[
period
])
}
return
nil
}
// 获取家族之星排行
// param period: day|week|month
func
GetGroupPowerStarRankPeriod
(
model
*
domain
.
Model
,
period
string
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
,
targetDate
...
string
)
([]
*
GroupPowerStarRank
,
error
)
{
var
res
[]
*
GroupPowerStarRank
date
:=
""
switch
period
{
case
"day"
:
date
=
time
.
Now
()
.
Format
(
"2006-01-02"
)
case
"week"
:
date
=
now
.
BeginningOfWeek
()
.
Format
(
"2006-01-02"
)
case
"month"
:
date
=
now
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
)
}
if
len
(
date
)
<=
0
{
return
res
,
errors
.
New
(
"illegal date"
)
}
if
len
(
targetDate
)
>
0
{
date
=
targetDate
[
0
]
}
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
_type
,
period
,
groupPowerId
,
date
)
rows
,
err
:=
model
.
RedisCluster
.
ZRevRangeByScoreWithScores
(
model
,
key
,
&
redis
.
ZRangeBy
{
Min
:
"-inf"
,
Max
:
"+inf"
,
Offset
:
int64
(
offset
),
Count
:
int64
(
limit
),
})
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetGroupPowerStarRankPeriod fail:%v"
,
err
)
return
res
,
err
}
for
_
,
v
:=
range
rows
{
res
=
append
(
res
,
&
GroupPowerStarRank
{
Period
:
period
,
GroupPowerId
:
groupPowerId
,
UserId
:
cast
.
ToUint64
(
v
.
Member
),
Type
:
_type
,
Score
:
mysql
.
Num
(
v
.
Score
),
})
}
return
res
,
nil
}
// 获取家族之星三个排行榜的各自第一名
func
GetGroupPowerMonthStartTop1
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
)
([]
*
GroupPowerStarRank
,
error
)
{
var
res
[]
*
GroupPowerStarRank
r1
,
err
:=
GetGroupPowerStarRankPeriod
(
model
,
"month"
,
groupPowerId
,
groupPower_e
.
GroupPowerStarTypeFamous
,
0
,
1
)
if
err
!=
nil
{
return
res
,
err
}
r2
,
err
:=
GetGroupPowerStarRankPeriod
(
model
,
"month"
,
groupPowerId
,
groupPower_e
.
GroupPowerStarTypeActive
,
0
,
1
)
if
err
!=
nil
{
return
res
,
err
}
r3
,
err
:=
GetGroupPowerStarRankPeriod
(
model
,
"month"
,
groupPowerId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
0
,
1
)
if
err
!=
nil
{
return
res
,
err
}
res
=
append
(
res
,
r1
...
)
res
=
append
(
res
,
r2
...
)
res
=
append
(
res
,
r3
...
)
return
res
,
nil
}
domain/cache/group_c/enter_room.go
View file @
577a8fef
...
@@ -4,6 +4,7 @@ import (
...
@@ -4,6 +4,7 @@ import (
"fmt"
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"github.com/go-redis/redis/v8"
"github.com/go-redis/redis/v8"
"github.com/spf13/cast"
"hilo-group/_const/redis_key/group_k"
"hilo-group/_const/redis_key/group_k"
"strconv"
"strconv"
"time"
"time"
...
@@ -49,16 +50,23 @@ func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint6
...
@@ -49,16 +50,23 @@ func GetLastRoomVisitors(model *domain.Model, imGroupId string) (userIds []uint6
// 获取最近进入的房间
// 获取最近进入的房间
// 3个月
// 3个月
func
GetUserRecentRooms
(
model
*
domain
.
Model
,
userId
uint64
)
(
imGroupIds
[]
string
)
{
func
GetUserRecentRooms
(
model
*
domain
.
Model
,
userId
uint64
,
offset
,
limit
int64
)
(
imGroupIds
[]
string
,
roomEnterTime
map
[
string
]
int64
)
{
roomEnterTime
=
make
(
map
[
string
]
int64
)
userKey
:=
group_k
.
GetUserEnterRoomUserKey
(
userId
)
userKey
:=
group_k
.
GetUserEnterRoomUserKey
(
userId
)
var
err
error
res
,
err
:=
model
.
Redis
.
ZRevRangeByScoreWithScores
(
model
,
userKey
,
&
redis
.
ZRangeBy
{
imGroupIds
,
err
=
model
.
Redis
.
ZRangeByScore
(
model
,
userKey
,
&
redis
.
ZRangeBy
{
Min
:
fmt
.
Sprintf
(
"%d"
,
time
.
Now
()
.
AddDate
(
0
,
-
3
,
0
)
.
Unix
()),
Min
:
fmt
.
Sprintf
(
"%d"
,
time
.
Now
()
.
AddDate
(
0
,
-
3
,
0
)
.
Unix
()),
Max
:
"+inf"
,
Max
:
"+inf"
,
Offset
:
offset
,
Count
:
limit
,
})
.
Result
()
})
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
return
}
}
for
_
,
v
:=
range
res
{
imGroupId
:=
cast
.
ToString
(
v
.
Member
)
imGroupIds
=
append
(
imGroupIds
,
imGroupId
)
roomEnterTime
[
imGroupId
]
=
int64
(
v
.
Score
)
}
return
return
}
}
...
...
domain/cache/group_c/group.go
View file @
577a8fef
...
@@ -83,17 +83,17 @@ func SetGroupMemberTTL(groupId string, ttl time.Duration) (bool, error) {
...
@@ -83,17 +83,17 @@ func SetGroupMemberTTL(groupId string, ttl time.Duration) (bool, error) {
func
GetGroupConsume
(
groupId
string
)
(
uint64
,
error
)
{
func
GetGroupConsume
(
groupId
string
)
(
uint64
,
error
)
{
key
:=
getGroupConsumeKey
(
groupId
)
key
:=
getGroupConsumeKey
(
groupId
)
return
redisCli
.
RedisClient
.
Get
(
context
.
Background
(),
key
)
.
Uint64
()
return
redisCli
.
RedisCl
usterCl
ient
.
Get
(
context
.
Background
(),
key
)
.
Uint64
()
}
}
func
SetGroupConsume
(
groupId
string
,
consume
uint64
,
ttl
time
.
Duration
)
error
{
func
SetGroupConsume
(
groupId
string
,
consume
uint64
,
ttl
time
.
Duration
)
error
{
key
:=
getGroupConsumeKey
(
groupId
)
key
:=
getGroupConsumeKey
(
groupId
)
return
redisCli
.
RedisClient
.
Set
(
context
.
Background
(),
key
,
consume
,
ttl
)
.
Err
()
return
redisCli
.
RedisCl
usterCl
ient
.
Set
(
context
.
Background
(),
key
,
consume
,
ttl
)
.
Err
()
}
}
func
ClearGroupConsume
(
groupId
string
)
error
{
func
ClearGroupConsume
(
groupId
string
)
error
{
key
:=
getGroupConsumeKey
(
groupId
)
key
:=
getGroupConsumeKey
(
groupId
)
return
redisCli
.
RedisClient
.
Del
(
context
.
Background
(),
key
)
.
Err
()
return
redisCli
.
RedisCl
usterCl
ient
.
Del
(
context
.
Background
(),
key
)
.
Err
()
}
}
// 增加编辑用户cd
// 增加编辑用户cd
...
...
domain/cache/mic_c/queue.go
View file @
577a8fef
...
@@ -14,14 +14,14 @@ func QueueOnMic(model *domain.Model, onMic *mic_ev.OnMicEvent) error {
...
@@ -14,14 +14,14 @@ func QueueOnMic(model *domain.Model, onMic *mic_ev.OnMicEvent) error {
queue
:=
mic_k
.
GetOnMicQueue
()
queue
:=
mic_k
.
GetOnMicQueue
()
onMic
.
Ts
=
time
.
Now
()
.
UnixNano
()
// 给一个时间戳
onMic
.
Ts
=
time
.
Now
()
.
UnixNano
()
// 给一个时间戳
body
,
_
:=
json
.
Marshal
(
onMic
)
body
,
_
:=
json
.
Marshal
(
onMic
)
return
model
.
Redis
.
RPush
(
model
,
queue
,
string
(
body
))
.
Err
()
return
model
.
Redis
Cluster
.
RPush
(
model
,
queue
,
string
(
body
))
.
Err
()
}
}
// redis pop on mic
// redis pop on mic
func
BLPopQueueOnMic
(
model
*
domain
.
Model
)
*
mic_ev
.
OnMicEvent
{
func
BLPopQueueOnMic
(
model
*
domain
.
Model
)
*
mic_ev
.
OnMicEvent
{
var
res
*
mic_ev
.
OnMicEvent
var
res
*
mic_ev
.
OnMicEvent
queue
:=
mic_k
.
GetOnMicQueue
()
queue
:=
mic_k
.
GetOnMicQueue
()
strs
,
err
:=
model
.
Redis
.
BLPop
(
model
,
time
.
Second
,
queue
)
.
Result
()
strs
,
err
:=
model
.
Redis
Cluster
.
BLPop
(
model
,
time
.
Second
,
queue
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
if
err
!=
redis
.
Nil
{
if
err
!=
redis
.
Nil
{
model
.
Log
.
Errorf
(
"BLPopQueueOnMic fail:%v"
,
err
)
model
.
Log
.
Errorf
(
"BLPopQueueOnMic fail:%v"
,
err
)
...
...
domain/cache/modelRedis.go
View file @
577a8fef
...
@@ -27,17 +27,17 @@ func SetJSON(model *domain.Model, key string, obj interface{}) (err error) {
...
@@ -27,17 +27,17 @@ func SetJSON(model *domain.Model, key string, obj interface{}) (err error) {
if
err
!=
nil
{
if
err
!=
nil
{
return
err
return
err
}
}
return
model
.
Redis
.
Set
(
model
.
Context
,
key
,
value
,
DEFAULT_TTL
)
.
Err
()
return
model
.
Redis
Cluster
.
Set
(
model
.
Context
,
key
,
value
,
DEFAULT_TTL
)
.
Err
()
}
}
// 获取redis中json结构体
// 获取redis中json结构体
// return err: may redisV8.Nil
// return err: may redisV8.Nil
func
GetJSON
(
model
*
domain
.
Model
,
key
string
,
obj
interface
{})
(
err
error
)
{
func
GetJSON
(
model
*
domain
.
Model
,
key
string
,
obj
interface
{})
(
err
error
)
{
var
value
[]
byte
var
value
[]
byte
defer
func
()
{
//
defer func() {
model
.
Log
.
Infof
(
"GetJson key:%v,value:%s,obj:%v,err:%v"
,
key
,
value
,
obj
,
err
)
//
model.Log.Infof("GetJson key:%v,value:%s,obj:%v,err:%v", key, value, obj, err)
}()
//
}()
value
,
err
=
model
.
Redis
.
Get
(
model
.
Context
,
key
)
.
Bytes
()
value
,
err
=
model
.
Redis
Cluster
.
Get
(
model
.
Context
,
key
)
.
Bytes
()
if
err
!=
nil
{
if
err
!=
nil
{
// may redisV2.Nil
// may redisV2.Nil
return
return
...
@@ -59,7 +59,7 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
...
@@ -59,7 +59,7 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
if
time
.
Now
()
.
After
(
deadline
)
{
if
time
.
Now
()
.
After
(
deadline
)
{
return
false
return
false
}
}
flag
,
err
:=
model
.
Redis
.
SetNX
(
model
,
key
,
"1"
,
expireTimeout
)
.
Result
()
flag
,
err
:=
model
.
Redis
Cluster
.
SetNX
(
model
,
key
,
"1"
,
expireTimeout
)
.
Result
()
if
err
!=
nil
||
!
flag
{
if
err
!=
nil
||
!
flag
{
time
.
Sleep
(
time
.
Millisecond
*
10
)
time
.
Sleep
(
time
.
Millisecond
*
10
)
}
else
{
}
else
{
...
@@ -70,5 +70,5 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
...
@@ -70,5 +70,5 @@ func TryLock(model *domain.Model, key string, acquireTimeout, expireTimeout time
// 解锁
// 解锁
func
UnLock
(
model
*
domain
.
Model
,
key
string
)
{
func
UnLock
(
model
*
domain
.
Model
,
key
string
)
{
model
.
Redis
.
Del
(
model
,
key
)
model
.
Redis
Cluster
.
Del
(
model
,
key
)
}
}
domain/cache/res_c/country.go
View file @
577a8fef
package
res_c
package
res_c
import
(
import
(
"context"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"
hilo-group/_const/redis_key
"
"
github.com/bluele/gcache
"
"hilo-group/domain/model/res_m"
"hilo-group/domain/model/res_m"
"time"
"time"
)
)
// 统一改成lru
var
countryIconLru
=
gcache
.
New
(
1000
)
.
LRU
()
.
Build
()
var
countryIconKey
=
"country:icon"
var
countryAreaLru
=
gcache
.
New
(
1000
)
.
LRU
()
.
Build
()
var
countryAreaKey
=
"country:area"
func
GetCountryIconMap
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
func
GetCountryIconMap
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
m
,
err
:=
GetAllCountryIcon
(
model
)
m
,
err
:=
GetAllCountryIcon
(
model
)
if
err
!=
nil
||
len
(
m
)
<=
0
{
if
err
!=
nil
||
len
(
m
)
<=
0
{
...
@@ -24,17 +30,22 @@ func GetCountryIconMap(model *domain.Model) (map[string]string, error) {
...
@@ -24,17 +30,22 @@ func GetCountryIconMap(model *domain.Model) (map[string]string, error) {
}
}
func
GetAllCountryIcon
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
func
GetAllCountryIcon
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
key
:=
redis_key
.
GetCountryIconKey
()
//key := redis_key.GetCountryIconKey()
return
model
.
Redis
.
HGetAll
(
context
.
Background
(),
key
)
.
Result
()
if
data
,
err
:=
countryIconLru
.
Get
(
countryIconKey
);
err
==
nil
{
return
data
.
(
map
[
string
]
string
),
nil
}
//return model.Redis.HGetAll(context.Background(), key).Result()
return
map
[
string
]
string
{},
nil
}
}
func
SaveAllCountryIcon
(
model
*
domain
.
Model
,
icons
map
[
string
]
string
)
(
int64
,
error
)
{
func
SaveAllCountryIcon
(
model
*
domain
.
Model
,
icons
map
[
string
]
string
)
{
key
:=
redis_key
.
GetCountryIconKey
()
//key := redis_key.GetCountryIconKey()
ret
,
err
:=
model
.
Redis
.
HSet
(
context
.
Background
(),
key
,
icons
)
.
Result
()
//ret, err := model.Redis.HSet(context.Background(), key, icons).Result()
if
err
==
nil
{
//if err == nil {
model
.
Redis
.
Expire
(
context
.
Background
(),
key
,
time
.
Minute
*
10
)
// model.Redis.Expire(context.Background(), key, time.Minute*10)
}
//}
return
ret
,
err
//return ret, err
_
=
countryIconLru
.
SetWithExpire
(
countryIconKey
,
icons
,
time
.
Minute
*
10
)
}
}
func
GetCountryAreaMap
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
func
GetCountryAreaMap
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
...
@@ -53,15 +64,20 @@ func GetCountryAreaMap(model *domain.Model) (map[string]string, error) {
...
@@ -53,15 +64,20 @@ func GetCountryAreaMap(model *domain.Model) (map[string]string, error) {
}
}
func
GetAllCountryArea
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
func
GetAllCountryArea
(
model
*
domain
.
Model
)
(
map
[
string
]
string
,
error
)
{
key
:=
redis_key
.
GetCountryAreaKey
()
//key := redis_key.GetCountryAreaKey()
return
model
.
Redis
.
HGetAll
(
context
.
Background
(),
key
)
.
Result
()
//return model.Redis.HGetAll(context.Background(), key).Result()
if
data
,
err
:=
countryAreaLru
.
Get
(
countryAreaKey
);
err
==
nil
{
return
data
.
(
map
[
string
]
string
),
nil
}
return
map
[
string
]
string
{},
nil
}
}
func
SaveAllCountryArea
(
model
*
domain
.
Model
,
data
map
[
string
]
string
)
(
int64
,
error
)
{
func
SaveAllCountryArea
(
model
*
domain
.
Model
,
data
map
[
string
]
string
)
{
key
:=
redis_key
.
GetCountryAreaKey
()
//key := redis_key.GetCountryAreaKey()
ret
,
err
:=
model
.
Redis
.
HSet
(
context
.
Background
(),
key
,
data
)
.
Result
()
//ret, err := model.Redis.HSet(context.Background(), key, data).Result()
if
err
==
nil
{
//if err == nil {
model
.
Redis
.
Expire
(
context
.
Background
(),
key
,
time
.
Minute
*
10
)
// model.Redis.Expire(context.Background(), key, time.Minute*10)
}
//}
return
ret
,
err
//return ret, err
_
=
countryAreaLru
.
SetWithExpire
(
countryAreaKey
,
data
,
time
.
Minute
*
10
)
}
}
domain/cache/room_c/userRoomVisit.go
View file @
577a8fef
...
@@ -2,42 +2,44 @@ package room_c
...
@@ -2,42 +2,44 @@ package room_c
import
(
import
(
"context"
"context"
"errors"
"fmt"
"fmt"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/resource/redisCli"
"github.com/bluele/gcache"
redis2
"github.com/go-redis/redis/v8"
redis2
"github.com/go-redis/redis/v8"
"github.com/spf13/cast"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key"
"
strconv
"
"
hilo-group/_const/redis_key/group_k
"
"time"
"time"
)
)
// 处理访问房间的相关缓存
// 处理访问房间的相关缓存
func
ProcessRoomVisit
(
groupId
string
,
userId
uint64
)
error
{
func
ProcessRoomVisit
(
groupId
string
,
userId
uint64
)
error
{
key
:=
redis_key
.
GetPrefixGroupInUserDuration
(
groupId
)
//
key := redis_key.GetPrefixGroupInUserDuration(groupId)
now
:=
time
.
Now
()
//
now := time.Now()
ret
,
err
:=
redisCli
.
GetRedis
()
.
ZAdd
(
context
.
Background
(),
key
,
&
redis2
.
Z
{
//
ret, err := redisCli.GetRedis().ZAdd(context.Background(), key, &redis2.Z{
Score
:
float64
(
now
.
Unix
()),
//
Score: float64(now.Unix()),
Member
:
userId
,
//
Member: userId,
})
.
Result
()
//
}).Result()
if
err
!=
nil
{
//
if err != nil {
return
err
//
return err
}
//
}
mylogrus
.
MyLog
.
Infof
(
"ProcessRoomVisit, ZADD %s, return %d"
,
key
,
ret
)
//
mylogrus.MyLog.Infof("ProcessRoomVisit, ZADD %s, return %d", key, ret)
//
// 每群定时清一次数据可以了
//
//
每群定时清一次数据可以了
if
now
.
Second
()
%
redis_key
.
GroupInDurationClearPeriod
==
0
{
//
if now.Second()%redis_key.GroupInDurationClearPeriod == 0 {
rc
,
err
:=
clearRoomVisit
(
groupId
,
now
.
AddDate
(
0
,
0
,
-
redis_key
.
GroupInDurationTTL
))
//
rc, err := clearRoomVisit(groupId, now.AddDate(0, 0, -redis_key.GroupInDurationTTL))
if
err
==
nil
{
//
if err == nil {
mylogrus
.
MyLog
.
Infof
(
"ProcessRoomVisit, clearRoomVisit %s, return %d"
,
key
,
rc
)
//
mylogrus.MyLog.Infof("ProcessRoomVisit, clearRoomVisit %s, return %d", key, rc)
}
else
{
//
} else {
mylogrus
.
MyLog
.
Warnf
(
"ProcessRoomVisit, clearRoomVisit %s, failed %s"
,
key
,
err
.
Error
())
//
mylogrus.MyLog.Warnf("ProcessRoomVisit, clearRoomVisit %s, failed %s", key, err.Error())
}
//
}
}
//
}
// 马上更新roomVisitCount
// 马上更新roomVisitCount
if
_
,
err
:=
GetSetRoomVisitCount
(
groupId
);
err
!=
nil
{
if
_
,
err
:=
GetSetRoomVisitCount
(
groupId
);
err
!=
nil
{
mylogrus
.
MyLog
.
Warnf
(
"ProcessRoomVisit, failed for key %s, err: %s"
,
key
,
err
.
Error
())
mylogrus
.
MyLog
.
Errorf
(
"ProcessRoomVisit, failed for groupId %s, err: %s"
,
groupId
,
err
.
Error
())
}
}
return
nil
return
nil
...
@@ -59,7 +61,10 @@ func ProcessUserRoomVisit(userId uint64, groupId string) error {
...
@@ -59,7 +61,10 @@ func ProcessUserRoomVisit(userId uint64, groupId string) error {
}
}
// 查询用户访问过的房间及其时间
// 查询用户访问过的房间及其时间
// todo 去掉查询,redis性能
func
GetUserRoomVisit
(
userId
uint64
)
(
map
[
string
]
int64
,
error
)
{
func
GetUserRoomVisit
(
userId
uint64
)
(
map
[
string
]
int64
,
error
)
{
result
:=
make
(
map
[
string
]
int64
,
0
)
return
result
,
nil
key
:=
redis_key
.
GetUserEnterRoomKey
(
userId
)
key
:=
redis_key
.
GetUserEnterRoomKey
(
userId
)
ret
,
err
:=
redisCli
.
GetRedis
()
.
ZRangeWithScores
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
ret
,
err
:=
redisCli
.
GetRedis
()
.
ZRangeWithScores
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -67,7 +72,6 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) {
...
@@ -67,7 +72,6 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) {
}
}
//mylogrus.MyLog.Infof("GetUserRoomVisit, ZRangeWithScores %s, return %v", key, ret)
//mylogrus.MyLog.Infof("GetUserRoomVisit, ZRangeWithScores %s, return %v", key, ret)
result
:=
make
(
map
[
string
]
int64
,
0
)
for
_
,
i
:=
range
ret
{
for
_
,
i
:=
range
ret
{
result
[
i
.
Member
.
(
string
)]
=
int64
(
i
.
Score
)
result
[
i
.
Member
.
(
string
)]
=
int64
(
i
.
Score
)
}
}
...
@@ -75,53 +79,63 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) {
...
@@ -75,53 +79,63 @@ func GetUserRoomVisit(userId uint64) (map[string]int64, error) {
}
}
// 批量获取房间访问人数
// 批量获取房间访问人数
// 带上lru
var
roomVisitCountLru
=
gcache
.
New
(
100
)
.
LRU
()
.
Build
()
func
MGetRoomVisitCount
(
groupIds
[]
string
)
(
map
[
string
]
string
,
error
)
{
func
MGetRoomVisitCount
(
groupIds
[]
string
)
(
map
[
string
]
string
,
error
)
{
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
visit
:=
make
(
map
[
string
]
string
)
visit
:=
make
(
map
[
string
]
string
)
if
len
(
groupIds
)
<=
0
{
if
len
(
groupIds
)
<=
0
{
return
visit
,
nil
return
visit
,
nil
}
}
res
,
err
:=
redisCli
.
GetRedis
()
.
HMGet
(
context
.
Background
(),
key
,
groupIds
...
)
.
Result
()
lKey
:=
"room:visit:count"
if
data
,
err
:=
roomVisitCountLru
.
Get
(
lKey
);
err
==
nil
{
return
data
.
(
map
[
string
]
string
),
nil
}
// 用redisCluster中的zset代替,只是取出大于10的
zKey
:=
redis_key
.
GetPrefixRoomVisitCountZset
()
cnt
:=
10
if
!
config
.
AppIsRelease
()
{
cnt
=
0
}
zRes
,
err
:=
redisCli
.
GetClusterRedis
()
.
ZRevRangeByScoreWithScores
(
context
.
Background
(),
zKey
,
&
redis2
.
ZRangeBy
{
Min
:
fmt
.
Sprintf
(
"%d"
,
cnt
),
Max
:
"+inf"
,
})
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"MGetRoomVisitCount zset fail:%v"
,
err
)
return
visit
,
err
return
visit
,
err
}
}
if
len
(
res
)
!=
len
(
groupIds
)
{
for
_
,
v
:=
range
zRes
{
return
visit
,
errors
.
New
(
fmt
.
Sprintf
(
"MGetRoomVisitCount fail,miss match len,%v-%v"
,
len
(
res
),
len
(
groupIds
)))
visit
[
cast
.
ToString
(
v
.
Member
)]
=
cast
.
ToString
(
v
.
Score
)
}
for
i
,
groupId
:=
range
groupIds
{
if
cnt
,
ok
:=
res
[
i
]
.
(
string
);
ok
{
visit
[
groupId
]
=
cnt
}
}
}
_
=
roomVisitCountLru
.
SetWithExpire
(
lKey
,
visit
,
time
.
Minute
*
15
)
return
visit
,
nil
return
visit
,
nil
}
}
func
GetSetRoomVisitCount
(
groupId
string
)
(
int64
,
error
)
{
func
GetSetRoomVisitCount
(
groupId
string
)
(
int64
,
error
)
{
key
:=
redis_key
.
GetPrefixGroupInUserDuration
(
groupId
)
//key := redis_key.GetPrefixGroupInUserDuration(groupId)
key
:=
group_k
.
GetUserEnterRoomGroupKey
(
groupId
)
vc
,
err
:=
redisCli
.
GetRedis
()
.
ZCard
(
context
.
Background
(),
key
)
.
Result
()
vc
,
err
:=
redisCli
.
GetRedis
()
.
ZCard
(
context
.
Background
(),
key
)
.
Result
()
// 查到合法值后,更新二级缓存
// 查到合法值后,更新二级缓存
if
err
==
nil
&&
vc
>=
0
{
if
err
==
nil
&&
vc
>=
0
{
ret
,
err
:=
saveRoomVisitCount
(
groupId
,
vc
)
if
err
:=
saveRoomVisitCount
(
groupId
,
vc
);
err
!=
nil
{
mylogrus
.
MyLog
.
Infof
(
"saveRoomVisitCount %s, ret = %d, err: %v"
,
groupId
,
ret
,
err
)
mylogrus
.
MyLog
.
Errorf
(
"saveRoomVisitCount %s, err: %v"
,
groupId
,
err
)
}
}
}
return
vc
,
err
return
vc
,
err
}
}
func
saveRoomVisitCount
(
groupId
string
,
count
int64
)
(
int64
,
error
)
{
func
saveRoomVisitCount
(
groupId
string
,
count
int64
)
error
{
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
//
key := redis_key.GetPrefixRoomVisitCount()
return
redisCli
.
GetRedis
()
.
HSet
(
context
.
Background
(),
key
,
groupId
,
strconv
.
FormatInt
(
count
,
10
))
.
Resul
t
()
zKey
:=
redis_key
.
GetPrefixRoomVisitCountZse
t
()
}
// zset同步存一份到redis集群
if
err
:=
redisCli
.
GetClusterRedis
()
.
ZAdd
(
context
.
Background
(),
zKey
,
&
redis2
.
Z
{
func
clearRoomVisit
(
groupId
string
,
t
time
.
Time
)
(
int64
,
error
)
{
Score
:
float64
(
count
),
value
:=
strconv
.
FormatInt
(
t
.
Unix
(),
10
)
Member
:
groupId
,
ret
,
err
:=
redisCli
.
GetRedis
()
.
ZRemRangeByScore
(
context
.
Background
(),
redis_key
.
GetPrefixGroupInUserDuration
(
groupId
),
"0"
,
value
)
.
Result
()
})
.
Err
();
err
!=
nil
{
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"GetPrefixRoomVisitCountZset fail %s"
,
err
.
Error
())
return
0
,
err
return
err
}
}
return
ret
,
nil
return
nil
}
//return redisCli.GetRedis().HSet(context.Background(), key, groupId, strconv.FormatInt(count, 10)).Result()
func
GetAllRoomVisitCount
()
(
map
[
string
]
string
,
error
)
{
key
:=
redis_key
.
GetPrefixRoomVisitCount
()
return
redisCli
.
GetRedis
()
.
HGetAll
(
context
.
Background
(),
key
)
.
Result
()
}
}
domain/cache/user_c/svip_vip_noble.go
0 → 100644
View file @
577a8fef
package
user_c
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"sync"
"time"
)
type
UserLevel
struct
{
UserId
mysql
.
ID
Level
int
}
var
svipVipNobleLock
sync
.
RWMutex
var
svipLevel
=
make
(
map
[
mysql
.
ID
]
int
)
// userId->svipLevel
var
nobleLevel
=
make
(
map
[
mysql
.
ID
]
uint16
)
// userId->nobleLevel
var
userVips
=
make
(
map
[
mysql
.
ID
]
bool
)
// userId->isVip
// 加载数据到lru
func
LoadAllSvipVipNoble
(
model
*
domain
.
Model
)
{
start
:=
time
.
Now
()
var
svips
[]
UserLevel
svipMap
:=
make
(
map
[
mysql
.
ID
]
int
)
if
err
:=
model
.
DB
()
.
Table
(
"user_svip"
)
.
Select
(
"user_id,level"
)
.
Where
(
"level > 0"
)
.
Find
(
&
svips
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"LoadAllSvip fail:%v"
,
err
)
}
else
{
for
_
,
v
:=
range
svips
{
svipMap
[
v
.
UserId
]
=
v
.
Level
}
}
var
nobles
[]
UserLevel
nobleMap
:=
make
(
map
[
mysql
.
ID
]
uint16
)
if
err
:=
model
.
DB
()
.
Table
(
"user_noble"
)
.
Select
(
"user_id,MAX(level) level"
)
.
Where
(
"level > 0 AND end_time > ?"
,
time
.
Now
())
.
Group
(
"user_id"
)
.
Find
(
&
nobles
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"LoadAllNoble fail:%v"
,
err
)
}
else
{
for
_
,
v
:=
range
nobles
{
nobleMap
[
v
.
UserId
]
=
uint16
(
v
.
Level
)
}
}
var
vips
[]
UserLevel
vipMap
:=
make
(
map
[
mysql
.
ID
]
bool
)
if
err
:=
model
.
DB
()
.
Table
(
"user_vip"
)
.
Select
(
"user_id"
)
.
Where
(
"expire_at > ?"
,
time
.
Now
())
.
Find
(
&
vips
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"LoadAllVip fail:%v"
,
err
)
}
else
{
for
_
,
v
:=
range
vips
{
vipMap
[
v
.
UserId
]
=
true
}
}
// 上锁赋值
svipVipNobleLock
.
Lock
()
svipLevel
=
svipMap
nobleLevel
=
nobleMap
userVips
=
vipMap
svipVipNobleLock
.
Unlock
()
model
.
Log
.
Infof
(
"LoadAllSvipVipNoble svip:%v,vip:%v,noble:%v,cost:%vs"
,
len
(
svipMap
),
len
(
vipMap
),
len
(
nobleMap
),
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
}
func
BatchGetNobleLevel
(
model
*
domain
.
Model
,
userIds
[]
uint64
)
map
[
uint64
]
uint16
{
res
:=
make
(
map
[
uint64
]
uint16
)
svipVipNobleLock
.
RLock
()
defer
svipVipNobleLock
.
RUnlock
()
for
_
,
userId
:=
range
userIds
{
res
[
userId
]
=
nobleLevel
[
userId
]
}
return
res
}
func
MGetUserSvipLevel
(
model
*
domain
.
Model
,
userIds
[]
uint64
)
map
[
uint64
]
int
{
res
:=
make
(
map
[
uint64
]
int
)
svipVipNobleLock
.
RLock
()
defer
svipVipNobleLock
.
RUnlock
()
for
_
,
userId
:=
range
userIds
{
res
[
userId
]
=
svipLevel
[
userId
]
}
return
res
}
func
BatchGetVips
(
model
*
domain
.
Model
,
userIds
[]
uint64
)
map
[
uint64
]
*
int64
{
res
:=
make
(
map
[
uint64
]
*
int64
)
svipVipNobleLock
.
RLock
()
defer
svipVipNobleLock
.
RUnlock
()
for
_
,
userId
:=
range
userIds
{
vip
:=
int64
(
1
)
if
userVips
[
userId
]
{
res
[
userId
]
=
&
vip
}
}
return
res
}
domain/cache/user_c/user.go
View file @
577a8fef
...
@@ -38,6 +38,36 @@ func GetUserTinyById(model *domain.Model, userId mysql.ID) (*user_m.UserTiny, er
...
@@ -38,6 +38,36 @@ func GetUserTinyById(model *domain.Model, userId mysql.ID) (*user_m.UserTiny, er
return
userTiny
,
nil
return
userTiny
,
nil
}
}
// 获取用户简要信息
// param userId 用户id
func
MGetUserTinyById
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
[]
*
user_m
.
UserTiny
{
var
users
[]
*
user_m
.
UserTiny
for
_
,
userId
:=
range
userIds
{
if
user
,
_
:=
GetUserTinyById
(
model
,
userId
);
user
!=
nil
{
users
=
append
(
users
,
user
)
}
}
return
users
}
// 获取用户externalIds
// return []externalIds map[userId]extId map[userId]code
func
GetUserExternalIds
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
([]
string
,
map
[
uint64
]
string
,
map
[
uint64
]
string
)
{
var
res
[]
string
var
m
=
make
(
map
[
uint64
]
string
)
var
c
=
make
(
map
[
uint64
]
string
)
if
len
(
userIds
)
<=
0
{
return
res
,
m
,
c
}
users
:=
MGetUserTinyById
(
model
,
userIds
)
for
_
,
u
:=
range
users
{
res
=
append
(
res
,
u
.
ExternalId
)
m
[
u
.
ID
]
=
u
.
ExternalId
c
[
u
.
ID
]
=
u
.
Code
}
return
res
,
m
,
c
}
// 获取用户简要信息By ExternalId
// 获取用户简要信息By ExternalId
func
GetUserByExternalId
(
model
*
domain
.
Model
,
externalId
mysql
.
Str
)
(
*
user_m
.
UserTiny
,
error
)
{
func
GetUserByExternalId
(
model
*
domain
.
Model
,
externalId
mysql
.
Str
)
(
*
user_m
.
UserTiny
,
error
)
{
userId
,
err
:=
ToUserId
(
model
,
externalId
)
userId
,
err
:=
ToUserId
(
model
,
externalId
)
...
@@ -52,7 +82,7 @@ func ToUserId(model *domain.Model, externalId mysql.Str) (mysql.ID, error) {
...
@@ -52,7 +82,7 @@ func ToUserId(model *domain.Model, externalId mysql.Str) (mysql.ID, error) {
if
externalId
==
""
{
if
externalId
==
""
{
return
0
,
myerr
.
NewSysError
(
"externalId 不能为空"
)
return
0
,
myerr
.
NewSysError
(
"externalId 不能为空"
)
}
}
userId
,
err
:=
model
.
Redis
.
Get
(
model
.
Context
,
user_k
.
GetExternalIdToUidKey
(
externalId
))
.
Int64
()
userId
,
err
:=
model
.
Redis
Cluster
.
Get
(
model
.
Context
,
user_k
.
GetExternalIdToUidKey
(
externalId
))
.
Int64
()
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -75,7 +105,7 @@ func ToUserIdByCode(model *domain.Model, code mysql.Str) (mysql.ID, error) {
...
@@ -75,7 +105,7 @@ func ToUserIdByCode(model *domain.Model, code mysql.Str) (mysql.ID, error) {
if
code
==
""
{
if
code
==
""
{
return
0
,
myerr
.
NewSysError
(
"code 不能为空"
)
return
0
,
myerr
.
NewSysError
(
"code 不能为空"
)
}
}
userId
,
err
:=
model
.
Redis
.
Get
(
model
.
Context
,
user_k
.
GetCodeToUidKey
(
code
))
.
Int64
()
userId
,
err
:=
model
.
Redis
Cluster
.
Get
(
model
.
Context
,
user_k
.
GetCodeToUidKey
(
code
))
.
Int64
()
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -104,11 +134,11 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error {
...
@@ -104,11 +134,11 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error {
// return err
// return err
//}
//}
// cache externalId->userId
// cache externalId->userId
if
err
:=
model
.
Redis
.
SetEX
(
model
.
Context
,
user_k
.
GetExternalIdToUidKey
(
user
.
ExternalId
),
user
.
ID
,
cache
.
GetDefaultTTL
())
.
Err
();
err
!=
nil
{
if
err
:=
model
.
Redis
Cluster
.
SetEX
(
model
.
Context
,
user_k
.
GetExternalIdToUidKey
(
user
.
ExternalId
),
user
.
ID
,
cache
.
GetDefaultTTL
())
.
Err
();
err
!=
nil
{
return
err
return
err
}
}
// cache code->userId
// cache code->userId
if
err
:=
model
.
Redis
.
SetEX
(
model
.
Context
,
user_k
.
GetCodeToUidKey
(
user
.
Code
),
user
.
ID
,
cache
.
GetDefaultTTL
())
.
Err
();
err
!=
nil
{
if
err
:=
model
.
Redis
Cluster
.
SetEX
(
model
.
Context
,
user_k
.
GetCodeToUidKey
(
user
.
Code
),
user
.
ID
,
cache
.
GetDefaultTTL
())
.
Err
();
err
!=
nil
{
return
err
return
err
}
}
if
err
:=
cache
.
SetJSON
(
model
,
user_k
.
GetUserTinyKey
(
user
.
ID
),
userTiny
);
err
!=
nil
{
if
err
:=
cache
.
SetJSON
(
model
,
user_k
.
GetUserTinyKey
(
user
.
ID
),
userTiny
);
err
!=
nil
{
...
...
domain/model/common/cache_medal.go
View file @
577a8fef
package
common
package
common
import
(
import
(
"context"
"encoding/json"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/utils"
"git.hilo.cn/hilo-common/utils"
"hilo-group/_const/redis_key"
"github.com/bluele/gcache"
"hilo-group/myerr"
"time"
"time"
)
)
func
GetUserMedalMergeCache
(
userId
mysql
.
ID
)
([]
uint32
,
error
)
{
// 改成lru
bData
,
err
:=
GetCache
(
redis_key
.
GetUserMedalMerge
(
userId
))
var
userMedalMergeLru
=
gcache
.
New
(
10000
)
.
LRU
()
.
Build
()
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
res
:=
make
([]
uint32
,
0
)
func
GetUserMedalMergeCache
(
userId
mysql
.
ID
)
([]
uint32
,
error
)
{
err
=
json
.
Unmarshal
(
bData
,
&
res
)
if
data
,
err
:=
userMedalMergeLru
.
Get
(
userId
);
err
==
nil
{
if
err
!=
nil
{
return
data
.
([]
uint32
),
nil
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
return
res
,
nil
return
nil
,
nil
}
}
func
SetUserMedalMergeCache
(
userId
mysql
.
ID
,
data
[]
uint32
)
error
{
func
SetUserMedalMergeCache
(
userId
mysql
.
ID
,
data
[]
uint32
)
{
err
:=
SetCache
(
redis_key
.
GetUserMedalMerge
(
userId
),
data
,
time
.
Hour
*
2
)
_
=
userMedalMergeLru
.
SetWithExpire
(
userId
,
data
,
time
.
Minute
*
15
)
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"SetUserMedalMerge err:%s"
,
err
)
return
myerr
.
WrapErr
(
err
)
}
return
nil
}
}
// 删除勋章缓存, 延迟删除
// 删除勋章缓存, 延迟删除
...
@@ -44,41 +30,6 @@ func DelUserMedalMergeCacheDelay(userId mysql.ID) {
...
@@ -44,41 +30,6 @@ func DelUserMedalMergeCacheDelay(userId mysql.ID) {
}()
}()
}
}
func
DelUserMedalMergeCache
(
userId
mysql
.
ID
)
error
{
func
DelUserMedalMergeCache
(
userId
mysql
.
ID
)
{
err
:=
DelCache
(
redis_key
.
GetUserMedalMerge
(
userId
))
userMedalMergeLru
.
Remove
(
userId
)
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"DetUserMedalMerge err:%s, userId:%v"
,
err
,
userId
)
return
myerr
.
WrapErr
(
err
)
}
return
nil
}
func
DelCache
(
key
string
)
error
{
err
:=
redisCli
.
GetRedis
()
.
Del
(
context
.
Background
(),
key
)
.
Err
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"DelCache key:%s, err:%s"
,
key
,
err
)
return
err
}
return
nil
}
func
GetCache
(
key
string
)
([]
byte
,
error
)
{
data
,
err
:=
redisCli
.
GetRedis
()
.
Get
(
context
.
Background
(),
key
)
.
Bytes
()
if
err
!=
nil
{
return
nil
,
err
}
return
data
,
nil
}
func
SetCache
(
key
string
,
data
interface
{},
expire
time
.
Duration
)
error
{
jData
,
err
:=
json
.
Marshal
(
data
)
if
err
!=
nil
{
return
err
}
err
=
redisCli
.
GetRedis
()
.
Set
(
context
.
Background
(),
key
,
jData
,
expire
)
.
Err
()
if
err
!=
nil
{
mylogrus
.
MyLog
.
Errorf
(
"SetCache key:%s, data:%v, err:%s"
,
key
,
data
,
err
)
return
err
}
return
nil
}
}
domain/model/gift_m/gift.go
View file @
577a8fef
...
@@ -128,39 +128,39 @@ func (g *GiftOperate) GetConsumeByRange(beginTime, endTime time.Time) (uint32, u
...
@@ -128,39 +128,39 @@ func (g *GiftOperate) GetConsumeByRange(beginTime, endTime time.Time) (uint32, u
return
0
,
0
,
nil
return
0
,
0
,
nil
}
}
if
beginTime
.
Unix
()
>=
1691337600
&&
beginTime
.
Unix
()
<
1691942400
{
// 因为这周水果机被部分人刷币,所以这里做了特殊的处理
//
if beginTime.Unix() >= 1691337600 && beginTime.Unix() < 1691942400 { // 因为这周水果机被部分人刷币,所以这里做了特殊的处理
reduceMap
:=
map
[
string
]
uint64
{
//
reduceMap := map[string]uint64{
"HTGS#a63226380"
:
20000000
,
//
"HTGS#a63226380": 20000000,
//"HTGS#a42641278": 10000000,
//
//"HTGS#a42641278": 10000000,
"@TGS#3ZZ5GZLHA"
:
27141539
,
//
"@TGS#3ZZ5GZLHA": 27141539,
"HTGS#a81630128"
:
8955410
,
//
"HTGS#a81630128": 8955410,
"HTGS#a42300598"
:
50211301
,
//
"HTGS#a42300598": 50211301,
"HTGS#a40088696"
:
10000000
,
//
"HTGS#a40088696": 10000000,
"HTGS#a21700997"
:
14352310
,
//
"HTGS#a21700997": 14352310,
"HTGS#a83608384"
:
49644203
,
//
"HTGS#a83608384": 49644203,
"@TGS#33GDXTSIH"
:
50000000
,
//
"@TGS#33GDXTSIH": 50000000,
"HTGS#a50538513"
:
15000000
,
//
"HTGS#a50538513": 15000000,
"HTGS#a77282385"
:
15000000
,
//
"HTGS#a77282385": 15000000,
"HTGS#a59437326"
:
10000000
,
//
"HTGS#a59437326": 10000000,
"HTGS#a16909405"
:
10000000
,
//
"HTGS#a16909405": 10000000,
"HTGS#a44104431"
:
16861206
,
//
"HTGS#a44104431": 16861206,
"HTGS#a56794634"
:
59591313
,
//
"HTGS#a56794634": 59591313,
"HTGS#a11286025"
:
31232311
,
//
"HTGS#a11286025": 31232311,
"HTGS#a17238550"
:
52309338
,
//
"HTGS#a17238550": 52309338,
"HTGS#a83592361"
:
79545067
,
//
"HTGS#a83592361": 79545067,
"HTGS#a39882521"
:
10255093
,
//
"HTGS#a39882521": 10255093,
}
//
}
if
reduceNum
,
ok
:=
reduceMap
[
g
.
SceneUid
];
ok
{
//
if reduceNum, ok := reduceMap[g.SceneUid]; ok {
if
g
.
Log
!=
nil
{
//
if g.Log != nil {
g
.
Log
.
Infof
(
"fruit diamond reduceMap,groupId:%v,reduceNum:%v"
,
g
.
SceneUid
,
reduceNum
)
//
g.Log.Infof("fruit diamond reduceMap,groupId:%v,reduceNum:%v", g.SceneUid, reduceNum)
}
//
}
if
rows
[
0
]
.
Consume
>=
reduceNum
{
//
if rows[0].Consume >= reduceNum {
rows
[
0
]
.
Consume
-=
reduceNum
//
rows[0].Consume -= reduceNum
}
else
{
//
} else {
rows
[
0
]
.
Consume
=
0
//
rows[0].Consume = 0
}
//
}
}
//
}
}
//
}
return
rows
[
0
]
.
C
,
rows
[
0
]
.
Consume
,
nil
return
rows
[
0
]
.
C
,
rows
[
0
]
.
Consume
,
nil
}
}
...
@@ -182,9 +182,9 @@ func (g *GiftOperate) BatchGetConsumeByRange(beginTime, endTime time.Time) ([]Sc
...
@@ -182,9 +182,9 @@ func (g *GiftOperate) BatchGetConsumeByRange(beginTime, endTime time.Time) ([]Sc
return
rows
,
nil
return
rows
,
nil
}
}
func
(
g
*
GiftOperate
)
BatchGetSupportList
(
beginTime
,
endTime
time
.
Time
)
([]
uint64
,
error
)
{
func
(
g
*
GiftOperate
)
BatchGetSupportList
(
model
*
domain
.
Model
,
beginTime
,
endTime
time
.
Time
)
([]
uint64
,
error
)
{
userIds
:=
make
([]
uint64
,
0
)
userIds
:=
make
([]
uint64
,
0
)
err
:=
g
.
DB
()
.
Model
(
g
)
.
err
:=
model
.
DB
()
.
Model
(
g
)
.
Select
(
"DISTINCT(send_user_id) AS user_id"
)
.
Select
(
"DISTINCT(send_user_id) AS user_id"
)
.
Where
(
g
)
.
Where
(
"created_time BETWEEN ? AND ?"
,
beginTime
,
endTime
)
.
Pluck
(
"user_id"
,
&
userIds
)
.
Error
Where
(
g
)
.
Where
(
"created_time BETWEEN ? AND ?"
,
beginTime
,
endTime
)
.
Pluck
(
"user_id"
,
&
userIds
)
.
Error
if
err
!=
nil
{
if
err
!=
nil
{
...
...
domain/model/groupPower_m/group_grade.go
View file @
577a8fef
...
@@ -8,7 +8,7 @@ import (
...
@@ -8,7 +8,7 @@ import (
"gorm.io/gorm"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/clause"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/
domain/cache/groupPower_c
"
"hilo-group/
_const/redis_key/mic_k
"
"hilo-group/domain/event/group_power_ev"
"hilo-group/domain/event/group_power_ev"
"time"
"time"
)
)
...
@@ -41,25 +41,6 @@ type GroupPowerExpDetail struct {
...
@@ -41,25 +41,6 @@ type GroupPowerExpDetail struct {
Remark
string
Remark
string
}
}
type
GroupPowerOnMic
struct
{
Date
string
GroupPowerId
mysql
.
ID
UserId
mysql
.
ID
Seconds
int64
LastCalTs
int64
CreatedTime
time
.
Time
`gorm:"->"`
UpdatedTime
time
.
Time
`gorm:"->"`
}
type
GroupPowerOnMicDetail
struct
{
Date
string
GroupPowerId
mysql
.
ID
UserId
mysql
.
ID
Minute
int
CreatedTime
time
.
Time
`gorm:"->"`
UpdatedTime
time
.
Time
`gorm:"->"`
}
// 增加家族经验
// 增加家族经验
// 达到经验值之后升级
// 达到经验值之后升级
// 单进程同步执行,不考虑并发
// 单进程同步执行,不考虑并发
...
@@ -153,155 +134,24 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N
...
@@ -153,155 +134,24 @@ func IncrGroupPowerExp(txModel *domain.Model, groupPowerId mysql.ID, exp mysql.N
return
nil
return
nil
}
}
// 获取势力用户上麦加经验记录
func
GetGroupPowerUserOnMicDetails
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
)
([]
*
GroupPowerOnMicDetail
,
error
)
{
var
res
[]
*
GroupPowerOnMicDetail
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerOnMicDetail
{})
.
Where
(
"date = ? AND group_power_id = ? AND user_id = ?"
,
date
,
groupPowerId
,
userId
)
.
Find
(
&
res
)
.
Error
;
err
!=
nil
{
return
res
,
err
}
return
res
,
nil
}
// 获取势力用户上麦记录
func
GetGroupPowerOnMic
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
)
(
*
GroupPowerOnMic
,
error
)
{
gpom
:=
new
(
GroupPowerOnMic
)
date
:=
time
.
Now
()
.
Format
(
"2006-01-02"
)
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerOnMic
{})
.
Where
(
"date = ? AND group_power_id = ? AND user_id = ?"
,
date
,
groupPowerId
,
userId
)
.
First
(
gpom
)
.
Error
;
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
&
GroupPowerOnMic
{
Date
:
date
,
GroupPowerId
:
groupPowerId
,
UserId
:
userId
},
nil
}
return
nil
,
err
}
return
gpom
,
nil
}
const
MaxMinuteTimes
=
18
// 增加势力上麦经验
// 增加势力上麦经验
// 事务操作
// 事务操作
func
IncrGroupPowerExpOnMic
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
joinMicTimestamp
int64
)
error
{
func
IncrGroupPowerExpOnMic
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
)
error
{
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
key
:=
mic_k
.
GetMicGroupPowerOnMic
(
userId
)
// 获取用户上麦奖励历史
minutes
,
err
:=
model
.
Redis
.
IncrBy
(
model
,
key
,
1
)
.
Result
()
onMicDetails
,
err
:=
GetGroupPowerUserOnMicDetails
(
model
,
groupPowerId
,
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerExpOnMic fail:%v"
,
err
)
return
err
}
numDetails
:=
len
(
onMicDetails
)
if
numDetails
>=
MaxMinuteTimes
{
// 上麦经验贡献值最多1800,1分钟100
return
nil
}
onMic
,
err
:=
GetGroupPowerOnMic
(
model
,
groupPowerId
,
userId
)
if
err
!=
nil
{
return
err
}
nowTs
:=
time
.
Now
()
.
Unix
()
curTs
:=
joinMicTimestamp
day0Ts
:=
utils
.
GetZeroTime
(
time
.
Now
())
.
Unix
()
if
joinMicTimestamp
<
onMic
.
LastCalTs
{
curTs
=
onMic
.
LastCalTs
}
// 跨天
if
curTs
<
day0Ts
{
curTs
=
day0Ts
}
onMicSeconds
:=
nowTs
-
curTs
var
moreDetails
[]
*
GroupPowerOnMicDetail
totalMinuteTimes
:=
int
((
onMic
.
Seconds
+
onMicSeconds
)
/
600
)
// 今天实际能加经验次数
if
totalMinuteTimes
>=
MaxMinuteTimes
{
totalMinuteTimes
=
MaxMinuteTimes
}
if
totalMinuteTimes
>
numDetails
{
// 续上上一次的时间,从numDetails开始
for
mt
:=
numDetails
+
1
;
mt
<=
totalMinuteTimes
;
mt
++
{
moreDetails
=
append
(
moreDetails
,
&
GroupPowerOnMicDetail
{
Date
:
time
.
Now
()
.
Format
(
"2006-01-02"
),
GroupPowerId
:
groupPowerId
,
UserId
:
userId
,
Minute
:
mt
*
10
,
// 转换分钟
})
}
}
// 有更多麦上10分钟,可以加经验
if
len
(
moreDetails
)
>
0
{
for
_
,
detail
:=
range
moreDetails
{
// 添加明细,避免重复计算
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerOnMicDetail
{})
.
Create
(
detail
)
.
Error
;
err
!=
nil
{
return
err
}
// 每10分钟增加100点经验
//if err := IncrGroupPowerExp(model, groupPowerId, 100, userId, "上麦10分钟"); err != nil {
if
err
:=
groupPower_c
.
QueueGroupPowerGradeExp
(
model
,
groupPowerId
,
100
,
userId
,
"上麦10分钟"
);
err
!=
nil
{
return
err
}
}
// 更新micExp信息
onMic
.
Seconds
=
onMic
.
Seconds
+
onMicSeconds
onMic
.
LastCalTs
=
nowTs
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerOnMic
{})
.
Clauses
(
clause
.
OnConflict
{
Columns
:
[]
clause
.
Column
{{
Name
:
"date"
},
{
Name
:
"group_power_id"
}},
DoUpdates
:
clause
.
Assignments
(
map
[
string
]
interface
{}{
"seconds"
:
onMic
.
Seconds
,
"last_cal_ts"
:
nowTs
,
},
)})
.
Create
(
onMic
)
.
Error
;
err
!=
nil
{
return
err
}
}
return
nil
})
}
// 增加势力上麦时长-家族之星
// 事务操作
func
IncrGroupPowerStarOnMicMonth
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
joinMicTimestamp
int64
)
error
{
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
// 月统计
star
,
err
:=
GetGroupPowerMonthStar
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
)
curTs
:=
joinMicTimestamp
nowTs
:=
time
.
Now
()
.
Unix
()
month0Ts
:=
now
.
BeginningOfMonth
()
.
Unix
()
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
err
}
if
star
!=
nil
&&
joinMicTimestamp
<
star
.
LastCalTs
{
// 加入的时间比上次计算时间小
curTs
=
star
.
LastCalTs
}
// 跨月
if
curTs
<
month0Ts
{
curTs
=
month0Ts
}
score
:=
nowTs
-
curTs
err
=
IncrGroupPowerMonthStarScore
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
,
mysql
.
Num
(
score
),
nowTs
)
return
err
})
}
// 增加势力上麦时长-家族之星
// 事务操作
func
IncrGroupPowerStarOnMicDay
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
joinMicTimestamp
int64
)
error
{
return
model
.
Transaction
(
func
(
model
*
domain
.
Model
)
error
{
// 日统计
star
,
err
:=
GetGroupPowerDayStar
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
)
curTs
:=
joinMicTimestamp
nowTs
:=
time
.
Now
()
.
Unix
()
day0Ts
:=
now
.
BeginningOfDay
()
.
Unix
()
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
err
}
if
star
!=
nil
&&
joinMicTimestamp
<
star
.
LastCalTs
{
// 加入的时间比上次计算时间小
curTs
=
star
.
LastCalTs
}
// 跨天
if
curTs
<
day0Ts
{
curTs
=
day0Ts
}
score
:=
nowTs
-
curTs
err
=
IncrGroupPowerDayStarScore
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
,
mysql
.
Num
(
score
),
nowTs
)
return
err
return
err
})
}
model
.
Redis
.
Expire
(
model
,
key
,
time
.
Hour
*
24
)
// ttl 一天
// 每日最多1800经验 = 18个10分钟 = 180分钟
if
minutes
>
180
{
return
nil
}
if
minutes
%
10
==
0
{
return
IncrGroupPowerExp
(
model
,
groupPowerId
,
100
,
userId
,
"上麦10分钟"
)
}
return
nil
}
}
// 清理所有家族的经验
// 清理所有家族的经验
...
...
domain/model/groupPower_m/group_rank.go
View file @
577a8fef
...
@@ -15,12 +15,11 @@ type GroupPowerExpRank struct {
...
@@ -15,12 +15,11 @@ type GroupPowerExpRank struct {
// 获取家族经验排行榜
// 获取家族经验排行榜
// param limit: 排行榜人数
// param limit: 排行榜人数
// 10166 线上员工,对应的势力不上榜,groupPowerId=8951
,6171(产品要移走)
// 10166 线上员工,对应的势力不上榜,groupPowerId=8951
func
GetGroupPowerExpRank
(
model
*
domain
.
Model
,
beginDate
,
endDate
string
,
limit
int
,
gpStatus
groupPower_e
.
GroupPowerStatus
,
area
int
)
([]
GroupPowerExpRank
,
error
)
{
func
GetGroupPowerExpRank
(
model
*
domain
.
Model
,
beginDate
,
endDate
string
,
limit
int
,
gpStatus
groupPower_e
.
GroupPowerStatus
,
area
int
)
([]
GroupPowerExpRank
,
error
)
{
var
res
[]
GroupPowerExpRank
var
res
[]
GroupPowerExpRank
db
:=
model
.
DB
()
.
Table
(
"group_power_day_exp gpd"
)
.
Select
(
"gpd.group_power_id,SUM(gpd.exp) as exp"
)
.
db
:=
model
.
DB
()
.
Table
(
"group_power_day_exp gpd"
)
.
Select
(
"gpd.group_power_id,SUM(gpd.exp) as exp"
)
.
Where
(
"gpd.group_power_id <> 8951"
)
.
Where
(
"gpd.group_power_id <> 8951"
)
.
Where
(
"gpd.group_power_id <> 6171"
)
.
Where
(
"gpd.date BETWEEN ? AND ?"
,
beginDate
,
endDate
)
Where
(
"gpd.date BETWEEN ? AND ?"
,
beginDate
,
endDate
)
if
gpStatus
>
0
{
if
gpStatus
>
0
{
db
=
db
.
Joins
(
"left join group_power gp on gpd.group_power_id = gp.id"
)
.
Where
(
"gp.status = ?"
,
gpStatus
)
db
=
db
.
Joins
(
"left join group_power gp on gpd.group_power_id = gp.id"
)
.
Where
(
"gp.status = ?"
,
gpStatus
)
...
...
domain/model/groupPower_m/group_star.go
View file @
577a8fef
...
@@ -35,6 +35,7 @@ type GroupPowerDayStar struct {
...
@@ -35,6 +35,7 @@ type GroupPowerDayStar struct {
}
}
// 增加家族之星分数
// 增加家族之星分数
// Deprecated: 用redis
func
IncrGroupPowerMonthStarScore
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
score
mysql
.
Num
,
lastCalTs
int64
)
error
{
func
IncrGroupPowerMonthStarScore
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
score
mysql
.
Num
,
lastCalTs
int64
)
error
{
month
:=
time
.
Now
()
.
Format
(
"200601"
)
month
:=
time
.
Now
()
.
Format
(
"200601"
)
star
:=
&
GroupPowerMonthStar
{
star
:=
&
GroupPowerMonthStar
{
...
@@ -59,6 +60,7 @@ func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysq
...
@@ -59,6 +60,7 @@ func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysq
}
}
// 增加家族之星分数
// 增加家族之星分数
// Deprecated: 用redis代替
func
IncrGroupPowerDayStarScore
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
score
mysql
.
Num
,
lastCalTs
int64
)
error
{
func
IncrGroupPowerDayStarScore
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
score
mysql
.
Num
,
lastCalTs
int64
)
error
{
star
:=
&
GroupPowerDayStar
{
star
:=
&
GroupPowerDayStar
{
Date
:
time
.
Now
(),
Date
:
time
.
Now
(),
...
@@ -81,29 +83,8 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.
...
@@ -81,29 +83,8 @@ func IncrGroupPowerDayStarScore(model *domain.Model, groupPowerId, userId mysql.
return
nil
return
nil
}
}
// 获取家族之星分数
// 允许返回gorm.ErrRecordNotFound
func
GetGroupPowerDayStar
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
)
(
*
GroupPowerDayStar
,
error
)
{
res
:=
new
(
GroupPowerDayStar
)
date
:=
time
.
Now
()
if
err
:=
model
.
DB
()
.
Where
(
"date = ? AND group_power_id = ? AND user_id = ? AND `type` = ?"
,
date
.
Format
(
"2006-01-02"
),
groupPowerId
,
userId
,
_type
)
.
First
(
res
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
res
,
nil
}
// 获取家族之星分数
// 允许返回gorm.ErrRecordNotFound
func
GetGroupPowerMonthStar
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
)
(
*
GroupPowerMonthStar
,
error
)
{
res
:=
new
(
GroupPowerMonthStar
)
month
:=
time
.
Now
()
.
Format
(
"200601"
)
if
err
:=
model
.
DB
()
.
Where
(
"month = ? AND group_power_id = ? AND user_id = ? AND `type` = ?"
,
month
,
groupPowerId
,
userId
,
_type
)
.
First
(
res
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
res
,
nil
}
// 获取家族之星排行
// 获取家族之星排行
// Deprecated: 用redis
func
GetGroupPowerMonthStarRank
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
,
month
string
)
([]
*
GroupPowerMonthStar
,
error
)
{
func
GetGroupPowerMonthStarRank
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
,
month
string
)
([]
*
GroupPowerMonthStar
,
error
)
{
var
res
[]
*
GroupPowerMonthStar
var
res
[]
*
GroupPowerMonthStar
//month := time.Now().Format("200601")
//month := time.Now().Format("200601")
...
...
domain/model/group_m/factory.go
View file @
577a8fef
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"gorm.io/gorm"
"gorm.io/gorm"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key/mic_k"
"hilo-group/myerr"
"hilo-group/myerr"
"strconv"
"strconv"
"strings"
"strings"
...
@@ -242,6 +243,20 @@ func BatchGetAllMicUser(model *domain.Model, groupIds []string) (map[string][]my
...
@@ -242,6 +243,20 @@ func BatchGetAllMicUser(model *domain.Model, groupIds []string) (map[string][]my
if
len
(
groupIds
)
<=
0
{
if
len
(
groupIds
)
<=
0
{
return
result
,
nil
return
result
,
nil
}
}
// 获取群组中上麦用户
for
_
,
groupId
:=
range
groupIds
{
groupMicUserKey
:=
mic_k
.
GetGroupOnMicUser
(
groupId
)
userIds
,
err
:=
model
.
Redis
.
HVals
(
model
,
groupMicUserKey
)
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"BatchGetAllMicUser fail:%v"
,
err
)
}
for
_
,
userIdStr
:=
range
userIds
{
if
userId
,
_
:=
strconv
.
ParseUint
(
userIdStr
,
10
,
64
);
userId
>
0
{
result
[
groupId
]
=
append
(
result
[
groupId
],
userId
)
}
}
}
return
result
,
nil
keys
:=
make
([]
string
,
0
)
keys
:=
make
([]
string
,
0
)
for
_
,
g
:=
range
groupIds
{
for
_
,
g
:=
range
groupIds
{
...
...
domain/model/group_m/groupBanned.go
View file @
577a8fef
...
@@ -31,11 +31,10 @@ var bannedGroupCache = gcache.New(100).LRU().Build()
...
@@ -31,11 +31,10 @@ var bannedGroupCache = gcache.New(100).LRU().Build()
func
GetBannedGroups
(
model
*
domain
.
Model
)
([]
GroupBanned
,
error
)
{
func
GetBannedGroups
(
model
*
domain
.
Model
)
([]
GroupBanned
,
error
)
{
key
:=
"banned"
key
:=
"banned"
if
data
,
err
:=
bannedGroupCache
.
Get
(
key
);
err
==
nil
{
if
data
,
err
:=
bannedGroupCache
.
Get
(
key
);
err
==
nil
{
model
.
Log
.
Infof
(
"GetBannedGroups cache:%v"
,
len
(
data
.
([]
GroupBanned
)))
return
data
.
([]
GroupBanned
),
nil
return
data
.
([]
GroupBanned
),
nil
}
}
result
:=
make
([]
GroupBanned
,
0
)
result
:=
make
([]
GroupBanned
,
0
)
err
:=
model
.
D
b
.
Find
(
&
result
)
.
Error
err
:=
model
.
D
B
()
.
Find
(
&
result
)
.
Error
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
domain/model/group_m/mic.go
View file @
577a8fef
...
@@ -3,6 +3,7 @@ package group_m
...
@@ -3,6 +3,7 @@ package group_m
import
(
import
(
"context"
"context"
"encoding/json"
"encoding/json"
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/mylogrus"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/config"
...
@@ -14,6 +15,7 @@ import (
...
@@ -14,6 +15,7 @@ import (
"gorm.io/gorm"
"gorm.io/gorm"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key/mic_k"
"hilo-group/common"
"hilo-group/common"
"hilo-group/domain/model/noble_m"
"hilo-group/domain/model/noble_m"
"hilo-group/domain/model/res_m"
"hilo-group/domain/model/res_m"
...
@@ -255,6 +257,10 @@ func (mic *Mic) In(userId uint64, externalId string) error {
...
@@ -255,6 +257,10 @@ func (mic *Mic) In(userId uint64, externalId string) error {
return
bizerr
.
GroupMicUserHasIn
return
bizerr
.
GroupMicUserHasIn
}
}
// 增加群组中上麦用户
groupMicUserKey
:=
mic_k
.
GetGroupOnMicUser
(
mic
.
GroupUuid
)
mic
.
model
.
Redis
.
HSet
(
mic
.
model
,
groupMicUserKey
,
mic
.
I
,
userId
)
//离开动作已结束,增加到队列中
//离开动作已结束,增加到队列中
MicChangeRPush
(
mic
.
model
,
mic
.
GroupUuid
,
mic
.
I
)
MicChangeRPush
(
mic
.
model
,
mic
.
GroupUuid
,
mic
.
I
)
...
@@ -385,6 +391,10 @@ func (micUser *MicUser) leave(operateUserId uint64, operateExternalId string) er
...
@@ -385,6 +391,10 @@ func (micUser *MicUser) leave(operateUserId uint64, operateExternalId string) er
//return bizerr.GroupMicErr
//return bizerr.GroupMicErr
}
}
// 减少群组中上麦用户
groupMicUserKey
:=
mic_k
.
GetGroupOnMicUser
(
micUser
.
GroupUuid
)
micUser
.
model
.
Redis
.
HDel
(
micUser
.
model
,
groupMicUserKey
,
fmt
.
Sprintf
(
"%d"
,
micUser
.
I
))
//离开动作已结束,增加到队列中
//离开动作已结束,增加到队列中
MicChangeRPush
(
micUser
.
model
,
micUser
.
GroupUuid
,
micUser
.
I
)
MicChangeRPush
(
micUser
.
model
,
micUser
.
GroupUuid
,
micUser
.
I
)
...
@@ -824,12 +834,14 @@ func groupMicHasIn(model *domain.Model, groupId string, userId mysql.ID) {
...
@@ -824,12 +834,14 @@ func groupMicHasIn(model *domain.Model, groupId string, userId mysql.ID) {
}
else
{
}
else
{
println
(
n
)
println
(
n
)
}
}
if
_
,
err
:=
redisCli
.
GetRedis
()
.
ZAdd
(
context
.
Background
(),
redis_key
.
GetPrefixGroupMicHasInUserTime
(),
&
redis2
.
Z
{
// 下面的是只写,不查的。 todo 直接干掉???
Score
:
float64
(
time
.
Now
()
.
Unix
()),
// 只是知道用户在哪个时间点上了哪个群的麦,但是不知道上了哪个麦位置, 而且micUser已经有统计这些信息了
Member
:
getMemberStr
(
groupId
,
userId
),
//if _, err := redisCli.GetRedis().ZAdd(context.Background(), redis_key.GetPrefixGroupMicHasInUserTime(), &redis2.Z{
})
.
Result
();
err
!=
nil
{
// Score: float64(time.Now().Unix()),
model
.
Log
.
Errorf
(
"groupMicHasIn redis:GetPrefixGroupMicHasInTime groupId:%v err:%v"
,
groupId
,
err
)
// Member: getMemberStr(groupId, userId),
}
//}).Result(); err != nil {
// model.Log.Errorf("groupMicHasIn redis:GetPrefixGroupMicHasInTime groupId:%v err:%v", groupId, err)
//}
}
}
const
micHasInScript
=
"local flag = redis.call('EXISTS', '{key1}', '{key2}', '{key3}', '{key4}', '{key5}', '{key6}', '{key7}', '{key8}', '{key9}', '{key10}', '{key11}', '{key12}', '{key13}', '{key14}', '{key15}', '{key16}', '{key17}', '{key18}', '{key19}', '{key20}') if flag == 0 then redis.call('Srem', '{key}', '{remKey}') end return flag "
const
micHasInScript
=
"local flag = redis.call('EXISTS', '{key1}', '{key2}', '{key3}', '{key4}', '{key5}', '{key6}', '{key7}', '{key8}', '{key9}', '{key10}', '{key11}', '{key12}', '{key13}', '{key14}', '{key15}', '{key16}', '{key17}', '{key18}', '{key19}', '{key20}') if flag == 0 then redis.call('Srem', '{key}', '{remKey}') end return flag "
...
@@ -914,7 +926,40 @@ func GetMicHasInGroupNum(model *domain.Model) (map[string]int64, error) {
...
@@ -914,7 +926,40 @@ func GetMicHasInGroupNum(model *domain.Model) (map[string]int64, error) {
}
}
// cache 1min
// cache 1min
_
=
micGroupNumCache
.
SetWithExpire
(
micGroupNumKey
,
resultGroupUuids
,
time
.
Minute
*
15
)
_
=
micGroupNumCache
.
SetWithExpire
(
micGroupNumKey
,
resultGroupUuids
,
time
.
Minute
*
15
)
//model.Log.Infof("GetMicHasInGroupNum cache miss:%v", resultGroupUuids)
return
resultGroupUuids
,
nil
}
// 获取麦上人数
func
GetMicHasInGroupNumByList
(
model
*
domain
.
Model
,
groupIds
[]
string
)
(
map
[
string
]
int64
,
error
)
{
resultGroupUuids
:=
make
(
map
[
string
]
int64
,
len
(
groupIds
))
micHasInKey
:=
redis_key
.
GetPrefixGroupMicHasIn
()
for
_
,
group
:=
range
groupIds
{
isMem
,
err
:=
redisCli
.
GetRedis
()
.
SIsMember
(
context
.
Background
(),
micHasInKey
,
group
)
.
Result
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetMicHasInGroupNumByList err:%v"
,
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
if
isMem
{
s
:=
strings
.
Replace
(
micHasInScript
,
"{key}"
,
micHasInKey
,
-
1
)
s
=
strings
.
Replace
(
s
,
"{remKey}"
,
group
,
-
1
)
for
i
:=
1
;
i
<=
MaxMicNum
;
i
++
{
s
=
strings
.
Replace
(
s
,
"{key"
+
strconv
.
Itoa
(
i
)
+
"}"
,
redis_key
.
GetPrefixGroupMicUser
(
group
,
i
),
-
1
)
}
//r, err := redis2.NewScript(s).Run(context.Background(), redisCli.GetRedis(), []string{}).Result()
sha1
,
err
:=
model
.
Redis
.
ScriptLoad
(
model
,
s
)
.
Result
()
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
micNum
,
err
:=
model
.
Redis
.
EvalSha
(
model
,
sha1
,
nil
,
nil
)
.
Int64
()
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
//d := r.(int64)
if
micNum
>
0
{
resultGroupUuids
[
group
]
=
micNum
}
}
}
return
resultGroupUuids
,
nil
return
resultGroupUuids
,
nil
}
}
...
...
domain/model/group_m/micData.go
View file @
577a8fef
...
@@ -96,7 +96,7 @@ func MicGroupKickOutRPush(model *domain.Model, groupUid string, userExternalId s
...
@@ -96,7 +96,7 @@ func MicGroupKickOutRPush(model *domain.Model, groupUid string, userExternalId s
}
}
// socket通知被拉黑者退房
// socket通知被拉黑者退房
rpc
.
SendQuitRoom
(
beKickuserId
,
2
,
txGroupId
)
rpc
.
SendQuitRoom
(
beKickuserId
,
2
,
txGroupId
)
if
n
,
err
:=
redisCli
.
GetRedis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
if
n
,
err
:=
redisCli
.
Get
Cluster
Redis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
model
.
Log
.
Errorf
(
"MicChangeRPush MicGroupKickOutRPush err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicGroupKickOutRPush err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
return
return
}
else
{
}
else
{
...
@@ -130,7 +130,7 @@ func MicSocketMicOutRPush(model *domain.Model, groupUid string, userExternalId s
...
@@ -130,7 +130,7 @@ func MicSocketMicOutRPush(model *domain.Model, groupUid string, userExternalId s
model
.
Log
.
Errorf
(
"MicChangeRPush MicSocketMicOutRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicSocketMicOutRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
return
return
}
}
if
n
,
err
:=
redisCli
.
GetRedis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
if
n
,
err
:=
redisCli
.
Get
Cluster
Redis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
model
.
Log
.
Errorf
(
"MicChangeRPush MicSocketMicOutRPush err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicSocketMicOutRPush err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
return
return
}
else
{
}
else
{
...
@@ -165,7 +165,7 @@ func MicNumChangeRPush(model *domain.Model, groupUid string, micNumType group_e.
...
@@ -165,7 +165,7 @@ func MicNumChangeRPush(model *domain.Model, groupUid string, micNumType group_e.
model
.
Log
.
Errorf
(
"MicChangeRPush MicNumChangeRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicNumChangeRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
return
return
}
}
if
n
,
err
:=
redisCli
.
GetRedis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
if
n
,
err
:=
redisCli
.
Get
Cluster
Redis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
model
.
Log
.
Errorf
(
"MicChangeRPush MicNumChangeRPush err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicNumChangeRPush err:%+v, groupUuid:%v, micContent:%+v"
,
err
,
groupUid
,
string
(
str
))
return
return
}
else
{
}
else
{
...
@@ -206,7 +206,7 @@ func MicEmptyRPush(model *domain.Model, groupUid string, i int) {
...
@@ -206,7 +206,7 @@ func MicEmptyRPush(model *domain.Model, groupUid string, i int) {
model
.
Log
.
Errorf
(
"MicChangeRPush MicEmptyRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, i:%v, micContent:%+v"
,
err
,
groupUid
,
i
,
string
(
micContent
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicEmptyRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, i:%v, micContent:%+v"
,
err
,
groupUid
,
i
,
string
(
micContent
))
return
return
}
}
if
n
,
err
:=
redisCli
.
GetRedis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
if
n
,
err
:=
redisCli
.
Get
Cluster
Redis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
model
.
Log
.
Errorf
(
"MicChangeRPush MicEmptyRPush err:%+v, groupUuid:%v, i:%v, micContent:%+v"
,
err
,
groupUid
,
i
,
string
(
micContent
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicEmptyRPush err:%+v, groupUuid:%v, i:%v, micContent:%+v"
,
err
,
groupUid
,
i
,
string
(
micContent
))
return
return
}
else
{
}
else
{
...
@@ -243,7 +243,7 @@ func MicChangeRPush(model *domain.Model, groupUid string, i int) {
...
@@ -243,7 +243,7 @@ func MicChangeRPush(model *domain.Model, groupUid string, i int) {
model
.
Log
.
Errorf
(
"MicChangeRPush MicChangeRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, i:%v, micContent:%+v"
,
err
,
groupUid
,
i
,
string
(
micContentStr
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicChangeRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, i:%v, micContent:%+v"
,
err
,
groupUid
,
i
,
string
(
micContentStr
))
return
return
}
}
if
n
,
err
:=
redisCli
.
GetRedis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
if
n
,
err
:=
redisCli
.
Get
Cluster
Redis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
model
.
Log
.
Errorf
(
"MicChangeRPush MicChangeRPush err:%+v, groupUuid:%v, i:%v, micContent:%+v"
,
err
,
groupUid
,
i
,
string
(
micContentStr
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicChangeRPush err:%+v, groupUuid:%v, i:%v, micContent:%+v"
,
err
,
groupUid
,
i
,
string
(
micContentStr
))
return
return
}
else
{
}
else
{
...
@@ -288,7 +288,7 @@ func MicAllRPush(model *domain.Model, groupUid string, externalId string) error
...
@@ -288,7 +288,7 @@ func MicAllRPush(model *domain.Model, groupUid string, externalId string) error
model
.
Log
.
Errorf
(
"MicChangeRPush MicAllRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, externalId:%v, micContent:%+v"
,
err
,
groupUid
,
externalId
,
string
(
micContentStr
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicAllRPush Marshal MicSystemMsg err:%+v, groupUuid:%v, externalId:%v, micContent:%+v"
,
err
,
groupUid
,
externalId
,
string
(
micContentStr
))
continue
continue
}
}
if
n
,
err
:=
redisCli
.
GetRedis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
if
n
,
err
:=
redisCli
.
Get
Cluster
Redis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
model
.
Log
.
Errorf
(
"MicChangeRPush MicAllRPush err:%+v, groupUuid:%v, externalId:%v, micContent:%+v"
,
err
,
groupUid
,
externalId
,
string
(
micContentStr
))
model
.
Log
.
Errorf
(
"MicChangeRPush MicAllRPush err:%+v, groupUuid:%v, externalId:%v, micContent:%+v"
,
err
,
groupUid
,
externalId
,
string
(
micContentStr
))
continue
continue
}
else
{
}
else
{
...
@@ -312,7 +312,7 @@ func MicRPush(model *domain.Model, txGroupId string, msg GroupSystemMsg) error {
...
@@ -312,7 +312,7 @@ func MicRPush(model *domain.Model, txGroupId string, msg GroupSystemMsg) error {
model
.
Log
.
Errorf
(
"MicRPush Marshal MicSystemMsg err:%+v, txGroupId:%v, micContent:%+v"
,
err
,
txGroupId
,
string
(
str
))
model
.
Log
.
Errorf
(
"MicRPush Marshal MicSystemMsg err:%+v, txGroupId:%v, micContent:%+v"
,
err
,
txGroupId
,
string
(
str
))
return
err
return
err
}
}
if
n
,
err
:=
redisCli
.
GetRedis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
if
n
,
err
:=
redisCli
.
Get
Cluster
Redis
()
.
RPush
(
context
.
Background
(),
redis_key
.
GetMicInfoChange
(),
string
(
str
))
.
Result
();
err
!=
nil
||
n
==
0
{
model
.
Log
.
Errorf
(
"MicRPush err:%+v, txGroupId:%v, micContent:%+v"
,
err
,
txGroupId
,
string
(
str
))
model
.
Log
.
Errorf
(
"MicRPush err:%+v, txGroupId:%v, micContent:%+v"
,
err
,
txGroupId
,
string
(
str
))
return
err
return
err
}
}
...
...
domain/model/group_m/room.go
View file @
577a8fef
...
@@ -14,6 +14,7 @@ import (
...
@@ -14,6 +14,7 @@ import (
"gorm.io/gorm/clause"
"gorm.io/gorm/clause"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key/group_k"
"hilo-group/domain/cache/room_c"
"hilo-group/domain/cache/room_c"
"hilo-group/domain/model/user_m"
"hilo-group/domain/model/user_m"
"hilo-group/myerr"
"hilo-group/myerr"
...
@@ -49,14 +50,14 @@ func RoomLivingExpire(model *domain.Model, groupUid string, userId uint64) {
...
@@ -49,14 +50,14 @@ func RoomLivingExpire(model *domain.Model, groupUid string, userId uint64) {
model
.
Log
.
Infof
(
"room RoomLivingExpire userId:%v, groupUid:%v"
,
userId
,
groupUid
)
model
.
Log
.
Infof
(
"room RoomLivingExpire userId:%v, groupUid:%v"
,
userId
,
groupUid
)
//
//
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
i
,
err
:=
redisCli
.
GetRedis
()
.
ZAdd
(
context
.
Background
(),
key
,
&
redis2
.
Z
{
_
,
err
:=
model
.
RedisCluster
.
ZAdd
(
context
.
Background
(),
key
,
&
redis2
.
Z
{
Score
:
float64
(
time
.
Now
()
.
Unix
()),
Score
:
float64
(
time
.
Now
()
.
Unix
()),
Member
:
getMemberStr
(
groupUid
,
userId
),
Member
:
getMemberStr
(
groupUid
,
userId
),
})
.
Result
()
})
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"RoomLivingExpire ZAdd key:%v, groupUid:%v, userId:%v, err:%v"
,
key
,
groupUid
,
userId
,
err
)
model
.
Log
.
Errorf
(
"RoomLivingExpire ZAdd key:%v, groupUid:%v, userId:%v, err:%v"
,
key
,
groupUid
,
userId
,
err
)
}
else
{
}
else
{
model
.
Log
.
Infof
(
"RoomLivingExpire ZAdd key:%v, groupUid:%v, userId:%v result:%v"
,
key
,
groupUid
,
userId
,
i
)
//
model.Log.Infof("RoomLivingExpire ZAdd key:%v, groupUid:%v, userId:%v result:%v", key, groupUid, userId, i)
}
}
}
}
...
@@ -69,14 +70,14 @@ func RoomLivingIn(model *domain.Model, groupUid string, userId uint64, externalI
...
@@ -69,14 +70,14 @@ func RoomLivingIn(model *domain.Model, groupUid string, userId uint64, externalI
}
}
//
//
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
i
,
err
:=
redisCli
.
GetRedis
()
.
ZAdd
(
context
.
Background
(),
key
,
&
redis2
.
Z
{
_
,
err
:=
model
.
RedisCluster
.
ZAdd
(
context
.
Background
(),
key
,
&
redis2
.
Z
{
Score
:
float64
(
time
.
Now
()
.
Unix
()),
Score
:
float64
(
time
.
Now
()
.
Unix
()),
Member
:
getMemberStr
(
groupUid
,
userId
),
Member
:
getMemberStr
(
groupUid
,
userId
),
})
.
Result
()
})
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"UpdateRoomLiving ZAdd key:%v, groupUid:%v, userId:%v, err:%v"
,
key
,
groupUid
,
userId
,
err
)
model
.
Log
.
Errorf
(
"UpdateRoomLiving ZAdd key:%v, groupUid:%v, userId:%v, err:%v"
,
key
,
groupUid
,
userId
,
err
)
}
else
{
}
else
{
model
.
Log
.
Infof
(
"UpdateRoomLiving ZAdd key:%v, groupUid:%v, userId:%v result:%v"
,
key
,
groupUid
,
userId
,
i
)
//
model.Log.Infof("UpdateRoomLiving ZAdd key:%v, groupUid:%v, userId:%v result:%v", key, groupUid, userId, i)
}
}
go
func
(
myContext
*
mycontext
.
MyContext
,
groupId
string
)
{
go
func
(
myContext
*
mycontext
.
MyContext
,
groupId
string
)
{
...
@@ -111,11 +112,11 @@ func roomLivingLeave(model *domain.Model, userId uint64, groupId string) ([]stri
...
@@ -111,11 +112,11 @@ func roomLivingLeave(model *domain.Model, userId uint64, groupId string) ([]stri
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
//if err := redisCli.ClearExpired(key, expireMinute); err != nil {
//if err := redisCli.ClearExpired(key, expireMinute); err != nil {
if
err
:=
model
.
Redis
.
ZRemRangeByScore
(
model
,
key
,
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
-
expireMinute
,
10
))
.
Err
();
err
!=
nil
{
if
err
:=
model
.
Redis
Cluster
.
ZRemRangeByScore
(
model
,
key
,
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
-
expireMinute
,
10
))
.
Err
();
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
data
,
err
:=
redisCli
.
GetRedis
()
.
ZRange
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
data
,
err
:=
model
.
RedisCluster
.
ZRange
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
...
@@ -124,12 +125,12 @@ func roomLivingLeave(model *domain.Model, userId uint64, groupId string) ([]stri
...
@@ -124,12 +125,12 @@ func roomLivingLeave(model *domain.Model, userId uint64, groupId string) ([]stri
for
i
,
_
:=
range
data
{
for
i
,
_
:=
range
data
{
gid
,
uid
:=
analysisMemberStr
(
data
[
i
])
gid
,
uid
:=
analysisMemberStr
(
data
[
i
])
if
uid
==
userId
&&
(
groupId
==
""
||
gid
==
groupId
)
{
if
uid
==
userId
&&
(
groupId
==
""
||
gid
==
groupId
)
{
if
_
,
err
:=
redisCli
.
GetRedis
()
.
ZRem
(
context
.
Background
(),
key
,
getMemberStr
(
gid
,
uid
))
.
Result
();
err
!=
nil
{
if
_
,
err
:=
model
.
RedisCluster
.
ZRem
(
context
.
Background
(),
key
,
getMemberStr
(
gid
,
uid
))
.
Result
();
err
!=
nil
{
model
.
Log
.
Errorf
(
"RoomLivingLeave ZRem key:%s, groupId:%s, userId:%d, err:%v"
,
key
,
gid
,
uid
,
err
)
model
.
Log
.
Errorf
(
"RoomLivingLeave ZRem key:%s, groupId:%s, userId:%d, err:%v"
,
key
,
gid
,
uid
,
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
else
{
}
else
{
groupIds
=
append
(
groupIds
,
gid
)
groupIds
=
append
(
groupIds
,
gid
)
model
.
Log
.
Infof
(
"RoomLivingLeave ZRem success key:%s, groupId:%s, userId:%d"
,
key
,
gid
,
uid
)
//
model.Log.Infof("RoomLivingLeave ZRem success key:%s, groupId:%s, userId:%d", key, gid, uid)
}
}
// 发信令,让前端重新拉取,接受容错,
// 发信令,让前端重新拉取,接受容错,
...
@@ -271,11 +272,11 @@ func RoomLivingExistsUserId(groupUid string) ([]uint64, error) {
...
@@ -271,11 +272,11 @@ func RoomLivingExistsUserId(groupUid string) ([]uint64, error) {
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
//if err := redisCli.ClearExpired(key, expireMinute); err != nil {
//if err := redisCli.ClearExpired(key, expireMinute); err != nil {
var
model
=
domain
.
CreateModelNil
()
var
model
=
domain
.
CreateModelNil
()
if
err
:=
model
.
Redis
.
ZRemRangeByScore
(
model
,
key
,
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
-
expireMinute
,
10
))
.
Err
();
err
!=
nil
{
if
err
:=
model
.
Redis
Cluster
.
ZRemRangeByScore
(
model
,
key
,
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
-
expireMinute
,
10
))
.
Err
();
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
groupUserIdstrs
,
err
:=
redisCli
.
GetRedis
()
.
ZRevRange
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
groupUserIdstrs
,
err
:=
model
.
RedisCluster
.
ZRevRange
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
...
@@ -299,11 +300,11 @@ func RoomLivingUserIdFilter(userIds []mysql.ID) (map[mysql.ID]string, error) {
...
@@ -299,11 +300,11 @@ func RoomLivingUserIdFilter(userIds []mysql.ID) (map[mysql.ID]string, error) {
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
//if err := redisCli.ClearExpired(key, expireMinute); err != nil {
//if err := redisCli.ClearExpired(key, expireMinute); err != nil {
model
:=
domain
.
CreateModelNil
()
model
:=
domain
.
CreateModelNil
()
if
err
:=
model
.
Redis
.
ZRemRangeByScore
(
model
,
key
,
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
-
expireMinute
,
10
))
.
Err
();
err
!=
nil
{
if
err
:=
model
.
Redis
Cluster
.
ZRemRangeByScore
(
model
,
key
,
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
-
expireMinute
,
10
))
.
Err
();
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
groupUserIdstrs
,
err
:=
redisCli
.
GetRedis
()
.
ZRange
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
groupUserIdstrs
,
err
:=
model
.
RedisCluster
.
ZRange
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
...
@@ -324,12 +325,12 @@ func RoomLivingUserIdFilter(userIds []mysql.ID) (map[mysql.ID]string, error) {
...
@@ -324,12 +325,12 @@ func RoomLivingUserIdFilter(userIds []mysql.ID) (map[mysql.ID]string, error) {
func
RoomLivingExistsGroup
(
model
*
domain
.
Model
)
(
map
[
string
]
map
[
uint64
]
struct
{},
error
)
{
func
RoomLivingExistsGroup
(
model
*
domain
.
Model
)
(
map
[
string
]
map
[
uint64
]
struct
{},
error
)
{
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
key
:=
redis_key
.
GetPrefixGroupRoomLiving
()
//if err := redisCli.ClearExpired(key, expireMinute); err != nil {
//if err := redisCli.ClearExpired(key, expireMinute); err != nil {
if
err
:=
model
.
Redis
.
ZRemRangeByScore
(
model
,
key
,
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
-
expireMinute
,
10
))
.
Err
();
err
!=
nil
{
if
err
:=
model
.
Redis
Cluster
.
ZRemRangeByScore
(
model
,
key
,
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
Unix
()
-
expireMinute
,
10
))
.
Err
();
err
!=
nil
{
model
.
Log
.
Infof
(
"RoomLivingExistsGroup: err:%v"
,
err
)
model
.
Log
.
Infof
(
"RoomLivingExistsGroup: err:%v"
,
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
groupUserIdstrs
,
err
:=
redisCli
.
GetRedis
()
.
ZRange
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
groupUserIdstrs
,
err
:=
model
.
RedisCluster
.
ZRange
(
context
.
Background
(),
key
,
0
,
-
1
)
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
...
@@ -343,7 +344,7 @@ func RoomLivingExistsGroup(model *domain.Model) (map[string]map[uint64]struct{},
...
@@ -343,7 +344,7 @@ func RoomLivingExistsGroup(model *domain.Model) (map[string]map[uint64]struct{},
groupGroup
[
tempGroupUid
]
=
map
[
uint64
]
struct
{}{
userId
:
{}}
groupGroup
[
tempGroupUid
]
=
map
[
uint64
]
struct
{}{
userId
:
{}}
}
}
}
}
model
.
Log
.
Infof
(
"RoomLivingExistsGroup size = %d"
,
len
(
groupGroup
))
//
model.Log.Infof("RoomLivingExistsGroup size = %d", len(groupGroup))
return
groupGroup
,
nil
return
groupGroup
,
nil
}
}
...
@@ -389,18 +390,8 @@ func GetAllGroupsSorted(model *domain.Model) ([]string, error) {
...
@@ -389,18 +390,8 @@ func GetAllGroupsSorted(model *domain.Model) ([]string, error) {
// 取房间最近N天的访问人数
// 取房间最近N天的访问人数
func
GetRoomVisitCount
(
groupId
string
)
(
int64
,
error
)
{
func
GetRoomVisitCount
(
groupId
string
)
(
int64
,
error
)
{
// 每群定时请一次数据可以了
key
:=
group_k
.
GetUserEnterRoomGroupKey
(
groupId
)
now
:=
time
.
Now
()
visitCount
,
err
:=
redisCli
.
GetRedis
()
.
ZCard
(
context
.
Background
(),
key
)
.
Result
()
if
now
.
Second
()
%
redis_key
.
GroupInDurationClearPeriod
==
0
{
// 先移除(N天之前的),后统计
if
_
,
err
:=
redisCli
.
GetRedis
()
.
ZRemRangeByScore
(
context
.
Background
(),
redis_key
.
GetPrefixGroupInUserDuration
(
groupId
),
"0"
,
strconv
.
FormatInt
(
time
.
Now
()
.
AddDate
(
0
,
0
,
-
redis_key
.
GroupInDurationTTL
)
.
Unix
(),
10
))
.
Result
();
err
!=
nil
{
return
0
,
err
}
}
visitCount
,
err
:=
redisCli
.
GetRedis
()
.
ZCard
(
context
.
Background
(),
redis_key
.
GetPrefixGroupInUserDuration
(
groupId
))
.
Result
()
if
err
!=
nil
{
if
err
!=
nil
{
return
0
,
err
return
0
,
err
}
}
...
@@ -429,15 +420,12 @@ func BatchGetRoomVisitCount(logE *logrus.Entry, groupIds []string) (map[string]i
...
@@ -429,15 +420,12 @@ func BatchGetRoomVisitCount(logE *logrus.Entry, groupIds []string) (map[string]i
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
//logE.Infof("MGetRoomVisitCount:%v", roomVisitCount)
visitCount
:=
make
(
map
[
string
]
int64
)
visitCount
:=
make
(
map
[
string
]
int64
)
for
_
,
groupId
:=
range
groupIds
{
for
_
,
groupId
:=
range
groupIds
{
// 先从二级缓存中找
// 先从二级缓存中找
if
c
,
ok
:=
roomVisitCount
[
groupId
];
ok
{
if
c
,
ok
:=
roomVisitCount
[
groupId
];
ok
{
if
vc
,
err
:=
strconv
.
ParseInt
(
c
,
10
,
64
);
err
==
nil
&&
vc
>
0
{
if
vc
,
err
:=
strconv
.
ParseInt
(
c
,
10
,
64
);
err
==
nil
&&
vc
>
0
{
logE
.
Debugf
(
"GetRoomVisitCount, from roomVisitCount %s - %d"
,
groupId
,
vc
)
visitCount
[
groupId
]
=
vc
visitCount
[
groupId
]
=
vc
}
}
}
else
{
}
else
{
...
...
domain/model/group_m/support.go
View file @
577a8fef
...
@@ -57,6 +57,24 @@ func GetAllGroupSupportResult(db *gorm.DB, period string) (map[string]uint8, err
...
@@ -57,6 +57,24 @@ func GetAllGroupSupportResult(db *gorm.DB, period string) (map[string]uint8, err
return
result
,
nil
return
result
,
nil
}
}
func
GetGroupSupportResult
(
db
*
gorm
.
DB
,
period
string
,
groupIds
[]
string
)
(
map
[
string
]
uint8
,
error
)
{
if
len
(
period
)
<=
0
{
return
nil
,
nil
}
gsr
:=
GroupSupportResult
{
Period
:
period
,
}
rows
:=
make
([]
GroupSupportResult
,
0
)
if
err
:=
db
.
Where
(
gsr
)
.
Where
(
"group_uid in (?)"
,
groupIds
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
result
:=
make
(
map
[
string
]
uint8
)
for
_
,
i
:=
range
rows
{
result
[
i
.
GroupUid
]
=
i
.
Grade
}
return
result
,
nil
}
//群组扶持奖励,利益分配者
//群组扶持奖励,利益分配者
type
GroupSupportAwardAdmin
struct
{
type
GroupSupportAwardAdmin
struct
{
mysql
.
Entity
mysql
.
Entity
...
@@ -102,14 +120,14 @@ func (gsa *GroupSupportAwardMgr) Get(db *gorm.DB) ([]GroupSupportAwardMgr, error
...
@@ -102,14 +120,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 +136,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
...
@@ -118,9 +136,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 +151,9 @@ func AddGroupSupportAward(model *domain.Model, groupUid string, issuerUserId mys
...
@@ -133,9 +151,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/model/mgr_m/banner.go
View file @
577a8fef
...
@@ -105,7 +105,7 @@ func (rb *RoomBanner) GetRoomBanners(db *gorm.DB, vcAllow bool) ([]RoomBanner, e
...
@@ -105,7 +105,7 @@ func (rb *RoomBanner) GetRoomBanners(db *gorm.DB, vcAllow bool) ([]RoomBanner, e
for
_
,
v
:=
range
rows
{
for
_
,
v
:=
range
rows
{
// 版本控制
// 版本控制
if
!
vcAllow
&&
(
v
.
ID
==
241
||
v
.
ID
==
781
||
v
.
ID
==
771
||
v
.
ID
==
911
||
v
.
ID
==
841
||
if
!
vcAllow
&&
(
v
.
ID
==
241
||
v
.
ID
==
781
||
v
.
ID
==
771
||
v
.
ID
==
911
||
v
.
ID
==
841
||
v
.
ID
==
851
||
v
.
ID
==
1001
||
v
.
ID
==
981
||
v
.
ID
==
1451
)
{
v
.
ID
==
851
||
v
.
ID
==
1001
||
v
.
ID
==
981
||
v
.
ID
==
1451
||
v
.
ID
==
1621
)
{
continue
continue
}
}
res
=
append
(
res
,
v
)
res
=
append
(
res
,
v
)
...
...
domain/model/mic_m/mic.go
View file @
577a8fef
...
@@ -7,6 +7,7 @@ import (
...
@@ -7,6 +7,7 @@ import (
"git.hilo.cn/hilo-common/utils"
"git.hilo.cn/hilo-common/utils"
"gorm.io/gorm"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"gorm.io/gorm/clause"
"hilo-group/_const/redis_key/mic_k"
"time"
"time"
)
)
...
@@ -75,6 +76,45 @@ func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64)
...
@@ -75,6 +76,45 @@ func IncrUserOnMic(model *domain.Model, userId mysql.ID, joinMicTimestamp int64)
})
})
}
}
// 增加用户上麦时长
// 事务操作
func
IncrUserOnMicV2
(
model
*
domain
.
Model
,
userId
mysql
.
ID
)
error
{
for
_
,
tz
:=
range
timezone_e
.
Timezones
{
day
:=
time
.
Now
()
.
In
(
timezone_e
.
TimezoneLocMap
[
tz
])
.
Format
(
"2006-01-02"
)
if
err
:=
model
.
DB
()
.
Model
(
UserOnMic
{})
.
Clauses
(
clause
.
OnConflict
{
Columns
:
[]
clause
.
Column
{{
Name
:
"date"
},
{
Name
:
"user_id"
},
{
Name
:
"tz"
}},
DoUpdates
:
clause
.
Assignments
(
map
[
string
]
interface
{}{
"seconds"
:
gorm
.
Expr
(
"seconds + ?"
,
60
),
}),
})
.
Create
(
&
UserOnMic
{
Date
:
day
,
UserId
:
userId
,
Seconds
:
60
,
Tz
:
tz
,
})
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrUserOnMic fail:%v"
,
err
)
return
err
}
}
return
nil
}
// 增加用户上麦时长
// Redis
func
IncrUserOnMicV3
(
model
*
domain
.
Model
,
userId
mysql
.
ID
)
error
{
for
_
,
tz
:=
range
timezone_e
.
Timezones
{
day
:=
time
.
Now
()
.
In
(
timezone_e
.
TimezoneLocMap
[
tz
])
.
Format
(
"2006-01-02"
)
tzStr
:=
"bj"
if
tz
==
timezone_e
.
TimezoneKSA
{
tzStr
=
"ksa"
}
tzKey
:=
mic_k
.
GetUserOnMicKey
(
userId
,
tzStr
,
day
)
model
.
RedisCluster
.
IncrBy
(
model
,
tzKey
,
60
)
model
.
RedisCluster
.
Expire
(
model
,
tzKey
,
time
.
Hour
*
24
*
30
)
// 30天上麦时长
}
return
nil
}
// 批量获取用户上麦时长
// 批量获取用户上麦时长
// @return userId->seconds
// @return userId->seconds
func
MGetUserOnMicSeconds
(
model
*
domain
.
Model
,
day
string
,
tz
timezone_e
.
Timezone
,
userIds
[]
uint64
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
func
MGetUserOnMicSeconds
(
model
*
domain
.
Model
,
day
string
,
tz
timezone_e
.
Timezone
,
userIds
[]
uint64
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
...
...
domain/model/res_m/country.go
View file @
577a8fef
...
@@ -213,3 +213,10 @@ func GetLangeByCountry(db *gorm.DB, country mysql.Str) (string, error) {
...
@@ -213,3 +213,10 @@ func GetLangeByCountry(db *gorm.DB, country mysql.Str) (string, error) {
return
""
,
myerr
.
WrapErr
(
err
)
return
""
,
myerr
.
WrapErr
(
err
)
}
}
}
}
//获取所有国家名字列表
func
GetCountryNameList
(
model
*
domain
.
Model
)
([]
string
,
error
)
{
res
:=
make
([]
string
,
0
)
err
:=
model
.
DB
()
.
Table
(
"res_country"
)
.
Select
(
"distinct(name) name"
)
.
Pluck
(
"name"
,
&
res
)
.
Error
return
res
,
myerr
.
WrapErr
(
err
)
}
domain/model/tim_m/user.go
View file @
577a8fef
...
@@ -387,10 +387,10 @@ func getOnlineStatus(extIds []string) ([]interface{}, error) {
...
@@ -387,10 +387,10 @@ func getOnlineStatus(extIds []string) ([]interface{}, error) {
for
_
,
e
:=
range
extIds
{
for
_
,
e
:=
range
extIds
{
keys
=
append
(
keys
,
redis_key
.
GetOnLineStatusKey
(
e
))
keys
=
append
(
keys
,
redis_key
.
GetOnLineStatusKey
(
e
))
}
}
return
redisCli
.
RedisClient
.
MGet
(
context
.
Background
(),
keys
...
)
.
Result
()
return
redisCli
.
RedisCl
usterCl
ient
.
MGet
(
context
.
Background
(),
keys
...
)
.
Result
()
}
}
func
setOnlineStatus
(
extId
string
,
status
uint
,
ttl
time
.
Duration
)
error
{
func
setOnlineStatus
(
extId
string
,
status
uint
,
ttl
time
.
Duration
)
error
{
key
:=
redis_key
.
GetOnLineStatusKey
(
extId
)
key
:=
redis_key
.
GetOnLineStatusKey
(
extId
)
return
redisCli
.
RedisClient
.
Set
(
context
.
Background
(),
key
,
status
,
ttl
)
.
Err
()
return
redisCli
.
RedisCl
usterCl
ient
.
Set
(
context
.
Background
(),
key
,
status
,
ttl
)
.
Err
()
}
}
domain/model/user_m/medal.go
View file @
577a8fef
...
@@ -70,8 +70,8 @@ func GetUserMedalMerge(logger *logrus.Entry, db *gorm.DB, userId mysql.ID) ([]ui
...
@@ -70,8 +70,8 @@ func GetUserMedalMerge(logger *logrus.Entry, db *gorm.DB, userId mysql.ID) ([]ui
}
}
}
}
}
}
logger
.
Infof
(
"maxGrade %+v"
,
maxGrades
)
//
logger.Infof("maxGrade %+v", maxGrades)
logger
.
Infof
(
"maxMedalIds %+v"
,
maxMedalIds
)
//
logger.Infof("maxMedalIds %+v", maxMedalIds)
mIds
:=
result
mIds
:=
result
result
=
make
([]
uint32
,
0
)
result
=
make
([]
uint32
,
0
)
...
...
domain/model/user_m/user.go
View file @
577a8fef
...
@@ -144,3 +144,39 @@ func GetUsers(model *domain.Model, ids []mysql.ID) ([]*User, error) {
...
@@ -144,3 +144,39 @@ func GetUsers(model *domain.Model, ids []mysql.ID) ([]*User, error) {
}
}
return
res
,
nil
return
res
,
nil
}
}
// 获取用户externalIds
// return []externalIds map[userId]extId map[userId]code
func
GetUserExternalIds
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
([]
string
,
map
[
uint64
]
string
,
map
[
uint64
]
string
)
{
var
res
[]
string
var
m
=
make
(
map
[
uint64
]
string
)
var
c
=
make
(
map
[
uint64
]
string
)
if
len
(
userIds
)
<=
0
{
return
res
,
m
,
c
}
var
users
[]
User
total
:=
len
(
userIds
)
const
NUM
=
500
start
,
end
:=
0
,
NUM
for
start
<
total
{
if
end
>
total
{
end
=
total
}
var
tmp
[]
User
tmpUserId
:=
userIds
[
start
:
end
]
if
err
:=
model
.
DB
()
.
Model
(
User
{})
.
Where
(
"id in (?)"
,
tmpUserId
)
.
Select
(
"id,external_id,code"
)
.
Find
(
&
tmp
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetUserExternalIds fail:%v"
,
err
)
}
else
if
len
(
tmp
)
>
0
{
users
=
append
(
users
,
tmp
...
)
}
start
+=
NUM
end
+=
NUM
}
for
_
,
user
:=
range
users
{
res
=
append
(
res
,
user
.
ExternalId
)
m
[
user
.
ID
]
=
user
.
ExternalId
c
[
user
.
ID
]
=
user
.
Code
}
return
res
,
m
,
c
}
domain/service/group_mic_s/group_mic.go
View file @
577a8fef
...
@@ -8,8 +8,10 @@ import (
...
@@ -8,8 +8,10 @@ import (
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/rpc"
"git.hilo.cn/hilo-common/rpc"
uuid
"github.com/satori/go.uuid"
uuid
"github.com/satori/go.uuid"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/redis_key"
"hilo-group/_const/redis_key"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/event/group_ev"
"hilo-group/domain/event/group_ev"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/group_m"
...
@@ -317,15 +319,13 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u
...
@@ -317,15 +319,13 @@ func (s *GroupMicService) IncrGroupPowerOnMicExpAndTime(groupId string, userId u
return
nil
return
nil
}
}
// 增加势力上麦经验
// 增加势力上麦经验
if
err
:=
groupPower_m
.
IncrGroupPowerExpOnMic
(
model
,
groupPowerId
,
userId
,
joinMicTimestamp
);
err
!=
nil
{
if
err
:=
groupPower_m
.
IncrGroupPowerExpOnMic
(
model
,
groupPowerId
,
userId
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerExpOnMic fail:%v"
,
err
)
model
.
Log
.
Errorf
(
"IncrGroupPowerExpOnMic fail:%v"
,
err
)
}
}
// 增加势力上麦时长-月
// 增加势力上麦时长-天/周/月
if
err
:=
groupPower_m
.
IncrGroupPowerStarOnMicMonth
(
model
,
groupPowerId
,
userId
,
joinMicTimestamp
);
err
!=
nil
{
//if err := groupPower_m.IncrGroupPowerStarOnMicDay(model, groupPowerId, userId, joinMicTimestamp); err != nil {
model
.
Log
.
Errorf
(
"IncrGroupPowerStarOnMicMonth fail:%v"
,
err
)
if
err
:=
groupPower_c
.
IncrGroupPowerDayStarScore
(
model
,
groupPowerId
,
userId
,
}
groupPower_e
.
GroupPowerStarTypeActive
,
60
);
err
!=
nil
{
// 增加势力上麦时长-天
if
err
:=
groupPower_m
.
IncrGroupPowerStarOnMicDay
(
model
,
groupPowerId
,
userId
,
joinMicTimestamp
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerStarOnMicDay fail:%v"
,
err
)
model
.
Log
.
Errorf
(
"IncrGroupPowerStarOnMicDay fail:%v"
,
err
)
}
}
return
nil
return
nil
...
...
domain/service/group_power_s/group_power.go
View file @
577a8fef
...
@@ -13,6 +13,7 @@ import (
...
@@ -13,6 +13,7 @@ import (
"hilo-group/_const/enum/msg_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/user_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/cache/user_c"
"hilo-group/domain/cache/user_c"
"hilo-group/domain/event/group_power_ev"
"hilo-group/domain/event/group_power_ev"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/groupPower_m"
...
@@ -154,7 +155,12 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI
...
@@ -154,7 +155,12 @@ func GetGroupPowerRankResp(model *domain.Model, beginDate, endDate string, userI
}
}
func
GetGroupPowerStar
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
,
month
string
)
([]
*
group_power_cv
.
CvGroupPowerStarData
,
error
)
{
func
GetGroupPowerStar
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
,
month
string
)
([]
*
group_power_cv
.
CvGroupPowerStarData
,
error
)
{
rank
,
err
:=
groupPower_m
.
GetGroupPowerMonthStarRank
(
model
,
groupPowerId
,
_type
,
offset
,
limit
,
month
)
monthTime
,
err
:=
time
.
Parse
(
"200601"
,
month
)
if
err
!=
nil
{
return
nil
,
err
}
//rank, err := groupPower_m.GetGroupPowerMonthStarRank(model, groupPowerId, _type, offset, limit, month)
rank
,
err
:=
groupPower_c
.
GetGroupPowerStarRankPeriod
(
model
,
"month"
,
groupPowerId
,
_type
,
offset
,
limit
,
monthTime
.
Format
(
"2006-01-02"
))
if
err
!=
nil
{
if
err
!=
nil
{
return
nil
,
err
return
nil
,
err
}
}
...
...
domain/service/group_s/group.go
View file @
577a8fef
...
@@ -4,8 +4,8 @@ import (
...
@@ -4,8 +4,8 @@ import (
"encoding/json"
"encoding/json"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/config"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/bluele/gcache"
"gorm.io/gorm"
"gorm.io/gorm"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/mgr_e"
"hilo-group/_const/enum/mgr_e"
...
@@ -18,7 +18,6 @@ import (
...
@@ -18,7 +18,6 @@ import (
"hilo-group/domain/model/user_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/signal_s"
"hilo-group/domain/service/signal_s"
"hilo-group/myerr"
"hilo-group/myerr"
"strconv"
"time"
"time"
)
)
...
@@ -31,7 +30,7 @@ func NewGroupService(myContext *mycontext.MyContext) *GroupService {
...
@@ -31,7 +30,7 @@ func NewGroupService(myContext *mycontext.MyContext) *GroupService {
return
&
GroupService
{
svc
}
return
&
GroupService
{
svc
}
}
}
// 取本周最高的扶持等级
fixme:删除这个过渡函数
// 取本周最高的扶持等级
func
(
s
*
GroupService
)
GetWeekMaxSupportLevelMap
()
(
map
[
string
]
uint8
,
error
)
{
func
(
s
*
GroupService
)
GetWeekMaxSupportLevelMap
()
(
map
[
string
]
uint8
,
error
)
{
return
s
.
GetSupportLevelMap
(
time
.
Now
()
.
AddDate
(
0
,
0
,
-
group_e
.
SUPPORT_LEVEL_PERIOD_DAY
))
return
s
.
GetSupportLevelMap
(
time
.
Now
()
.
AddDate
(
0
,
0
,
-
group_e
.
SUPPORT_LEVEL_PERIOD_DAY
))
}
}
...
@@ -42,56 +41,57 @@ func (s *GroupService) GetSupportLevelMap(now time.Time) (map[string]uint8, erro
...
@@ -42,56 +41,57 @@ func (s *GroupService) GetSupportLevelMap(now time.Time) (map[string]uint8, erro
_
,
_
,
period
:=
group_m
.
GetSupportLevelTime
(
now
)
_
,
_
,
period
:=
group_m
.
GetSupportLevelTime
(
now
)
levels
,
err
:=
GetAllSupportLevel
(
model
,
period
)
levels
,
err
:=
GetAllSupportLevel
(
model
,
period
)
if
err
!
=
nil
{
if
err
=
=
nil
{
return
nil
,
err
return
levels
,
nil
}
}
model
.
Log
.
Debugf
(
"GetSupportLevelMap, GET %s: %v"
,
period
,
levels
)
// cache miss
result
:=
make
(
map
[
string
]
uint8
,
0
)
result
,
err
:=
group_m
.
GetAllGroupSupportResult
(
model
.
Db
,
period
)
if
len
(
levels
)
>
0
{
if
err
==
nil
{
for
g
,
l
:=
range
levels
{
SaveAllSupportLevel
(
model
,
period
,
result
)
le
,
err
:=
strconv
.
ParseUint
(
l
,
10
,
8
)
if
err
==
nil
{
result
[
g
]
=
uint8
(
le
)
}
}
}
else
{
result
,
err
=
group_m
.
GetAllGroupSupportResult
(
model
.
Db
,
period
)
if
err
==
nil
{
ret
,
err
:=
SaveAllSupportLevel
(
model
,
period
,
result
)
model
.
Log
.
Infof
(
"GetSupportLevelMap SAVE ret = %d, err: %v"
,
ret
,
err
)
}
}
}
return
result
,
nil
return
result
,
nil
}
}
func
SaveAllSupportLevel
(
model
*
domain
.
Model
,
date
string
,
levels
map
[
string
]
uint8
)
(
int64
,
error
)
{
//// 取本周最高的扶持等级
values
:=
make
(
map
[
string
]
interface
{},
0
)
//func (s *GroupService) GetWeekMaxSupportLevelMapByIds(groupIds []string) (map[string]uint8, error) {
for
g
,
l
:=
range
levels
{
// return s.GetSupportLevelMapByIds(groupIds, time.Now().AddDate(0, 0, -group_e.SUPPORT_LEVEL_PERIOD_DAY))
if
l
>
0
{
//}
values
[
g
]
=
l
//
}
//func (s *GroupService) GetSupportLevelMapByIds(groupIds []string, now time.Time) (map[string]uint8, error) {
}
// model := domain.CreateModel(s.svc.CtxAndDb)
if
len
(
values
)
<=
0
{
//
return
0
,
nil
// _, _, period := group_m.GetSupportLevelTime(now)
}
//
key
:=
redis_key
.
GetPrefixSupportLevel
(
date
)
// levels, err := GetAllSupportLevel(model, period)
ret
,
err
:=
model
.
Redis
.
HSet
(
model
,
key
,
values
)
.
Result
()
// if err == nil {
// return levels, nil
// }
// // cache miss
//
// result, err := group_m.GetGroupSupportResult(model.DB(), period, groupIds)
// if err == nil {
// SaveAllSupportLevel(model, period, result)
// }
// return result, nil
//}
if
err
==
nil
{
// supportLevelLru Cache
// 设置一个TTL保险一些 TODO: 可以优化,保证数据总是有的
var
supportLevelCache
=
gcache
.
New
(
100
)
.
LRU
()
.
Build
()
ttl
:=
time
.
Hour
if
!
config
.
AppIsRelease
()
{
func
SaveAllSupportLevel
(
model
*
domain
.
Model
,
date
string
,
levels
map
[
string
]
uint8
)
{
ttl
=
time
.
Minute
key
:=
redis_key
.
GetPrefixSupportLevel
(
date
)
}
_
=
supportLevelCache
.
SetWithExpire
(
key
,
levels
,
time
.
Hour
)
model
.
Redis
.
Expire
(
model
,
key
,
ttl
)
return
}
return
ret
,
err
}
}
func
GetAllSupportLevel
(
model
*
domain
.
Model
,
date
string
)
(
map
[
string
]
string
,
error
)
{
func
GetAllSupportLevel
(
model
*
domain
.
Model
,
date
string
)
(
map
[
string
]
uint8
,
error
)
{
key
:=
redis_key
.
GetPrefixSupportLevel
(
date
)
key
:=
redis_key
.
GetPrefixSupportLevel
(
date
)
return
model
.
Redis
.
HGetAll
(
model
,
key
)
.
Result
()
if
data
,
err
:=
supportLevelCache
.
Get
(
key
);
err
==
nil
{
return
data
.
(
map
[
string
]
uint8
),
nil
}
else
{
return
map
[
string
]
uint8
{},
err
}
}
}
func
(
s
*
GroupService
)
GetJoinGroupLimit
(
userId
mysql
.
ID
)
(
uint
,
error
)
{
func
(
s
*
GroupService
)
GetJoinGroupLimit
(
userId
mysql
.
ID
)
(
uint
,
error
)
{
...
...
domain/service/group_s/group_list.go
0 → 100644
View file @
577a8fef
package
group_s
import
(
"context"
"git.hilo.cn/hilo-common/_const/rediskey"
"git.hilo.cn/hilo-common/domain"
"github.com/go-redis/redis/v8"
"hilo-group/_const/enum/gift_e"
"hilo-group/cv/gift_cv"
"hilo-group/domain/cache/room_c"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/res_m"
"sort"
"strconv"
"time"
)
func
SortGroupCommonCountryList
(
model
*
domain
.
Model
)
{
// 常用的国家
countryMap
:=
map
[
string
]
struct
{}{
"India"
:
{},
"Indonesia"
:
{},
"Iraq"
:
{},
"KSA"
:
{},
"Kuwait"
:
{},
"Pakistan"
:
{},
"Turkey"
:
{}}
for
country
,
_
:=
range
countryMap
{
sortGroupList
,
err
:=
GetGroupSortList
(
model
,
country
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"SortGroupCommonCountryList err:%v"
,
err
)
return
}
// 写入redis
err
=
setToRedis
(
model
,
country
,
sortGroupList
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"SortGroupCommonCountryList country:%v, len(sortGroupList):%v, err:%v"
,
country
,
len
(
sortGroupList
),
err
)
return
}
time
.
Sleep
(
time
.
Second
*
3
)
}
}
func
SortGroupNotCommonCountryList
(
model
*
domain
.
Model
)
{
// 常用的国家
countryMap
:=
map
[
string
]
struct
{}{
"India"
:
{},
"Indonesia"
:
{},
"Iraq"
:
{},
"KSA"
:
{},
"Kuwait"
:
{},
"Pakistan"
:
{},
"Turkey"
:
{}}
// 取所有的国家名字
allCountryList
,
err
:=
res_m
.
GetCountryNameList
(
model
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"SortGroupNotCommonCountryList err:%v"
,
err
)
return
}
for
_
,
country
:=
range
allCountryList
{
if
_
,
ok
:=
countryMap
[
country
];
ok
{
continue
}
// 计算非常用国家
sortGroupList
,
err
:=
GetGroupSortList
(
model
,
country
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"SortGroupNotCommonCountryList err:%v"
,
err
)
return
}
// 写入redis
err
=
setToRedis
(
model
,
country
,
sortGroupList
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"SortGroupNotCommonCountryList country:%v, len(sortGroupList):%v, err:%v"
,
country
,
len
(
sortGroupList
),
err
)
return
}
time
.
Sleep
(
time
.
Second
*
5
)
}
}
func
setToRedis
(
model
*
domain
.
Model
,
country
string
,
groupList
[]
string
)
error
{
// 写入redis
key
:=
rediskey
.
GetGroupCountrySortList
(
country
)
for
idx
,
group
:=
range
groupList
{
err
:=
model
.
RedisCluster
.
ZRemRangeByRank
(
context
.
Background
(),
key
,
int64
(
idx
),
int64
(
idx
))
.
Err
()
// 先删除旧的
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"setToRedis SortGroup key:%v, idx:%v, err:%v"
,
key
,
idx
,
err
)
return
err
}
// 插入
err
=
model
.
RedisCluster
.
ZAdd
(
context
.
Background
(),
key
,
&
redis
.
Z
{
Score
:
float64
(
idx
),
Member
:
group
})
.
Err
()
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"setToRedis SortGroup key:%v, idx:%v, group:%s, err:%v"
,
key
,
idx
,
group
,
err
)
return
err
}
if
idx
%
1000
==
0
{
time
.
Sleep
(
time
.
Millisecond
*
50
)
}
}
return
nil
}
// 计算国家群组列表排序
func
GetGroupSortList
(
model
*
domain
.
Model
,
country
string
)
([]
string
,
error
)
{
bannedGroups
,
err
:=
group_m
.
GetBannedGroupsMap
(
model
)
if
err
!=
nil
{
return
nil
,
err
}
beginTime
:=
time
.
Now
()
groups
,
banCount
,
visitCount
,
err
:=
GetCandidatesByCountry
(
model
,
bannedGroups
,
country
)
if
err
!=
nil
{
return
nil
,
err
}
endTime
:=
time
.
Now
()
model
.
Log
.
Infof
(
"GroupCountryListSort: candidates size = %d, takes %d ms banned = %d, visitCount size = %d"
,
len
(
groups
),
endTime
.
Sub
(
beginTime
)
.
Milliseconds
(),
banCount
,
len
(
visitCount
))
// 获取麦上有人的所有群组及麦上人数
micGroupNum
,
err
:=
group_m
.
GetMicHasInGroupNum
(
model
)
if
err
!=
nil
{
return
nil
,
err
}
model
.
Log
.
Infof
(
"GroupCountryListSort, micGroupNum : %v"
,
micGroupNum
)
model
.
Log
.
Infof
(
"GroupCountryListSort cost2:%v"
,
time
.
Now
()
.
Sub
(
beginTime
))
sortedGroupIds
:=
make
([]
string
,
0
)
diamondGroupIds
:=
make
([]
string
,
0
)
for
i
,
_
:=
range
groups
{
// 麦上没人也放出来
sortedGroupIds
=
append
(
sortedGroupIds
,
i
)
// 麦上有人才计算流水
if
micGroupNum
[
i
]
>
0
{
diamondGroupIds
=
append
(
diamondGroupIds
,
i
)
}
}
now
:=
time
.
Now
()
bTime
:=
now
.
Add
(
-
time
.
Minute
*
30
)
g
:=
gift_cv
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
}
diamonds
,
err
:=
g
.
GetRangeConsumeSummaryV2
(
bTime
,
now
,
diamondGroupIds
)
if
err
!=
nil
{
return
nil
,
err
}
model
.
Log
.
Infof
(
"GroupCountryListSort, diamonds in 30 mins: %v"
,
diamonds
)
model
.
Log
.
Infof
(
"GroupCountryListSort cost3:%v"
,
time
.
Now
()
.
Sub
(
beginTime
))
//supportLevels, err := NewGroupService(model.MyContext).GetWeekMaxSupportLevelMap()
//if err != nil {
// return nil, err
//}
//model.Log.Infof("GroupCountryListSort, supportLevels : %v", supportLevels)
model
.
Log
.
Infof
(
"GroupCountryListSort cost4:%v"
,
time
.
Now
()
.
Sub
(
beginTime
))
// 排序优先级2022-07-25
sort
.
Slice
(
sortedGroupIds
,
func
(
i
,
j
int
)
bool
{
gi
:=
sortedGroupIds
[
i
]
gj
:=
sortedGroupIds
[
j
]
// 1、按麦上人数多少排序
if
micGroupNum
[
gi
]
>
micGroupNum
[
gj
]
{
return
true
}
else
if
micGroupNum
[
gi
]
<
micGroupNum
[
gj
]
{
return
false
}
// 2、麦上人数相同,按30分钟内送礼钻石数排序
if
diamonds
[
gi
]
>
diamonds
[
gj
]
{
return
true
}
else
if
diamonds
[
gi
]
<
diamonds
[
gj
]
{
return
false
}
// 3. 根据热度排序groupInUserDuration
if
visitCount
[
gi
]
>
visitCount
[
gj
]
{
return
true
}
else
if
visitCount
[
gi
]
<
visitCount
[
gj
]
{
return
false
}
// * Final resort: 群组CODE,短号优先,然后按字母序
return
len
(
groups
[
gi
]
.
Code
)
<
len
(
groups
[
gj
]
.
Code
)
||
len
(
groups
[
gi
]
.
Code
)
==
len
(
groups
[
gj
]
.
Code
)
&&
groups
[
gi
]
.
Code
<
groups
[
gj
]
.
Code
})
model
.
Log
.
Infof
(
"GroupCountryListSort cost5:%v"
,
time
.
Now
()
.
Sub
(
beginTime
))
return
sortedGroupIds
,
nil
}
// 国家群候选:没有密码且没被封禁的群, 有国家
func
GetCandidatesByCountry
(
model
*
domain
.
Model
,
bannedGroups
map
[
string
]
uint64
,
country
string
)
(
map
[
string
]
*
group_m
.
GroupInfo
,
int
,
map
[
string
]
int64
,
error
)
{
noPwdGroups
,
err
:=
group_m
.
FindOwnerCountryGroups
(
model
,
country
)
if
err
!=
nil
{
return
nil
,
0
,
nil
,
err
}
var
groupIds
[]
string
for
_
,
v
:=
range
noPwdGroups
{
groupIds
=
append
(
groupIds
,
v
.
ImGroupId
)
// imGroupId
}
//roomVisitCount, err := room_c.GetAllRoomVisitCount()
roomVisitCount
,
err
:=
room_c
.
MGetRoomVisitCount
(
groupIds
)
if
err
!=
nil
{
return
nil
,
0
,
nil
,
err
}
gameRoom
:=
group_m
.
GetGameGroupsMap
(
model
)
banCount
:=
0
groups
:=
make
(
map
[
string
]
*
group_m
.
GroupInfo
,
0
)
visitCount
:=
make
(
map
[
string
]
int64
)
for
i
,
v
:=
range
noPwdGroups
{
// 过滤掉被封禁的群
if
bannedGroups
[
v
.
ImGroupId
]
!=
0
{
banCount
++
continue
}
// 过滤游戏房
if
gameRoom
[
v
.
ImGroupId
]
{
continue
}
// 先从二级缓存中找
if
c
,
ok
:=
roomVisitCount
[
v
.
ImGroupId
];
ok
{
if
vc
,
err
:=
strconv
.
ParseInt
(
c
,
10
,
64
);
err
==
nil
&&
vc
>
0
{
//model.Log.Debugf("getPopularCandidates, from roomVisitCount %s(%s) - %d", v.ImGroupId, v.Code, vc)
groups
[
v
.
ImGroupId
]
=
&
noPwdGroups
[
i
]
visitCount
[
v
.
ImGroupId
]
=
vc
}
}
else
{
// 如果没有,就从roomVisit中取
if
vc
,
err
:=
room_c
.
GetSetRoomVisitCount
(
v
.
ImGroupId
);
err
==
nil
&&
vc
>
0
{
model
.
Log
.
Infof
(
"getPopularCandidates, from roomVisit %s(%s) - %d"
,
v
.
ImGroupId
,
v
.
Code
,
vc
)
groups
[
v
.
ImGroupId
]
=
&
noPwdGroups
[
i
]
visitCount
[
v
.
ImGroupId
]
=
vc
}
}
}
return
groups
,
banCount
,
visitCount
,
nil
}
func
GetVisitCount
(
groupIds
[]
string
)
(
map
[
string
]
int64
,
error
)
{
roomVisitCount
,
err
:=
room_c
.
MGetRoomVisitCount
(
groupIds
)
if
err
!=
nil
{
return
nil
,
err
}
visitCount
:=
make
(
map
[
string
]
int64
)
for
_
,
v
:=
range
groupIds
{
// 先从二级缓存中找
if
c
,
ok
:=
roomVisitCount
[
v
];
ok
{
if
vc
,
err
:=
strconv
.
ParseInt
(
c
,
10
,
64
);
err
==
nil
&&
vc
>
0
{
visitCount
[
v
]
=
vc
}
}
else
{
// 如果没有,就从roomVisit中取
if
vc
,
err
:=
room_c
.
GetSetRoomVisitCount
(
v
);
err
==
nil
&&
vc
>
0
{
visitCount
[
v
]
=
vc
}
}
}
return
visitCount
,
nil
}
domain/service/group_s/group_support.go
View file @
577a8fef
...
@@ -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
passed
:=
true
userIds
=
make
([]
uint64
,
0
)
for
_
,
i
:=
range
m
{
m
:=
make
(
map
[
uint64
]
uint64
)
if
_
,
ok
:=
awards
[
i
];
ok
{
for
_
,
u
:=
range
uids
{
if
i
==
u
{
m
,
err
:=
user_m
.
GetSameImeiMap
(
model
,
u
)
passed
=
false
if
err
!=
nil
{
model
.
Log
.
Infof
(
"GroupSupportList: rule out %d, already awarded"
,
i
)
return
err
}
else
{
}
passed
=
false
model
.
Log
.
Infof
(
"GroupSupportList: rule out %d, imei awarded"
,
i
)
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
)
if
passed
==
true
{
userIds
=
append
(
userIds
,
u
)
_
,
supportLevel
,
err
:=
s
.
GetSupportLevel
(
groupId
)
}
else
{
if
err
!=
nil
{
out
=
append
(
out
,
u
)
return
err
}
}
}
model
.
Log
.
Infof
(
"GroupSupportList: uids %v, map %v"
,
uids
,
m
)
if
uint32
(
len
(
userIds
))
>
supportLevel
{
if
uint32
(
len
(
userIds
))
>
supportLevel
{
model
.
Log
.
Infof
(
"GroupSupportList: rule out %v, limit exeeded"
,
userIds
[
supportLevel
:
])
model
.
Log
.
Infof
(
"GroupSupportList: rule out %v, limit exeeded"
,
userIds
[
supportLevel
:
])
out
=
append
(
out
,
userIds
[
supportLevel
:
]
...
)
out
=
append
(
out
,
userIds
[
supportLevel
:
]
...
)
userIds
=
userIds
[
0
:
supportLevel
]
userIds
=
userIds
[
0
:
supportLevel
]
}
result
=
userIds
return
nil
})
if
err
==
nil
{
return
result
,
out
,
nil
}
else
{
return
nil
,
nil
,
err
}
}
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,50 @@ 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
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
&&
err
!=
redis
.
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
&&
err
!=
redis
.
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
{
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
}
}
...
...
local.ini
View file @
577a8fef
...
@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
...
@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
[REDIS]
[REDIS]
REDIS_HOST
=
47.244.34.27:6379
REDIS_HOST
=
47.244.34.27:6379
REDIS_PASSWORD
=
8QZ9JD1zLvPR3yHf
REDIS_PASSWORD
=
8QZ9JD1zLvPR3yHf
REDIS_CLUSTER_HOST
=
47.244.34.27:6379
REDIS_CLUSTER_PASSWORD
=
8QZ9JD1zLvPR3yHf
[JWT]
[JWT]
SECRET
=
hilo1632
SECRET
=
hilo1632
ISSUER_API
=
hiloApi
ISSUER_API
=
hiloApi
...
...
route/group_power_r/group_power.go
View file @
577a8fef
...
@@ -23,6 +23,7 @@ import (
...
@@ -23,6 +23,7 @@ import (
"hilo-group/cv/group_power_cv"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/medal_cv"
"hilo-group/cv/medal_cv"
"hilo-group/cv/user_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/cache/res_c"
"hilo-group/domain/cache/res_c"
"hilo-group/domain/cache/user_c"
"hilo-group/domain/cache/user_c"
"hilo-group/domain/model/game_m"
"hilo-group/domain/model/game_m"
...
@@ -820,7 +821,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -820,7 +821,7 @@ func GroupPowerInfo(c *gin.Context) (*mycontext.MyContext, error) {
}
}
}
}
// 补上家族之星三个榜一
// 补上家族之星三个榜一
stars
,
err
:=
groupPower_
m
.
GetGroupPowerMonthStartTop1
(
model
,
gp
.
ID
)
stars
,
err
:=
groupPower_
c
.
GetGroupPowerMonthStartTop1
(
model
,
gp
.
ID
)
if
err
!=
nil
{
if
err
!=
nil
{
return
myContext
,
myerr
.
WrapErr
(
err
)
return
myContext
,
myerr
.
WrapErr
(
err
)
}
}
...
...
route/group_power_r/group_rank.go
View file @
577a8fef
...
@@ -10,6 +10,7 @@ import (
...
@@ -10,6 +10,7 @@ import (
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/user_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_power_s"
"hilo-group/domain/service/group_power_s"
...
@@ -264,7 +265,7 @@ func GroupPowerStarPeriod(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -264,7 +265,7 @@ func GroupPowerStarPeriod(c *gin.Context) (*mycontext.MyContext, error) {
}
}
var
model
=
domain
.
CreateModelContext
(
myContext
)
var
model
=
domain
.
CreateModelContext
(
myContext
)
offset
,
limit
:=
(
param
.
PageIndex
-
1
)
*
param
.
PageSize
,
param
.
PageSize
offset
,
limit
:=
(
param
.
PageIndex
-
1
)
*
param
.
PageSize
,
param
.
PageSize
rank
,
err
:=
groupPower_
m
.
GetGroupPowerStarRankPeriod
(
model
,
period
,
param
.
GroupPowerId
,
param
.
Type
,
offset
,
limit
)
rank
,
err
:=
groupPower_
c
.
GetGroupPowerStarRankPeriod
(
model
,
period
,
param
.
GroupPowerId
,
param
.
Type
,
offset
,
limit
)
if
err
!=
nil
{
if
err
!=
nil
{
return
myContext
,
err
return
myContext
,
err
}
}
...
...
route/group_power_r/inner.go
View file @
577a8fef
package
group_power_r
package
group_power_r
import
(
import
(
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/_const/redis_key/groupPower_k"
"hilo-group/cv/group_power_cv"
"hilo-group/cv/group_power_cv"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/msg_m"
"hilo-group/domain/model/msg_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/model/user_m"
"hilo-group/domain/service/group_power_s"
"hilo-group/domain/service/group_power_s"
"hilo-group/myerr/bizerr"
"hilo-group/resp"
"hilo-group/resp"
"time"
)
)
type
MGetGroupPowerReq
struct
{
type
MGetGroupPowerReq
struct
{
...
@@ -93,3 +98,66 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -93,3 +98,66 @@ func Test(c *gin.Context) (*mycontext.MyContext, error) {
//}
//}
return
nil
,
nil
return
nil
,
nil
}
}
type
GroupPowerDayStar
struct
{
Date
time
.
Time
GroupPowerId
uint64
Type
groupPower_e
.
GroupPowerStarType
UserId
uint64
Score
uint64
}
// @Tags 国家势力-内部
// @Summary 同步家族之星到redis
// @Success 200
// @Router /inner/groupPower/sync/star [get]
func
SyncStar
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
t
:=
time
.
Now
()
start
:=
c
.
Query
(
"start"
)
end
:=
c
.
Query
(
"end"
)
if
len
(
start
)
<=
0
||
len
(
end
)
<=
0
{
return
myCtx
,
bizerr
.
InvalidParameter
}
var
model
=
domain
.
CreateModelContext
(
myCtx
)
var
stars
[]
GroupPowerDayStar
if
err
:=
model
.
DB
()
.
Table
(
"group_power_day_star"
)
.
Select
(
"`date`,group_power_id,type,user_id,SUM(score) score"
)
.
Where
(
"`date` BETWEEN ? AND ?"
,
start
,
end
)
.
Group
(
"`date`,group_power_id,type,user_id"
)
.
Find
(
&
stars
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"SyncStar fail:%v"
,
err
)
return
myCtx
,
err
}
ttl
:=
map
[
string
]
time
.
Duration
{
"day"
:
time
.
Hour
*
24
*
7
,
"week"
:
time
.
Hour
*
24
*
7
*
30
,
"month"
:
time
.
Hour
*
24
*
7
*
30
*
2
,
}
num
:=
len
(
stars
)
for
i
,
star
:=
range
stars
{
for
_
,
period
:=
range
[]
string
{
"day"
,
"week"
,
"month"
}
{
var
dateStr
string
switch
period
{
case
"day"
:
dateStr
=
star
.
Date
.
Format
(
"2006-01-02"
)
case
"week"
:
dateStr
=
now
.
With
(
star
.
Date
)
.
BeginningOfWeek
()
.
Format
(
"2006-01-02"
)
case
"month"
:
dateStr
=
now
.
With
(
star
.
Date
)
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
)
}
key
:=
groupPower_k
.
GetGroupPowerStarRankKey
(
star
.
Type
,
period
,
star
.
GroupPowerId
,
dateStr
)
model
.
RedisCluster
.
ZIncrBy
(
model
,
key
,
float64
(
star
.
Score
),
fmt
.
Sprintf
(
"%d"
,
star
.
UserId
))
model
.
RedisCluster
.
Expire
(
model
,
key
,
ttl
[
period
])
model
.
Log
.
Infof
(
"SyncStar i:%v,star:%v"
,
i
,
star
)
}
}
type
res
struct
{
Num
int
Cost
float64
}
resp
.
ResponseOk
(
c
,
res
{
Num
:
num
,
Cost
:
time
.
Now
()
.
Sub
(
t
)
.
Seconds
(),
})
return
myCtx
,
nil
}
route/group_r/group_info.go
View file @
577a8fef
...
@@ -374,7 +374,7 @@ func PluginReady(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -374,7 +374,7 @@ func PluginReady(c *gin.Context) (*mycontext.MyContext, error) {
// @Router /v1/imGroup/roomInfo/{groupId} [get]
// @Router /v1/imGroup/roomInfo/{groupId} [get]
func
GetRoomInfo
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
func
GetRoomInfo
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myContext
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
myContext
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
start
:=
time
.
Now
()
groupId
:=
c
.
Param
(
"groupId"
)
groupId
:=
c
.
Param
(
"groupId"
)
if
len
(
groupId
)
<=
0
{
if
len
(
groupId
)
<=
0
{
return
myContext
,
myerr
.
NewSysError
(
"groupId 为必填项"
)
return
myContext
,
myerr
.
NewSysError
(
"groupId 为必填项"
)
...
@@ -407,7 +407,8 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -407,7 +407,8 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
deviceType
,
appVersion
:=
cast
.
ToString
(
_deviceType
),
cast
.
ToString
(
_appVersion
)
deviceType
,
appVersion
:=
cast
.
ToString
(
_deviceType
),
cast
.
ToString
(
_appVersion
)
vc
:=
version_m
.
GetVersionControlByPlatform
(
model
,
deviceType
)
vc
:=
version_m
.
GetVersionControlByPlatform
(
model
,
deviceType
)
allow
,
err
:=
utils
.
CompareVersion
(
appVersion
,
fmt
.
Sprintf
(
"<= %s"
,
vc
.
AuditVersion
))
allow
,
err
:=
utils
.
CompareVersion
(
appVersion
,
fmt
.
Sprintf
(
"<= %s"
,
vc
.
AuditVersion
))
model
.
Log
.
Infof
(
"GetRoomInfo CompareVersion appVersion:%v,auditVersion:%v,allow:%v,err:%v"
,
appVersion
,
vc
.
AuditVersion
,
allow
,
err
)
model
.
Log
.
Infof
(
"GetRoomInfo cost 0:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
themeUrl
:=
""
themeUrl
:=
""
var
themeId
uint64
=
0
var
themeId
uint64
=
0
...
@@ -464,7 +465,8 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -464,7 +465,8 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
},
},
}
}
roles
,
_
,
err
:=
group_m
.
GetRolesInGroup
(
model
,
groupInfo
.
ImGroupId
)
model
.
Log
.
Infof
(
"GetRoomInfo cost 1:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
roles
,
orderList
,
err
:=
group_m
.
GetRolesInGroup
(
model
,
groupId
)
if
err
!=
nil
{
if
err
!=
nil
{
return
myContext
,
err
return
myContext
,
err
}
}
...
@@ -507,11 +509,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -507,11 +509,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
}
}
}
}
roles
,
orderList
,
err
:=
group_m
.
GetRolesInGroup
(
model
,
groupId
)
model
.
Log
.
Infof
(
"GetRoomInfo cost 2:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
if
err
!=
nil
{
return
myContext
,
err
}
users
,
err
:=
user_cv
.
GetUserTinyMap
(
orderList
)
users
,
err
:=
user_cv
.
GetUserTinyMap
(
orderList
)
if
err
!=
nil
{
if
err
!=
nil
{
return
myContext
,
err
return
myContext
,
err
...
@@ -549,6 +547,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -549,6 +547,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
}
}
result
.
WelcomeText
=
strings
.
ReplaceAll
(
result
.
WelcomeText
,
"@%s"
,
""
)
result
.
WelcomeText
=
strings
.
ReplaceAll
(
result
.
WelcomeText
,
"@%s"
,
""
)
model
.
Log
.
Infof
(
"GetRoomInfo cost 3:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
// 补上房间流水勋章
// 补上房间流水勋章
var
pe
*
medal_cv
.
PicElement
var
pe
*
medal_cv
.
PicElement
result
.
TotalConsume
,
pe
,
err
=
medal_cv
.
GetGroupConsumeMedal
(
model
,
groupId
)
result
.
TotalConsume
,
pe
,
err
=
medal_cv
.
GetGroupConsumeMedal
(
model
,
groupId
)
...
@@ -558,7 +557,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -558,7 +557,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
result
.
GroupMedals
=
append
(
result
.
GroupMedals
,
medal_cv
.
PicElement
{
PicUrl
:
pe
.
PicUrl
})
result
.
GroupMedals
=
append
(
result
.
GroupMedals
,
medal_cv
.
PicElement
{
PicUrl
:
pe
.
PicUrl
})
}
}
resMedals
:=
[]
res_m
.
ResMedal
{}
var
resMedals
[]
res_m
.
ResMedal
err
=
mysql
.
Db
.
Model
(
&
res_m
.
ResMedal
{})
.
err
=
mysql
.
Db
.
Model
(
&
res_m
.
ResMedal
{})
.
Joins
(
"INNER JOIN group_medal m ON m.res_medal_id = res_medal.id"
)
.
Joins
(
"INNER JOIN group_medal m ON m.res_medal_id = res_medal.id"
)
.
Where
(
"m.im_group_id = ?"
,
groupId
)
.
Where
(
"m.im_group_id = ?"
,
groupId
)
.
...
@@ -573,8 +572,9 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -573,8 +572,9 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
})
})
}
}
}
else
{
}
else
{
model
.
Log
.
Info
f
(
"GetRoomInfo: group_medal: %s"
,
err
.
Error
())
model
.
Log
.
Error
f
(
"GetRoomInfo: group_medal: %s"
,
err
.
Error
())
}
}
model
.
Log
.
Infof
(
"GetRoomInfo cost 4:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
// 获取国家信息
// 获取国家信息
country
,
area
,
err
:=
user_m
.
GetUserCountryArea
(
model
,
userId
)
country
,
area
,
err
:=
user_m
.
GetUserCountryArea
(
model
,
userId
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -601,18 +601,21 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -601,18 +601,21 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
})
})
}
}
}
else
{
}
else
{
model
.
Log
.
Info
f
(
"GetRoomInfo: GetRoomBanners: %s"
,
err
.
Error
())
model
.
Log
.
Error
f
(
"GetRoomInfo: GetRoomBanners: %s"
,
err
.
Error
())
}
}
result
.
LuckyWheel
,
err
=
group_cv
.
GetLuckWheelState
(
model
,
groupId
)
model
.
Log
.
Infof
(
"GetRoomInfo cost 5:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
result
.
LuckyWheel
,
err
=
group_cv
.
GetLuckWheelState
(
model
,
groupId
)
// todo check 耗时
if
err
!=
nil
{
if
err
!=
nil
{
model
.
Log
.
Info
f
(
"GetRoomInfo: GetLuckWheelState: %s"
,
err
.
Error
())
model
.
Log
.
Error
f
(
"GetRoomInfo: GetLuckWheelState: %s"
,
err
.
Error
())
}
}
model
.
Log
.
Infof
(
"GetRoomInfo cost 6:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
// 群主的详情
// 群主的详情
owner
,
err
:=
user_cv
.
Get
UserDetail
(
model
,
groupInfo
.
Owner
,
userId
)
owner
,
err
:=
user_cv
.
Get
RoomInfoOwner
(
model
,
groupInfo
.
Owner
,
userId
)
result
.
Owner
=
user_cv
.
UserDetailToRoomInfoOwner
(
owner
)
result
.
Owner
=
user_cv
.
UserDetailToRoomInfoOwner
(
owner
)
if
err
!=
nil
{
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetRoomInfo: GetUserBase: %s"
,
err
.
Error
())
model
.
Log
.
Errorf
(
"GetRoomInfo: GetUserBase: %s"
,
err
.
Error
())
}
}
model
.
Log
.
Infof
(
"GetRoomInfo cost 7:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
// 进场特效类型
// 进场特效类型
var
entryEffectType
int
// 进场特效类型 1: CP 2:神秘人 3:贵族 4:vip ,顺序从小到大
var
entryEffectType
int
// 进场特效类型 1: CP 2:神秘人 3:贵族 4:vip ,顺序从小到大
...
@@ -639,6 +642,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -639,6 +642,7 @@ func GetRoomInfo(c *gin.Context) (*mycontext.MyContext, error) {
entryEffectType
=
1
entryEffectType
=
1
}
}
result
.
EntryEffectType
=
entryEffectType
result
.
EntryEffectType
=
entryEffectType
model
.
Log
.
Infof
(
"GetRoomInfo cost 8:%v"
,
time
.
Now
()
.
Sub
(
start
)
.
Seconds
())
resp
.
ResponseOk
(
c
,
result
)
resp
.
ResponseOk
(
c
,
result
)
return
myContext
,
nil
return
myContext
,
nil
...
@@ -848,7 +852,7 @@ func GroupBannerList(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -848,7 +852,7 @@ func GroupBannerList(c *gin.Context) (*mycontext.MyContext, error) {
}
}
// 版本控制
// 版本控制
if
!
allow
&&
(
v
.
ID
==
2301
||
v
.
ID
==
4711
||
v
.
ID
==
2321
||
v
.
ID
==
5341
||
v
.
ID
==
5331
||
v
.
ID
==
5631
||
v
.
ID
==
5471
||
if
!
allow
&&
(
v
.
ID
==
2301
||
v
.
ID
==
4711
||
v
.
ID
==
2321
||
v
.
ID
==
5341
||
v
.
ID
==
5331
||
v
.
ID
==
5631
||
v
.
ID
==
5471
||
v
.
ID
==
5461
||
v
.
ID
==
5771
||
v
.
ID
==
5811
||
v
.
ID
==
5881
||
v
.
ID
==
8781
)
{
v
.
ID
==
5461
||
v
.
ID
==
5771
||
v
.
ID
==
5811
||
v
.
ID
==
5881
||
v
.
ID
==
8781
||
v
.
ID
==
10351
)
{
model
.
Log
.
Infof
(
"CompareVersion appVersion:%v,auditVersion:%v,allow:%v,err:%v,skip top recharge"
,
appVersion
,
vc
.
AuditVersion
,
allow
,
err
)
model
.
Log
.
Infof
(
"CompareVersion appVersion:%v,auditVersion:%v,allow:%v,err:%v,skip top recharge"
,
appVersion
,
vc
.
AuditVersion
,
allow
,
err
)
continue
continue
}
}
...
...
route/group_r/group_list.go
View file @
577a8fef
This diff is collapsed.
Click to expand it.
route/group_r/group_op.go
View file @
577a8fef
...
@@ -1871,9 +1871,9 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -1871,9 +1871,9 @@ func GroupIn(c *gin.Context) (*mycontext.MyContext, error) {
myContext
.
Log
.
Infof
(
"GroupIn, ProcessRoomVisit err: %s"
,
err
.
Error
())
myContext
.
Log
.
Infof
(
"GroupIn, ProcessRoomVisit err: %s"
,
err
.
Error
())
}
}
// 更新用户进入房间缓存记录
// 更新用户进入房间缓存记录
if
err
=
room_c
.
ProcessUserRoomVisit
(
userId
,
groupId
);
err
!=
nil
{
//
if err = room_c.ProcessUserRoomVisit(userId, groupId); err != nil {
myContext
.
Log
.
Infof
(
"GroupIn, ProcessUserRoomVisit err: %s"
,
err
.
Error
())
//
myContext.Log.Infof("GroupIn, ProcessUserRoomVisit err: %s", err.Error())
}
//
}
resp
.
ResponseOk
(
c
,
group_cv
.
GroupChannelId
{
resp
.
ResponseOk
(
c
,
group_cv
.
GroupChannelId
{
ChannelId
:
channelId
,
ChannelId
:
channelId
,
Token
:
token
,
Token
:
token
,
...
...
route/group_r/group_support.go
View file @
577a8fef
...
@@ -6,13 +6,11 @@ import (
...
@@ -6,13 +6,11 @@ import (
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"hilo-group/_const/enum/gift_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/group_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/_const/enum/msg_e"
"hilo-group/cv/group_cv"
"hilo-group/cv/group_cv"
"hilo-group/cv/user_cv"
"hilo-group/cv/user_cv"
"hilo-group/domain/cache/group_c"
"hilo-group/domain/cache/group_c"
"hilo-group/domain/model/gift_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/group_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"
...
@@ -111,18 +109,28 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -111,18 +109,28 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) {
result
:=
group_cv
.
SupportPageDetail
{
GroupId
:
txGroupId
}
result
:=
group_cv
.
SupportPageDetail
{
GroupId
:
txGroupId
}
now
:=
time
.
Now
()
now
:=
time
.
Now
()
beginTime
,
endTime
,
_
:=
group_m
.
GetSupportLevelTime
(
now
)
_
,
endTime
,
period
:=
group_m
.
GetSupportLevelTime
(
now
)
result
.
RemainSecond
=
endTime
.
Unix
()
-
now
.
Unix
()
result
.
RemainSecond
=
endTime
.
Unix
()
-
now
.
Unix
()
g
:=
gift_m
.
GiftOperate
{
SceneType
:
gift_e
.
GroupSceneType
,
SceneUid
:
groupId
,
Model
:
model
}
//g := gift_m.GiftOperate{SceneType: gift_e.GroupSceneType, SceneUid: groupId, Model: model}
result
.
CurrentCount
,
result
.
CurrentConsume
,
err
=
g
.
GetConsumeByRange
(
beginTime
,
endTime
)
//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
{
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetSupportDetail groupId:%s, err:%v"
,
groupId
,
err
)
return
myContext
,
err
return
myContext
,
err
}
}
beginTime
,
endTime
,
_
=
group_m
.
GetSupportLevelTime
(
now
.
AddDate
(
0
,
0
,
-
group_e
.
SUPPORT_LEVEL_PERIOD_DAY
))
_
,
_
,
periodLast
:=
group_m
.
GetSupportLevelTime
(
now
.
AddDate
(
0
,
0
,
-
group_e
.
SUPPORT_LEVEL_PERIOD_DAY
))
result
.
LastCount
,
result
.
LastConsume
,
err
=
g
.
GetConsumeByRange
(
beginTime
,
endTime
)
//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
{
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetSupportDetail groupId:%s, err:%v"
,
groupId
,
err
)
return
myContext
,
err
return
myContext
,
err
}
}
...
@@ -152,7 +160,7 @@ func GetSupportDetail(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -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
}
gsaa
:=
group_m
.
GroupSupportAwardAdmin
{
Period
:
period
,
GroupUid
:
groupId
}
rows
,
err
:=
gsaa
.
Get
(
model
.
Db
)
rows
,
err
:=
gsaa
.
Get
(
model
.
Db
)
if
err
!=
nil
{
if
err
!=
nil
{
...
@@ -335,20 +343,24 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -335,20 +343,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 +394,12 @@ func TakeSupportAward(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -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
{
if
err
!=
nil
{
return
myContext
,
err
return
myContext
,
err
}
}
...
...
route/router.go
View file @
577a8fef
...
@@ -42,7 +42,8 @@ func InitRouter() *gin.Engine {
...
@@ -42,7 +42,8 @@ func InitRouter() *gin.Engine {
imGroup
.
GET
(
"/myRecent"
,
wrapper
(
group_r
.
GetRecentGroup
))
imGroup
.
GET
(
"/myRecent"
,
wrapper
(
group_r
.
GetRecentGroup
))
imGroup
.
GET
(
"/myPermanent"
,
wrapper
(
group_r
.
GetMyGroup
))
imGroup
.
GET
(
"/myPermanent"
,
wrapper
(
group_r
.
GetMyGroup
))
//
//
imGroup
.
GET
(
"/visitors/:groupId"
,
wrapper
(
group_r
.
GetGroupVisitors
))
imGroup
.
GET
(
"/visitors/:groupId"
,
wrapper
(
group_r
.
GetGroupVisitorsV2
))
imGroup
.
GET
(
"/visitors2/:groupId"
,
wrapper
(
group_r
.
GetGroupVisitors
))
// 自测用,跟上面的反过来
imGroup
.
GET
(
"/ownPublicGroup/:userExternalId"
,
wrapper
(
group_r
.
GetOwnPublicGroup
))
imGroup
.
GET
(
"/ownPublicGroup/:userExternalId"
,
wrapper
(
group_r
.
GetOwnPublicGroup
))
//// 2.19的新接口
//// 2.19的新接口
imGroup
.
GET
(
"/ownGroup"
,
wrapper
(
group_r
.
GetOwnGroup
))
imGroup
.
GET
(
"/ownGroup"
,
wrapper
(
group_r
.
GetOwnGroup
))
...
@@ -106,7 +107,7 @@ func InitRouter() *gin.Engine {
...
@@ -106,7 +107,7 @@ func InitRouter() *gin.Engine {
imGroup
.
POST
(
"/mgr/clearScreen"
,
wrapper
(
group_r
.
GroupMgrClearScreen
))
imGroup
.
POST
(
"/mgr/clearScreen"
,
wrapper
(
group_r
.
GroupMgrClearScreen
))
imGroup
.
GET
(
"/online/users"
,
wrapper
(
group_r
.
GroupInUsers
))
imGroup
.
GET
(
"/online/users"
,
wrapper
(
group_r
.
GroupInUsers
))
imGroup
.
GET
(
"/online/users/new"
,
wrapper
(
group_r
.
GroupInUserNew
))
imGroup
.
GET
(
"/online/users/new"
,
wrapper
(
group_r
.
GroupInUserNew
))
imGroup
.
GET
(
"/country"
,
wrapper
(
group_r
.
GetGroupByCountry
))
imGroup
.
GET
(
"/country"
,
wrapper
(
group_r
.
GetGroupByCountry
V2
))
imGroup
.
GET
(
"/country/prior"
,
wrapper
(
group_r
.
GroupountryPrior
))
imGroup
.
GET
(
"/country/prior"
,
wrapper
(
group_r
.
GroupountryPrior
))
//
//
imGroup
.
POST
(
"/theme/custom"
,
wrapper
(
group_r
.
GroupThemeAdd
))
imGroup
.
POST
(
"/theme/custom"
,
wrapper
(
group_r
.
GroupThemeAdd
))
...
...
test/group_power_test.go
View file @
577a8fef
...
@@ -3,8 +3,10 @@ package test
...
@@ -3,8 +3,10 @@ package test
import
(
import
(
"fmt"
"fmt"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/redisCli"
"git.hilo.cn/hilo-common/utils"
"git.hilo.cn/hilo-common/utils"
"github.com/jinzhu/now"
"github.com/jinzhu/now"
"hilo-group/domain/cache/groupPower_c"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/model/group_m"
"hilo-group/domain/service/group_power_s"
"hilo-group/domain/service/group_power_s"
...
@@ -69,3 +71,14 @@ func TestGetRandomImProvider(t *testing.T) {
...
@@ -69,3 +71,14 @@ func TestGetRandomImProvider(t *testing.T) {
fmt
.
Printf
(
"true--------------times0:%v
\n
"
,
times0
)
fmt
.
Printf
(
"true--------------times0:%v
\n
"
,
times0
)
fmt
.
Printf
(
"true--------------times1:%v
\n
"
,
times1
)
fmt
.
Printf
(
"true--------------times1:%v
\n
"
,
times1
)
}
}
func
TestMonthStar
(
t
*
testing
.
T
)
{
monthTime
,
err
:=
time
.
Parse
(
"200601"
,
"202307"
)
if
err
!=
nil
{
panic
(
err
)
}
redisCli
.
InitCluster
()
res
,
err
:=
groupPower_c
.
GetGroupPowerStarRankPeriod
(
domain
.
CreateModelNil
(),
"month"
,
242
,
1
,
0
,
10
,
monthTime
.
Format
(
"2006-01-02"
))
println
(
res
)
println
(
err
)
}
test/local.ini
View file @
577a8fef
...
@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
...
@@ -11,6 +11,8 @@ MYSQL_DB=hilo_code
[REDIS]
[REDIS]
REDIS_HOST
=
47.244.34.27:6379
REDIS_HOST
=
47.244.34.27:6379
REDIS_PASSWORD
=
8QZ9JD1zLvPR3yHf
REDIS_PASSWORD
=
8QZ9JD1zLvPR3yHf
REDIS_CLUSTER_HOST
=
47.244.34.27:6379
REDIS_CLUSTER_PASSWORD
=
8QZ9JD1zLvPR3yHf
[JWT]
[JWT]
SECRET
=
hilo1632
SECRET
=
hilo1632
ISSUER_API
=
hiloApi
ISSUER_API
=
hiloApi
...
...