diff --git a/controllers/article.js b/controllers/article.js index e74beeb..b44db64 100644 --- a/controllers/article.js +++ b/controllers/article.js @@ -1,4 +1,3 @@ -var ObjectID = require('mongodb').ObjectID; var articlefind = async (ctx, next) => { let articlelist; await dbs.find("articlelists").then((res) => { @@ -8,7 +7,7 @@ var articlefind = async (ctx, next) => { } var articleadd = async (ctx, next) => { let month=parseInt(new Date(Date.now()).getMonth())+1 - await dbs.add("articlelists", { articletitle:ctx.query.title, date: new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes() + ':' + new Date(Date.now()).getSeconds(), type: ctx.query.type, tags:ctx.query.tags.split(",")}) + await dbs.add("articlelists", { articletitle:ctx.query.title, date: new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes() + ':' + new Date(Date.now()).getSeconds(),content:ctx.query.content,uid:1}) console.log(ctx.query) ctx.body = "添加成功" } @@ -22,7 +21,7 @@ var articledel=async(ctx,next)=>{ var articleupdate=async (ctx,next)=>{ let month=parseInt(new Date(Date.now()).getMonth())+1 - await dbs.update("articlelists",{num_key:parseInt(ctx.query.key)},{articletitle:ctx.query.title, udate: new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes() + ':' + new Date(Date.now()).getSeconds() , type: ctx.query.type, tags:ctx.query.tags.split(",")}) + await dbs.update("articlelists",{num_key:parseInt(ctx.query.key)},{articletitle:ctx.query.title, udate: new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes() + ':' + new Date(Date.now()).getSeconds()}) ctx.body="修改成功" // console.log(new Date(Date.now()).getFullYear ()+ '/' + month+ '/' + new Date(Date.now()).getDate() + ' ' + new Date(Date.now()).getHours() + ':' + new Date(Date.now()).getMinutes()) // console.log(new Date(Date.now()).getDate()) diff --git a/controllers/grouping.js b/controllers/grouping.js index e69de29..6de38ef 100644 --- a/controllers/grouping.js +++ b/controllers/grouping.js @@ -0,0 +1,49 @@ +var groupadd = async (ctx, next) => { + await dbs.add("group", { groupname: ctx.query.groupname, fuid: ctx.query.fuid }) + ctx.body = "添加成功" +} +var groupdel = async (ctx, next) => { + await dbs.remove("group", { num_key: parseInt(ctx.query.key) }) + ctx.body = "删除成功" +} +var groupfind = async (ctx, next) => { + let group = [] + await dbs.find("group").then((res) => { + // console.log(res) + for (let i in res.data) { + if (parseInt(res.data[i].fuid) == 0) { + // console.log(res.data[i]) + group.push({ name: res.data[i].groupname, num_key: res.data[i].num_key, child: [] }) + } + // console.log(res.data[i].num_key,res.data[i].fuid) + + } + for (let m in res.data) { + console.log(res.data[m].num_key, parseInt(res.data[m].fuid)) + // console.log(1111) + if (res.data[m].num_key == parseInt(res.data[m].fuid)){ + for (let n in group) { + if (group[n].num_key == parseInt(res.data[m].fuid)) { + group[n].child.push({ name: res.data[m].groupname, num_key: res.data[m].num_key, child: [] }) + } + } + + } + for (let n in group) { + if (group[n].num_key == parseInt(res.data[m].fuid)) { + group[n].child.push({ name: res.data[m].groupname, num_key: res.data[m].num_key, child: [] }) + } + } + } + // for(let m in res.data){ + // if(res.data[m]) + // } + console.log(JSON.stringify(group)) + ctx.body = group + }) +} +module.exports = { + 'GET /groupadd': groupadd, + 'GET /groupdel': groupdel, + 'GET /groupfind': groupfind, +}; \ No newline at end of file