'use strict'; const Service = require('../core/base_service'); const { Op } = require('sequelize'); const fileName = "Diff"; class DiffService extends Service { // 比较身份证号 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 == null ? true : 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 == null ? true : 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 == null ? true : result.dataValues.phone == phone ? true : search.length == 0; } } catch (error) { const blockName = fileName + "--" + "diffPhone"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } } module.exports = DiffService;