北斗应用技术培训考试管理系统
This commit is contained in:
79
app/controller/Cntev.js
Normal file
79
app/controller/Cntev.js
Normal file
@@ -0,0 +1,79 @@
|
||||
const Controller = require('../core/base_controller');
|
||||
|
||||
const fileName = "Cntev";
|
||||
|
||||
class CntevController extends Controller {
|
||||
// 核验用户身份证二要素
|
||||
async CNTEV() {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let rdmcode = await this.checkUid(ctx);
|
||||
if (!rdmcode) {
|
||||
this.setResponse(ctx, 401, 'token过期或错误', "none");
|
||||
return;
|
||||
}
|
||||
const finishedList = ctx.request.body.finishedList;
|
||||
const failedResult = await ctx.service.cntev.siftFailedList(finishedList);
|
||||
const validateResult = await ctx.service.cntev.validateList(finishedList);
|
||||
if (failedResult == "error" || validateResult == "error") {
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
return;
|
||||
}
|
||||
let finishList = [];
|
||||
if (failedResult && failedResult.length > 0) {
|
||||
failedResult.forEach(async element => {
|
||||
const check = await ctx.app.redis.get('db3').get(element.dataValues.identity_card);
|
||||
if (check == null) {
|
||||
ctx.curl('http://127.0.0.1:' + 8011 + '/CNTEV', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
user_name: element.dataValues.user_name,
|
||||
identity_card: element.dataValues.identity_card,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await ctx.service.cntev.updateCNTEV(element.dataValues.user_name, element.dataValues.identity_card, JSON.parse(check).real_check);
|
||||
await ctx.app.redis.get('db3').del(element.dataValues.identity_card);
|
||||
finishList.push(element.dataValues.identity_card);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (validateResult && validateResult.length > 0) {
|
||||
validateResult.forEach(async element => {
|
||||
const check = await ctx.app.redis.get('db3').get(element.dataValues.identity_card);
|
||||
if (check == null) {
|
||||
ctx.curl('http://127.0.0.1:' + 8011 + '/CNTEV', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
user_name: element.dataValues.user_name,
|
||||
identity_card: element.dataValues.identity_card,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await ctx.service.cntev.updateCNTEV(element.dataValues.user_name, element.dataValues.identity_card, JSON.parse(check).real_check);
|
||||
await ctx.app.redis.get('db3').del(element.dataValues.identity_card);
|
||||
finishList.push(element.dataValues.identity_card);
|
||||
}
|
||||
});
|
||||
}
|
||||
if (failedResult && failedResult.length > 0 || validateResult && validateResult.length > 0) {
|
||||
const data = { finishList };
|
||||
this.setResponse(ctx, 303, '核验中', "deconstruction", data);
|
||||
} else {
|
||||
this.setResponse(ctx, 200, '核验成功', "none");
|
||||
}
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "CNTEV";
|
||||
ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error);
|
||||
this.setResponse(ctx, 500, '服务器错误', "none");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = CntevController;
|
||||
Reference in New Issue
Block a user