NutzCN Logo
短点 没原来的好,都乱套了
发布于 3093天前 作者 大鲨鱼 1863 次浏览 复制 上一个帖子 下一个帖子
标签: 建议

addDo: function (req, res) {
var body = req.body;
var parentId = parseInt(body.parentId);
Sys_unit.findOne({id: parentId}).exec(function (err, unit) {
var path = '';
if (unit)path = unit.path || '';
Sys_unit.find().where({parentId: parentId}).sort({path: 'desc'}).limit(1).exec(function (ferr, objs) {
if (objs.length > 0) {
var num = parseInt(objs[0].path) + 1;
path = StringUtil.getPath(num, objs[0].path.length);
}else{
path=path+'0001';
}
body.path = path;
body.location = 0;
body.createdBy = req.session.user.id;
Sys_unit.create(body).exec(function (cerr, obj) {
if (cerr || !obj)return res.json({code: 1, msg: sails.__('add.fail')});
if (parentId > 0) {
Sys_unit.update({id: parentId}, {hasChildren: true}).exec(function(e,o){});
}
return res.json({code: 0, msg: sails.__('add.ok')});
});
});
});

},

0 回复
添加回复
请先登陆
回到顶部