Commit a42df9b5 authored by maggie's avatar maggie

Merge branch 'c_server_ts_perf' of...

Merge branch 'c_server_ts_perf' of http://gitlab2.dui88.com/qinhaitao/taobao-mini-template into c_server_ts_perf
parents c89f518e 1e081524
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { services, checkParams, registeInfos } from '../decorator/common' import { services, checkParams, registeInfos } from '../decorator/common'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { AwardsService } from '../service' import { AwardsService } from '../service/common'
import preCheck from '../decorator/common/preCheck' import preCheck from '../decorator/common/preCheck'
import { import {
checkActivityTime, checkActivityTime,
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { services, checkParams, registeInfos, noCheckUser } from '../decorator/common' import { services, checkParams, registeInfos, noCheckUser } from '../decorator/common'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { BaseService } from '../service' import { BaseService } from '../service/common'
export default class BaseController { export default class BaseController {
/** /**
* 活动基本信息 * 活动基本信息
......
...@@ -32,8 +32,16 @@ export default class StatController { ...@@ -32,8 +32,16 @@ export default class StatController {
{ activityInfo, userInfo }: IControllerInfos, { activityInfo, userInfo }: IControllerInfos,
[statService]: [StatService] [statService]: [StatService]
) { ) {
const commonStatGetstatsResult1 = await statService.getStats(context.data.activityId, context.data.startDay, context.data.endDay) const commonStatGetstatsResult1 = await statService.getStats(
const commonStatBuildexcelResult2 = await statService.buildExcel(context.data.startDay, context.data.endDay, commonStatGetstatsResult1) context.data.activityId,
context.data.startDay,
context.data.endDay
)
const commonStatBuildexcelResult2 = await statService.buildExcel(
context.data.startDay,
context.data.endDay,
commonStatGetstatsResult1
)
return resultsModel.success({ return resultsModel.success({
...commonStatBuildexcelResult2 ...commonStatBuildexcelResult2
}) })
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { services, checkParams, preCheck, preUpdate } from '../decorator/common' import { services, checkParams, preCheck, preUpdate } from '../decorator/common'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { UserService, GameService } from '../service' import { UserService, GameService } from '../service/common'
import { checkActivityTime, checkJoinId, checkUserInfo, checkVip } from '../utils/common/check' import { checkActivityTime, checkJoinId, checkUserInfo, checkVip } from '../utils/common/check'
import { updateUserInfo } from '../utils/common/update' import { updateUserInfo } from '../utils/common/update'
...@@ -35,7 +35,7 @@ export default class Game { ...@@ -35,7 +35,7 @@ export default class Game {
@preCheck([checkActivityTime, checkVip, checkUserInfo({ gameTimes: { $gte: 3 } }, '游戏次数不足,做点任务吧')]) @preCheck([checkActivityTime, checkVip, checkUserInfo({ gameTimes: { $gte: 3 } }, '游戏次数不足,做点任务吧')])
@preUpdate([ @preUpdate([
updateUserInfo({ updateUserInfo({
$where: 'this.gameTimes >3', $where: 'this.gameTimes>3',
$inc: { gameTimes: -3 } $inc: { gameTimes: -3 }
}) })
]) ])
...@@ -60,7 +60,7 @@ export default class Game { ...@@ -60,7 +60,7 @@ export default class Game {
[gameService]: [GameService] [gameService]: [GameService]
) { ) {
const { id, score } = context.data 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) return resultsModel.success(result)
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { services, checkParams, registeInfos, preUpdate } from '../decorator/common' import { services, checkParams, registeInfos, preUpdate } from '../decorator/common'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { UserService, AccessService } from '../service' import { UserService, AccessService } from '../service/common'
import { noCheckUser } from '../decorator/common' import { noCheckUser } from '../decorator/common'
export default class LoginController { export default class LoginController {
/** /**
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { services, preCheck, registeInfos, preUpdate, checkParams } from '../decorator/common/' import { services, preCheck, registeInfos, preUpdate, checkParams } from '../decorator/common/'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { UserService, StatService, TaskService } from '../service' import { UserService, StatService, TaskService } from '../service/common'
import { STAT_TYPE } from '../constants' import { STAT_TYPE } from '../constants'
import { checkActivityTime, checkInviteId, checkHelpRecord, checkNewVip } from '../utils/common/check' import { checkActivityTime, checkInviteId, checkHelpRecord, checkNewVip } from '../utils/common/check'
import { updateVip } from '../utils/common/update/' import { updateVip } from '../utils/common/update/'
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { checkParams, services } from '../decorator/common' import { checkParams, services } from '../decorator/common'
import { StatService } from '../service' import { StatService } from '../service/common'
/** @format */ /** @format */
export default class StatController { export default class StatController {
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
import { checkParams, services, registeInfos, preCheck } from '../decorator/common' import { checkParams, services, registeInfos, preCheck } from '../decorator/common'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { TaskService, BaseService } from '../service' import { TaskService, BaseService } from '../service/common'
import { ITaskInfo } from '../service/task.service' import { ITaskInfo } from '../service/common/task.service'
import { checkActivityTime, checkTaskLimit, checkExchangeCreditsTask, checkRemainTimes } from '../utils/common/check/' import { checkActivityTime, checkTaskLimit, checkExchangeCreditsTask, checkRemainTimes } from '../utils/common/check/'
import { preUpdate } from '../decorator/common' import { preUpdate } from '../decorator/common'
import { updateVip, updateSignTask, updateOrderGoods } from '../utils/common/update' import { updateVip, updateSignTask, updateOrderGoods } from '../utils/common/update'
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
import { services, checkParams, registeInfos } from '../decorator/common' import { services, checkParams, registeInfos } from '../decorator/common'
import { resultsModel } from '../sdk' import { resultsModel } from '../sdk'
import { UserService } from '../service' import { UserService } from '../service/common'
interface IRankList { interface IRankList {
userNick: string userNick: string
......
/** @format */ /** @format */
import { isEmpty, merge } from 'lodash' import { isEmpty, merge } from 'lodash'
import { UserService } from '../../service' import { UserService } from '../../service/common'
import { recordErrorLog } from '../../utils/common/logger' import { recordErrorLog } from '../../utils/common/logger'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../errorCode' import { CODE_TYPES } from '../../errorCode'
......
/** @format */ /** @format */
import { UserService, BaseService } from '../../service' import { UserService, BaseService } from '../../service/common'
import { getSellerSession } from '../../utils' import { getSellerSession } from '../../utils'
import { formatVipCbUrl, getShopVip } from '../../utils/common/vip' import { formatVipCbUrl, getShopVip } from '../../utils/common/vip'
import { CODE_TYPES } from '../../errorCode' import { CODE_TYPES } from '../../errorCode'
......
...@@ -4,7 +4,7 @@ import { logFn, recordErrorLog } from '../../utils' ...@@ -4,7 +4,7 @@ import { logFn, recordErrorLog } from '../../utils'
import { resultsModel } from '../../sdk' import { resultsModel } from '../../sdk'
import { CODE_TYPES } from '../../constants' import { CODE_TYPES } from '../../constants'
import { doHandler } from '../../utils/' import { doHandler } from '../../utils/'
import { UserService, BaseService } from '../../service' import { UserService, BaseService } from '../../service/common'
type Constructor = new (...args: any[]) => {} type Constructor = new (...args: any[]) => {}
......
...@@ -12,7 +12,7 @@ import GameController from './controller/game.controller' ...@@ -12,7 +12,7 @@ import GameController from './controller/game.controller'
const { getVipInfo, getRankList } = new UserController() const { getVipInfo, getRankList } = new UserController()
const { login } = new LoginController() const { login } = new LoginController()
const { getGameInfo, startGame } = new GameController() const { getGameInfo, startGame, submitGame } = new GameController()
const { const {
getTaskList, getTaskList,
receiveTaskRewards, receiveTaskRewards,
...@@ -42,6 +42,8 @@ export default { ...@@ -42,6 +42,8 @@ export default {
getStats, getStats,
addStat, addStat,
getRankList, getRankList,
// 游戏类
getGameInfo, getGameInfo,
startGame startGame,
submitGame
} }
...@@ -8,12 +8,13 @@ import { BaseDao, TBAPIS } from '../../sdk' ...@@ -8,12 +8,13 @@ import { BaseDao, TBAPIS } from '../../sdk'
import { JOIN_DB_NAME } from '../../db' import { JOIN_DB_NAME } from '../../db'
import { ACTIVITY_STATUS } from '../../constants' import { ACTIVITY_STATUS } from '../../constants'
import { getToday } from '../../utils' import { getToday } from '../../utils'
import UserService from './user.service'
export default class GameService { export default class GameService extends UserService {
context: IContext<IParams> context: IContext<IParams>
joindao: IBaseDao joindao: IBaseDao
constructor(context: IContext<IParams>) { constructor(context: IContext<IParams>) {
this.context = context super(context)
this.joindao = new BaseDao(context, JOIN_DB_NAME) this.joindao = new BaseDao(context, JOIN_DB_NAME)
} }
...@@ -41,7 +42,28 @@ export default class GameService { ...@@ -41,7 +42,28 @@ export default class GameService {
return { id } 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 now = Date.now()
const today = getToday() const today = getToday()
const duration = now - joinInfo.createTime const duration = now - joinInfo.createTime
...@@ -53,18 +75,28 @@ export default class GameService { ...@@ -53,18 +75,28 @@ export default class GameService {
submitDay: today submitDay: today
} }
await this.joindao.update( await this.joindao.update({ _id: id }, { $set: playInfo })
{
_id: id return playInfo
},
{
$set: 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 { return {
score, maxScore,
duration updateScoreTime,
totalScore: totalScore + score
} }
} }
} }
...@@ -177,7 +177,7 @@ class UserService extends BaseService { ...@@ -177,7 +177,7 @@ class UserService extends BaseService {
return { return {
list: list.map((v, i) => { list: list.map((v, i) => {
return { return {
score: v[sortValueKey], [sortValueKey]: v[sortValueKey],
avatar: v.avatar, avatar: v.avatar,
userNick: formatUserNick(v.userNick), userNick: formatUserNick(v.userNick),
rank: i + 1 rank: i + 1
...@@ -222,7 +222,7 @@ class UserService extends BaseService { ...@@ -222,7 +222,7 @@ class UserService extends BaseService {
rank, rank,
userNick, userNick,
avatar, avatar,
score: userValue [sortValueKey]: userValue
} }
} }
......
...@@ -16,6 +16,11 @@ interface IUserInfo { ...@@ -16,6 +16,11 @@ interface IUserInfo {
remainTimes?: IRemainTimesInfo remainTimes?: IRemainTimesInfo
taskInfo?: object taskInfo?: object
login?: object login?: object
// 游戏类
gameTimes?: number
maxScore?: number
totalScore?: number
updateScoreTime?: number
} }
interface IRemainTimesInfo { interface IRemainTimesInfo {
......
...@@ -23,15 +23,15 @@ export function formatUpdateUserProjection(projection: IUpdateQuery): IUpdateQue ...@@ -23,15 +23,15 @@ export function formatUpdateUserProjection(projection: IUpdateQuery): IUpdateQue
} }
// 用户昵称脱敏 // 用户昵称脱敏
export function formatUserNick(name: string) { export function formatUserNick(name: string, replaceStr = '***') {
let newStr: string let newStr: string
if (name.length === 2) { 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) { } else if (name.length > 2) {
let char = '***' let char = replaceStr
newStr = name.substr(0, 1) + char + name.substr(-1, 1) newStr = name.substr(0, 1) + char + name.substr(-1, 1)
} else { } else {
newStr = name + '***' newStr = name + replaceStr
} }
return newStr return newStr
} }
......
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
], ],
"exclude": [ "exclude": [
"./src/controller/common/**", "./src/controller/common/**",
"./src/controller/custom/**",
"./dist/**/*" "./dist/**/*"
] ]
} }
\ No newline at end of file
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