Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-group
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
hujiebin
hilo-group
Commits
2c5e4e50
Commit
2c5e4e50
authored
Mar 09, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:增加势力上麦时长-家族之星
parent
4bddac36
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
49 additions
and
9 deletions
+49
-9
group_grade.go
domain/model/groupPower_m/group_grade.go
+17
-0
group_star.go
domain/model/groupPower_m/group_star.go
+16
-2
event_init.go
domain/service/event_s/event_init.go
+6
-4
group_mic.go
domain/service/group_mic_s/group_mic.go
+10
-3
No files found.
domain/model/groupPower_m/group_grade.go
View file @
2c5e4e50
...
...
@@ -223,6 +223,23 @@ func IncrGroupPowerExpOnMic(model *domain.Model, groupPowerId, userId mysql.ID,
})
}
// 增加势力上麦时长-家族之星
// 事务操作
func
IncrGroupPowerStarOnMic
(
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
if
err
!=
nil
&&
err
!=
gorm
.
ErrRecordNotFound
{
return
err
}
if
star
!=
nil
&&
joinMicTimestamp
==
star
.
LastCalTs
{
curTs
=
star
.
LastCalTs
}
score
:=
time
.
Now
()
.
Unix
()
-
curTs
return
IncrGroupPowerMonthStarScore
(
model
,
groupPowerId
,
userId
,
groupPower_e
.
GroupPowerStarTypeActive
,
mysql
.
Num
(
score
),
curTs
)
})
}
// 清理所有家族的经验
func
ClearGroupPowerExp
(
model
*
domain
.
Model
)
error
{
var
groupPowerGrades
[]
*
GroupPowerGrade
...
...
domain/model/groupPower_m/group_star.go
View file @
2c5e4e50
...
...
@@ -16,12 +16,13 @@ type GroupPowerMonthStar struct {
UserId
mysql
.
ID
Type
groupPower_e
.
GroupPowerStarType
Score
mysql
.
Num
LastCalTs
int64
CreatedTime
time
.
Time
`gorm:"->"`
UpdatedTime
time
.
Time
`gorm:"->"`
}
// 增加家族之星分数
func
IncrGroupPowerMonthStarScore
(
model
*
domain
.
Model
,
groupPowerId
,
userId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
score
mysql
.
Num
)
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"
)
star
:=
&
GroupPowerMonthStar
{
Month
:
month
,
...
...
@@ -33,7 +34,9 @@ func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysq
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerMonthStar
{})
.
Clauses
(
clause
.
OnConflict
{
Columns
:
[]
clause
.
Column
{{
Name
:
"month"
},
{
Name
:
"group_power_id"
},
{
Name
:
"user_id"
},
{
Name
:
"type"
}},
DoUpdates
:
clause
.
Assignments
(
map
[
string
]
interface
{}{
"score"
:
gorm
.
Expr
(
"score + ?"
,
star
.
Score
)}),
"score"
:
gorm
.
Expr
(
"score + ?"
,
star
.
Score
),
"last_cal_ts"
:
lastCalTs
,
}),
})
.
Create
(
star
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore fail:%v"
,
err
)
return
err
...
...
@@ -41,6 +44,17 @@ func IncrGroupPowerMonthStarScore(model *domain.Model, groupPowerId, userId mysq
return
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
}
// 获取家族之星排行
func
GetGroupPowerMonthStarRank
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
)
([]
*
GroupPowerMonthStar
,
error
)
{
var
res
[]
*
GroupPowerMonthStar
...
...
domain/service/event_s/event_init.go
View file @
2c5e4e50
...
...
@@ -438,7 +438,7 @@ func SendGift() {
// 送礼加分
if
data
,
ok
:=
groupPowers
[
sendGiftEvent
.
SendUserId
];
ok
{
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
);
err
!=
nil
{
if
err
:=
groupPower_m
.
IncrGroupPowerMonthStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeFamous
,
diamonds
,
0
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore famous fail:%v"
,
err
)
}
}
...
...
@@ -446,7 +446,7 @@ func SendGift() {
for
_
,
userId
:=
range
sendGiftEvent
.
ReceiveUserIds
{
if
data
,
ok
:=
groupPowers
[
userId
];
ok
{
diamonds
:=
sendGiftEvent
.
GiftN
*
sendGiftEvent
.
ResGift
.
DiamondNum
if
err
:=
groupPower_m
.
IncrGroupPowerMonthStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
diamonds
);
err
!=
nil
{
if
err
:=
groupPower_m
.
IncrGroupPowerMonthStarScore
(
model
,
data
.
GroupPowerId
,
data
.
UserId
,
groupPower_e
.
GroupPowerStarTypeCharm
,
diamonds
,
0
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore charm fail:%v"
,
err
)
}
}
...
...
@@ -456,17 +456,19 @@ func SendGift() {
}
func
OnMic
()
{
mic_ev
.
AddOnMicEventSync
(
func
(
model
*
domain
.
Model
,
e
interface
{})
error
{
// 上麦经验/上麦时长
mic_ev
.
AddOnMicEventAsync
(
func
(
model
*
domain
.
Model
,
e
interface
{})
error
{
event
,
ok
:=
e
.
(
*
mic_ev
.
OnMicEvent
)
if
!
ok
{
model
.
Log
.
Errorf
(
"AddOnMicEventSync event type err"
)
return
nil
}
if
err
:=
group_mic_s
.
NewGroupPowerService
(
model
.
MyContext
)
.
GroupPowerOnMicExp
(
event
.
GroupUuid
,
event
.
UserId
,
event
.
Timestamp
);
err
!=
nil
{
if
err
:=
group_mic_s
.
NewGroupPowerService
(
model
.
MyContext
)
.
IncrGroupPowerOnMicExpAndTime
(
event
.
GroupUuid
,
event
.
UserId
,
event
.
Timestamp
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"cron micIn GroupPowerOnMicExp err:%v"
,
err
)
}
else
{
model
.
Log
.
Infof
(
"cron micIn GroupPowerOnMicExp success, groupId:%v, userId:%v"
,
event
.
GroupUuid
,
event
.
UserId
)
}
return
nil
})
}
domain/service/group_mic_s/group_mic.go
View file @
2c5e4e50
...
...
@@ -289,8 +289,8 @@ func (s *GroupMicService) GroupIMMassByMgr(groupId string, userId uint64, extern
})
}
// 增加势力上麦经验
func
(
s
*
GroupMicService
)
GroupPowerOnMicExp
(
groupId
string
,
userId
uint64
,
joinMicTimestamp
int64
)
error
{
// 增加势力上麦经验
/时长
func
(
s
*
GroupMicService
)
IncrGroupPowerOnMicExpAndTime
(
groupId
string
,
userId
uint64
,
joinMicTimestamp
int64
)
error
{
var
model
=
domain
.
CreateModelContext
(
s
.
svc
.
MyContext
)
exists
,
groupPowerId
,
err
:=
groupPower_m
.
CheckGroupPowerUser
(
model
,
userId
)
if
err
!=
nil
{
...
...
@@ -315,5 +315,12 @@ func (s *GroupMicService) GroupPowerOnMicExp(groupId string, userId uint64, join
return
nil
}
// 增加势力上麦经验
return
groupPower_m
.
IncrGroupPowerExpOnMic
(
model
,
groupPowerId
,
userId
,
joinMicTimestamp
)
if
err
:=
groupPower_m
.
IncrGroupPowerExpOnMic
(
model
,
groupPowerId
,
userId
,
joinMicTimestamp
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerExpOnMic fail:%v"
,
err
)
}
// 增加势力上麦时长
if
err
:=
groupPower_m
.
IncrGroupPowerStarOnMic
(
model
,
groupPowerId
,
userId
,
joinMicTimestamp
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerOnMicTime fail:%v"
,
err
)
}
return
nil
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment