Commit 9172e7e9 authored by 陈志良's avatar 陈志良

1

parent 717640fb
...@@ -614,7 +614,175 @@ router.post('/thread/:tid/comment/create', function(req, res, next) { ...@@ -614,7 +614,175 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
} }
}); });
}); });
//新增文章评论
router.post('/thread/:tid/comment/create/new', function(req, res, next) {
var userId = req.session.mobileForumUser.userId;
var newCommentId = null;
forumLimitActionRefService.checkLimitActionProhibitionOfSpeech(userId, function(err, isProhibition){
if(err){
console.error(err);
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
if(isProhibition){
res.json(returnCode.PROHIBITION_OF_SPEECH);
}else{
var tid = req.params.tid || null;
if (tid) {
var integral = req.session.openUser.integral || 0;
var exp = req.session.openUser.exp || 0;
var destination = req.body.destination || '1';
//1.检查是否有权限
forumRolePermissionService.checkRolePermiss(req.session.user.ent_code, 'comment', integral, exp, function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
if (result) { //有操作权限
var content = req.body.content;
if (content) { //评论不能为空
//2.获取论坛文章
forumThreadService.getThreadById(tid, function(err, thread) {
if (err) {
res.json(returnCode.BUSY);
} else {
async.parallel([
function(callback) {
var floor = 1;
var entity = {
ent_code: req.session.user.ent_code,
from: user.getMobileUser(req),
content: content,
ip: req.ip,
thread: thread,
level: '1',
floor: floor
};
var conditions = {
thread: thread._id,
level: '1'
};
forumCommentService.count(conditions, function(err, count) {
if (err) {
console.log(err);
callback(err, null);
} else {
// callback(null, count);
if(count){
entity.floor = count + 1;
}
//4.创建文章评论
forumCommentService.createComment(entity, function(err, newComment) {
if (err) {
callback(err, null);
} else {
newCommentId = newComment._id;
var comments = thread.comments;
var array = [];
if (comments && comments.items && comments.items.length > 0) {
array = comments.items;
}
array.push(newComment._id);
forumThreadService.updateThreadById(tid, {
comments: array
}, function(err, result) {
if (err) {
callback(err, null);
} else {
callback(null, null);
}
});
}
});
}
});
},
function(callback) {
//3.更新文章统计数据(评论数)
if (thread) {
forumThreadService.updateThreadCommentCountInc(tid, function(err, results) {
if (err) {
console.log(err);
callback(err, null);
} else {
callback(null, null);
}
});
} else {
callback('cannot find thread by id', null);
}
}
], function(err, results) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
forumLimitActionRefService.checkLimitActionProhibitionAddIntegral(userId, function(err, flag){
if(err){
console.error(err);
}else{
if(!flag){
httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'comment');
}
}
});
async.parallel([
function(callback) {
//获取创建评论
var conditions = {
thread: tid,
level: '1'
};
forumCommentService.getPopulateCommentById(newCommentId, function(err, doc) {
if (err) {
console.log(err);
callback(err, null);
} else {
callback(null, doc);
}
});
},
function(callback) {
forumThreadService.getThreadById(tid, function(err, thread) {
if (err) {
console.log(err);
callback(err, null);
} else {
callback(null, thread);
}
});
}
], function(err, results) {
if (err) {
res.json(returnCode.BUSY);
} else {
var rs = {};
rs.data = results[0];
var result = _.assign(rs, returnCode.SUCCESS);
res.json(result);
}
});
}
});
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
} else {
res.json(returnCode.ACTION_NOT_PERMISSION);
}
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
}
}
});
});
//新建文章评论的子评论 //新建文章评论的子评论
router.post('/thread/:tid/comment/:cid/create', function(req, res, next) { router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
var userId = req.session.mobileForumUser.userId; var userId = req.session.mobileForumUser.userId;
......
...@@ -288,4 +288,16 @@ exports.getCommentParent = function(cid,callback){ ...@@ -288,4 +288,16 @@ exports.getCommentParent = function(cid,callback){
ForumComment.findOne({comments:{$in:[cid]}},function(err,doc){ ForumComment.findOne({comments:{$in:[cid]}},function(err,doc){
callback(err,doc); callback(err,doc);
}); });
};
//根据ID获取评论
exports.getPopulateCommentById=function(cid,callback){
ForumComment.findById({_id:cid}).populate({path:'from to', select:'uid nickName icon'}).exec(function(err,c){
if (err) {
console.error(err);
callback(null, null);
} else{
callback(null ,c);
}
});
}; };
\ No newline at end of file
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