Commit 1dad89c0 authored by 黄广星's avatar 黄广星

添加后台逻辑删除接口

parent a2cc8fae
...@@ -49,12 +49,12 @@ router.post('/thread/create', function(req, res, next) { ...@@ -49,12 +49,12 @@ router.post('/thread/create', function(req, res, next) {
ent_code = req.session.user.ent_code, ent_code = req.session.user.ent_code,
icon = req.session.user.headPic, icon = req.session.user.headPic,
nickName = req.session.user.name; nickName = req.session.user.name;
if(icon && icon.indexOf('http://')==-1){ if (icon && icon.indexOf('http://') == -1) {
if(process.env.NODE_ENV === 'production'){ if (process.env.NODE_ENV === 'production') {
icon = 'http://fs.wxpai.cn/' + icon; icon = 'http://fs.wxpai.cn/' + icon;
}else{ } else {
icon = 'http://dev.fs.wxpai.cn/' + icon; icon = 'http://dev.fs.wxpai.cn/' + icon;
} }
} }
req.body.ent_code = ent_code; req.body.ent_code = ent_code;
if (!req.body.share) { if (!req.body.share) {
...@@ -77,22 +77,22 @@ router.post('/thread/create', function(req, res, next) { ...@@ -77,22 +77,22 @@ router.post('/thread/create', function(req, res, next) {
//更新后台对应用户信息 //更新后台对应用户信息
var isUpdate = false, var isUpdate = false,
updateObj = {}; updateObj = {};
if(icon){ if (icon) {
if(!user.icon || user.icon != icon){ if (!user.icon || user.icon != icon) {
isUpdate = true; isUpdate = true;
updateObj.icon = icon; updateObj.icon = icon;
} }
} }
if(nickName){ if (nickName) {
if(!nickName || !user.nickName || user.nickName !=nickName){ if (!nickName || !user.nickName || user.nickName != nickName) {
isUpdate =true; isUpdate = true;
updateObj.nickName = nickName; updateObj.nickName = nickName;
} }
} }
if(isUpdate){ if (isUpdate) {
user.update(updateObj,function(err,data){ user.update(updateObj, function(err, data) {
if(err)console.log(err); if (err) console.log(err);
}); });
} }
//创建帖子 //创建帖子
req.body.from = user._id; req.body.from = user._id;
...@@ -112,7 +112,7 @@ router.post('/thread/create', function(req, res, next) { ...@@ -112,7 +112,7 @@ router.post('/thread/create', function(req, res, next) {
//创建后台对应用户 //创建后台对应用户
var entity = { var entity = {
uid: uid, uid: uid,
ent_code:ent_code, ent_code: ent_code,
nickName: nickName, nickName: nickName,
icon: icon icon: icon
}; };
...@@ -157,22 +157,25 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -157,22 +157,25 @@ router.get('/thread/:tid/get', function(req, res, next) {
} }
}); });
}, },
function(thread,callback) { function(thread, callback) {
if(thread && thread.info && thread.info._id){ if (thread && thread.info && thread.info._id) {
forumTagService.getAllTag({ent_code:req.session.user.ent_code,info:thread.info._id}, 1, 100, function(err, results) { forumTagService.getAllTag({
ent_code: req.session.user.ent_code,
info: thread.info._id
}, 1, 100, function(err, results) {
if (err) { if (err) {
callback(err, null); callback(err, null);
} else { } else {
callback(null, [thread,results]); callback(null, [thread, results]);
} }
}); });
}else{ } else {
callback(null,[thread]); callback(null, [thread]);
} }
}, },
function(datas,callback) { function(datas, callback) {
forumUserService.getUserByUid(uid,function(err, results) { forumUserService.getUserByUid(uid, function(err, results) {
if (err) { if (err) {
callback(err, null); callback(err, null);
} else { } else {
...@@ -186,8 +189,8 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -186,8 +189,8 @@ router.get('/thread/:tid/get', function(req, res, next) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
var isSameAuthor = false; var isSameAuthor = false;
if(results[0].from && results[0].from.uid){ if (results[0].from && results[0].from.uid) {
if(!isNaN(results[0].from.uid)){ if (!isNaN(results[0].from.uid)) {
isSameAuthor = true; isSameAuthor = true;
} }
} }
...@@ -225,8 +228,8 @@ router.post('/thread/:tid/update', function(req, res, next) { ...@@ -225,8 +228,8 @@ router.post('/thread/:tid/update', function(req, res, next) {
if (err) { if (err) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
if(!isNaN(req.body.status)){ if (!isNaN(req.body.status)) {
forumAboutMEService.updateThreadStatus(thread._id,thread.status) forumAboutMEService.updateThreadStatus(thread._id, thread.status)
} }
res.json({ res.json({
message: "success", message: "success",
...@@ -256,6 +259,24 @@ router.post('/thread/:tid/delete', function(req, res, next) { ...@@ -256,6 +259,24 @@ router.post('/thread/:tid/delete', function(req, res, next) {
} }
}); });
//逻辑删除文章
router.post('/thread/:tid/disable', function(req, res, next) {
var tid = req.params.tid;
if (tid) {
forumThreadService.logicDeleteThreadById(tid, function(err, flag) {
if (err) {
res.json(returnCode.BUSY);
} else {
forumAboutMEService.updateThreadStatus(tid, 3);
res.json(returnCode.SUCCESS);
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//文章置顶 //文章置顶
router.post('/thread/:tid/:fid/top', function(req, res, next) { router.post('/thread/:tid/:fid/top', function(req, res, next) {
var tid = req.params.tid; //文章ID var tid = req.params.tid; //文章ID
...@@ -295,29 +316,29 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) { ...@@ -295,29 +316,29 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
var tid = req.params.tid, var tid = req.params.tid,
fid = req.params.fid, fid = req.params.fid,
ent_code = req.session.user.ent_code, ent_code = req.session.user.ent_code,
mid = req.body.mid;//板块ID mid = req.body.mid; //板块ID
if (tid && fid) { if (tid && fid) {
forumThreadService.updateRecommendByThreadId(tid, function(err, thread) { forumThreadService.updateRecommendByThreadId(tid, function(err, thread) {
if (err) { if (err) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
if(mid){ if (mid) {
forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(tid, function(err, flag){ forumLimitOperationService.checkLimitOperationProhibitionAddIntegral(tid, function(err, flag) {
if(err){ if (err) {
console.error(err); console.error(err);
res.json(returnCode.PROHIBITION_OF_SPEECH); res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{ } else {
if(flag){ if (flag) {
res.json(returnCode.PROHIBITION_OF_SPEECH); res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{ } else {
httpService.sendRequest(ent_code,mid,'thread_recomment'); httpService.sendRequest(ent_code, mid, 'thread_recomment');
res.json(returnCode.SUCCESS); res.json(returnCode.SUCCESS);
} }
} }
}); });
}else{ } else {
res.json(returnCode.SUCCESS); res.json(returnCode.SUCCESS);
} }
} }
}); });
...@@ -358,7 +379,9 @@ router.get('/threads/list', function(req, res, next) { ...@@ -358,7 +379,9 @@ router.get('/threads/list', function(req, res, next) {
var conditions = { var conditions = {
ent_code: req.session.user.ent_code, ent_code: req.session.user.ent_code,
level: 1, level: 1,
status:{$ne:3} status: {
$ne: 3
}
}; };
if (infoId) { if (infoId) {
conditions.info = infoId; conditions.info = infoId;
...@@ -380,15 +403,15 @@ router.get('/threads/list', function(req, res, next) { ...@@ -380,15 +403,15 @@ router.get('/threads/list', function(req, res, next) {
$options: 'i' $options: 'i'
} }
} }
if(type){ if (type) {
conditions.type = type; conditions.type = type;
} }
if(status){ if (status) {
conditions.status = status; conditions.status = status;
} }
if(nickName){ if (nickName) {
forumThreadService.getAllThreadByFidAndNickName(nickName, conditions, pageNo, pageSize, null, function(err, results) { forumThreadService.getAllThreadByFidAndNickName(nickName, conditions, pageNo, pageSize, null, function(err, results) {
if (err) { if (err) {
console.error(err); console.error(err);
...@@ -406,7 +429,7 @@ router.get('/threads/list', function(req, res, next) { ...@@ -406,7 +429,7 @@ router.get('/threads/list', function(req, res, next) {
} }
} }
}); });
}else{ } else {
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, null, function(err, results) { forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, null, function(err, results) {
if (err) { if (err) {
console.error(err); console.error(err);
...@@ -426,7 +449,7 @@ router.get('/threads/list', function(req, res, next) { ...@@ -426,7 +449,7 @@ router.get('/threads/list', function(req, res, next) {
}); });
} }
}); });
...@@ -445,8 +468,11 @@ router.get('/thread/:tid/comment/list', function(req, res, next) { ...@@ -445,8 +468,11 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
// $ne: 2 // $ne: 2
// } //过滤被删除的数据,status 为 2 表示删除 // } //过滤被删除的数据,status 为 2 表示删除
}; };
if(content){ if (content) {
conditions.content = { $regex:content, $options: 'i' }; conditions.content = {
$regex: content,
$options: 'i'
};
} }
if (tid) { if (tid) {
//获取最新5条评论 //获取最新5条评论
...@@ -456,20 +482,20 @@ router.get('/thread/:tid/comment/list', function(req, res, next) { ...@@ -456,20 +482,20 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
var asyncTasks = []; var asyncTasks = [];
_.forEach(results.items,function(e){ _.forEach(results.items, function(e) {
asyncTasks.push(function(cb){ asyncTasks.push(function(cb) {
if(e.level == 1){ if (e.level == 1) {
cb(null,e); cb(null, e);
}else{ } else {
forumCommentService.getCommentParent(e._id,function(err,p_comment){ forumCommentService.getCommentParent(e._id, function(err, p_comment) {
var comment = e.toObject(); var comment = e.toObject();
comment.floor = p_comment.floor; comment.floor = p_comment.floor;
cb(null,comment); cb(null, comment);
}); });
} }
}); });
}); });
async.parallel(asyncTasks,function(err,items){ async.parallel(asyncTasks, function(err, items) {
results.items = items; results.items = items;
res.json(_.assign(results, returnCode.SUCCESS)); res.json(_.assign(results, returnCode.SUCCESS));
}); });
...@@ -489,9 +515,9 @@ router.get('/thread/:tid/comment/list/:floor', function(req, res, next) { ...@@ -489,9 +515,9 @@ router.get('/thread/:tid/comment/list/:floor', function(req, res, next) {
ent_code: req.session.user.ent_code, ent_code: req.session.user.ent_code,
thread: tid, thread: tid,
level: '1', level: '1',
floor:floor floor: floor
}; };
if (tid && floor) { if (tid && floor) {
forumCommentService.getAllComment(conditions, 1, 1, function(err, results) { forumCommentService.getAllComment(conditions, 1, 1, function(err, results) {
if (err) { if (err) {
...@@ -499,23 +525,23 @@ router.get('/thread/:tid/comment/list/:floor', function(req, res, next) { ...@@ -499,23 +525,23 @@ router.get('/thread/:tid/comment/list/:floor', function(req, res, next) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
var asyncTasks = []; var asyncTasks = [];
if(results.items && results.items[0] && results.items[0].comments.length>0){ if (results.items && results.items[0] && results.items[0].comments.length > 0) {
var items = [results.items[0]]; var items = [results.items[0]];
_.forEach(results.items[0].comments,function(e){ _.forEach(results.items[0].comments, function(e) {
var subComment = e.toObject(); var subComment = e.toObject();
subComment.floor = results.items[0].floor; subComment.floor = results.items[0].floor;
if(content){ if (content) {
if(subComment.content.indexOf(content) != -1){ if (subComment.content.indexOf(content) != -1) {
items.push(subComment); items.push(subComment);
} }
}else{ } else {
items.push(subComment); items.push(subComment);
} }
}); });
results.items = items; results.items = items;
results.total = items.length; results.total = items.length;
res.json(_.assign(results, returnCode.SUCCESS)); res.json(_.assign(results, returnCode.SUCCESS));
}else{ } else {
res.json(_.assign(results, returnCode.SUCCESS)); res.json(_.assign(results, returnCode.SUCCESS));
} }
} }
...@@ -531,66 +557,68 @@ router.post('/thread/comment/update/:cid', function(req, res, next) { ...@@ -531,66 +557,68 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
var status = req.body.status; var status = req.body.status;
if (cid) { if (cid) {
async.waterfall([ async.waterfall([
function(callback){ function(callback) {
//获取评论实例 //获取评论实例
forumCommentService.getCommentById(cid,callback); forumCommentService.getCommentById(cid, callback);
}, },
function(comment,callback){ function(comment, callback) {
//更新评论状态 //更新评论状态
forumCommentService.updateCommentStatusById(cid, status,function(err,update){ forumCommentService.updateCommentStatusById(cid, status, function(err, update) {
callback(err,comment); callback(err, comment);
}); });
}, },
function(comment,callback){ function(comment, callback) {
//是否删除评论 //是否删除评论
if(status == 2){ if (status == 2) {
//一级评论 //一级评论
if(comment.level == 1){ if (comment.level == 1) {
var commentList = result.comments; var commentList = result.comments;
var comments = forumThreadService.remove(commentList, cid); var comments = forumThreadService.remove(commentList, cid);
forumThreadService.updateThreadById(comment.thread, { forumThreadService.updateThreadById(comment.thread, {
comments:comments, comments: comments,
$inc: { comment_count: -1 } $inc: {
comment_count: -1
}
}, function(err, result) { }, function(err, result) {
callback(err); callback(err);
}); });
}else{ } else {
forumThreadService.updateThreadCommentCount(comment.thread, function(err, result) { forumThreadService.updateThreadCommentCount(comment.thread, function(err, result) {
if (err) { if (err) {
callback(err); callback(err);
}else{ } else {
// 更新评论的子评论列表 // 更新评论的子评论列表
forumCommentService.getCommentParent(cid,function(err,p_comment){ forumCommentService.getCommentParent(cid, function(err, p_comment) {
if(err || !p_comment){ if (err || !p_comment) {
callback(err || 'comment not exist'); callback(err || 'comment not exist');
}else{ } else {
var commentList = p_comment.comments; var commentList = p_comment.comments;
var comments = forumCommentService.remove(commentList, cid); var comments = forumCommentService.remove(commentList, cid);
forumCommentService.updateCommentById(p_comment._id, { forumCommentService.updateCommentById(p_comment._id, {
comments:comments comments: comments
}, function(err, update) { }, function(err, update) {
callback(err); callback(err);
}); });
} }
}); });
} }
}); });
} }
}else{ } else {
if(comment && comment.level==1){ if (comment && comment.level == 1) {
forumAboutMEService.updateCommentLevel1Status(comment._id,status); forumAboutMEService.updateCommentLevel1Status(comment._id, status);
} }
if(comment && comment.level==2){ if (comment && comment.level == 2) {
forumAboutMEService.updateCommentLevel2Status(comment._id,status); forumAboutMEService.updateCommentLevel2Status(comment._id, status);
} }
callback(); callback();
} }
} }
],function(err,restult){ ], function(err, restult) {
if(err){ if (err) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
}else{ } else {
res.json(returnCode.SUCCESS); res.json(returnCode.SUCCESS);
} }
}); });
...@@ -626,7 +654,7 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) { ...@@ -626,7 +654,7 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
forumAboutMEService.saveCommentLevel2BySearch(tid,cid,replayComment_id); forumAboutMEService.saveCommentLevel2BySearch(tid, cid, replayComment_id);
res.json(returnCode.SUCCESS); res.json(returnCode.SUCCESS);
} }
}); });
...@@ -693,10 +721,10 @@ router.post('/thread/comment/add', function(req, res, next) { ...@@ -693,10 +721,10 @@ router.post('/thread/comment/add', function(req, res, next) {
function(callback) { function(callback) {
forumUserService.getUserByUid(uid, callback); forumUserService.getUserByUid(uid, callback);
}, },
function(user,callback){ function(user, callback) {
//获取发表人 //获取发表人
if(!user){ if (!user) {
var userentity = { var userentity = {
uid: uid, uid: uid,
nickName: req.session.user.name, nickName: req.session.user.name,
icon: req.session.user.headPic icon: req.session.user.headPic
...@@ -709,63 +737,65 @@ router.post('/thread/comment/add', function(req, res, next) { ...@@ -709,63 +737,65 @@ router.post('/thread/comment/add', function(req, res, next) {
callback(); callback();
} }
}); });
}else{ } else {
var icon = req.session.user.headPic; var icon = req.session.user.headPic;
if(icon){ if (icon) {
if(icon.indexOf('http://') == -1){ if (icon.indexOf('http://') == -1) {
icon = req.host != 'piplus.wxpai.cn'?'http://img3.wxpai.cn/'+ icon : 'http://img2.wxpai.cn/' + icon; icon = req.host != 'piplus.wxpai.cn' ? 'http://img3.wxpai.cn/' + icon : 'http://img2.wxpai.cn/' + icon;
} }
if(icon && (!user.icon || user.icon !== icon)){ if (icon && (!user.icon || user.icon !== icon)) {
forumUserService.updateUserById(user._id,{icon:icon},function(err){ forumUserService.updateUserById(user._id, {
if(err){ icon: icon
console.log(err); }, function(err) {
if (err) {
console.log(err);
} }
}); });
} }
} }
entity.from = user; entity.from = user;
callback(); callback();
} }
}, },
function(callback){ function(callback) {
//获取楼层 //获取楼层
if(entity.level == 1){ if (entity.level == 1) {
var conditions = { var conditions = {
thread:entity.thread, thread: entity.thread,
level:'1' level: '1'
} }
forumCommentService.count(conditions, function(err, count) { forumCommentService.count(conditions, function(err, count) {
if (err) { if (err) {
callback(err); callback(err);
} else { } else {
if(count){ if (count) {
entity.floor = count + 1; entity.floor = count + 1;
}else{ } else {
entity.floor = 1; entity.floor = 1;
} }
callback(); callback();
} }
}); });
}else{ } else {
callback(); callback();
} }
}, },
function(callback){ function(callback) {
// 添加评论 // 添加评论
forumCommentService.createComment(entity, function(err, comment) { forumCommentService.createComment(entity, function(err, comment) {
if (err) { if (err) {
callback(err); callback(err);
} else { } else {
forumThreadService.getById(tid,function(err,thread){ forumThreadService.getById(tid, function(err, thread) {
if(entity.level == 1){ if (entity.level == 1) {
forumAboutMEService.saveCommentLevel1(thread,comment); forumAboutMEService.saveCommentLevel1(thread, comment);
} }
var comments = thread.comments; var comments = thread.comments;
var array = []; var array = [];
if (comments && comments.length > 0) { if (comments && comments.length > 0) {
array = comments; array = comments;
} }
array.push(comment._id); array.push(comment._id);
...@@ -780,7 +810,7 @@ router.post('/thread/comment/add', function(req, res, next) { ...@@ -780,7 +810,7 @@ router.post('/thread/comment/add', function(req, res, next) {
errorcode: 0, errorcode: 0,
errormsg: '请求成功' errormsg: '请求成功'
} }
callback(null,returnData); callback(null, returnData);
}); });
}); });
} }
...@@ -843,138 +873,138 @@ router.post('/thread/:tid/updateComments', function(req, res, next) { ...@@ -843,138 +873,138 @@ router.post('/thread/:tid/updateComments', function(req, res, next) {
// }); // });
}); });
var checkOpenIds = function(openIds,openId){ var checkOpenIds = function(openIds, openId) {
var restult = false; var restult = false;
for(var i =0;i<openIds.length;i+=1){ for (var i = 0; i < openIds.length; i += 1) {
if(openIds[i] == openId){ if (openIds[i] == openId) {
restult = true; restult = true;
break; break;
} }
} }
return restult; return restult;
}; };
var getSubSpreadPaths = function(openIds,c,pvs,cb){ var getSubSpreadPaths = function(openIds, c, pvs, cb) {
c.children = []; c.children = [];
for(var i =0;i<pvs.length;i+=1){ for (var i = 0; i < pvs.length; i += 1) {
if(pvs[i].source.uid == c.openId){ if (pvs[i].source.uid == c.openId) {
var flag = false; var flag = false;
for(var j =0;j<c.children.length;j+=1){ for (var j = 0; j < c.children.length; j += 1) {
if(c.children[j].openId == pvs[i].open_id){ if (c.children[j].openId == pvs[i].open_id) {
flag = true; flag = true;
break; break;
}
}
if(!flag && !checkOpenIds(openIds,pvs[i].open_id)){
c.children.push({
openId:pvs[i].open_id,
nickName:pvs[i].user.displayName || '未知',
name:pvs[i].user.nickName || '未知'
});
openIds.push(pvs[i].open_id);
} }
} }
if (!flag && !checkOpenIds(openIds, pvs[i].open_id)) {
c.children.push({
openId: pvs[i].open_id,
nickName: pvs[i].user.displayName || '未知',
name: pvs[i].user.nickName || '未知'
});
openIds.push(pvs[i].open_id);
}
} }
var new_pvs = []; }
for(var i =0;i<pvs.length;i+=1){ var new_pvs = [];
if(pvs[i].source.uid !== c.openId){ for (var i = 0; i < pvs.length; i += 1) {
new_pvs.push(pvs[i]); if (pvs[i].source.uid !== c.openId) {
} new_pvs.push(pvs[i]);
} }
pvs = new_pvs; }
if(c.children.length >0){ pvs = new_pvs;
var thenTask = []; if (c.children.length > 0) {
_.forEach(c.children,function(c){ var thenTask = [];
thenTask.push(function(scb){ _.forEach(c.children, function(c) {
getSubSpreadPaths(openIds,c,pvs,scb); thenTask.push(function(scb) {
}); getSubSpreadPaths(openIds, c, pvs, scb);
})
then.parallel(thenTask).then(function(cont,childrens){
c.children = childrens;
cb(null,c);
}); });
}else{ })
cb(null,c); then.parallel(thenTask).then(function(cont, childrens) {
} c.children = childrens;
cb(null, c);
});
} else {
cb(null, c);
}
}; };
// 更新文章评论 // 更新文章评论
router.get('/thread/:tid/spreadchain', function(req, res, next) { router.get('/thread/:tid/spreadchain', function(req, res, next) {
var tid = req.params.tid || null, var tid = req.params.tid || null,
ent_code = req.session.user.ent_code; ent_code = req.session.user.ent_code;
var openIds = []; var openIds = [];
then.parallel([ then.parallel([
function(cont){ function(cont) {
ForumThread.findOne({ ForumThread.findOne({
_id:tid, _id: tid,
ent_code:ent_code ent_code: ent_code
}).populate('from').exec(function(err,doc){ }).populate('from').exec(function(err, doc) {
cont(err,doc); cont(err, doc);
}); });
}, },
function(cont){ function(cont) {
ForumPVLog.find({ ForumPVLog.find({
thread:tid, thread: tid,
ent_code:ent_code ent_code: ent_code
}).sort('source created').populate('user source').exec(function(err,docs){ }).sort('source created').populate('user source').exec(function(err, docs) {
cont(err,docs); cont(err, docs);
}); });
} }
]).then(function(cont,results){ ]).then(function(cont, results) {
var thread = results[0], var thread = results[0],
pvs = results[1]; pvs = results[1];
var data = { var data = {
openId:thread.from.uid, openId: thread.from.uid,
name:thread.from.nickName, name: thread.from.nickName,
nickName:thread.from.displayName, nickName: thread.from.displayName,
children:[] children: []
} }
//获取一级传播 //获取一级传播
for(var i = 0;i<pvs.length;i+=1){ for (var i = 0; i < pvs.length; i += 1) {
var pv = pvs[i]; var pv = pvs[i];
if(!pv.source){ if (!pv.source) {
var flag = false; var flag = false;
for(var j = 0;j<data.children.length;j+=1){ for (var j = 0; j < data.children.length; j += 1) {
var c = data.children[j]; var c = data.children[j];
if(c.openId === pv.open_id){ if (c.openId === pv.open_id) {
flag = true; flag = true;
break; break;
} }
} }
if(!flag && pv.open_id !== data.openId && !checkOpenIds(openIds,pv.open_id)){ if (!flag && pv.open_id !== data.openId && !checkOpenIds(openIds, pv.open_id)) {
data.children.push({ data.children.push({
openId:pv.open_id, openId: pv.open_id,
nickName:pv.user.displayName || '未知', nickName: pv.user.displayName || '未知',
name:pv.user.nickName || '未知' name: pv.user.nickName || '未知'
}); });
openIds.push(pv.open_id); openIds.push(pv.open_id);
} }
} }
} }
//获取非一级传播 //获取非一级传播
var new_pvs = []; var new_pvs = [];
for(var i = 0;i<pvs.length;i+=1){ for (var i = 0; i < pvs.length; i += 1) {
if(pvs[i].source && pvs[i].source.uid !== data.openId && pvs[i].open_id !== data.openId){ if (pvs[i].source && pvs[i].source.uid !== data.openId && pvs[i].open_id !== data.openId) {
new_pvs.push(pvs[i]); new_pvs.push(pvs[i]);
} }
} }
pvs = new_pvs; pvs = new_pvs;
//递归其他传播 //递归其他传播
var thenTask = []; var thenTask = [];
_.forEach(data.children,function(c){ _.forEach(data.children, function(c) {
thenTask.push(function(cb){ thenTask.push(function(cb) {
getSubSpreadPaths(openIds,c,pvs,cb); getSubSpreadPaths(openIds, c, pvs, cb);
}); });
}) })
then.parallel(thenTask).then(function(cont,childrens){ then.parallel(thenTask).then(function(cont, childrens) {
data.children = childrens; data.children = childrens;
var rs = { var rs = {
data:data data: data
} }
openIds = []; openIds = [];
res.json(_.assign(rs, returnCode.SUCCESS)); res.json(_.assign(rs, returnCode.SUCCESS));
}); });
}).fail(function(cont,err){ }).fail(function(cont, err) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment