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
a263b25f
Commit
a263b25f
authored
Jun 20, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into feature/user-detail
parents
9b41cb9d
50c31efc
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
1 deletion
+81
-1
old_cp.go
domain/model/cp_m/old_cp.go
+59
-0
rank.go
domain/model/cp_m/rank.go
+9
-0
inner.go
route/user_r/inner.go
+5
-1
cp_test.go
test/cp_test.go
+8
-0
No files found.
domain/model/cp_m/old_cp.go
0 → 100644
View file @
a263b25f
package
cp_m
import
(
"git.hilo.cn/hilo-common/domain"
"git.hilo.cn/hilo-common/resource/mysql"
"gorm.io/gorm"
"hilo-user/myerr"
)
type
StatusCp
=
mysql
.
Type
const
(
Connect
StatusCp
=
1
Disconnect
StatusCp
=
2
)
type
OldCp
struct
{
mysql
.
Entity
//必须保证userId1 > userId2
UserId1
mysql
.
ID
UserId2
mysql
.
ID
Score
mysql
.
Num
DayScore
mysql
.
Num
PeriodDay
mysql
.
Str
WeekScore
mysql
.
Num
PeriodWeek
mysql
.
Str
MonthScore
mysql
.
Num
PeriodMonth
mysql
.
Str
Status
StatusCp
//中断时长
DisconnectSecond
int64
}
func
(
OldCp
)
TableName
()
string
{
return
"cp"
}
// 获取旧的绑定中的cp
func
GetOldConnectCp
(
model
*
domain
.
Model
,
tmpUserId1
mysql
.
ID
,
tmpUserId2
mysql
.
ID
)
(
*
OldCp
,
error
)
{
userId1
:=
tmpUserId1
userId2
:=
tmpUserId2
if
tmpUserId1
<
tmpUserId2
{
userId1
=
tmpUserId2
userId2
=
tmpUserId1
}
cp
:=
OldCp
{}
if
err
:=
model
.
Db
.
Where
(
&
OldCp
{
UserId1
:
userId1
,
UserId2
:
userId2
,
Status
:
Connect
,
})
.
First
(
&
cp
)
.
Error
;
err
!=
nil
{
if
err
==
gorm
.
ErrRecordNotFound
{
return
nil
,
nil
}
else
{
return
nil
,
myerr
.
WrapErr
(
err
)
}
}
return
&
cp
,
nil
}
domain/model/cp_m/rank.go
View file @
a263b25f
...
@@ -58,3 +58,12 @@ func GetCpDayRank(model *domain.Model, beginDate, endDate string, cpId mysql.ID)
...
@@ -58,3 +58,12 @@ func GetCpDayRank(model *domain.Model, beginDate, endDate string, cpId mysql.ID)
}
}
return
rank
return
rank
}
}
// 获取Cp历史分数
func
SumCpPoints
(
model
*
domain
.
Model
,
cpId
mysql
.
ID
)
mysql
.
Num
{
var
score
CpDayRank
if
err
:=
model
.
DB
()
.
Model
(
CpDayRank
{})
.
Where
(
"cp_id = ?"
,
cpId
)
.
Select
(
"SUM(score) score"
)
.
Scan
(
&
score
)
.
Error
;
err
!=
nil
{
model
.
Log
.
Errorf
(
"SumCpPoints fail:%v"
,
err
)
}
return
score
.
Score
}
route/user_r/inner.go
View file @
a263b25f
...
@@ -157,11 +157,15 @@ func GetUserCp(c *gin.Context) (*mycontext.MyContext, error) {
...
@@ -157,11 +157,15 @@ func GetUserCp(c *gin.Context) (*mycontext.MyContext, error) {
if
msgId
,
ok
:=
cp_e
.
CpLevelTitle
[
level
.
Level
];
ok
{
if
msgId
,
ok
:=
cp_e
.
CpLevelTitle
[
level
.
Level
];
ok
{
title
=
cp_cv
.
GetTranslate
(
msgId
,
req
.
Language
)
title
=
cp_cv
.
GetTranslate
(
msgId
,
req
.
Language
)
}
}
var
oldScore
uint32
if
oldCp
,
_
:=
cp_m
.
GetOldConnectCp
(
model
,
cpRelation
.
UserId1
,
cpRelation
.
UserId2
);
oldCp
!=
nil
{
oldScore
=
uint32
(
oldCp
.
Score
)
}
response
=
cp_cv
.
CvCp
{
response
=
cp_cv
.
CvCp
{
CpUserInfo
:
userBases
[
cpUserId
],
CpUserInfo
:
userBases
[
cpUserId
],
CpLevel
:
cp_cv
.
CvCpLevel
{
CpLevel
:
cp_cv
.
CvCpLevel
{
Level
:
cpLevel
,
Level
:
cpLevel
,
Points
:
cp_e
.
CpLevelPoints
[
cpLevel
]
+
level
.
Points
,
Points
:
oldScore
+
cp_m
.
SumCpPoints
(
model
,
cpRelation
.
Id
),
// 历史分数
Title
:
title
,
Title
:
title
,
},
},
MyPrivilegeList
:
myPrivilegeList
,
MyPrivilegeList
:
myPrivilegeList
,
...
...
test/cp_test.go
View file @
a263b25f
...
@@ -30,3 +30,11 @@ func TestCalLoc(t *testing.T) {
...
@@ -30,3 +30,11 @@ func TestCalLoc(t *testing.T) {
loc
=
timezone_e
.
GetFixedTimezone
(
"GMT+5"
)
loc
=
timezone_e
.
GetFixedTimezone
(
"GMT+5"
)
println
(
time
.
Now
()
.
In
(
loc
)
.
Format
(
"2006-01-02 15:04:05"
))
println
(
time
.
Now
()
.
In
(
loc
)
.
Format
(
"2006-01-02 15:04:05"
))
}
}
func
TestSumCpScore
(
t
*
testing
.
T
)
{
model
:=
domain
.
CreateModelNil
()
old
,
err
:=
cp_m
.
GetOldConnectCp
(
model
,
7642
,
4549
)
t
.
Logf
(
"%v-%v"
,
old
,
err
)
n
:=
cp_m
.
SumCpPoints
(
model
,
1
)
t
.
Logf
(
"%v"
,
n
)
}
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