'use strict'; const Service = require('../core/base_service'); const { Op } = require('sequelize'); const fileName = "System"; class SystemService extends Service { // 系统获取考试信息接口 async examMsg() { const { ctx } = this; try { // 该接口只返回可报名的考试信息,即 status 为 0 的考试信息 const where = { status: 0 }; const result = await ctx.model.Examination.findAll({ where }); return result.length == 0 ? false : result; } catch (error) { const blockName = fileName + "--" + "examMsg"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 比较身份证号 async diffIdentityCard(identity_card, type, uid) { const { ctx } = this; try { let attributes = ['identity_card'], where = { identity_card }, dbOptions = { attributes, where }; const search = await ctx.model.Examinee.findAll(dbOptions); if (type == 'register') { return search.length == 0; } else if (type == 'edit') { where = { uid }; dbOptions = { attributes, where }; const result = await ctx.model.Examinee.findOne(dbOptions); return result.dataValues.identity_card == identity_card ? true : search.length == 0; } } catch (error) { const blockName = fileName + "--" + "diffIdentityCard"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 比较邮箱 async diffEmail(email, type, uid) { const { ctx } = this; try { let attributes = ['email'], where = { email }, dbOptions = { attributes, where }; const search = await ctx.model.Examinee.findAll(dbOptions); if (type == 'register') { return search.length == 0; } else if (type == 'edit') { where = { uid }; dbOptions = { attributes, where }; const result = await ctx.model.Examinee.findOne(dbOptions); return result.dataValues.email == email ? true : search.length == 0; } } catch (error) { const blockName = fileName + "--" + "diffEmail"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 比较电话号码 async diffPhone(phone, type, uid) { const { ctx } = this; try { let attributes = ['phone'], where = { phone }, dbOptions = { attributes, where }; const search = await ctx.model.Examinee.findAll(dbOptions); if (type == 'register') { return search.length == 0; } else if (type == 'edit') { where = { uid }; dbOptions = { attributes, where }; const result = await ctx.model.Examinee.findOne(dbOptions); return result.dataValues.phone == phone ? true : search.length == 0; } } catch (error) { const blockName = fileName + "--" + "diffPhone"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 用户注册接口 async registered(form, auditForm) { const { ctx } = this; try { const result = await ctx.model.Examinee.create(form); await ctx.model.Audit.create(auditForm); return result ? true : false; } catch (error) { const blockName = fileName + "--" + "registered"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } } module.exports = SystemService;