feature:
修改账号接口返回结构 修改部分账号接口逻辑
This commit is contained in:
@@ -4,12 +4,14 @@ export const STATUS = {
|
||||
WRONG_PARMS: { code: 1, simStr: '参数错误' },
|
||||
TOKEN_ERR: { code: 2, simStr: 'token失效' },
|
||||
INTERNAL_ERR: { code: 3, simStr: '内部错误' },
|
||||
CONNECTOR_ERR: { code: 4, simStr: '连接服配置错误'},
|
||||
// 账号相关状态 10000 - 19999
|
||||
SMS_IN_60S: { code: 10001, simStr: '60秒内只能发送一次' },
|
||||
SMS_CNT_LIMIT: { code: 10002, simStr: '今日短信条数已达上限' },
|
||||
SMS_INVALID: { code: 10003, simStr: '验证码无效' },
|
||||
SERVER_NOT_FOUND: { code: 10004, simStr: '未找到服务器列表' },
|
||||
ROLE_NOT_FOUND: { code: 10005, simStr: '未找到角色' },
|
||||
DUP_LOGIN: { code: 10006, simStr: '重复登录' },
|
||||
// 战斗相关状态 20000 - 29999
|
||||
// 战斗通用 20000 - 20099
|
||||
// 主线 20100 - 20199
|
||||
|
||||
@@ -3,6 +3,9 @@ import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
||||
|
||||
class ServerInfo {
|
||||
@prop({ required: true })
|
||||
id: number;
|
||||
|
||||
@prop({ required: true })
|
||||
name: string;
|
||||
|
||||
@@ -55,7 +58,7 @@ export default class Game extends BaseModel {
|
||||
public static async getServerListByType(serverType: string) {
|
||||
let game = await GameModel.findOne().lean();
|
||||
if (!game) {
|
||||
const serverInfo: ServerInfo = { name: '常山少年', host: 'pinus_test.trgame.cn', port: 3014, status: 1, createTime: new Date(), serverType: 'official' };
|
||||
const serverInfo: ServerInfo = { id: 1, name: '常山少年', host: 'pinus_test.trgame.cn', port: 3014, status: 1, createTime: new Date(), serverType: 'official' };
|
||||
const iconUrl = `https://download.tgamebox.cn/avatar/${APP_ID}/1.png`;
|
||||
game = await GameModel.findOneAndUpdate(
|
||||
{},
|
||||
|
||||
@@ -2,6 +2,7 @@ import { COUNTER } from './../consts/consts';
|
||||
import { CounterModel } from './Counter';
|
||||
import BaseModel from './BaseModel';
|
||||
import { index, getModelForClass, prop } from '@typegoose/typegoose';
|
||||
import { genCode } from 'app/pubUtils/util';
|
||||
|
||||
/**
|
||||
* 用户字段接口
|
||||
@@ -16,6 +17,9 @@ export default class User extends BaseModel {
|
||||
@prop({ required: true })
|
||||
username: string;
|
||||
|
||||
@prop({ required: true })
|
||||
userCode: string; // 用户唯一字符串标识
|
||||
|
||||
@prop({ required: true })
|
||||
token: string;
|
||||
|
||||
@@ -65,8 +69,9 @@ export default class User extends BaseModel {
|
||||
let update = {};
|
||||
if (!user) {
|
||||
const uid = await CounterModel.getNewCounter(COUNTER.UID);
|
||||
const userCode = genCode(8);
|
||||
const doc = new UserModel();
|
||||
update = Object.assign(update, { platform, pkgName, serverType, createTime: curTime, uid, username: `用户${uid}` }, doc.toJSON());
|
||||
update = Object.assign(update, { platform, pkgName, serverType, createTime: curTime, uid, userCode, username: `用户${uid}` }, doc.toJSON());
|
||||
}
|
||||
update = Object.assign(update, { token, lastLoginTime: curTime });
|
||||
user = await UserModel.findOneAndUpdate({ tel }, update, { upsert: true, new: true }).lean(lean);
|
||||
|
||||
@@ -184,5 +184,8 @@ export function getRandEelm(source: Array<any> = [], cnt = 1): Array<any> {
|
||||
|
||||
export function resResult(status: {code: number, simStr: string}, data = null, customMsg = '') {
|
||||
const { code, simStr } = status;
|
||||
if (code !== STATUS.SUCCESS.code) {
|
||||
console.log(`normal err, code: ${code}, des: ${customMsg || simStr}`);
|
||||
}
|
||||
return {code, msg: customMsg || simStr, data};
|
||||
}
|
||||
Reference in New Issue
Block a user