北斗应用技术培训报名系统
This commit is contained in:
279
app/service/Exam.js
Normal file
279
app/service/Exam.js
Normal file
@@ -0,0 +1,279 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fileName = "Exam";
|
||||
|
||||
class ExamService extends Service {
|
||||
// 用户报名接口
|
||||
async application(uid, form) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let where = { uid }
|
||||
const user = await ctx.model.Examinee.findOne({ where });
|
||||
if (!user) return false;
|
||||
where = { user_uid: uid, exam_uid: form.exam_uid }
|
||||
const application = await ctx.model.Application.findOne({ where });
|
||||
let result;
|
||||
if (!application) {
|
||||
result = await ctx.model.Application.create(form);
|
||||
return result ? true : false;
|
||||
} else {
|
||||
result = await ctx.model.Application.update(form, { where });
|
||||
return result[0] != 0;
|
||||
};
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "application";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 用户取消报名接口
|
||||
async cancelApplication(uid, exam_uid) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Application.update({ status: 3, result: "用户已取消报名" }, { where: { user_uid: uid, exam_uid } });
|
||||
return result[0] != 0;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "cancelApplication";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 用户查看所有考试接口
|
||||
async examList(uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['uid', 'exam_name', 'status', 'application_end', 'exam_start', 'exam_end'],
|
||||
where = {}, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['uid', 'exam_name'], key = ['status'], between = ['application_end', 'exam_start', 'exam_end'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [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 };
|
||||
const result = await ctx.model.Examination.findAndCountAll(dbOptions);
|
||||
if (result.rows.length == 0) return false;
|
||||
const examUids = result.rows.map(exam => exam.dataValues.uid);
|
||||
const applicationStatus = await ctx.model.Application.findAll({ where: { user_uid: uid, exam_uid: { [Op.in]: examUids } } });
|
||||
const statusMap = new Map();
|
||||
applicationStatus.forEach(item => {
|
||||
statusMap.set(item.dataValues.exam_uid, item.dataValues.status);
|
||||
});
|
||||
result.rows.forEach(exam => {
|
||||
statusMap.get(exam.dataValues.uid) == undefined ?
|
||||
exam.dataValues.applicationStatus = 4 :
|
||||
exam.dataValues.applicationStatus = statusMap.get(exam.dataValues.uid);
|
||||
});
|
||||
let passExamArr = result.rows.map(exam => exam.dataValues.status == 0 ? exam.dataValues.uid : '').filter(item => item !== '')
|
||||
const applicationCheck = await ctx.model.Application.findAll({ attributes: ['exam_uid', 'status'], where: { user_uid: uid, exam_uid: passExamArr, status: { [Op.in]: [0, 1] } } });
|
||||
let applicationCheckSwitch = false;
|
||||
result.rows.forEach((item) => {
|
||||
item.dataValues.applicationCheck = 0;
|
||||
item.dataValues.applicationCheckSwitch = false;
|
||||
applicationCheck.forEach(element => {
|
||||
if (element.dataValues.exam_uid == item.dataValues.uid) {
|
||||
if (element.dataValues.status == 0 || element.dataValues.status == 1) {
|
||||
item.dataValues.applicationCheck = 1;
|
||||
applicationCheckSwitch = true;
|
||||
}
|
||||
}
|
||||
})
|
||||
});
|
||||
if (applicationCheckSwitch) {
|
||||
result.rows.forEach((items) => {
|
||||
items.dataValues.applicationCheckSwitch = true;
|
||||
});
|
||||
}
|
||||
return result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "examList";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 用户查看考试结果接口
|
||||
async gradesList(user_uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['exam_uid', 'status', 'grades', 'pass_type'],
|
||||
where = { user_uid }, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['exam_uid'], key = ['status', 'grades', 'pass_type'], between = [];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [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']);
|
||||
}
|
||||
});
|
||||
let examination = ['exam_name'],
|
||||
examinationWhere = {},
|
||||
examinationOrder = [],
|
||||
examinationJoinSubstring = [],
|
||||
examinationSubstring = ['exam_name'],
|
||||
examinationKey = [],
|
||||
examinationBetween = [];
|
||||
examination.forEach(item => {
|
||||
if (searchOptions[item]) {
|
||||
if (searchOptions[item] == '*空') {
|
||||
if (examinationJoinSubstring.includes(item)) {
|
||||
examinationWhere[item] = null;
|
||||
} else {
|
||||
examinationWhere[item] = [null, ''];
|
||||
}
|
||||
} else if (examinationSubstring.includes(item)) {
|
||||
examinationWhere[item] = { [Op.substring]: searchOptions[item] };
|
||||
} else if (examinationKey.includes(item)) {
|
||||
examinationWhere[item] = searchOptions[item];
|
||||
} else if (examinationBetween.includes(item)) {
|
||||
examinationWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[item] == true) {
|
||||
examinationOrder.push([item, 'ASC']);
|
||||
} else if (sortOptions[item] == false) {
|
||||
examinationOrder.push([item, 'DESC']);
|
||||
}
|
||||
});
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examination,
|
||||
attributes: ['exam_name', 'status'],
|
||||
where: examinationWhere,
|
||||
order: examinationOrder
|
||||
}
|
||||
];
|
||||
ctx.model.Grades.belongsTo(ctx.model.Examination, { foreignKey: 'exam_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, offset, limit, where, order, include };
|
||||
const result = await ctx.model.Grades.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "gradesList";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 用户查看报名历史接口
|
||||
async applicationList(user_uid, body) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let { offset, limit, searchOptions, sortOptions } = body;
|
||||
offset = (offset - 1) * limit;
|
||||
let attributes = ['exam_uid', 'source', 'status', 'pay_status', 'result', 'created_at'],
|
||||
where = { user_uid }, order = [], dbOptions, joinSubstring = [],
|
||||
substring = ['exam_uid', 'source', 'result'], key = ['status', 'pay_status'], between = ['created_at', 'application_end', 'exam_start', 'exam_end'];
|
||||
attributes.forEach(element => {
|
||||
if (searchOptions[element]) {
|
||||
if (searchOptions[element] == '*空') {
|
||||
if (joinSubstring.includes(element)) {
|
||||
where[element] = null;
|
||||
} else {
|
||||
where[element] = [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']);
|
||||
}
|
||||
});
|
||||
let examination = ['exam_name', 'application_end', 'exam_start', 'exam_end'],
|
||||
examinationWhere = {},
|
||||
examinationOrder = [],
|
||||
examinationJoinSubstring = [],
|
||||
examinationSubstring = ['exam_name'],
|
||||
examinationKey = [],
|
||||
examinationBetween = ['application_end', 'exam_start', 'exam_end'];
|
||||
examination.forEach(item => {
|
||||
if (searchOptions[item]) {
|
||||
if (searchOptions[item] == '*空') {
|
||||
if (examinationJoinSubstring.includes(item)) {
|
||||
examinationWhere[item] = null;
|
||||
} else {
|
||||
examinationWhere[item] = [null, ''];
|
||||
}
|
||||
} else if (examinationSubstring.includes(item)) {
|
||||
examinationWhere[item] = { [Op.substring]: searchOptions[item] };
|
||||
} else if (examinationKey.includes(item)) {
|
||||
examinationWhere[item] = searchOptions[item];
|
||||
} else if (examinationBetween.includes(item)) {
|
||||
examinationWhere[item] = { [Op.between]: [searchOptions[item][0], searchOptions[item][1]] };
|
||||
}
|
||||
}
|
||||
if (sortOptions[item] == true) {
|
||||
examinationOrder.push([item, 'ASC']);
|
||||
} else if (sortOptions[item] == false) {
|
||||
examinationOrder.push([item, 'DESC']);
|
||||
}
|
||||
});
|
||||
let include = [
|
||||
{
|
||||
model: ctx.model.Examination,
|
||||
attributes: ['exam_name', 'status', 'application_end', 'exam_start', 'exam_end'],
|
||||
where: examinationWhere,
|
||||
order: examinationOrder
|
||||
}
|
||||
];
|
||||
ctx.model.Application.belongsTo(ctx.model.Examination, { foreignKey: 'exam_uid', targetKey: 'uid' });
|
||||
dbOptions = { attributes, offset, limit, where, order, include };
|
||||
const result = await ctx.model.Application.findAndCountAll(dbOptions);
|
||||
return result.rows.length == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "applicationList";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = ExamService;
|
||||
109
app/service/System.js
Normal file
109
app/service/System.js
Normal file
@@ -0,0 +1,109 @@
|
||||
'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;
|
||||
183
app/service/User.js
Normal file
183
app/service/User.js
Normal file
@@ -0,0 +1,183 @@
|
||||
'use strict';
|
||||
|
||||
const Service = require('../core/base_service');
|
||||
|
||||
const { Op } = require('sequelize');
|
||||
|
||||
const fs = require('fs');
|
||||
const path = require('path');
|
||||
|
||||
const fileName = "User";
|
||||
|
||||
class UserService extends Service {
|
||||
// 信息完整性,合法性校验
|
||||
async checkInfo(uid) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['user_name', 'identity_card', 'real_check', 'status'],
|
||||
where = { uid },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
if (result == null || result.dataValues.status == 2 || result.dataValues.real_check == 2) return false;
|
||||
let type = 'OK';
|
||||
const { user_name, identity_card, real_check } = result.dataValues;
|
||||
if (real_check == 0) {
|
||||
type = 'CNTEV';
|
||||
const check = await ctx.app.redis.get('db3').get(identity_card);
|
||||
if (check == null) {
|
||||
ctx.curl('http://127.0.0.1:' + 8011 + '/CNTEV', {
|
||||
dataType: 'json',
|
||||
contentType: 'application/x-www-form-urlencoded',
|
||||
method: 'POST',
|
||||
timeout: 3000,
|
||||
data: {
|
||||
user_name,
|
||||
identity_card,
|
||||
},
|
||||
});
|
||||
} else {
|
||||
await ctx.service.user.updateCNTEV(user_name, identity_card, JSON.parse(check).real_check);
|
||||
await ctx.app.redis.get('db3').del(identity_card);
|
||||
}
|
||||
}
|
||||
return type;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "checkInfo";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 用户照片是否存在判断
|
||||
async checkPhoto(uid) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['identity_card'],
|
||||
where = { uid },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
if (result == null) return false;
|
||||
const filePath = path.join(__dirname, `../public/userPhoto/${ result.dataValues.identity_card }.jpg`);
|
||||
// const filePath = `/disk/a/userPhoto/${ result.dataValues.identity_card }.jpg`;
|
||||
const fileExists = fs.existsSync(filePath);
|
||||
let exist = false;
|
||||
if (fileExists) {
|
||||
// 文件存在
|
||||
exist = true;
|
||||
} else {
|
||||
// 文件不存在
|
||||
let attributes = ['identity_card'],
|
||||
where = { user_uid: uid },
|
||||
order = [['created_at', 'DESC']],
|
||||
limit = 1,
|
||||
offset = 1,
|
||||
dbOptions = { attributes, where, order, limit, offset };
|
||||
const oldIdentityCard = await ctx.model.Audit.findOne(dbOptions);
|
||||
if(!oldIdentityCard) {
|
||||
exist = false;
|
||||
} else {
|
||||
const oldFilePath = path.join(__dirname, `../public/userPhoto/${ oldIdentityCard.dataValues.identity_card }.jpg`);
|
||||
// const oldFilePath = `/disk/a/userPhoto/${ oldIdentityCard.dataValues.identity_card }.jpg`;
|
||||
const fileExists = fs.existsSync(oldFilePath);
|
||||
if (fileExists) {
|
||||
// 文件存在
|
||||
fs.renameSync(oldFilePath, filePath);
|
||||
// 文件改名
|
||||
exist = true;
|
||||
} else {
|
||||
// 文件不存在
|
||||
exist = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 本机服务器地址
|
||||
// 'http://127.0.0.1:8019'
|
||||
// 'http://192.168.31.28:8019'
|
||||
// 公司服务器地址
|
||||
// 'http://123.57.205.46:8019'
|
||||
// 'http://certlogin.hwasmart.com//bdTrainingExam'
|
||||
return { exist, photoUrl: exist ? 'http://127.0.0.1:8019' + `/public/userPhoto/${ result.dataValues.identity_card }.jpg?time=${ new Date().getTime() }` : '#' };
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "checkPhoto";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 身份证二要素核验
|
||||
async CNTEV(user_name, identity_card) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['real_check'],
|
||||
where = { user_name, identity_card },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
if (result == null) return false;
|
||||
return result.dataValues.real_check;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "CNTEV";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 身份证二要素核验状态更新
|
||||
async updateCNTEV(user_name, identity_card, real_check) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const where = { user_name, identity_card };
|
||||
await ctx.model.Examinee.update({ real_check }, { where });
|
||||
await ctx.model.Audit.update({ status: real_check }, { where });
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "CNTEV";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 用户上传照片接口
|
||||
async uploadPhoto(uid, files) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
let attributes = ['identity_card'],
|
||||
where = { uid },
|
||||
dbOptions = { attributes, where };
|
||||
const result = await ctx.model.Examinee.findOne(dbOptions);
|
||||
if (result == null) return false;
|
||||
// 重命名用户上传的文件并保存到证件照文件夹中
|
||||
files[0].filename = result.dataValues.identity_card + '.jpg';
|
||||
const { filename, filepath } = files[0];
|
||||
const uploadDir = path.join(__dirname, '../public/userPhoto'); // 设置文件保存目录
|
||||
// const uploadDir = '/disk/a/userPhoto'; // 设置服务器文件保存目录
|
||||
const newPath = path.join(uploadDir, filename); // 构造新文件路径
|
||||
// 确保上传目录存在
|
||||
if (!fs.existsSync(uploadDir)) {
|
||||
fs.mkdirSync(uploadDir, { recursive: true });
|
||||
}
|
||||
// 使用 copyFileSync 复制文件,而不是 renameSync
|
||||
fs.copyFileSync(filepath, newPath);
|
||||
// 删除临时文件
|
||||
fs.unlinkSync(filepath);
|
||||
return true;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "uploadPhoto";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
|
||||
// 用户找回密码接口
|
||||
async resetPassword(updateForm, phone) {
|
||||
const { ctx } = this;
|
||||
try {
|
||||
const result = await ctx.model.Examinee.update(updateForm, { where: { phone } });
|
||||
return result[0] == 0 ? false : result;
|
||||
} catch (error) {
|
||||
const blockName = fileName + "--" + "resetPassword";
|
||||
ctx.app.middleware.log('../../serviceLog', blockName + ">>>>" + error);
|
||||
return 'error';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = UserService;
|
||||
Reference in New Issue
Block a user