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
0b17c301
Commit
0b17c301
authored
May 29, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
成就页
parent
48d2038a
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
71 additions
and
1 deletion
+71
-1
rank.go
cv/cp_cv/rank.go
+14
-1
achievement.go
domain/model/cp_m/achievement.go
+9
-0
rank.go
route/cp_r/rank.go
+47
-0
router.go
route/router.go
+1
-0
No files found.
cv/cp_cv/rank.go
View file @
0b17c301
package
cp_cv
import
"hilo-user/cv/user_cv"
import
(
"hilo-user/_const/enum/cp_e"
"hilo-user/cv/user_cv"
)
type
CvCp
struct
{
CpId
uint64
`json:"cpId"`
// cpId
...
...
@@ -9,3 +12,13 @@ type CvCp struct {
Score
uint32
`json:"score"`
// 分值
//Ranking int `json:"ranking"` // 排名
}
type
CvCpAchievement
struct
{
CpId
uint64
`json:"cpId"`
// cpId
User1
user_cv
.
UserTiny
`json:"user1"`
// user1
User2
user_cv
.
UserTiny
`json:"user2"`
// user2
Type
cp_e
.
CpAchievement
`json:"type"`
// 成就类型 1:等级 2:空间访问人数 3:月榜最高 4:周榜最高 5:日榜最高
TypeDesc
string
`json:"typeDesc"`
// 成就类型翻译
Score
uint32
`json:"score"`
// 分值
TimeUnix
int64
`json:"timeUnix"`
// 达成成就时间戳
}
domain/model/cp_m/achievement.go
View file @
0b17c301
...
...
@@ -40,3 +40,12 @@ func UpdateCpAchievement(model *domain.Model, cpId, userId1, userId2 mysql.ID, T
// update if less than
return
model
.
DB
()
.
Model
(
CpAchievement
{})
.
Where
(
"cp_id = ? AND `type` = ?"
,
cpId
,
Type
)
.
Where
(
"score < ?"
,
score
)
.
UpdateColumn
(
"score"
,
score
)
.
Error
}
// 获取用户cp成就
func
GetCpAchievements
(
model
*
domain
.
Model
,
cpId
mysql
.
ID
)
[]
CpAchievement
{
var
achievements
[]
CpAchievement
if
err
:=
model
.
DB
()
.
Model
(
CpAchievement
{})
.
Where
(
"cp_id = ?"
,
cpId
)
.
Find
(
&
achievements
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"GetAchievements fail:%v"
,
err
)
}
return
achievements
}
route/cp_r/rank.go
View file @
0b17c301
...
...
@@ -6,9 +6,11 @@ import (
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"github.com/jinzhu/now"
"hilo-user/_const/enum/cp_e"
"hilo-user/cv/cp_cv"
"hilo-user/cv/user_cv"
"hilo-user/domain/model/cp_m"
"hilo-user/domain/model/user_m"
"hilo-user/myerr/bizerr"
"hilo-user/req"
"hilo-user/resp"
...
...
@@ -143,3 +145,48 @@ func CpMy(c *gin.Context) (*mycontext.MyContext, error) {
resp
.
ResponseOk
(
c
,
response
)
return
myCtx
,
nil
}
// @Tags CP v2
// @Summary 成就页
// @Param token header string true "token"
// @Param nonce header string true "随机数字"
// @Success 200 {object} []cp_cv.CvCpAchievement
// @Router /v2/cp/achievement [get]
func
CpAchievement
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
userId
,
err
:=
req
.
GetUserId
(
c
)
if
err
!=
nil
{
return
myCtx
,
err
}
model
:=
domain
.
CreateModelContext
(
myCtx
)
relation
,
exits
:=
cp_m
.
GetCpRelation
(
model
,
userId
)
var
response
=
make
([]
cp_cv
.
CvCpAchievement
,
0
)
TypeDescMap
:=
map
[
cp_e
.
CpAchievement
]
string
{
// todo 翻译
cp_e
.
CpAchievementLevel
:
"等级分值最高"
,
cp_e
.
CpAchievementVisitors
:
"空间访问量最高"
,
cp_e
.
CpAchievementMonthRank
:
"月榜最高"
,
cp_e
.
CpAchievementWeekRank
:
"周榜最高"
,
cp_e
.
CpAchievementDayRank
:
"天榜最高"
,
}
if
exits
{
users
,
err
:=
user_m
.
GetUserMapByIds
(
model
,
[]
mysql
.
ID
{
relation
.
UserId1
,
relation
.
UserId2
})
if
err
!=
nil
{
return
myCtx
,
err
}
achievements
:=
cp_m
.
GetCpAchievements
(
model
,
relation
.
ID
)
for
_
,
a
:=
range
achievements
{
response
=
append
(
response
,
cp_cv
.
CvCpAchievement
{
CpId
:
a
.
CpId
,
User1
:
user_cv
.
UserToTiny
(
users
[
a
.
UserId1
]),
User2
:
user_cv
.
UserToTiny
(
users
[
a
.
UserId2
]),
Type
:
a
.
Type
,
TypeDesc
:
TypeDescMap
[
a
.
Type
],
Score
:
a
.
Score
,
TimeUnix
:
a
.
UpdatedTime
.
Unix
(),
})
}
}
else
{
}
resp
.
ResponseOk
(
c
,
response
)
return
nil
,
nil
}
route/router.go
View file @
0b17c301
...
...
@@ -35,6 +35,7 @@ func InitRouter() *gin.Engine {
cp
.
PUT
(
"/privilege/openClose"
,
wrapper
(
cp_r
.
CpPrivilegeOpenClose
))
cp
.
GET
(
"/rank/:queryType"
,
wrapper
(
cp_r
.
CpRank
))
cp
.
GET
(
"/my/:queryType"
,
wrapper
(
cp_r
.
CpMy
))
cp
.
GET
(
"/achievement"
,
wrapper
(
cp_r
.
CpAchievement
))
}
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