Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
H
hilo-user
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
chenweijian
hilo-user
Commits
059d1c27
Commit
059d1c27
authored
May 29, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:myCp
parent
56b527c7
Changes
9
Show whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
131 additions
and
28 deletions
+131
-28
rank.go
cv/cp_cv/rank.go
+5
-5
space.go
cv/cp_cv/space.go
+1
-1
user.go
cv/user_cv/user.go
+2
-1
level.go
domain/model/cp_m/level.go
+26
-5
rank.go
domain/model/cp_m/rank.go
+10
-0
cp_level.go
domain/service/event_s/cp_level.go
+1
-1
rank.go
route/cp_r/rank.go
+73
-7
space.go
route/cp_r/space.go
+12
-8
router.go
route/router.go
+1
-0
No files found.
cv/cp_cv/rank.go
View file @
059d1c27
...
...
@@ -7,5 +7,5 @@ type CvCp struct {
User1
*
user_cv
.
CvUserBase
`json:"user1"`
// user1
User2
*
user_cv
.
CvUserBase
`json:"user2"`
// user2
Score
uint32
`json:"score"`
// 分值
Ranking
int
`json:"ranking"`
// 排名
//
Ranking int `json:"ranking"` // 排名
}
cv/cp_cv/space.go
View file @
059d1c27
...
...
@@ -24,7 +24,7 @@ type CvCpLevel struct {
Points
uint32
`json:"points"`
// CP值
NextPoints
uint32
`json:"nextPoints,omitempty"`
// 下个等级所需CP值
RemainPoints
uint32
`json:"remainPoints,omitempty"`
// 还需要多少CP值到下一个级别
ExpireAt
string
`json:"expireAt,omitempty"`
// 有效期
ExpireAt
Unix
int64
`json:"expireAtUnix,omitempty"`
// 有效期,时间戳
}
// 资源等级
...
...
cv/user_cv/user.go
View file @
059d1c27
...
...
@@ -104,7 +104,8 @@ func GetUserBases(userIds []mysql.ID, myUserId mysql.ID) ([]*CvUserBase, error)
}
svips
,
err
:=
rpc
.
MGetUserSvip
(
domain
.
CreateModelNil
(),
userIds
)
if
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
mylogrus
.
MyLog
.
Errorf
(
"MGetUserSvip fail:%v"
,
err
)
//return nil, myerr.WrapErr(err)
}
headwearMap
,
err
:=
headwear_cv
.
BatchGetCvHeadwears
(
userIds
)
...
...
domain/model/cp_m/
grade
.go
→
domain/model/cp_m/
level
.go
View file @
059d1c27
...
...
@@ -44,21 +44,42 @@ type CpLevelDetail struct {
Remark
string
}
// 获取cp等级
func
GetCpLevel
(
model
*
domain
.
Model
,
cpId
mysql
.
ID
)
CpLevel
{
var
level
CpLevel
if
err
:=
model
.
DB
()
.
Model
(
CpLevel
{})
.
Where
(
"cp_id = ?"
,
cpId
)
.
First
(
&
level
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetCpLevel fail:%v"
,
err
)
}
return
level
}
// 添加cp等级积分增减明细
func
AddCpLevelDetail
(
model
*
domain
.
Model
,
detail
CpLevelDetail
)
error
{
return
model
.
DB
()
.
Create
(
&
detail
)
.
Error
}
// 获取cpRelation
// 因为cp的业务逻辑唯一性,只要user_id1命中其中一个即可
func
GetCpRelation
(
model
*
domain
.
Model
,
userId1
,
userId2
mysql
.
ID
)
(
cpRelation
CpRelationTmp
,
exits
bool
)
{
if
err
:=
model
.
DB
()
.
Model
(
CpRelationTmp
{})
.
Where
(
"user_id1 = ?"
,
userId1
)
.
First
(
&
cpRelation
)
.
Error
;
err
!=
nil
{
// 获取cpRelation pair
func
GetCpRelation
(
model
*
domain
.
Model
,
userId
mysql
.
ID
)
(
cpRelation
CpRelationTmp
,
exits
bool
)
{
if
err
:=
model
.
DB
()
.
Model
(
CpRelationTmp
{})
.
Where
(
"user_id1 = ? or user_id2 = ?"
,
userId
,
userId
)
.
First
(
&
cpRelation
)
.
Error
;
err
!=
nil
{
if
err
!=
gorm
.
ErrRecordNotFound
{
model
.
Log
.
Errorf
(
"GetCpRelation fail:%v"
,
err
)
return
}
}
else
{
exits
=
true
}
return
}
// 获取cpRelation pair
func
GetCpRelationPair
(
model
*
domain
.
Model
,
userId1
,
userId2
mysql
.
ID
)
(
cpRelation
CpRelationTmp
,
exits
bool
)
{
if
err
:=
model
.
DB
()
.
Model
(
CpRelationTmp
{})
.
Where
(
"user_id1 = ? AND user_id2 = ?"
,
userId1
,
userId2
)
.
First
(
&
cpRelation
)
.
Error
;
err
!=
nil
{
if
err
!=
gorm
.
ErrRecordNotFound
{
model
.
Log
.
Errorf
(
"GetCpRelation fail:%v"
,
err
)
return
}
else
{
// gorm.ErrRecordNotFound
if
err
:=
model
.
DB
()
.
Model
(
CpRelationTmp
{})
.
Where
(
"user_id1 = ?
"
,
userId2
)
.
First
(
&
cpRelation
)
.
Error
;
err
!=
nil
{
if
err
:=
model
.
DB
()
.
Model
(
CpRelationTmp
{})
.
Where
(
"user_id1 = ?
AND user_id2 = ?"
,
userId2
,
userId1
)
.
First
(
&
cpRelation
)
.
Error
;
err
!=
nil
{
if
err
!=
gorm
.
ErrRecordNotFound
{
model
.
Log
.
Errorf
(
"GetCpRelation fail:%v"
,
err
)
return
...
...
domain/model/cp_m/rank.go
View file @
059d1c27
...
...
@@ -47,3 +47,13 @@ func PageCpDayRank(model *domain.Model, beginDate, endDate string, offset, limit
}
return
ranks
}
// 获取指定cp排行榜
func
GetCpDayRank
(
model
*
domain
.
Model
,
beginDate
,
endDate
string
,
cpId
mysql
.
ID
)
CpDayRank
{
var
rank
CpDayRank
if
err
:=
model
.
DB
()
.
Table
(
"cp_day_rank"
)
.
Where
(
"date BETWEEN ? AND ?"
,
beginDate
,
endDate
)
.
Where
(
"cp_id = ?"
,
cpId
)
.
First
(
&
rank
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetCpDayRank fail:%v"
,
err
)
}
return
rank
}
domain/service/event_s/cp_level.go
View file @
059d1c27
...
...
@@ -18,7 +18,7 @@ func CpGiftEvent() {
for
_
,
receiverUid
:=
range
sendGiftEvent
.
ReceiveUserIds
{
diamonds
:=
sendGiftEvent
.
GiftN
*
sendGiftEvent
.
ResGift
.
DiamondNum
// 有cp关系
if
cpRelation
,
exits
:=
cp_m
.
GetCpRelation
(
model
,
sendGiftEvent
.
SendUserId
,
receiverUid
);
exits
{
if
cpRelation
,
exits
:=
cp_m
.
GetCpRelation
Pair
(
model
,
sendGiftEvent
.
SendUserId
,
receiverUid
);
exits
{
if
err
:=
cp_m
.
AddCpLevelPoints
(
model
,
cpRelation
,
diamonds
);
err
!=
nil
{
model
.
Log
.
Errorf
(
"AddCpLevelPoints fail:%v"
,
err
)
}
...
...
route/cp_r/rank.go
View file @
059d1c27
...
...
@@ -23,7 +23,7 @@ import (
// @Param pageSize query int true "请求数量 默认:10" default(10)
// @Param queryType path string true "类型:day/week/month"
// @Success 200 {object} []cp_cv.CvCp
// @Router /v2/cp/rank/
{queryType}
[get]
// @Router /v2/cp/rank/
:queryType
[get]
func
CpRank
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
userId
,
err
:=
req
.
GetUserId
(
c
)
...
...
@@ -65,15 +65,81 @@ func CpRank(c *gin.Context) (*mycontext.MyContext, error) {
if
err
!=
nil
{
return
myCtx
,
err
}
for
i
,
rank
:=
range
ranks
{
for
_
,
rank
:=
range
ranks
{
response
=
append
(
response
,
cp_cv
.
CvCp
{
CpId
:
rank
.
CpId
,
User1
:
userBase
[
rank
.
UserId1
],
User2
:
userBase
[
rank
.
UserId2
],
Score
:
rank
.
Score
,
Ranking
:
i
+
1
+
offset
,
//
Ranking: i + 1 + offset,
})
}
resp
.
ResponsePageBaseOk
(
c
,
response
,
pageReq
.
PageIndex
+
1
,
len
(
ranks
)
>=
pageReq
.
PageSize
)
return
myCtx
,
nil
}
// @Tags CP v2
// @Summary 我的cp
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Param pageIndex query int true "偏移值 默认:1" default(1)
// @Param pageSize query int true "请求数量 默认:10" default(10)
// @Param queryType path string true "类型:day/week/month"
// @Success 200 {object} cp_cv.CvCp
// @Router /v2/cp/my/:queryType [get]
func
CpMy
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
userId
,
err
:=
req
.
GetUserId
(
c
)
if
err
!=
nil
{
return
myCtx
,
err
}
queryType
:=
c
.
Param
(
"queryType"
)
if
queryType
!=
"day"
&&
queryType
!=
"week"
&&
queryType
!=
"month"
{
return
myCtx
,
bizerr
.
InvalidParameter
}
var
beginDate
,
endDate
string
switch
queryType
{
case
"day"
:
beginDate
,
endDate
=
time
.
Now
()
.
Format
(
"2006-01-02"
),
time
.
Now
()
.
Format
(
"2006-01-02"
)
case
"week"
:
beginDate
=
now
.
BeginningOfWeek
()
.
Format
(
"2006-01-02"
)
endDate
=
now
.
EndOfWeek
()
.
Format
(
"2006-01-02"
)
case
"month"
:
beginDate
=
now
.
BeginningOfMonth
()
.
Format
(
"2006-01-02"
)
endDate
=
now
.
EndOfMonth
()
.
Format
(
"2006-01-02"
)
}
model
:=
domain
.
CreateModelContext
(
myCtx
)
relation
,
exits
:=
cp_m
.
GetCpRelation
(
model
,
userId
)
var
userIds
[]
mysql
.
ID
var
scores
uint32
if
exits
{
// 保证一下自己是userId1
userIds
=
append
(
userIds
,
userId
)
if
relation
.
UserId1
==
userId
{
userIds
=
append
(
userIds
,
relation
.
UserId2
)
}
else
{
userIds
=
append
(
userIds
,
relation
.
UserId1
)
}
rank
:=
cp_m
.
GetCpDayRank
(
model
,
beginDate
,
endDate
,
relation
.
ID
)
scores
=
rank
.
Score
}
else
{
userIds
=
append
(
userIds
,
userId
)
relation
.
UserId1
=
userId
}
userBases
,
err
:=
user_cv
.
GetUserBaseMap
(
userIds
,
userId
)
if
err
!=
nil
{
return
myCtx
,
err
}
response
:=
cp_cv
.
CvCp
{
CpId
:
relation
.
ID
,
Score
:
scores
,
}
if
relation
.
UserId1
>
0
{
response
.
User1
=
userBases
[
relation
.
UserId1
]
}
if
relation
.
UserId2
>
0
{
response
.
User2
=
userBases
[
relation
.
UserId2
]
}
resp
.
ResponseOk
(
c
,
response
)
return
myCtx
,
nil
}
route/cp_r/space.go
View file @
059d1c27
...
...
@@ -37,17 +37,21 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
if
err
!=
nil
{
return
myContext
,
err
}
cpUserInfo
,
err
:=
user_m
.
GetUserByExtId
(
model
,
externalId
)
// todo get from cp2 db
cpUserInfo
,
err
:=
user_m
.
GetUserByExtId
(
model
,
externalId
)
if
err
!=
nil
{
return
myContext
,
err
}
expireAt
:=
""
// todo
cpLevel
:=
cp_e
.
CpLevel5
// todo get from db
nextPoints
:=
cp_e
.
CpLevelPoints
[
cp_e
.
CpLevelMax
]
remainPoints
:=
mysql
.
Num
(
0
)
expireAtUnix
,
cpLevel
:=
int64
(
0
),
cp_e
.
CpLevel0
nextPoints
,
remainPoints
,
curPoints
:=
cp_e
.
CpLevelPoints
[
cp_e
.
CpLevel1
],
mysql
.
Num
(
0
),
mysql
.
Num
(
0
)
cpRelation
,
exists
:=
cp_m
.
GetCpRelation
(
model
,
cpUserInfo
.
ID
)
if
exists
{
level
:=
cp_m
.
GetCpLevel
(
model
,
cpRelation
.
ID
)
cpLevel
,
curPoints
=
level
.
Level
,
level
.
Points
expireAtUnix
=
level
.
ExpireAt
.
Unix
()
}
if
cpLevel
!=
cp_e
.
CpLevelMax
{
nextPoints
=
cp_e
.
CpLevelPoints
[
cpLevel
+
1
]
remainPoints
=
nextPoints
-
cp_e
.
CpLevelPoints
[
cpLevel
]
// todo get from db
remainPoints
=
nextPoints
-
cp_e
.
CpLevelPoints
[
cpLevel
]
-
curPoints
}
privilegeList
:=
cp_cv
.
CopyCpLevelPrivilegeList
(
cpLevel
,
lang
)
userPrivileges
,
err
:=
cp_m
.
MGetUserSvipPrivilege
(
model
,
[]
uint64
{
userId
})
...
...
@@ -66,10 +70,10 @@ func CpSpace(c *gin.Context) (*mycontext.MyContext, error) {
},
CpLevel
:
cp_cv
.
CvCpLevel
{
Level
:
cpLevel
,
Points
:
cp_e
.
CpLevelPoints
[
cpLevel
]
,
// todo get from db
Points
:
cp_e
.
CpLevelPoints
[
cpLevel
]
+
curPoints
,
NextPoints
:
nextPoints
,
RemainPoints
:
remainPoints
,
ExpireAt
:
expireAt
,
ExpireAt
Unix
:
expireAtUnix
,
},
ResLevelList
:
cp_cv
.
CvResLevelList
,
PrivilegeList
:
privilegeList
,
...
...
route/router.go
View file @
059d1c27
...
...
@@ -34,6 +34,7 @@ func InitRouter() *gin.Engine {
cp
.
GET
(
"/space"
,
wrapper
(
cp_r
.
CpSpace
))
cp
.
PUT
(
"/privilege/openClose"
,
wrapper
(
cp_r
.
CpPrivilegeOpenClose
))
cp
.
GET
(
"/rank/:queryType"
,
wrapper
(
cp_r
.
CpRank
))
cp
.
GET
(
"/my/:queryType"
,
wrapper
(
cp_r
.
CpMy
))
}
inner
:=
r
.
Group
(
"/inner"
)
inner
.
Use
(
ExceptionHandle
,
LoggerHandle
)
...
...
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