Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
T
taobao-mini-template
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
2
Issues
2
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
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
qinhaitao
taobao-mini-template
Commits
3858a3a8
Commit
3858a3a8
authored
Nov 09, 2020
by
qinhaitao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat:
🎸
提交接口\
parent
76c36558
Changes
8
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
72 additions
and
25 deletions
+72
-25
stat.controller.ts
v2.0/src/controller/common/stat.controller.ts
+10
-2
game.controller.ts
v2.0/src/controller/game.controller.ts
+2
-2
index.ts
v2.0/src/index.ts
+4
-2
game.service.ts
v2.0/src/service/common/game.service.ts
+44
-13
user.service.ts
v2.0/src/service/common/user.service.ts
+2
-2
user.d.ts
v2.0/src/typings/user.d.ts
+5
-0
format.ts
v2.0/src/utils/common/format.ts
+4
-4
tsconfig.json
v2.0/tsconfig.json
+1
-0
No files found.
v2.0/src/controller/common/stat.controller.ts
View file @
3858a3a8
...
...
@@ -31,8 +31,16 @@ export default class StatController {
{
activityInfo
,
userInfo
}:
IControllerInfos
,
[
statService
]:
[
StatService
]
)
{
const
commonStatGetstatsResult1
=
await
statService
.
getStats
(
context
.
data
.
activityId
,
context
.
data
.
startDay
,
context
.
data
.
endDay
)
const
commonStatBuildexcelResult2
=
await
statService
.
buildExcel
(
context
.
data
.
startDay
,
context
.
data
.
endDay
,
commonStatGetstatsResult1
)
const
commonStatGetstatsResult1
=
await
statService
.
getStats
(
context
.
data
.
activityId
,
context
.
data
.
startDay
,
context
.
data
.
endDay
)
const
commonStatBuildexcelResult2
=
await
statService
.
buildExcel
(
context
.
data
.
startDay
,
context
.
data
.
endDay
,
commonStatGetstatsResult1
)
return
resultsModel
.
success
({
...
commonStatBuildexcelResult2
})
...
...
v2.0/src/controller/game.controller.ts
View file @
3858a3a8
...
...
@@ -35,7 +35,7 @@ export default class Game {
@
preCheck
([
checkActivityTime
,
checkVip
,
checkUserInfo
({
gameTimes
:
{
$gte
:
3
}
},
'游戏次数不足,做点任务吧'
)])
@
preUpdate
([
updateUserInfo
({
$where
:
'this.gameTimes
>3'
,
$where
:
'this.gameTimes>3'
,
$inc
:
{
gameTimes
:
-
3
}
})
])
...
...
@@ -60,7 +60,7 @@ export default class Game {
[
gameService
]:
[
GameService
]
)
{
const
{
id
,
score
}
=
context
.
data
const
result
=
await
gameService
.
submitGame
(
id
,
score
,
joinInfo
)
const
result
=
await
gameService
.
submitGame
(
id
,
score
,
userInfo
,
joinInfo
)
return
resultsModel
.
success
(
result
)
}
...
...
v2.0/src/index.ts
View file @
3858a3a8
...
...
@@ -12,7 +12,7 @@ import GameController from './controller/game.controller'
const
{
getVipInfo
,
getRankList
}
=
new
UserController
()
const
{
login
}
=
new
LoginController
()
const
{
getGameInfo
,
startGame
}
=
new
GameController
()
const
{
getGameInfo
,
startGame
,
submitGame
}
=
new
GameController
()
const
{
getTaskList
,
receiveTaskRewards
,
...
...
@@ -42,6 +42,8 @@ export default {
getStats
,
addStat
,
getRankList
,
// 游戏类
getGameInfo
,
startGame
startGame
,
submitGame
}
v2.0/src/service/common/game.service.ts
View file @
3858a3a8
...
...
@@ -9,11 +9,11 @@ import { JOIN_DB_NAME } from '../../db'
import
{
ACTIVITY_STATUS
}
from
'../../constants'
import
{
getToday
}
from
'../../utils'
export
default
class
GameService
{
export
default
class
GameService
extends
UserService
{
context
:
IContext
<
IParams
>
joindao
:
IBaseDao
constructor
(
context
:
IContext
<
IParams
>
)
{
this
.
context
=
context
super
(
context
)
this
.
joindao
=
new
BaseDao
(
context
,
JOIN_DB_NAME
)
}
...
...
@@ -41,7 +41,28 @@ export default class GameService {
return
{
id
}
}
async
submitGame
(
id
:
string
,
score
:
number
,
joinInfo
:
IJoinRecord
)
{
async
submitGame
(
id
:
string
,
score
:
number
,
userInfo
:
IUserInfo
,
joinInfo
:
IJoinRecord
)
{
const
{
duration
}
=
await
this
.
updateJoinRecord
(
id
,
score
,
userInfo
,
joinInfo
)
const
{
maxScore
,
totalScore
}
=
await
this
.
updateUserScore
(
score
,
userInfo
)
const
myRankInfo
=
await
this
.
getMyRankInfo
(
'maxScore'
,
'updateScoreTime'
,
userInfo
)
const
{
gameTimes
,
avatar
,
userNick
}
=
userInfo
return
{
score
,
maxScore
,
totalScore
,
gameTimes
,
duration
,
avatar
,
userNick
,
rank
:
myRankInfo
.
rank
}
}
async
updateJoinRecord
(
id
:
string
,
score
:
number
,
userInfo
:
IUserInfo
,
joinInfo
:
IJoinRecord
)
{
const
now
=
Date
.
now
()
const
today
=
getToday
()
const
duration
=
now
-
joinInfo
.
createTime
...
...
@@ -53,18 +74,28 @@ export default class GameService {
submitDay
:
today
}
await
this
.
joindao
.
update
(
{
_id
:
id
},
{
$set
:
playInfo
}
)
await
this
.
joindao
.
update
({
_id
:
id
},
{
$set
:
playInfo
})
return
playInfo
}
async
updateUserScore
(
score
:
number
,
userInfo
:
IUserInfo
)
{
const
now
=
Date
.
now
()
const
newMaxScore
=
score
>=
userInfo
?.
maxScore
const
maxScore
=
newMaxScore
?
score
:
userInfo
?.
maxScore
const
updateScoreTime
=
newMaxScore
?
now
:
userInfo
?.
updateScoreTime
const
{
_id
,
totalScore
}
=
userInfo
await
this
.
updateUser
(
_id
,
{
$set
:
{
maxScore
,
updateScoreTime
},
$inc
:
{
totalScore
:
score
}
})
return
{
score
,
duration
maxScore
,
updateScoreTime
,
totalScore
:
totalScore
+
score
}
}
}
v2.0/src/service/common/user.service.ts
View file @
3858a3a8
...
...
@@ -177,7 +177,7 @@ class UserService extends BaseService {
return
{
list
:
list
.
map
((
v
,
i
)
=>
{
return
{
score
:
v
[
sortValueKey
],
[
sortValueKey
]
:
v
[
sortValueKey
],
avatar
:
v
.
avatar
,
userNick
:
formatUserNick
(
v
.
userNick
),
rank
:
i
+
1
...
...
@@ -222,7 +222,7 @@ class UserService extends BaseService {
rank
,
userNick
,
avatar
,
score
:
userValue
[
sortValueKey
]
:
userValue
}
}
...
...
v2.0/src/typings/user.d.ts
View file @
3858a3a8
...
...
@@ -16,6 +16,11 @@ interface IUserInfo {
remainTimes
?:
IRemainTimesInfo
taskInfo
?:
object
login
?:
object
// 游戏类
gameTimes
?:
number
maxScore
?:
number
totalScore
?:
number
updateScoreTime
?:
number
}
interface
IRemainTimesInfo
{
...
...
v2.0/src/utils/common/format.ts
View file @
3858a3a8
...
...
@@ -23,15 +23,15 @@ export function formatUpdateUserProjection(projection: IUpdateQuery): IUpdateQue
}
// 用户昵称脱敏
export
function
formatUserNick
(
name
:
string
)
{
export
function
formatUserNick
(
name
:
string
,
replaceStr
=
'***'
)
{
let
newStr
:
string
if
(
name
.
length
===
2
)
{
newStr
=
name
.
substr
(
0
,
1
)
+
'***'
+
name
.
substr
(
-
1
,
1
)
newStr
=
name
.
substr
(
0
,
1
)
+
replaceStr
+
name
.
substr
(
-
1
,
1
)
}
else
if
(
name
.
length
>
2
)
{
let
char
=
'***'
let
char
=
replaceStr
newStr
=
name
.
substr
(
0
,
1
)
+
char
+
name
.
substr
(
-
1
,
1
)
}
else
{
newStr
=
name
+
'***'
newStr
=
name
+
replaceStr
}
return
newStr
}
...
...
v2.0/tsconfig.json
View file @
3858a3a8
...
...
@@ -23,6 +23,7 @@
],
"exclude"
:
[
"./src/controller/common/**"
,
"./src/controller/custom/**"
,
"./dist/**/*"
]
}
\ No newline at end of file
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