'use strict'; module.exports = () => { return async function(ctx, next) { await next(); if (ctx.request.method === 'POST') { let optmethod = ''; if (ctx.params) { optmethod = '更新方法'; } else { optmethod = '新增方法'; } // 根据传入的 if (ctx.request.header.uid) { const res = await ctx.service.otheruser.findUserByUserid(ctx.request.header.uid); const newdata = { ...res, optmethod, optservice: ctx.request.url, optdata: JSON.stringify(ctx.request.body), opttime: new Date() }; try { await ctx.service.optlog.create(newdata); } catch (error) { console.log(error); } } } else if (ctx.request.method === 'DELETE') { // 根据传入的 if (ctx.request.header.uid) { const res = await ctx.service.otheruser.findUserByUserid(ctx.request.header.uid); const newdata = { ...res, optmethod: '删除方法', optservice: ctx.request.url, optdata: JSON.stringify(ctx.request.body), opttime: new Date() }; try { await ctx.service.optlog.create(newdata); } catch (error) { console.log(error); } } } }; };