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: '用户名或密码错误' msg: '用户名或密码错误'
}); });
const token = createToken({ const token = createToken({
adminId: admin._id adminId: admin._id,
adminName: name
}, JWT_SECRET, {}); }, JWT_SECRET, {});
return res.json({ return res.json({
code: 0, code: 0,

View File

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

View File

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

View File

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