Commit 02b9cdd4 authored by 陈志良's avatar 陈志良

Merge branch 'Notice' into SANDBOX

parents 3792d9cc 5cd8c8ae
......@@ -17,7 +17,7 @@ router.get('/commentTips', function(req, res, next) {
if(err){
res.json(returnCode.UNCHECK_ERROR(err));
}else{
res.json(_.assign(result, returnCode.SUCCESS));
res.json(_.assign({data:result}, returnCode.SUCCESS));
}
});
});
......@@ -29,19 +29,19 @@ router.put('/commentTips/:id', function(req, res, next) {
if(err){
res.json(returnCode.UNCHECK_ERROR(err));
}else{
res.json(_.assign(result, returnCode.SUCCESS));
res.json(_.assign({data:result}, returnCode.SUCCESS));
}
});
});
router.put('/commentTips/del', function(req, res, next) {
router.post('/commentTips/del', function(req, res, next) {
var userId = user.getMobileUser(req);
var entcode = req.session.user.ent_code;
commentTips.clear(entcode,userId,function(err,result){
if(err){
res.json(returnCode.UNCHECK_ERROR(err));
}else{
res.json(_.assign(result, returnCode.SUCCESS));
res.json(_.assign({data:result}, returnCode.SUCCESS));
}
});
});
\ No newline at end of file
......@@ -14,7 +14,7 @@ var forumShareLogService = require('../../service/forumShareLogService');
var forumCommentService = require('../../service/forumCommentService');
var forumUserThreadControlService = require('../../service/forumUserThreadControlService');
var forumLimitActionRefService = require('../../service/forumLimitActionRefService');
var commentTips = require('../../utils/commentTips');
var httpService = require('../../service/httpService');
var user = require('../../utils/user');
......@@ -447,8 +447,6 @@ router.post('/thread/:tid/share', function(req, res, next) {
//新增文章评论
router.post('/thread/:tid/comment/add', function(req, res, next) {
var userId = req.session.mobileForumUser.userId;
console.log('!!!!!!!!!!!!!!!!!!!!!!!!!!!');
var data = null;
forumLimitActionRefService.checkLimitActionProhibitionOfSpeech(userId, function(err, isProhibition){
if(err){
console.error(err);
......@@ -508,7 +506,9 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
if (err) {
callback(err, null);
} else {
data = newComment ;
if(user.getMobileUser(req) !== thread.from){//文章的作者不等于评论的作者才增加消息数
commentTips.incrTips(req.session.user.ent_code,thread.from);
}
var comments = thread.comments;
// console.log('=========');
// console.log(comments);
......@@ -522,9 +522,9 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
comments: array
}, function(err, result) {
if (err) {
callback(err, null);
callback(err, newComment);
} else {
callback(null, null);
callback(null, newComment);
}
});
}
......@@ -561,9 +561,17 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
}
}
});
var rs = {};
rs.data = data;
res.json(_.assign(rs, returnCode.SUCCESS));
forumCommentService.getPopulateCommentById(results[0]._id, function(err, c) {
if (err) {
res.json(returnCode.BUSY);
} else {
console.log(c);
var rs = {};
rs.data = c;
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
}
});
......@@ -645,6 +653,9 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
if (err) {
callback(err, null);
} else {
if(user.getMobileUser(req) !== thread.from){//文章的作者不等于评论的作者才增加消息数
commentTips.incrTips(req.session.user.ent_code,thread.from);
}
var comments = thread.comments;
// console.log('=========');
// console.log(comments);
......@@ -803,6 +814,9 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
if (err) {
callback(err, null);
} else {
if(user.getMobileUser(req) !== req.body.to){//被评论人 和评论人不是同一个
commentTips.incrTips(req.session.user.ent_code,req.body.to);
}
var comments = comment.comments;
var array = [];
if (comments && comments.length > 0) {
......@@ -845,23 +859,16 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
}
}
});
// httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'reply');
ForumComment.populate(results[0], {
path: 'from to',
select: 'uid nickName icon comments'
}, function(err, c) {
forumCommentService.getPopulateCommentById(results[0]._id, function(err, c) {
if (err) {
res.json(returnCode.BUSY);
} else {
var rs = {};
rs.data = results[0];
rs.data = c;
res.json(_.assign(rs, returnCode.SUCCESS));
}
});
// res.json(returnCode.SUCCESS);
}
});
}
......@@ -881,7 +888,6 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
}
});
});
//更改评论状态为3(删除)
router.post('/thread/:tid/comment/:cid/disable', function(req, res, next) {
var user_id = user.getMobileUser(req),
......
......@@ -300,4 +300,96 @@ exports.getPopulateCommentById=function(cid,callback){
callback(null ,c);
}
});
};
//我的评论
var countMyComment = function(conditions,callback) {
ForumComment.find(conditions)
.count(conditions, function (err, count) {
if(err){
console.error(err);
callback(err,null);
}else{
callback(null,count);
}
});
};
function populateParentComment(doc, callback){
if (doc && doc._id && doc.level === 2) {
ForumComment.findOne({comments: { $elemMatch : doc._id },status:1}).exec(function(err,c){
if (err) {
console.error(err);
callback(null, null);
} else{
if(c){
callback(null ,c);
}else{
callback(null);
}
}
});
} else{
callback(null, null);
}
}
//我的评论
exports.getMyComment = function(conditions,pageNo,pageSize,callback){
countMyComment(conditions,function(err,count){
if(err){
callback(err);
}else{
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumComment.find(conditions)
.populate({
path: 'thread',
select: '_id content title type level tag'
}).populate({path:'from to', select:'uid nickName icon'}).limit(limit).skip(skip).sort('-created').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err,null);
} else {
var obj={};
obj.total=count;
obj.pageNo=pageNo;
obj.pageSize=pageSize;
obj.items=docs;
if (docs && docs.length > 0) {
var asyncTasks = [];
docs.forEach(function(doc){
asyncTasks.push(function(callback) {
populateParentComment(doc, function(err,c){
if(err){
callback(err,null);
}else{
var newobj = doc.toObject();
newobj.parent = c;
delete newobj.comments;
callback(null,newobj);
}
});
});
});
async.parallel(asyncTasks, function(err, results) {
if (err) {
console.log(err);
callback(null, null);
} else {
obj.items=results;
callback(null,obj);
}
});
}else{
callback(null,obj);
}
}
});
}
});
};
\ 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