Commit 93141e04 authored by qinhaitao's avatar qinhaitao

Merge branch 'c_server_issues_solve' into 'c_server_ts_perf'

修改

See merge request !20
parents 4f67af43 aae54743
...@@ -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": [
......
/** @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
......
...@@ -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
} }
...@@ -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)
......
...@@ -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 PVpromise = this.accessdao.count({ activityId, createDay: day })
// 访问UV // 访问UV
const UV = await this.userdao.count({ activityId, [`login.${day}`]: { $exists: true } }) const UVpromise = 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 vipPVpromise = 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 vipUVpromise = 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 noVipPVpromise = 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 newVipUVpromise = this.userdao.count({ activityId, 'member.newMember': true, 'member.bememberDay': day })
const newFollowUV = await this.userdao.count({ activityId, 'follow.newFollow': true, 'follow.followDay': day }) const newFollowUVpromise = 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
} }
......
...@@ -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
} }
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment