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' import { UserReward } from '../../models/UserReward' class GameUserController extends BaseController { // TODO:: 增加返回未使用的券 @role('anon') @router('post /api/:accountId/login') @router('post /weapp/login') async gameUserLogin(req, res) { const { accountId } = req.params if (!accountId) { throw new ZError(11, 'accountId needed') } let user = (await GameUser.findOrCreate({ accountId })).doc user.updateFromReq(req.params) await user.save() const token = await res.jwtSign({ id: user.id, accountId }) return { token } } //TODO:: 根据真实的配表获取数据 @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 } @role('anon') @router('post /api/:accountid/tickets') async userTickets(req: any) { const { accountid, sid } = req.params const result = await UserReward.ticketList(accountid, sid) return result } }