From 80df32f6935fc848920863378039ee4c2d170633 Mon Sep 17 00:00:00 2001 From: zhl Date: Thu, 20 May 2021 12:42:20 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E7=94=A8=E6=88=B7=E7=BB=9F?= =?UTF-8?q?=E8=AE=A1=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/api/controllers/game_user.controller.ts | 23 +++++++++++++++++++++ src/utils/number.util.ts | 10 +++++++++ 2 files changed, 33 insertions(+) create mode 100644 src/utils/number.util.ts diff --git a/src/api/controllers/game_user.controller.ts b/src/api/controllers/game_user.controller.ts index 340d7e2..53e3d10 100644 --- a/src/api/controllers/game_user.controller.ts +++ b/src/api/controllers/game_user.controller.ts @@ -2,6 +2,7 @@ import BaseController from '../../common/base.controller' import { role, router } from '../../decorators/router' import { GameUser } from '../../models/GameUser' import { ZError } from '../../common/ZError' +import { getRandom } from '../../utils/number.util' class GameUserController extends BaseController { // TODO:: 增加返回未使用的券 @@ -19,4 +20,26 @@ class GameUserController extends BaseController { return {token} } + @role('anon') + @router('post /api/:accountid/stats') + async userStatic(req: any) { + const data: any = { + map: [ + {id: 0, name: '知识面', score: getRandom(20), max: 20}, + {id: 1, name: '知识深度', score: getRandom(20), max: 20}, + {id: 2, name: '反应能力', score: getRandom(20), max: 20}, + {id: 3, name: '毅力', score: getRandom(20), max: 20}, + {id: 4, name: '其他', score: getRandom(20), max: 20}, + ], + rightCount: 100, + errorCount: 100, + singleCount: 20, + singleWin: 15, + singleLose: 5, + activityCount: 20, + examCount: 21 + } + return data + } + } diff --git a/src/utils/number.util.ts b/src/utils/number.util.ts new file mode 100644 index 0000000..d78d41f --- /dev/null +++ b/src/utils/number.util.ts @@ -0,0 +1,10 @@ +/** + * 随机数 + * @param {number} max + * @param {number} min + * @return {number} + */ +export function getRandom(max: number, min?: number): number { + min = min || 0; + return Math.floor(Math.random()*(max-min)+min); +}