Commit d28dc44b authored by 陈家荣's avatar 陈家荣

Merge branch 'newfunc_0620_comment_list' into SANDBOX

parents f24ec691 60b3e06f
......@@ -1642,6 +1642,51 @@ router.get('/thread/:tid/comment/list/all', function(req, res, next) {
}
});
router.get('/thread/:tid/comment/list/allV2', function(req, res, next) {
var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1;
var tid = req.params.tid || null;
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var ent_code = req.session.user.ent_code;
var conditions = {
ent_code: ent_code,
thread: tid,
level: '1'
};
if (tid) {
//获取最新5条评论
forumCommentService.getAllComment_allstatus_v2(conditions, pageNo, pageSize, function(err, results) {
if (err) {
console.log(err);
res.json(returnCode.BUSY);
} else {
//判断是否已经点赞
util.loadLevel(req.session.user.ent_code, results.items, function() {
redisPraiseLog.get(ent_code, user.getMobileUser(req), 'comment', function(error, docs) {
_.forEach(results.items, function(d, i) {
if (results.items[i].toObject) {
results.items[i] = results.items[i].toObject();
}
results.items[i].isPraise = false;
for (var k = docs.length - 1; k >= 0; k--) {
if (results.items[i]._id == docs[k]) {
results.items[i].isPraise = true;
break;
}
};
});
res.json(_.assign(results, returnCode.SUCCESS));
});
});
}
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//不过滤掉已删除的二级评论
router.get('/thread/:tid/comment/list/byFloor/all', function(req, res, next) {
......
......@@ -808,6 +808,40 @@ exports.getAllComment_allstatus = function(conditions, pageNo, pageSize, callbac
});
};
exports.getAllComment_allstatus_v2 = function(conditions, pageNo, pageSize, callback) {
countAll(conditions, function(err, count) {
if (err) {
console.error(err);
callback(err, null);
} else {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumComment.find(conditions,listCommentFields).populate('from','uid mid nickName icon exp honorTitles').populate({
path: 'comments',
options: {
where:{status:1},
limit: 2,
sort: '-_id',
populate:'from to'
}
}).populate('to','uid mid nickName icon exp').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;
callback(null, obj);
}
});
}
});
};
//评论
function populateComment_allstatus(doc, callback) {
if (doc && doc.comments.length > 0) {
......
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