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
93141e04
Commit
93141e04
authored
May 27, 2021
by
qinhaitao
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'c_server_issues_solve' into 'c_server_ts_perf'
修改 See merge request
!20
parents
4f67af43
aae54743
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
91 additions
and
43 deletions
+91
-43
package.json
v2.0/package.json
+2
-1
game.controller.ts
v2.0/src/controller/game.controller.ts
+4
-3
index.ts
v2.0/src/index.ts
+7
-1
game.service.ts
v2.0/src/service/common/game.service.ts
+21
-3
stat.service.ts
v2.0/src/service/common/stat.service.ts
+54
-35
joinRecord.d.ts
v2.0/src/typings/joinRecord.d.ts
+3
-0
No files found.
v2.0/package.json
View file @
93141e04
...
...
@@ -16,7 +16,8 @@
},
"scripts"
:
{
"start"
:
"tsc"
,
"mock"
:
"cd mockServer && npm start"
"mock"
:
"cd mockServer && npm start"
,
"preinstall"
:
"cd mockServer && yarn"
},
"config"
:
{
"notNeedLogin"
:
[
...
...
v2.0/src/controller/game.controller.ts
View file @
93141e04
/** @format */
import
{
services
,
checkParams
,
preCheck
,
preUpdate
}
from
'../decorator/common'
import
{
services
,
checkParams
,
preCheck
,
preUpdate
,
registeInfos
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
CommonUserService
,
CommonGameService
}
from
'../service/common'
import
{
...
...
@@ -38,15 +38,16 @@ export default class Game {
}
@
checkParams
([
'activityId'
])
@
registeInfos
([
'vipInfo'
])
@
services
([
CommonGameService
])
@
preCheck
([
checkActivityTime
,
checkVip
,
checkGameTimes
(
3
)])
@
preUpdate
([
reduceGameTimes
(
3
)])
async
startGame
(
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
{
userInfo
,
activityInfo
,
vipInfo
}:
IControllerInfos
,
[
gameService
]:
[
CommonGameService
]
)
{
const
joinResult
=
await
gameService
.
addJoinRecord
(
userInfo
)
const
joinResult
=
await
gameService
.
addJoinRecord
(
userInfo
,
vipInfo
)
return
resultsModel
.
success
({
...
joinResult
...
...
v2.0/src/index.ts
View file @
93141e04
...
...
@@ -17,6 +17,8 @@ import CustomTest1Controller from './controller/custom/test1.controller'
const
CustomTest1ControllerInstance
=
new
CustomTest1Controller
()
import
CustomTest2Controller
from
'./controller/custom/test2.controller'
const
CustomTest2ControllerInstance
=
new
CustomTest2Controller
()
import
GameController
from
'./controller/game.controller'
const
CommonGameController
=
new
GameController
()
export
default
{
getVipInfo
:
CommonUserControllerInstance
.
getVipInfo
,
...
...
@@ -39,5 +41,9 @@ export default {
testAddStat
:
CustomTest1ControllerInstance
.
testAddStat
,
testGetStats
:
CustomTest1ControllerInstance
.
testGetStats
,
test2addStat
:
CustomTest2ControllerInstance
.
test2addStat
,
test2getStats
:
CustomTest2ControllerInstance
.
test2getStats
test2getStats
:
CustomTest2ControllerInstance
.
test2getStats
,
startGame
:
CommonGameController
.
startGame
,
submitGame
:
CommonGameController
.
submitGame
,
getGameInfo
:
CommonGameController
.
getGameInfo
,
getMyRankPrize
:
CommonGameController
.
getMyRankPrize
}
v2.0/src/service/common/game.service.ts
View file @
93141e04
...
...
@@ -18,12 +18,13 @@ export default class GameService extends UserService {
this
.
joindao
=
new
BaseDao
(
context
,
JOIN_DB_NAME
)
}
async
addJoinRecord
(
userInfo
:
IUserInfo
)
{
async
addJoinRecord
(
userInfo
:
IUserInfo
,
vipInfo
:
IVipInfo
)
{
const
{
openId
,
data
:
{
activityId
}
data
:
{
activityId
,
inviteId
}
}
=
this
.
context
const
{
userNick
,
avatar
}
=
userInfo
const
{
isVip
}
=
vipInfo
const
now
=
Date
.
now
()
const
today
=
getToday
()
const
record
:
IJoinRecord
=
{
...
...
@@ -34,7 +35,10 @@ export default class GameService extends UserService {
createTime
:
now
,
updateTime
:
now
,
score
:
0
,
createDay
:
today
createDay
:
today
,
inviteId
,
isVip
,
status
:
1
}
const
id
=
await
this
.
joindao
.
insertOne
(
record
)
...
...
@@ -50,6 +54,20 @@ export default class GameService extends UserService {
userInfo
:
IUserInfo
,
joinInfo
:
IJoinRecord
)
{
const
gameResult
=
await
this
.
joindao
.
update
(
{
_id
:
id
,
$where
:
`this.status === 1`
},
{
$set
:
{
status
:
2
}
}
)
if
(
gameResult
!==
1
)
{
// 该局游戏实际已结束,有并发
return
{
data
:
1
}
}
const
{
duration
}
=
await
this
.
updateJoinRecord
(
id
,
score
,
userInfo
,
joinInfo
)
const
{
maxScore
,
totalScore
}
=
await
this
.
updateUserScore
(
score
,
userInfo
)
...
...
v2.0/src/service/common/stat.service.ts
View file @
93141e04
...
...
@@ -68,25 +68,21 @@ export default class StatService {
const
endDayTimestamp
=
formatDate
(
endDay
).
getTimestamp
()
while
(
curDayTimestamp
<=
endDayTimestamp
)
{
// 访问PV
const
PV
=
await
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
})
const
PV
promise
=
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
})
// 访问UV
const
UV
=
await
this
.
userdao
.
count
({
activityId
,
[
`login.
${
day
}
`
]:
{
$exists
:
true
}
})
const
UV
promise
=
this
.
userdao
.
count
({
activityId
,
[
`login.
${
day
}
`
]:
{
$exists
:
true
}
})
// 新增UV
const
newUV
=
await
this
.
userdao
.
count
({
activityId
,
createDay
:
day
})
// 新增PV
// const newPV = await this.userdao.count({ activityId, createDay: day })
const
newUVpromise
=
this
.
userdao
.
count
({
activityId
,
createDay
:
day
})
// 新增UV(通过邀请)
const
newUVFromInviteUV
=
(
await
this
.
accessdao
.
aggregate
([
const
newUVFromInviteUVpromise
=
this
.
accessdao
.
aggregate
([
{
$match
:
{
activityId
,
createDay
:
day
,
inviteId
:
{
$exists
:
true
}
}
},
{
$project
:
{
openId
:
true
}
},
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
])
).
length
// 已入会(老会员)PV
const
vipPV
=
await
this
.
accessdao
.
count
({
const
vipPV
promise
=
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
,
//@ts-ignore
...
...
@@ -95,7 +91,7 @@ export default class StatService {
})
// 已入会(老会员)UV
const
vipUV
=
await
this
.
userdao
.
count
({
const
vipUV
promise
=
this
.
userdao
.
count
({
activityId
,
[
`login.
${
day
}
`
]:
{
$exists
:
true
},
$or
:
[
...
...
@@ -107,30 +103,26 @@ export default class StatService {
})
// 未入会PV
const
noVipPV
=
await
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
,
isVip
:
false
})
const
noVipPV
promise
=
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
,
isVip
:
false
})
// 未入会UV
const
noVipUV
=
(
await
this
.
accessdao
.
aggregate
([
const
noVipUVpromise
=
this
.
accessdao
.
aggregate
([
{
$match
:
{
activityId
,
createDay
:
day
,
isVip
:
false
}
},
{
$project
:
{
openId
:
true
}
},
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
])
).
length
// 新增入会UV
const
newVipUV
=
await
this
.
userdao
.
count
({
activityId
,
'member.newMember'
:
true
,
'member.bememberDay'
:
day
})
const
newVipUV
promise
=
this
.
userdao
.
count
({
activityId
,
'member.newMember'
:
true
,
'member.bememberDay'
:
day
})
const
newFollowUV
=
await
this
.
userdao
.
count
({
activityId
,
'follow.newFollow'
:
true
,
'follow.followDay'
:
day
})
const
newFollowUV
promise
=
this
.
userdao
.
count
({
activityId
,
'follow.newFollow'
:
true
,
'follow.followDay'
:
day
})
// 助力成功UV
const
helpSuccessUV
=
(
await
this
.
statdao
.
aggregate
([
const
helpSuccessUVpromise
=
this
.
statdao
.
aggregate
([
{
$match
:
{
activityId
,
createDay
:
day
,
type
:
STAT_TYPE
.
INITE_SUCCESS
}
},
{
$project
:
{
openId
:
true
}
},
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
])
).
length
// 根据任务类型获取完成任务的人数
// example: await getTaskCompleteUV('collectGoods', day)
...
...
@@ -141,22 +133,48 @@ export default class StatService {
})
}
const
[
PV
,
UV
,
newUV
,
newUVFromInviteUV
,
vipPV
,
vipUV
,
noVipPV
,
noVipUV
,
newVipUV
,
newFollowUV
,
helpSuccessUV
,
]
=
await
Promise
.
all
([
PVpromise
,
UVpromise
,
newUVpromise
,
newUVFromInviteUVpromise
,
vipPVpromise
,
vipUVpromise
,
noVipPVpromise
,
noVipUVpromise
,
newVipUVpromise
,
newFollowUVpromise
,
helpSuccessUVpromise
,
])
const
keyValueMapper
=
{
时间
:
day
,
访问
PV
:
PV
,
访问
UV
:
UV
,
新增
UV
:
newUV
,
'新增UV(通过邀请)'
:
newUVFromInviteUV
,
'新增UV(通过邀请)'
:
newUVFromInviteUV
.
length
,
'已入会(老会员)PV'
:
vipPV
,
'已入会(老会员)UV'
:
vipUV
,
未入会
PV
:
noVipPV
,
未入会
UV
:
noVipUV
,
未入会
UV
:
noVipUV
.
length
,
新入会
UV
:
newVipUV
,
新增关注
UV
:
newFollowUV
,
助力成功
UV
:
helpSuccessUV
助力成功
UV
:
helpSuccessUV
.
length
//收藏商品任务完成UV: await getTaskCompleteUV('collectGoods', day)
}
console
.
log
(
keyValueMapper
,
'xlsxData'
)
console
.
log
(
'keyValueMapper::::::::::'
,
keyValueMapper
)
if
(
day
===
startDay
)
{
xlsxData
.
push
(
Object
.
keys
(
keyValueMapper
))
...
...
@@ -167,6 +185,7 @@ export default class StatService {
curDayTimestamp
=
tommorrow
day
=
dateFormatter
(
transformBeijingDate
(
tommorrow
),
'yyyy/MM/dd'
)
}
console
.
log
(
'xlsxData::::::::::'
,
xlsxData
)
return
xlsxData
}
...
...
v2.0/src/typings/joinRecord.d.ts
View file @
93141e04
...
...
@@ -12,4 +12,7 @@ interface IJoinRecord {
createDay
:
string
duration
?:
number
submitTime
?:
number
inviteId
?:
string
isVip
?:
boolean
status
?:
number
}
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