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 @@
...
@@ -16,7 +16,8 @@
},
},
"scripts"
:
{
"scripts"
:
{
"start"
:
"tsc"
,
"start"
:
"tsc"
,
"mock"
:
"cd mockServer && npm start"
"mock"
:
"cd mockServer && npm start"
,
"preinstall"
:
"cd mockServer && yarn"
},
},
"config"
:
{
"config"
:
{
"notNeedLogin"
:
[
"notNeedLogin"
:
[
...
...
v2.0/src/controller/game.controller.ts
View file @
93141e04
/** @format */
/** @format */
import
{
services
,
checkParams
,
preCheck
,
preUpdate
}
from
'../decorator/common'
import
{
services
,
checkParams
,
preCheck
,
preUpdate
,
registeInfos
}
from
'../decorator/common'
import
{
resultsModel
}
from
'../sdk'
import
{
resultsModel
}
from
'../sdk'
import
{
CommonUserService
,
CommonGameService
}
from
'../service/common'
import
{
CommonUserService
,
CommonGameService
}
from
'../service/common'
import
{
import
{
...
@@ -38,15 +38,16 @@ export default class Game {
...
@@ -38,15 +38,16 @@ export default class Game {
}
}
@
checkParams
([
'activityId'
])
@
checkParams
([
'activityId'
])
@
registeInfos
([
'vipInfo'
])
@
services
([
CommonGameService
])
@
services
([
CommonGameService
])
@
preCheck
([
checkActivityTime
,
checkVip
,
checkGameTimes
(
3
)])
@
preCheck
([
checkActivityTime
,
checkVip
,
checkGameTimes
(
3
)])
@
preUpdate
([
reduceGameTimes
(
3
)])
@
preUpdate
([
reduceGameTimes
(
3
)])
async
startGame
(
async
startGame
(
context
:
IContext
<
IParams
>
,
context
:
IContext
<
IParams
>
,
{
userInfo
,
activityInfo
}:
IControllerInfos
,
{
userInfo
,
activityInfo
,
vipInfo
}:
IControllerInfos
,
[
gameService
]:
[
CommonGameService
]
[
gameService
]:
[
CommonGameService
]
)
{
)
{
const
joinResult
=
await
gameService
.
addJoinRecord
(
userInfo
)
const
joinResult
=
await
gameService
.
addJoinRecord
(
userInfo
,
vipInfo
)
return
resultsModel
.
success
({
return
resultsModel
.
success
({
...
joinResult
...
joinResult
...
...
v2.0/src/index.ts
View file @
93141e04
...
@@ -17,6 +17,8 @@ import CustomTest1Controller from './controller/custom/test1.controller'
...
@@ -17,6 +17,8 @@ import CustomTest1Controller from './controller/custom/test1.controller'
const
CustomTest1ControllerInstance
=
new
CustomTest1Controller
()
const
CustomTest1ControllerInstance
=
new
CustomTest1Controller
()
import
CustomTest2Controller
from
'./controller/custom/test2.controller'
import
CustomTest2Controller
from
'./controller/custom/test2.controller'
const
CustomTest2ControllerInstance
=
new
CustomTest2Controller
()
const
CustomTest2ControllerInstance
=
new
CustomTest2Controller
()
import
GameController
from
'./controller/game.controller'
const
CommonGameController
=
new
GameController
()
export
default
{
export
default
{
getVipInfo
:
CommonUserControllerInstance
.
getVipInfo
,
getVipInfo
:
CommonUserControllerInstance
.
getVipInfo
,
...
@@ -39,5 +41,9 @@ export default {
...
@@ -39,5 +41,9 @@ export default {
testAddStat
:
CustomTest1ControllerInstance
.
testAddStat
,
testAddStat
:
CustomTest1ControllerInstance
.
testAddStat
,
testGetStats
:
CustomTest1ControllerInstance
.
testGetStats
,
testGetStats
:
CustomTest1ControllerInstance
.
testGetStats
,
test2addStat
:
CustomTest2ControllerInstance
.
test2addStat
,
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 {
...
@@ -18,12 +18,13 @@ export default class GameService extends UserService {
this
.
joindao
=
new
BaseDao
(
context
,
JOIN_DB_NAME
)
this
.
joindao
=
new
BaseDao
(
context
,
JOIN_DB_NAME
)
}
}
async
addJoinRecord
(
userInfo
:
IUserInfo
)
{
async
addJoinRecord
(
userInfo
:
IUserInfo
,
vipInfo
:
IVipInfo
)
{
const
{
const
{
openId
,
openId
,
data
:
{
activityId
}
data
:
{
activityId
,
inviteId
}
}
=
this
.
context
}
=
this
.
context
const
{
userNick
,
avatar
}
=
userInfo
const
{
userNick
,
avatar
}
=
userInfo
const
{
isVip
}
=
vipInfo
const
now
=
Date
.
now
()
const
now
=
Date
.
now
()
const
today
=
getToday
()
const
today
=
getToday
()
const
record
:
IJoinRecord
=
{
const
record
:
IJoinRecord
=
{
...
@@ -34,7 +35,10 @@ export default class GameService extends UserService {
...
@@ -34,7 +35,10 @@ export default class GameService extends UserService {
createTime
:
now
,
createTime
:
now
,
updateTime
:
now
,
updateTime
:
now
,
score
:
0
,
score
:
0
,
createDay
:
today
createDay
:
today
,
inviteId
,
isVip
,
status
:
1
}
}
const
id
=
await
this
.
joindao
.
insertOne
(
record
)
const
id
=
await
this
.
joindao
.
insertOne
(
record
)
...
@@ -50,6 +54,20 @@ export default class GameService extends UserService {
...
@@ -50,6 +54,20 @@ export default class GameService extends UserService {
userInfo
:
IUserInfo
,
userInfo
:
IUserInfo
,
joinInfo
:
IJoinRecord
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
{
duration
}
=
await
this
.
updateJoinRecord
(
id
,
score
,
userInfo
,
joinInfo
)
const
{
maxScore
,
totalScore
}
=
await
this
.
updateUserScore
(
score
,
userInfo
)
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 {
...
@@ -68,25 +68,21 @@ export default class StatService {
const
endDayTimestamp
=
formatDate
(
endDay
).
getTimestamp
()
const
endDayTimestamp
=
formatDate
(
endDay
).
getTimestamp
()
while
(
curDayTimestamp
<=
endDayTimestamp
)
{
while
(
curDayTimestamp
<=
endDayTimestamp
)
{
// 访问PV
// 访问PV
const
PV
=
await
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
})
const
PV
promise
=
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
})
// 访问UV
// 访问UV
const
UV
=
await
this
.
userdao
.
count
({
activityId
,
[
`login.
${
day
}
`
]:
{
$exists
:
true
}
})
const
UV
promise
=
this
.
userdao
.
count
({
activityId
,
[
`login.
${
day
}
`
]:
{
$exists
:
true
}
})
// 新增UV
// 新增UV
const
newUV
=
await
this
.
userdao
.
count
({
activityId
,
createDay
:
day
})
const
newUVpromise
=
this
.
userdao
.
count
({
activityId
,
createDay
:
day
})
// 新增PV
// const newPV = await this.userdao.count({ activityId, createDay: day })
// 新增UV(通过邀请)
// 新增UV(通过邀请)
const
newUVFromInviteUV
=
(
const
newUVFromInviteUVpromise
=
this
.
accessdao
.
aggregate
([
await
this
.
accessdao
.
aggregate
([
{
$match
:
{
activityId
,
createDay
:
day
,
inviteId
:
{
$exists
:
true
}
}
},
{
$match
:
{
activityId
,
createDay
:
day
,
inviteId
:
{
$exists
:
true
}
}
},
{
$project
:
{
openId
:
true
}
},
{
$project
:
{
openId
:
true
}
},
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
])
])
).
length
// 已入会(老会员)PV
// 已入会(老会员)PV
const
vipPV
=
await
this
.
accessdao
.
count
({
const
vipPV
promise
=
this
.
accessdao
.
count
({
activityId
,
activityId
,
createDay
:
day
,
createDay
:
day
,
//@ts-ignore
//@ts-ignore
...
@@ -95,7 +91,7 @@ export default class StatService {
...
@@ -95,7 +91,7 @@ export default class StatService {
})
})
// 已入会(老会员)UV
// 已入会(老会员)UV
const
vipUV
=
await
this
.
userdao
.
count
({
const
vipUV
promise
=
this
.
userdao
.
count
({
activityId
,
activityId
,
[
`login.
${
day
}
`
]:
{
$exists
:
true
},
[
`login.
${
day
}
`
]:
{
$exists
:
true
},
$or
:
[
$or
:
[
...
@@ -107,30 +103,26 @@ export default class StatService {
...
@@ -107,30 +103,26 @@ export default class StatService {
})
})
// 未入会PV
// 未入会PV
const
noVipPV
=
await
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
,
isVip
:
false
})
const
noVipPV
promise
=
this
.
accessdao
.
count
({
activityId
,
createDay
:
day
,
isVip
:
false
})
// 未入会UV
// 未入会UV
const
noVipUV
=
(
const
noVipUVpromise
=
this
.
accessdao
.
aggregate
([
await
this
.
accessdao
.
aggregate
([
{
$match
:
{
activityId
,
createDay
:
day
,
isVip
:
false
}
},
{
$match
:
{
activityId
,
createDay
:
day
,
isVip
:
false
}
},
{
$project
:
{
openId
:
true
}
},
{
$project
:
{
openId
:
true
}
},
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
])
])
).
length
// 新增入会UV
// 新增入会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
// 助力成功UV
const
helpSuccessUV
=
(
const
helpSuccessUVpromise
=
this
.
statdao
.
aggregate
([
await
this
.
statdao
.
aggregate
([
{
$match
:
{
activityId
,
createDay
:
day
,
type
:
STAT_TYPE
.
INITE_SUCCESS
}
},
{
$match
:
{
activityId
,
createDay
:
day
,
type
:
STAT_TYPE
.
INITE_SUCCESS
}
},
{
$project
:
{
openId
:
true
}
},
{
$project
:
{
openId
:
true
}
},
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
{
$group
:
{
_id
:
'$openId'
,
count
:
{
$sum
:
1
}
}
}
])
])
).
length
// 根据任务类型获取完成任务的人数
// 根据任务类型获取完成任务的人数
// example: await getTaskCompleteUV('collectGoods', day)
// example: await getTaskCompleteUV('collectGoods', day)
...
@@ -141,22 +133,48 @@ export default class StatService {
...
@@ -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
=
{
const
keyValueMapper
=
{
时间
:
day
,
时间
:
day
,
访问
PV
:
PV
,
访问
PV
:
PV
,
访问
UV
:
UV
,
访问
UV
:
UV
,
新增
UV
:
newUV
,
新增
UV
:
newUV
,
'新增UV(通过邀请)'
:
newUVFromInviteUV
,
'新增UV(通过邀请)'
:
newUVFromInviteUV
.
length
,
'已入会(老会员)PV'
:
vipPV
,
'已入会(老会员)PV'
:
vipPV
,
'已入会(老会员)UV'
:
vipUV
,
'已入会(老会员)UV'
:
vipUV
,
未入会
PV
:
noVipPV
,
未入会
PV
:
noVipPV
,
未入会
UV
:
noVipUV
,
未入会
UV
:
noVipUV
.
length
,
新入会
UV
:
newVipUV
,
新入会
UV
:
newVipUV
,
新增关注
UV
:
newFollowUV
,
新增关注
UV
:
newFollowUV
,
助力成功
UV
:
helpSuccessUV
助力成功
UV
:
helpSuccessUV
.
length
//收藏商品任务完成UV: await getTaskCompleteUV('collectGoods', day)
//收藏商品任务完成UV: await getTaskCompleteUV('collectGoods', day)
}
}
console
.
log
(
keyValueMapper
,
'xlsxData'
)
console
.
log
(
'keyValueMapper::::::::::'
,
keyValueMapper
)
if
(
day
===
startDay
)
{
if
(
day
===
startDay
)
{
xlsxData
.
push
(
Object
.
keys
(
keyValueMapper
))
xlsxData
.
push
(
Object
.
keys
(
keyValueMapper
))
...
@@ -167,6 +185,7 @@ export default class StatService {
...
@@ -167,6 +185,7 @@ export default class StatService {
curDayTimestamp
=
tommorrow
curDayTimestamp
=
tommorrow
day
=
dateFormatter
(
transformBeijingDate
(
tommorrow
),
'yyyy/MM/dd'
)
day
=
dateFormatter
(
transformBeijingDate
(
tommorrow
),
'yyyy/MM/dd'
)
}
}
console
.
log
(
'xlsxData::::::::::'
,
xlsxData
)
return
xlsxData
return
xlsxData
}
}
...
...
v2.0/src/typings/joinRecord.d.ts
View file @
93141e04
...
@@ -12,4 +12,7 @@ interface IJoinRecord {
...
@@ -12,4 +12,7 @@ interface IJoinRecord {
createDay
:
string
createDay
:
string
duration
?:
number
duration
?:
number
submitTime
?:
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