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
c1bc2b78
Commit
c1bc2b78
authored
Feb 17, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:新的接口
parent
1c378bf6
Changes
7
Show whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
81 additions
and
198 deletions
+81
-198
Makefile
Makefile
+1
-3
level.go
cv/user_cv/level.go
+11
-0
userNoble.go
domain/model/noble_m/userNoble.go
+0
-95
matchCharm.go
domain/model/user_m/matchCharm.go
+9
-51
matchWealth.go
domain/model/user_m/matchWealth.go
+9
-49
router.go
route/router.go
+6
-0
inner.go
route/user_r/inner.go
+45
-0
No files found.
Makefile
View file @
c1bc2b78
swag
:
swag init
\ No newline at end of file
proto
:
protoc
--go_out
=
./
--go-grpc_out
=
.
./protocol/
*
.proto
\ No newline at end of file
cv/user_cv/level.go
0 → 100644
View file @
c1bc2b78
package
user_cv
import
"git.hilo.cn/hilo-common/resource/mysql"
type
MGetUserLevelData
map
[
mysql
.
ID
]
CvUserLevel
type
CvUserLevel
struct
{
UserId
mysql
.
ID
`json:"userId"`
// 用户id
WealthUserGrade
uint32
`json:"wealthUserGrade"`
//财富等级
CharmUserGrade
uint32
`json:"charmUserGrade"`
//魅力等级
}
domain/model/noble_m/userNoble.go
deleted
100755 → 0
View file @
1c378bf6
package
noble_m
import
(
"gorm.io/gorm"
"hilo-user/resource/mysql"
"time"
)
type
UserNoble
struct
{
mysql
.
Entity
UserId
uint64
Level
uint16
EndTime
time
.
Time
}
func
(
ub
*
UserNoble
)
Create
(
db
*
gorm
.
DB
)
error
{
return
db
.
Create
(
ub
)
.
Error
}
func
(
ub
*
UserNoble
)
UpdateEndTime
(
db
*
gorm
.
DB
,
endTime
time
.
Time
)
(
int64
,
error
)
{
r
:=
db
.
Model
(
&
UserNoble
{})
.
Where
(
ub
)
.
Update
(
"end_time"
,
endTime
)
return
r
.
RowsAffected
,
r
.
Error
}
// 查询用户未过期的贵族
func
(
ub
*
UserNoble
)
Find
(
db
*
gorm
.
DB
)
([]
UserNoble
,
error
)
{
rows
:=
make
([]
UserNoble
,
0
)
if
err
:=
db
.
Where
(
ub
)
.
Where
(
"end_time>=NOW()"
)
.
Order
(
"level DESC"
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
rows
,
nil
}
// 查询用户所有的贵族(包括已过期)
func
(
ub
*
UserNoble
)
FindAll
(
db
*
gorm
.
DB
)
([]
UserNoble
,
error
)
{
rows
:=
make
([]
UserNoble
,
0
)
if
err
:=
db
.
Where
(
ub
)
.
Order
(
"level DESC"
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
return
rows
,
nil
}
func
RemoveNoble
(
db
*
gorm
.
DB
,
userId
uint64
,
level
uint16
)
error
{
ub
:=
UserNoble
{
UserId
:
userId
,
Level
:
level
,
}
return
ub
.
Delete
(
db
)
}
func
(
ub
*
UserNoble
)
Delete
(
db
*
gorm
.
DB
)
error
{
return
db
.
Where
(
ub
)
.
Delete
(
&
UserNoble
{})
.
Error
}
// 查询用户未过期的贵族
func
(
ub
*
UserNoble
)
batchGet
(
db
*
gorm
.
DB
,
userIds
[]
uint64
)
(
map
[
uint64
][]
UserNoble
,
error
)
{
rows
:=
make
([]
UserNoble
,
0
)
if
err
:=
db
.
Model
(
ub
)
.
Where
(
"end_time>=NOW() AND user_id IN ?"
,
userIds
)
.
Order
(
"level DESC"
)
.
Find
(
&
rows
)
.
Error
;
err
!=
nil
{
return
nil
,
err
}
result
:=
make
(
map
[
uint64
][]
UserNoble
,
0
)
for
_
,
i
:=
range
rows
{
if
_
,
ok
:=
result
[
i
.
UserId
];
!
ok
{
result
[
i
.
UserId
]
=
make
([]
UserNoble
,
0
)
}
result
[
i
.
UserId
]
=
append
(
result
[
i
.
UserId
],
i
)
}
return
result
,
nil
}
func
FindActiveNoble
(
db
*
gorm
.
DB
,
userId
uint64
)
(
*
UserNoble
,
error
)
{
ub
:=
UserNoble
{
UserId
:
userId
,
}
records
,
err
:=
ub
.
Find
(
db
)
if
err
!=
nil
{
return
nil
,
err
}
if
len
(
records
)
<=
0
{
return
nil
,
nil
}
return
&
records
[
0
],
nil
}
func
GetNobleLevel
(
db
*
gorm
.
DB
,
userId
uint64
)
(
uint16
,
error
)
{
noble
,
err
:=
FindActiveNoble
(
db
,
userId
)
if
err
!=
nil
{
return
0
,
err
}
if
noble
==
nil
{
return
0
,
nil
}
else
{
return
noble
.
Level
,
nil
}
}
domain/model/user_m/matchCharm.go
View file @
c1bc2b78
...
...
@@ -3,9 +3,6 @@ package user_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-user/_const/enum/match_e"
"hilo-user/myerr"
)
/**
...
...
@@ -19,54 +16,15 @@ type MatchCharmUserScore struct {
Grade
mysql
.
Num
}
//获取魅力等级
func
GetCharmGrade
(
model
*
domain
.
Model
,
userId
mysql
.
ID
)
(
uint32
,
uint32
,
error
)
{
var
charmUserScore
MatchCharmUserScore
if
err
:=
model
.
Db
.
Model
(
&
MatchCharmUserScore
{})
.
Where
(
&
MatchCharmUserScore
{
UserId
:
userId
,
})
.
First
(
&
charmUserScore
)
.
Error
;
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
0
,
0
,
nil
}
else
{
return
0
,
0
,
myerr
.
WrapErr
(
err
)
// 批量获取魅力等级
func
MGetCharmGrade
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
res
:=
make
(
map
[
mysql
.
ID
]
mysql
.
Num
)
var
charmUserScore
[]
*
MatchCharmUserScore
if
err
:=
model
.
Db
.
Model
(
&
MatchCharmUserScore
{})
.
Where
(
"user_id in ?"
,
userIds
)
.
Find
(
&
charmUserScore
)
.
Error
;
err
!=
nil
{
return
res
,
err
}
for
_
,
r
:=
range
charmUserScore
{
res
[
r
.
UserId
]
=
r
.
Grade
}
return
charmUserScore
.
Grade
,
charmUserScore
.
Score
,
nil
}
type
MatchCharmUserScoreDetail
struct
{
mysql
.
Entity
MatchCharmUserScoreId
mysql
.
ID
UserId
mysql
.
ID
BeforeScore
mysql
.
Num
Score
mysql
.
Num
AfterScore
mysql
.
Num
Type
match_e
.
MatchCharmUserScoreDetailType
OrginId
mysql
.
ID
}
func
addMatchCharmUserScoreDetail
(
model
*
domain
.
Model
,
matchCharmUserScoreId
mysql
.
ID
,
userId
mysql
.
ID
,
beforeScore
mysql
.
Num
,
score
mysql
.
Num
,
t
match_e
.
MatchCharmUserScoreDetailType
,
orginId
mysql
.
ID
)
error
{
if
err
:=
model
.
Db
.
Save
(
&
MatchCharmUserScoreDetail
{
MatchCharmUserScoreId
:
matchCharmUserScoreId
,
UserId
:
userId
,
BeforeScore
:
beforeScore
,
Score
:
score
,
AfterScore
:
beforeScore
+
score
,
Type
:
t
,
OrginId
:
orginId
,
})
.
Error
;
err
!=
nil
{
return
myerr
.
WrapErr
(
err
)
}
return
nil
}
/**
* 获取的分数同等级关系
**/
type
MatchCharmSetScoreGrade
struct
{
mysql
.
Entity
*
domain
.
Model
`gorm:"-"`
MinNum
mysql
.
Num
MaxNum
mysql
.
Num
Grade
mysql
.
Num
return
res
,
nil
}
domain/model/user_m/matchWealth.go
View file @
c1bc2b78
...
...
@@ -3,9 +3,6 @@ package user_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-user/_const/enum/match_e"
"hilo-user/myerr"
)
/**
...
...
@@ -19,52 +16,15 @@ type MatchWealthUserScore struct {
Grade
mysql
.
Num
}
/**
* 获取的分数同等级关系
**/
type
MatchWealthSetScoreGrade
struct
{
mysql
.
Entity
*
domain
.
Model
`gorm:"-"`
MinNum
mysql
.
Num
MaxNum
mysql
.
Num
Grade
mysql
.
Num
}
type
MatchWealthUserScoreDetail
struct
{
mysql
.
Entity
MatchWealthUserScoreId
mysql
.
ID
UserId
mysql
.
ID
BeforeScore
mysql
.
Num
Score
mysql
.
Num
AfterScore
mysql
.
Num
Type
match_e
.
MatchWealthUserScoreDetailType
OrginId
mysql
.
ID
}
func
addMatchWealthUserScoreDetail
(
model
*
domain
.
Model
,
matchWealthUserScoreId
mysql
.
ID
,
userId
mysql
.
ID
,
beforeScore
mysql
.
Num
,
score
mysql
.
Num
,
t
match_e
.
MatchWealthUserScoreDetailType
,
orginId
mysql
.
ID
)
error
{
if
err
:=
model
.
Db
.
Save
(
&
MatchWealthUserScoreDetail
{
MatchWealthUserScoreId
:
matchWealthUserScoreId
,
UserId
:
userId
,
BeforeScore
:
beforeScore
,
Score
:
score
,
AfterScore
:
beforeScore
+
score
,
Type
:
t
,
OrginId
:
orginId
,
})
.
Error
;
err
!=
nil
{
return
myerr
.
WrapErr
(
err
)
}
return
nil
}
//获取财富等级
func
GetWealthGrade
(
model
*
domain
.
Model
,
userId
mysql
.
ID
)
(
uint32
,
uint32
,
error
)
{
var
wealthUserScore
MatchWealthUserScore
if
err
:=
model
.
Db
.
Model
(
&
MatchWealthUserScore
{})
.
Where
(
&
MatchWealthUserScore
{
UserId
:
userId
})
.
First
(
&
wealthUserScore
)
.
Error
;
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
0
,
0
,
nil
}
else
{
return
0
,
0
,
myerr
.
WrapErr
(
err
)
// 批量获取财富等级
func
MGetWealthGrade
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
)
(
map
[
mysql
.
ID
]
mysql
.
Num
,
error
)
{
res
:=
make
(
map
[
mysql
.
ID
]
mysql
.
Num
)
var
wealthUserScore
[]
*
MatchWealthUserScore
if
err
:=
model
.
Db
.
Model
(
&
MatchWealthUserScore
{})
.
Where
(
"user_id in ?"
,
userIds
)
.
Find
(
&
wealthUserScore
)
.
Error
;
err
!=
nil
{
return
res
,
err
}
for
_
,
r
:=
range
wealthUserScore
{
res
[
r
.
UserId
]
=
r
.
Grade
}
return
wealthUserScore
.
Grade
,
wealthUserScore
.
Score
,
nil
return
res
,
nil
}
route/router.go
View file @
c1bc2b78
...
...
@@ -20,5 +20,11 @@ func InitRouter() *gin.Engine {
{
user
.
GET
(
"/nameplate"
,
wrapper
(
user_r
.
UserNameplate
))
}
inner
:=
r
.
Group
(
"/inner"
)
inner
.
Use
(
ExceptionHandle
,
LoggerHandle
)
innerUser
:=
inner
.
Group
(
"/user"
)
{
innerUser
.
GET
(
"/levels"
,
wrapper
(
user_r
.
MGetUserLevels
))
}
return
r
}
route/user_r/inner.go
0 → 100644
View file @
c1bc2b78
package
user_r
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/mycontext"
"git.hilo.cn/hilo-common/resource/mysql"
"github.com/gin-gonic/gin"
"hilo-user/cv/user_cv"
"hilo-user/domain/model/user_m"
"hilo-user/resp"
)
type
MGetUserLevelReq
struct
{
Ids
[]
mysql
.
ID
`form:"ids" binding:"required"`
}
// @Tags 用户-内部
// @Summary 批量获取用户等级
// @Param ids query string true "用户id,如:ids=1&ids=2&ids=3"
// @Success 200 {object} user_cv.MGetUserLevelData
// @Router /inner/user/levels [get]
func
MGetUserLevels
(
c
*
gin
.
Context
)
(
*
mycontext
.
MyContext
,
error
)
{
myCtx
:=
mycontext
.
CreateMyContext
(
c
.
Keys
)
var
model
=
domain
.
CreateModelContext
(
myCtx
)
var
req
MGetUserLevelReq
if
err
:=
c
.
ShouldBindQuery
(
&
req
);
err
!=
nil
{
return
myCtx
,
err
}
wealthGrade
,
err
:=
user_m
.
MGetWealthGrade
(
model
,
req
.
Ids
)
if
err
!=
nil
{
return
myCtx
,
err
}
charmGrade
,
err
:=
user_m
.
MGetCharmGrade
(
model
,
req
.
Ids
)
response
:=
user_cv
.
MGetUserLevelData
{}
for
_
,
userId
:=
range
req
.
Ids
{
response
[
userId
]
=
user_cv
.
CvUserLevel
{
UserId
:
userId
,
WealthUserGrade
:
wealthGrade
[
userId
],
CharmUserGrade
:
charmGrade
[
userId
],
}
}
resp
.
ResponseOk
(
c
,
response
)
return
myCtx
,
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