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
2afef13c
Commit
2afef13c
authored
Jun 05, 2023
by
chenweijian
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
cp信息
parent
929ac6dd
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
141 additions
and
18 deletions
+141
-18
space.go
cv/cp_cv/space.go
+1
-0
user.go
cv/user_cv/user.go
+14
-0
user.go
domain/cache/user_c/user.go
+89
-0
user.go
domain/model/user_m/user.go
+9
-0
cp_relation.go
route/cp_r/cp_relation.go
+28
-18
No files found.
cv/cp_cv/space.go
View file @
2afef13c
...
...
@@ -14,6 +14,7 @@ import (
type
CvCpInfo
struct
{
UserInfo
*
user_cv
.
UserTiny
`json:"userInfo"`
// 用户信息
CpUserInfo
*
user_cv
.
UserTiny
`json:"cpUserInfo,omitempty"`
// cp用户信息
CreatedUnix
int64
`json:"createdUnix"`
// cp创建时间
CpDays
int
`json:"cpDays"`
// cp天数
VisitTimes
int64
`json:"visitTimes"`
// 空间访问量
ApplyToUnbind
bool
`json:"applyToUnbind"`
// 是否申请撤销cp
...
...
cv/user_cv/user.go
View file @
2afef13c
...
...
@@ -42,6 +42,20 @@ func UserToTiny(user user_m.User) *UserTiny {
}
}
func
UserTinyToCvTiny
(
user
*
user_m
.
UserTiny
)
*
UserTiny
{
return
&
UserTiny
{
Id
:
user
.
ID
,
ExternalId
:
user
.
ExternalId
,
Avatar
:
user
.
Avatar
,
Nick
:
user
.
Nick
,
Sex
:
user
.
Sex
,
Code
:
user
.
Code
,
Country
:
user
.
Country
,
CountryIcon
:
user
.
CountryIcon
,
IsPrettyCode
:
user
.
IsPrettyCode
,
}
}
//用户基本信息
type
CvUserBase
struct
{
//不会有返回值
...
...
domain/cache/user_c/user.go
View file @
2afef13c
package
user_c
import
(
"git.hilo.cn/hilo-common/_const/common"
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"git.hilo.cn/hilo-common/utils"
redisV8
"github.com/go-redis/redis/v8"
"github.com/jinzhu/copier"
"hilo-user/_const/redis_key/user_k"
...
...
@@ -10,6 +12,7 @@ import (
"hilo-user/domain/model/user_m"
"hilo-user/myerr"
"hilo-user/myerr/bizerr"
"time"
)
// 获取用户简要信息
...
...
@@ -113,3 +116,89 @@ func cacheUserTiny(model *domain.Model, user *user_m.User) error {
}
return
nil
}
// 获取用户简要信息
// param userIds 用户id列表
func
GetUserTinyMap
(
model
*
domain
.
Model
,
userIds
[]
mysql
.
ID
,
isDefAvatar
bool
)
(
map
[
mysql
.
ID
]
*
user_m
.
UserTiny
,
error
)
{
redisNoIds
:=
make
([]
mysql
.
ID
,
0
)
res
:=
make
(
map
[
mysql
.
ID
]
*
user_m
.
UserTiny
)
for
_
,
id
:=
range
userIds
{
userTiny
:=
new
(
user_m
.
UserTiny
)
key
:=
user_k
.
GetUserTinyKey
(
id
)
err
:=
cache
.
GetJSON
(
model
,
key
,
userTiny
)
if
err
!=
nil
&&
err
!=
redisV8
.
Nil
{
return
nil
,
err
}
if
err
==
redisV8
.
Nil
{
redisNoIds
=
append
(
redisNoIds
,
id
)
}
else
if
userTiny
.
ID
>
0
{
res
[
id
]
=
userTiny
}
}
// 从db中读
users
,
err
:=
user_m
.
GetUsers
(
model
,
redisNoIds
)
if
err
!=
nil
{
return
nil
,
err
}
for
_
,
u
:=
range
users
{
userTiny
:=
ToUserTinyBy
(
u
)
err
=
cacheUserTiny
(
model
,
u
)
if
err
!=
nil
{
return
nil
,
err
}
res
[
userTiny
.
ID
]
=
userTiny
}
if
isDefAvatar
{
for
_
,
v
:=
range
res
{
if
len
(
v
.
Avatar
)
<=
0
{
if
v
.
Sex
==
mysql
.
MAN
{
v
.
Avatar
=
utils
.
MakeFullUrl
(
common
.
DefaultAvatarMan
)
}
else
if
v
.
Sex
==
mysql
.
WOMAN
{
v
.
Avatar
=
utils
.
MakeFullUrl
(
common
.
DefaultAvatarWoman
)
}
}
}
}
return
res
,
nil
}
func
ToUserTinyBy
(
user
*
user_m
.
User
)
*
user_m
.
UserTiny
{
return
&
user_m
.
UserTiny
{
ID
:
user
.
ID
,
Avatar
:
IfLogoutStr
(
IfLogout
(
user
.
LogoutTime
),
""
,
user
.
Avatar
),
ExternalId
:
user
.
ExternalId
,
Nick
:
IfLogoutNick
(
IfLogout
(
user
.
LogoutTime
),
user
.
Code
,
user
.
Nick
),
Sex
:
user
.
Sex
,
Code
:
user
.
Code
,
Country
:
user
.
Country
,
CountryIcon
:
user
.
CountryIcon
,
IsPrettyCode
:
user
.
IsPrettyCode
(),
IsLogout
:
IfLogout
(
user
.
LogoutTime
),
Birthday
:
BirthdayToUint64
(
&
user
.
Birthday
),
}
}
func
IfLogout
(
logoutTime
int64
)
bool
{
return
logoutTime
>
0
&&
time
.
Now
()
.
Unix
()
>
logoutTime
}
func
BirthdayToUint64
(
birthday
*
mysql
.
Timestamp
)
*
uint64
{
if
*
birthday
==
0
{
return
nil
}
return
(
*
uint64
)(
birthday
)
}
func
IfLogoutStr
(
condition
bool
,
trueVal
,
falseVal
string
)
string
{
if
condition
{
return
trueVal
}
return
falseVal
}
func
IfLogoutNick
(
condition
bool
,
code
string
,
nick
string
)
string
{
if
condition
{
return
"Hilo No."
+
code
}
return
nick
}
domain/model/user_m/user.go
View file @
2afef13c
...
...
@@ -135,3 +135,12 @@ func BirthdayToUint64(birthday *mysql.Timestamp) *uint64 {
}
return
(
*
uint64
)(
birthday
)
}
//获取用户
func
GetUsers
(
model
*
domain
.
Model
,
ids
[]
mysql
.
ID
)
([]
*
User
,
error
)
{
res
:=
make
([]
*
User
,
0
)
if
err
:=
model
.
Db
.
WithContext
(
model
.
Context
)
.
Where
(
"id in (?)"
,
ids
)
.
Find
(
&
res
)
.
Error
;
err
!=
nil
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
return
res
,
nil
}
route/cp_r/cp_relation.go
View file @
2afef13c
...
...
@@ -9,9 +9,11 @@ import (
"git.hilo.cn/hilo-common/myerr/comerr"
"git.hilo.cn/hilo-common/sdk/tencentyun"
"git.hilo.cn/hilo-common/txop/msg"
"git.hilo.cn/hilo-common/utils"
"github.com/gin-gonic/gin"
"hilo-user/_const/enum/cp_e"
"hilo-user/cv/cp_cv"
"hilo-user/cv/user_cv"
"hilo-user/domain/cache/user_c"
"hilo-user/domain/model/cp_m"
"hilo-user/domain/model/diamond_m"
...
...
@@ -21,6 +23,7 @@ import (
"hilo-user/req"
"hilo-user/resp"
"strconv"
"time"
)
// @Tags cp关系
...
...
@@ -329,13 +332,8 @@ func ReplyCpCancel(c *gin.Context) (*mycontext.MyContext, error) {
}
type
CpDetail
struct
{
Avatar1
string
`json:"avatar1"`
Avatar2
string
`json:"avatar2"`
Nick1
string
`json:"nick1"`
Nick2
string
`json:"nick2"`
Grade
int
`json:"grade"`
// 等级
GradeName
string
`json:"gradeName"`
// 等级称号
CreatedTime
int64
`json:"createdTime"`
// cp创建时间
CpInfo
cp_cv
.
CvCpInfo
`json:"cpInfo"`
// cp信息
CpLevel
cp_cv
.
CvCpLevel
`json:"cpLevel"`
// cp等级
}
// @Tags cp关系
...
...
@@ -360,18 +358,30 @@ func CpDetailPage(c *gin.Context) (*mycontext.MyContext, error) {
var
res
*
CpDetail
if
cp
.
Id
>
0
{
res
=
new
(
CpDetail
)
if
cp
.
UserId1
==
user
.
ID
{
res
.
Avatar1
=
user
.
Avatar
res
.
Nick1
=
user
.
Nick
user2
,
err
:=
user_c
.
GetUserTinyById
(
model
,
cp
.
UserId2
)
if
err
!=
nil
{
return
myCtx
,
err
}
res
.
Avatar2
=
user2
.
Avatar
res
.
Nick2
=
user2
.
Nick
userIds
:=
[]
uint64
{
cp
.
UserId1
,
cp
.
UserId2
}
userMap
,
err
:=
user_c
.
GetUserTinyMap
(
model
,
userIds
,
false
)
if
err
!=
nil
{
return
myCtx
,
err
}
res
.
CreatedTime
=
cp
.
CreatedTime
.
Unix
()
res
=
new
(
CpDetail
)
// 返回值
level
:=
cp_m
.
GetCpLevel
(
model
,
cp
.
Id
)
res
.
CpLevel
=
cp_cv
.
CvCpLevel
{
Level
:
level
.
Level
,
Points
:
cp_e
.
CpLevelPoints
[
level
.
Level
]
+
level
.
Points
,
StartPoints
:
cp_e
.
CpLevelPoints
[
level
.
Level
],
ExpireAtUnix
:
level
.
ExpireAt
.
Unix
(),
SettlementDate
:
level
.
ExpireAt
.
Format
(
utils
.
DATE_FORMAT
),
}
if
res
.
CpLevel
.
Level
!=
cp_e
.
CpLevelMax
{
res
.
CpLevel
.
EndPoints
=
cp_e
.
CpLevelPoints
[
res
.
CpLevel
.
Level
+
1
]
}
res
.
CpInfo
=
cp_cv
.
CvCpInfo
{
UserInfo
:
user_cv
.
UserTinyToCvTiny
(
userMap
[
cp
.
UserId1
]),
CpUserInfo
:
user_cv
.
UserTinyToCvTiny
(
userMap
[
cp
.
UserId1
]),
CpDays
:
int
(
time
.
Now
()
.
Sub
(
cp
.
CreatedTime
)
.
Hours
()
/
24
)
+
1
,
CreatedUnix
:
cp
.
CreatedTime
.
Unix
(),
}
}
...
...
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