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