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
b4ec010a
Commit
b4ec010a
authored
Jun 20, 2023
by
hujiebin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:分数用新旧相加
parent
eef32ec6
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
79 additions
and
1 deletion
+79
-1
old_cp.go
domain/model/cp_m/old_cp.go
+57
-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 @
b4ec010a
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"
}
func
GetOldCpOrNil
(
model
*
domain
.
Model
,
tmpUserId1
mysql
.
ID
,
tmpUserId2
mysql
.
ID
)
(
*
Cp
,
error
)
{
userId1
:=
tmpUserId1
userId2
:=
tmpUserId2
if
tmpUserId1
<
tmpUserId2
{
userId1
=
tmpUserId2
userId2
=
tmpUserId1
}
cp
:=
Cp
{}
if
err
:=
model
.
Db
.
Where
(
&
Cp
{
UserId1
:
userId1
,
UserId2
:
userId2
,
})
.
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 @
b4ec010a
...
...
@@ -58,3 +58,12 @@ func GetCpDayRank(model *domain.Model, beginDate, endDate string, cpId mysql.ID)
}
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 @
b4ec010a
...
...
@@ -157,11 +157,15 @@ func GetUserCp(c *gin.Context) (*mycontext.MyContext, error) {
if
msgId
,
ok
:=
cp_e
.
CpLevelTitle
[
level
.
Level
];
ok
{
title
=
cp_cv
.
GetTranslate
(
msgId
,
req
.
Language
)
}
var
oldScore
uint32
if
oldCp
,
_
:=
cp_m
.
GetOldCpOrNil
(
model
,
cpRelation
.
UserId1
,
cpRelation
.
UserId2
);
oldCp
!=
nil
{
oldScore
=
uint32
(
oldCp
.
Score
)
}
response
=
cp_cv
.
CvCp
{
CpUserInfo
:
userBases
[
cpUserId
],
CpLevel
:
cp_cv
.
CvCpLevel
{
Level
:
cpLevel
,
Points
:
cp_e
.
CpLevelPoints
[
cpLevel
]
+
level
.
Points
,
Points
:
oldScore
+
cp_m
.
SumCpPoints
(
model
,
cpRelation
.
Id
),
// 历史分数
Title
:
title
,
},
MyPrivilegeList
:
myPrivilegeList
,
...
...
test/cp_test.go
View file @
b4ec010a
...
...
@@ -30,3 +30,11 @@ func TestCalLoc(t *testing.T) {
loc
=
timezone_e
.
GetFixedTimezone
(
"GMT+5"
)
println
(
time
.
Now
()
.
In
(
loc
)
.
Format
(
"2006-01-02 15:04:05"
))
}
func
TestSumCpScore
(
t
*
testing
.
T
)
{
model
:=
domain
.
CreateModelNil
()
old
,
err
:=
cp_m
.
GetOldCpOrNil
(
model
,
76421
,
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