'use strict'; const Service = require('../core/base_service'); const { Op } = require('sequelize'); const fileName = "Audit"; class AuditService extends Service { // 管理系统查看用户关键信息变更 async auditList(uid, body) { const { ctx } = this; try { let { offset, limit, searchOptions, sortOptions } = body; offset = (offset - 1) * limit; let attributes = ['uid', 'user_name', 'identity_card', 'real_check', 'workplace', 'address', 'phone', 'email', 'status', 'created_at', 'updated_at', 'login_status'], where = {}, order = [], dbOptions, joinSubstring = [], substring = ['uid', 'user_name', 'identity_card', 'workplace', 'address', 'phone', 'email'], key = ['real_check', 'status', 'login_status'], between = ['created_at', 'updated_at']; attributes.forEach(element => { if (searchOptions[element]) { if (searchOptions[element] == '*空') { if (joinSubstring.includes(element)) { where[element] = null; } else { where[element] = [null, '']; } } else if (joinSubstring.includes(element)) { let targetKeyArr = []; where[element] = targetKeyArr.length > 0 ? targetKeyArr : 'null'; } else if (substring.includes(element)) { where[element] = { [Op.substring]: searchOptions[element] }; } else if (key.includes(element)) { where[element] = searchOptions[element]; } else if (between.includes(element)) { where[element] = { [Op.between]: [searchOptions[element][0], searchOptions[element][1]] }; } } if (sortOptions[element] == true) { order.push([element, 'ASC']); } else if (sortOptions[element] == false) { order.push([element, 'DESC']); } }); dbOptions = { attributes, offset, limit, where, order }; // 默认查询的 status 为 0,管理员可以请求其他状态的审核列表 // let status = 0; const result = await ctx.model.Audit.findAndCountAll(dbOptions); return result.rows.length == 0 ? false : result; } catch (error) { const blockName = fileName + "--" + "auditList"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 管理系统审核用户关键信息变更 async userMsgAudit(uid, body) { const { ctx } = this; try { console.log(uid); console.log(body); // const result = await ctx.model.Audit.update({ status: 1 }, { where: { status: 0, body } }); // console.log(result); // return result[0] == 0 ? false : true; return true; } catch (error) { const blockName = fileName + "--" + "userMsgAudit"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } // 保存导入考生报名信息和考生成绩时存在错误的数据,方便管理员查找问题 async importerror(form) { const { ctx } = this; try { await ctx.model.Importerror.bulkCreate(form); } catch (error) { const blockName = fileName + "--" + "importerror"; ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error); return 'error'; } } } module.exports = AuditService;