const Controller = require('../core/base_controller'); const fileName = "Exam"; class ExamController extends Controller { // 用户报名接口 async application() { 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 body = ctx.request.body; const form = { user_uid: uid, exam_uid: this.decryptRequest(body.uid), exam_name: this.decryptRequest(body.exam_name), source: "个人", status: 0, pay_status: 0, result: "用户个人报名", created_at: new Date() }; const result = await ctx.service.exam.application(uid, form); 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 + "--" + "application"; ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error); this.setResponse(ctx, 500, '服务器错误', "none"); } } // 用户取消报名接口 async cancelApplication() { 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 body = ctx.request.body; const exam_uid = this.decryptRequest(body.uid); const result = await ctx.service.exam.cancelApplication(uid, exam_uid); 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 + "--" + "cancelApplication"; ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error); this.setResponse(ctx, 500, '服务器错误', "none"); } } // 用户查看所有考试接口 async examList() { 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 body = ctx.request.body; const result = await ctx.service.exam.examList(uid, body); if (result == "error") { this.setResponse(ctx, 500, '服务器错误', "none"); return; } if (result) { let examMsg = []; result.rows.forEach(element => { examMsg.push(element.dataValues); }); const data = { examMsg, count: result.count }; this.setResponse(ctx, 200, '操作成功', "deconstruction", data); } else { this.setResponse(ctx, 404, '操作失败', "none"); } } catch (error) { const blockName = fileName + "--" + "examList"; ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error); this.setResponse(ctx, 500, '服务器错误', "none"); } } // 用户查看考试结果接口 async gradesList() { 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 body = ctx.request.body; const result = await ctx.service.exam.gradesList(uid, body); if (result == "error") { this.setResponse(ctx, 500, '服务器错误', "none"); return; } if (result) { let gradesMsg = []; result.rows.forEach(element => { gradesMsg.push(element.dataValues); }); const data = { gradesMsg, count: result.count }; this.setResponse(ctx, 200, '操作成功', "deconstruction", data); } else { this.setResponse(ctx, 404, '操作失败', "none"); } } catch (error) { const blockName = fileName + "--" + "gradesList"; ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error); this.setResponse(ctx, 500, '服务器错误', "none"); } } // 用户查看报名历史接口 async applicationList() { 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 body = ctx.request.body; const result = await ctx.service.exam.applicationList(uid, body); if (result == "error") { this.setResponse(ctx, 500, '服务器错误', "none"); return; } if (result) { let applicationMsg = []; result.rows.forEach(element => { applicationMsg.push(element.dataValues); }); const data = { applicationMsg, count: result.count }; this.setResponse(ctx, 200, '操作成功', "deconstruction", data); } else { this.setResponse(ctx, 404, '操作失败', "none"); } } catch (error) { const blockName = fileName + "--" + "applicationList"; ctx.app.middleware.log('../../controllerLog', blockName + ">>>>" + error); this.setResponse(ctx, 500, '服务器错误', "none"); } } } module.exports = ExamController;