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
c39d806b
Commit
c39d806b
authored
Mar 09, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:家族之星
parent
a6c36dee
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
187 additions
and
4 deletions
+187
-4
star.go
_const/enum/groupPower_e/star.go
+16
-0
group_rank.go
cv/group_power_cv/group_rank.go
+11
-3
groupPower.go
domain/model/groupPower_m/groupPower.go
+15
-0
group_star.go
domain/model/groupPower_m/group_star.go
+54
-0
event_init.go
domain/service/event_s/event_init.go
+33
-0
group_rank.go
route/group_power_r/group_rank.go
+57
-1
router.go
route/router.go
+1
-0
No files found.
_const/enum/groupPower_e/star.go
0 → 100644
View file @
c39d806b
package
groupPower_e
type
GroupPowerStarType
int
const
(
GroupPowerStarTypeFamous
GroupPowerStarType
=
1
// 送礼
GroupPowerStarTypeActive
GroupPowerStarType
=
2
// 活跃
GroupPowerStarTypeCharm
GroupPowerStarType
=
3
// 收礼
)
func
IsGroupPowerStarType
(
t
GroupPowerStarType
)
bool
{
if
t
!=
GroupPowerStarTypeFamous
&&
t
!=
GroupPowerStarTypeActive
&&
t
!=
GroupPowerStarTypeCharm
{
return
false
}
return
true
}
cv/group_power_cv/group_rank.go
View file @
c39d806b
...
@@ -3,8 +3,15 @@ package group_power_cv
...
@@ -3,8 +3,15 @@ package group_power_cv
import
(
import
(
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/mysql"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/_const/enum/groupPower_e"
"hilo-group/cv/user_cv"
)
)
// 家族榜单
type
CvGroupPowerRank
struct
{
MyGroupPower
CvGroupPowerRankData
`json:"myGroupPower"`
Items
[]
CvGroupPowerRankData
`json:"items"`
}
type
CvGroupPowerRankData
struct
{
type
CvGroupPowerRankData
struct
{
GroupPowerId
mysql
.
ID
`json:"groupPowerId"`
// 家族id
GroupPowerId
mysql
.
ID
`json:"groupPowerId"`
// 家族id
GroupPic
string
`json:"groupPic"`
// 家族图片
GroupPic
string
`json:"groupPic"`
// 家族图片
...
@@ -16,7 +23,8 @@ type CvGroupPowerRankData struct {
...
@@ -16,7 +23,8 @@ type CvGroupPowerRankData struct {
// todo 铭牌,图片等字段, 等伟健哥哥的结构体
// todo 铭牌,图片等字段, 等伟健哥哥的结构体
}
}
type
CvGroupPowerRank
struct
{
// 家族之星
MyGroupPower
CvGroupPowerRankData
`json:"myGroupPower"`
type
CvGroupPowerStarData
struct
{
Items
[]
CvGroupPowerRankData
`json:"items"`
user_cv
.
CvUserBase
`json:",inline"`
Score
mysql
.
Num
`json:"score"`
// 对应分值
}
}
domain/model/groupPower_m/groupPower.go
View file @
c39d806b
...
@@ -666,3 +666,18 @@ func GetGroupPowerGroups(model *domain.Model, groupPowerId mysql.ID) ([]*group_m
...
@@ -666,3 +666,18 @@ func GetGroupPowerGroups(model *domain.Model, groupPowerId mysql.ID) ([]*group_m
}
}
return
res
,
nil
return
res
,
nil
}
}
// 批量获取势力用户
// return userId->GroupPowerUser
func
BatchGetGroupPowerUser
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
GroupPowerUser
,
error
)
{
var
rows
[]
GroupPowerUser
res
:=
make
(
map
[
mysql
.
ID
]
GroupPowerUser
)
if
err
:=
model
.
Db
.
Model
(
GroupPowerUser
{})
.
Where
(
"user_id in ?"
,
userIds
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"BatchGetGroupPowerUser fail:%v"
,
err
)
return
res
,
err
}
for
i
,
v
:=
range
rows
{
res
[
v
.
UserId
]
=
rows
[
i
]
}
return
res
,
nil
}
domain/model/groupPower_m/group_star.go
0 → 100644
View file @
c39d806b
package
groupPower_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"gorm.io/gorm/clause"
"hilo-group/_const/enum/groupPower_e"
"time"
)
// 家族之星
type
GroupPowerMonthStar
struct
{
Month
string
GroupPowerId
mysql
.
ID
UserId
mysql
.
ID
Type
groupPower_e
.
GroupPowerStarType
Score
mysql
.
Num
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
{
month
:=
time
.
Now
()
.
Format
(
"200601"
)
star
:=
&
GroupPowerMonthStar
{
Month
:
month
,
GroupPowerId
:
groupPowerId
,
UserId
:
userId
,
Type
:
_type
,
Score
:
score
,
}
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
)}),
})
.
Create
(
star
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore fail:%v"
,
err
)
return
err
}
return
nil
}
// 获取家族之星排行
func
GetGroupPowerMonthStarRank
(
model
*
domain
.
Model
,
groupPowerId
mysql
.
ID
,
_type
groupPower_e
.
GroupPowerStarType
,
offset
,
limit
int
)
([]
*
GroupPowerMonthStar
,
error
)
{
var
res
[]
*
GroupPowerMonthStar
month
:=
time
.
Now
()
.
Format
(
"200601"
)
if
err
:=
model
.
DB
()
.
Model
(
GroupPowerMonthStar
{})
.
Where
(
"month = ? AND group_power_id = ? AND `type` = ?"
,
month
,
groupPowerId
,
_type
)
.
Order
(
"score desc"
)
.
Offset
(
offset
)
.
Limit
(
limit
)
.
Find
(
&
res
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetGroupPowerMonthStarRank fail:%v"
,
err
)
return
res
,
err
}
return
res
,
nil
}
domain/service/event_s/event_init.go
View file @
c39d806b
...
@@ -6,6 +6,7 @@ import (
...
@@ -6,6 +6,7 @@ import (
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/rpc"
"git.hilo.cn/hilo-common/rpc"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"hilo-group/_const/enum/groupPower_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/_const/enum/task_e"
"hilo-group/_const/enum/task_e"
...
@@ -417,4 +418,36 @@ func SendGift() {
...
@@ -417,4 +418,36 @@ func SendGift() {
}
}
return
nil
return
nil
})
})
// 家族之星-送礼/收礼
gift_ev
.
AddSendGiftEventAsync
(
func
(
model
*
domain
.
Model
,
event
interface
{})
error
{
sendGiftEvent
,
ok
:=
event
.
(
*
gift_ev
.
SendGiftEvent
)
if
!
ok
{
model
.
Log
.
Errorf
(
"AddSendGiftEventAsync event type err"
)
return
nil
}
var
userIds
=
[]
mysql
.
ID
{
sendGiftEvent
.
SendUserId
}
userIds
=
append
(
userIds
,
sendGiftEvent
.
ReceiveUserIds
...
)
groupPowers
,
err
:=
groupPower_m
.
BatchGetGroupPowerUser
(
model
,
userIds
)
if
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddSendGiftEventAsync fail:%v"
,
err
)
return
err
}
// 送礼加分
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
{
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore famous fail:%v"
,
err
)
}
}
// 收礼加分
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
{
model
.
Log
.
Errorf
(
"IncrGroupPowerMonthStarScore charm fail:%v"
,
err
)
}
}
}
return
nil
})
}
}
route/group_power_r/group_rank.go
View file @
c39d806b
...
@@ -9,7 +9,9 @@ import (
...
@@ -9,7 +9,9 @@ import (
"github.com/jinzhu/now"
"github.com/jinzhu/now"
"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/domain/model/groupPower_m"
"hilo-group/domain/model/groupPower_m"
"hilo-group/domain/model/user_m"
"hilo-group/myerr/bizerr"
"hilo-group/myerr/bizerr"
"hilo-group/req"
"hilo-group/req"
"hilo-group/resp"
"hilo-group/resp"
...
@@ -33,7 +35,6 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -33,7 +35,6 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
if
period
!=
"day"
&&
period
!=
"week"
&&
period
!=
"month"
{
if
period
!=
"day"
&&
period
!=
"week"
&&
period
!=
"month"
{
return
myContext
,
bizerr
.
InvalidParameter
return
myContext
,
bizerr
.
InvalidParameter
}
}
// day
var
beginDate
,
endDate
string
var
beginDate
,
endDate
string
switch
period
{
switch
period
{
case
"day"
:
case
"day"
:
...
@@ -93,3 +94,58 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -93,3 +94,58 @@ func GroupPowerRank(c *gin.Context) (*mycontext.MyContext, error) {
resp
.
ResponseOk
(
c
,
response
)
resp
.
ResponseOk
(
c
,
response
)
return
myContext
,
nil
return
myContext
,
nil
}
}
type
GroupPowerStarReq
struct
{
GroupPowerId
mysql
.
ID
`form:"groupPowerId" binding:"required"`
Type
groupPower_e
.
GroupPowerStarType
`form:"type" binding:"required"`
PageSize
int
`form:"pageSize" binding:"required"`
PageIndex
int
`form:"pageIndex" binding:"required"`
}
// @Tags 国家势力
// @Summary 家族之星
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Param groupPowerId query int true "分页大小 默认:10" default(10)
// @Param type query string true "类型 1:送礼 2:活跃 3:收礼物"
// @Param pageSize query int false "分页大小 默认:10" default(10)
// @Param pageIndex query int false "第几个分页,从1开始 默认:1" default(1)
// @Success 200 {object} []group_power_cv.CvGroupPowerStarData
// @Router /v1/groupPower/star [get]
func
GroupPowerStar
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myContext
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
param
:=
new
(
GroupPowerStarReq
)
if
err
:=
c
.
ShouldBindQuery
(
param
);
err
!=
nil
{
return
myContext
,
err
}
if
param
.
PageIndex
<=
0
{
param
.
PageIndex
=
1
}
var
model
=
domain
.
CreateModelContext
(
myContext
)
offset
,
limit
:=
(
param
.
PageIndex
-
1
)
*
param
.
PageSize
,
param
.
PageSize
rank
,
err
:=
groupPower_m
.
GetGroupPowerMonthStarRank
(
model
,
param
.
GroupPowerId
,
param
.
Type
,
offset
,
limit
)
if
err
!=
nil
{
return
myContext
,
err
}
var
response
[]
group_power_cv
.
CvGroupPowerStarData
var
userIds
[]
mysql
.
ID
for
_
,
row
:=
range
rank
{
userIds
=
append
(
userIds
,
row
.
UserId
)
}
users
,
err
:=
user_m
.
GetUserMapByIds
(
model
,
userIds
)
for
_
,
row
:=
range
rank
{
user
:=
users
[
row
.
UserId
]
response
=
append
(
response
,
group_power_cv
.
CvGroupPowerStarData
{
CvUserBase
:
user_cv
.
CvUserBase
{
Id
:
&
user
.
ID
,
ExternalId
:
&
user
.
ExternalId
,
Code
:
&
user
.
Code
,
Nick
:
&
user
.
Nick
,
Avatar
:
&
user
.
Avatar
,
},
Score
:
row
.
Score
,
})
}
resp
.
ResponseOk
(
c
,
response
)
return
myContext
,
nil
}
route/router.go
View file @
c39d806b
...
@@ -126,6 +126,7 @@ func InitRouter() *gin.Engine {
...
@@ -126,6 +126,7 @@ func InitRouter() *gin.Engine {
groupPower
.
GET
(
"/billboard/week"
,
wrapper
(
group_power_r
.
GroupPowerBillboardWeek
))
groupPower
.
GET
(
"/billboard/week"
,
wrapper
(
group_power_r
.
GroupPowerBillboardWeek
))
groupPower
.
GET
(
"/billboard/owner/week"
,
wrapper
(
group_power_r
.
GroupPowerBillboardOwnerWeek
))
groupPower
.
GET
(
"/billboard/owner/week"
,
wrapper
(
group_power_r
.
GroupPowerBillboardOwnerWeek
))
groupPower
.
GET
(
"/rank/:period"
,
wrapper
(
group_power_r
.
GroupPowerRank
))
groupPower
.
GET
(
"/rank/:period"
,
wrapper
(
group_power_r
.
GroupPowerRank
))
groupPower
.
GET
(
"/star"
,
wrapper
(
group_power_r
.
GroupPowerStar
))
}
}
return
r
return
r
}
}
...
...
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