This commit is contained in:
chaosBreaking
2019-10-12 21:46:17 +08:00
parent d85c774a93
commit 7a5a4c4e5f
4 changed files with 27 additions and 24 deletions

View File

@@ -46,7 +46,8 @@ module.exports = {
msg: '用户名或密码错误'
});
const token = createToken({
adminId: admin._id
adminId: admin._id,
adminName: name
}, JWT_SECRET, {});
return res.json({
code: 0,

View File

@@ -6,20 +6,20 @@ const handleTicket = require('./vreq.handler');
module.exports = {
// 处理工单请求的api
async reqHandle (req, res) {
const { adminId } = res.locals.user;
if (!adminId) return res.json({ code: 1, msg: '非法访问' });
const { id } = req.body;
const { adminId, adminName } = res.locals.user;
if (!adminId || !adminName) return res.json({ code: 1, msg: '非法访问' });
const { reqId } = req.body;
// 存在性检查
const ticket = await Vreq.findById(id).exec().catch(err => {
const vreq = await Vreq.findById(reqId).catch(err => {
mylog.error(err);
return null;
});
if (!ticket) return res.json({
if (!vreq) return res.json({
code: 1,
msg: 'unknow ticket'
msg: 'unknow vreq'
});
// 调用处理函数
handleTicket(ticket, adminId).then(data => {
handleTicket(vreq, adminName).then(data => {
return res.json({
code: 0,
msg: 'success',
@@ -35,8 +35,9 @@ module.exports = {
async getReqList (req, res) {
const { adminId } = res.locals.user;
if (!adminId) return res.json({ code: 1, msg: '非法访问' });
const { pageSize = 0, pageIndex = 1} = req.query;
return Vreq.find({}).skip((+pageIndex - 1) * +pageSize).limit(+pageSize).then(data => {
const { pageSize = 10, pageIndex = 1} = req.body.option || {};
const query = req.body.query;
return Vreq.find({ ...query }).skip((+pageIndex - 1) * +pageSize).limit(+pageSize).then(data => {
return res.json({
code: 0,
data
@@ -51,7 +52,7 @@ module.exports = {
async getReqDetail (req, res) {
const { adminId } = res.locals.user;
if (!adminId) return res.json({ code: 1, msg: '非法访问' });
const { ticketId } = req.query;
const { ticketId } = req.body.query;
return Vreq.findById(ticketId).then(data => {
return res.json({
code: 0,

View File

@@ -9,19 +9,16 @@ function createVerifyReq (data) {
});
}
async function handleReq (ticket, handlerId) {
// 所有工单在此处理只要状态未完结status !== 'finished',就可以多次调用改变状态。
ticket = await ticket.next(handlerId);
if (ticket.status === 'processing') {
await dealTicket(ticket);
await ticket.next(handlerId);
return ticket;
}
return null;
}
async function dealTicket (ticket, user) {
async function handleReq (vreq, adminName) {
await User.findByIdAndUpdate(vreq.userId, {
verifyLevel: vreq.verifyLevel
}).catch(err => mylog.error(err));
await vreq.updateOne({ status: 1, info: '审核通过', handler: adminName })
.catch(err => mylog.error(err));
return {
code: 0,
msg: '认证成功'
};
}
module.exports = {

View File

@@ -21,6 +21,10 @@ const VreqSchema = new mongoose.Schema({
type: String,
default: '审核中'
},
handler: {
type: String,
default: ''
},
option: {
type: {}
}