// 会员类型 const util = require('../utils') const db = require('../data') let [sql, rs] = ['', null] /** * 获取当前类的所有子类,含当前层 * get: /department/allchildren */ exports.AllChildren = async ctx => { const id = ctx.query.id const client = ctx.query.c if (!util.isInteger(id)) { ctx.body = { code: -2 } } else { const parent = await db.select('select top 1 path,name from member_type where id=' + id) if (parent === null) { ctx.body = { code: 1, message: '节点(' + id + ')未找到' } } else { if (client === 'ztree') { sql = `select id,parid as pId,name from member_type as a where path like '${parent.path},%' order by sort,id` rs = await db.select(sql) rs.forEach(item => rs.some(el => el.pId === item.id) && (item.isParent = 1)) rs.unshift({ id: Number(id), pId: 0, name: parent.name, isParent: 1, open: 1 }) } else { sql = `select id,parid,name from member_type where path like '${parent.path},%' order by sort,id` rs = await db.select(sql) rs.unshift({ id: Number(id), parid: 0, name: parent.name }) } ctx.body = { code: 0, data: rs } } } }