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 @@
},
"scripts": {
"start": "tsc",
"mock": "cd mockServer && npm start"
"mock": "cd mockServer && npm start",
"preinstall": "cd mockServer && yarn"
},
"config": {
"notNeedLogin": [
......
/** @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
......
......@@ -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
}
......@@ -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)
......
......@@ -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 PVpromise = this.accessdao.count({ activityId, createDay: day })
// 访问UV
const UV = await this.userdao.count({ activityId, [`login.${day}`]: { $exists: true } })
const UVpromise = 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 vipPVpromise = this.accessdao.count({
activityId,
createDay: day,
//@ts-ignore
......@@ -95,7 +91,7 @@ export default class StatService {
})
// 已入会(老会员)UV
const vipUV = await this.userdao.count({
const vipUVpromise = 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 noVipPVpromise = 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 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
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
}
......
......@@ -12,4 +12,7 @@ interface IJoinRecord {
createDay: string
duration?: 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