'use strict'; const Service = require('../core/base_service'); const { Op } = require('sequelize'); const fileName = "Home"; class HomeService extends Service { // 题库登录接口 async login(body) { const { ctx } = this; try { const phone = this.decryptRequest(body.phone); const password = this.decryptRequest(body.password); let attributes = ['uid', 'salt', 'password'], where = { phone }, dbOptions; dbOptions = { attributes, where } const user = await ctx.model.Examinee.findOne(dbOptions); if (user == null) return false; if (user.dataValues.password != this.shaForm(password, this.decryptRequest(user.dataValues.salt))) return false; const result = await ctx.model.Whitelist.findOne({ where: { user_uid: user.dataValues.uid } }); if (result == null) return false; if (result.dataValues.type == '0') return result; console.log(result.dataValues) console.log(new Date()) if (result.dataValues.type == '1' && result.dataValues.expired_at < new Date()) { return false; } else { return result; } } catch (error) { const blockName = fileName + "--" + "login"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 获取单选题接口 async radio(body) { const { ctx } = this; try { let limit = 1; let { offset } = body; offset = (offset - 1) * limit; let dbOptions = { offset, limit } const result = await ctx.model2.Radio.findAndCountAll(dbOptions); await ctx.model2.Radio.min('id').then(min => { result.min = min; }); return result.rows.length == 0 ? false : result; } catch (error) { const blockName = fileName + "--" + "radio"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 获取多选题接口 async multiple(body) { const { ctx } = this; try { let limit = 1; let { offset } = body; offset = (offset - 1) * limit; let dbOptions = { offset, limit } const result = await ctx.model2.Multiple.findAndCountAll(dbOptions); await ctx.model2.Multiple.min('id').then(min => { result.min = min; }); return result.rows.length == 0 ? false : result; } catch (error) { const blockName = fileName + "--" + "multiple"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 获取判断题接口 async judgment(body) { const { ctx } = this; try { let limit = 1; let { offset } = body; offset = (offset - 1) * limit; let dbOptions = { offset, limit } const result = await ctx.model2.Judgment.findAndCountAll(dbOptions); await ctx.model2.Judgment.min('id').then(min => { result.min = min; }); return result.rows.length == 0 ? false : result; } catch (error) { const blockName = fileName + "--" + "judgment"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 获取问答题接口 async interlocution(body) { const { ctx } = this; try { let limit = 1; let { offset } = body; offset = (offset - 1) * limit; let dbOptions = { offset, limit } const result = await ctx.model2.Interlocution.findAndCountAll(dbOptions); await ctx.model2.Interlocution.min('id').then(min => { result.min = min; }); return result.rows.length == 0 ? false : result; } catch (error) { const blockName = fileName + "--" + "interlocution"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } } module.exports = HomeService;