Commit 78d27df4 authored by 刘文胜's avatar 刘文胜

根据查询条件获取帖子总数,帖子数,用户发帖数,帖子加精数

parent 8230d29a
...@@ -134,3 +134,248 @@ router.get('/threadManagement/threads/list', function(req, res, next) { ...@@ -134,3 +134,248 @@ router.get('/threadManagement/threads/list', function(req, res, next) {
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, sortBy, callback); forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, sortBy, callback);
} }
}); });
//获取帖子总数,帖子数,用户发帖数,帖子加精数
router.get('/threadManagement/threads/statistics', function(req, res, next) {
var pageNo = 1;
var pageSize = 0;
var infoId = req.query.infoId;
var tagId = req.query.tagId;
var pid = req.query.pid;//父文章id
var content = req.query.content;//标题 或 内容
var type = req.query.type;//1普通文章,话题,照片墙
var nickName = req.query.nickName;
var mid = req.query.mid;
var begin_time=req.query.begin_time;
var end_time=req.query.end_time;
var tab = req.query.tab;//全部,官方贴,推荐贴,置顶帖,加精贴,活动贴,屏蔽贴
var sortBy = {//默认排序
created:-1
};
var conditions = {
ent_code: req.session.user.ent_code,
level: 1,
status: {
$ne: 3
}
};
if (infoId) {
conditions.info = infoId;
}
if (tagId) {
conditions.tag = {
$in: [tagId]
};
}
if (pid) {
conditions.pid = pid;
conditions.level = 2;
}
if (content) {
conditions.$or = [
{
title:{
$regex: content,
$options: 'i'
}
},
{
content:{
$regex: content,
$options: 'i'
}
}
];
}
if (type) {
conditions.type = Number(type);
}
if(tab){
if(tab === 'admin'){//官方贴
conditions.isPublishByBg = 1;
}
else if(tab === 'new_recommend'){//推荐贴
conditions.new_recommend = 1;
}
else if(tab === 'top'){//置顶贴
conditions.top = 1;
}
else if(tab === 'recommend'){//加精贴
conditions.recommend = 1;
}
else if(tab === 'event'){//活动贴
conditions.isEvent = 1;
}
else if(tab === 'closed'){//屏蔽贴
conditions.status = 0;
}
}
if(begin_time && end_time){
conditions.created = {$gte : begin_time, $lte : end_time};
} else if(end_time){
conditions.created = {$lte : end_time};
} else if(begin_time){
conditions.created = {$gte : begin_time};
}
async.parallel([function(cb){//获取帖子总数
var _conditions = {
ent_code: req.session.user.ent_code,
status: {
$ne: 3
}
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_total',count || 0]);
});
},function(cb){//获取帖子数
var _conditions = _.assign({}, conditions);
if (mid) {//查询对应用户的文章
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_total',count || 0]);
});
}
});
} else if (nickName) {
forumUserService.searchMembersByNickName(nickName, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_total',count || 0]);
});
}
});
} else {
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_total',count || 0]);
});
}
},function(cb){//获取用户发帖数
var _conditions = _.assign({isPublishByBg:{$ne:1}}, conditions);
if (mid) {//查询对应用户的文章
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_user_publish',count || 0]);
});
}
});
} else if (nickName) {
forumUserService.searchMembersByNickName(nickName, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_user_publish',count || 0]);
});
}
});
} else {
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_user_publish',count || 0]);
});
}
},function(cb){//获取加精帖子数
var _conditions = _.assign({recommend:1}, conditions);
if (mid) {//查询对应用户的文章
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_recommend',count || 0]);
});
}
});
} else if (nickName) {
forumUserService.searchMembersByNickName(nickName, function(err, users) {
if (err) {
cb(err, null);
} else {
var user_ids = [];
if(users){
_.forEach(users,function(user){
user_ids.push(user._id);
});
}
_conditions.from = {
"$in" : user_ids
};
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_recommend',count || 0]);
});
}
});
} else {
ForumThread.count(_conditions, function(err, count) {
cb(err,['thread_search_recommend',count || 0]);
});
}
}],function(err,results){
if(err){
console.log(err);
return res.json(returnCode.BUSY);
}
// 数组转对象_.zipObject([[‘fred‘, 30], [‘barney‘, 40]]);→ { ‘fred‘: 30, ‘barney‘: 40 }
res.json(_.assign({
data:_.zipObject(results)
}, returnCode.SUCCESS));
});
});
\ 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