Commit 3858a3a8 authored by qinhaitao's avatar qinhaitao

feat: 🎸 提交接口\

parent 76c36558
...@@ -31,8 +31,16 @@ export default class StatController { ...@@ -31,8 +31,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
}) })
......
...@@ -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)
} }
......
...@@ -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
} }
...@@ -9,11 +9,11 @@ import { JOIN_DB_NAME } from '../../db' ...@@ -9,11 +9,11 @@ import { JOIN_DB_NAME } from '../../db'
import { ACTIVITY_STATUS } from '../../constants' import { ACTIVITY_STATUS } from '../../constants'
import { getToday } from '../../utils' import { getToday } from '../../utils'
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 +41,28 @@ export default class GameService { ...@@ -41,7 +41,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 +74,28 @@ export default class GameService { ...@@ -53,18 +74,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