65 lines
2.3 KiB
JavaScript
65 lines
2.3 KiB
JavaScript
const Controller = require('../core/base_controller');
|
|
|
|
const fileName = "Check";
|
|
|
|
class CheckController extends Controller {
|
|
// 检查竞赛账号是否已经绑定北斗卡
|
|
async checkUser() {
|
|
const { ctx } = this;
|
|
try {
|
|
let rdmcode = await this.checkUid(ctx);
|
|
if (!rdmcode) {
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
|
return;
|
|
}
|
|
const uid = JSON.parse(rdmcode).uid;
|
|
const result = await ctx.service.check.checkUser(uid);
|
|
if (result == "error") {
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
return;
|
|
}
|
|
if (result) {
|
|
const data = {
|
|
card_id: result.dataValues.card_id,
|
|
};
|
|
this.setResponse(ctx, 200, '操作成功', "deconstruction", data);
|
|
} else {
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
|
}
|
|
} catch (error) {
|
|
const blockName = fileName + "--" + "checkUser";
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
}
|
|
}
|
|
|
|
// 检查北斗卡是否已经被绑定
|
|
async checkBind() {
|
|
const { ctx } = this;
|
|
try {
|
|
let rdmcode = await this.checkUid(ctx);
|
|
if (!rdmcode) {
|
|
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
|
return;
|
|
}
|
|
const { card_id } = ctx.request.body;
|
|
const result = await ctx.service.check.checkBind(card_id);
|
|
if (result == "error") {
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
return;
|
|
}
|
|
if (result) {
|
|
this.setResponse(ctx, 200, '操作成功', "none");
|
|
} else {
|
|
this.setResponse(ctx, 404, '操作失败', "none");
|
|
}
|
|
} catch (error) {
|
|
const blockName = fileName + "--" + "checkBind";
|
|
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
|
this.setResponse(ctx, 500, '服务器错误', "none");
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = CheckController;
|