Commit 7c887285 authored by 刘文胜's avatar 刘文胜

升级lodash到3.10 帖子管理接口 新增批量屏蔽,删除帖子(查询结果), 帖子评论批量屏蔽,删除(查询结果)

parent 40607f9e
......@@ -141,6 +141,332 @@ router.get('/threadManagement/threads/list', function(req, res, next) {
}
});
//删除查询结果的所有帖子
router.post('/threadManagement/threads/list/deleteAll', function(req, res, next) {
var infoId = req.body.infoId;
var tagId = req.body.tagId;
var pid = req.body.pid;//父文章id
var content = req.body.content;//标题 或 内容
var type = req.body.type;//1普通文章,话题,照片墙
var nickName = req.body.nickName;
var mid = req.body.mid;
var begin_time=req.body.begin_time;
var end_time=req.body.end_time;
var tab = req.body.tab;//全部,官方贴,推荐贴,置顶帖,加精贴,活动贴,屏蔽贴
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};
}
var callback = function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign({
data:result
}, returnCode.SUCCESS));
}
};
var deleteAll= function(condition,callback){
ForumThread.find(conditions).select('_id').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
} else {
var _tasks=[];
_.forEach(docs,function(doc){
_tasks.push(function(cb){
forumThreadService.logicDeleteThreadById(doc._id, function(err) {
if (err) {
cb(err, null);
} else {
forumAboutMEService.updateThreadStatus(doc._id, 3);
cb(null, true);
}
});
});
});
var chunks=_.chunk(_tasks, 100);
var tasks = [];
_.forEach(chunks,function(chunk){
tasks.push(function(cb){
async.parallel(chunk,function(err){
cb(err, true);
});
});
});
async.series(tasks,function(err){
callback(err, true);
});
}
});
};
if (mid) {
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
console.error(err);
callback(err, null);
} else {
//查询对应用户的文章
var user_ids = [];
for(var i in users){
user_ids.push(users[i]._id);
}
conditions.from = {
"$in" : user_ids
};
deleteAll(conditions,callback);
}
});
} else if (nickName) {
//查询到用户
forumUserService.searchMembersByNickName(nickName, function(err, users) {
if (err) {
console.error(err);
callback(err, null);
} else {
//查询对应用户的文章
var user_ids = [];
for(var i in users){
user_ids.push(users[i]._id);
}
conditions.from = {
"$in" : user_ids
};
deleteAll(conditions,callback);
}
});
} else {
deleteAll(conditions,callback);
}
});
//屏蔽查询结果的所有帖子
router.post('/threadManagement/threads/list/closeAll', function(req, res, next) {
var infoId = req.body.infoId;
var tagId = req.body.tagId;
var pid = req.body.pid;//父文章id
var content = req.body.content;//标题 或 内容
var type = req.body.type;//1普通文章,话题,照片墙
var nickName = req.body.nickName;
var mid = req.body.mid;
var begin_time=req.body.begin_time;
var end_time=req.body.end_time;
var tab = req.body.tab;//全部,官方贴,推荐贴,置顶帖,加精贴,活动贴,屏蔽贴
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};
}
var callback = function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign({
data:result
}, returnCode.SUCCESS));
}
};
var closeAll= function(condition,callback){
ForumThread.find(conditions).select('_id').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
} else {
var _tasks=[];
_.forEach(docs,function(doc){
_tasks.push(function(cb){
forumThreadService.updateThreadById(doc._id, {status:0}, function(err) {
if (err) {
cb(err, null);
} else {
forumAboutMEService.updateThreadStatus(doc._id, 0);
cb(null, true);
}
});
});
});
var chunks=_.chunk(_tasks, 100);
var tasks = [];
_.forEach(chunks,function(chunk){
tasks.push(function(cb){
async.parallel(chunk,function(err){
cb(err, true);
});
});
});
async.series(tasks,function(err){
callback(err, true);
});
}
});
};
if (mid) {
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
console.error(err);
callback(err, null);
} else {
//查询对应用户的文章
var user_ids = [];
for(var i in users){
user_ids.push(users[i]._id);
}
conditions.from = {
"$in" : user_ids
};
closeAll(conditions,callback);
}
});
} else if (nickName) {
//查询到用户
forumUserService.searchMembersByNickName(nickName, function(err, users) {
if (err) {
console.error(err);
callback(err, null);
} else {
//查询对应用户的文章
var user_ids = [];
for(var i in users){
user_ids.push(users[i]._id);
}
conditions.from = {
"$in" : user_ids
};
closeAll(conditions,callback);
}
});
} else {
closeAll(conditions,callback);
}
});
//获取帖子总数,帖子数,用户发帖数,帖子加精数
router.get('/threadManagement/threads/statistics', function(req, res, next) {
var infoId = req.query.infoId;
......@@ -576,7 +902,7 @@ router.get('/threadManagement/threads/:tid/comment/search', function(req, res, n
var conditions = {
ent_code: req.session.user.ent_code,
thread: tid,
level:1,
level:1
};
if (content) {
conditions.content = {
......@@ -617,6 +943,186 @@ router.get('/threadManagement/threads/:tid/comment/search', function(req, res, n
}
});
//删除帖子的评论(查询结果)
router.post('/threadManagement/threads/:tid/comment/search/deleteAll', function(req, res, next) {
var tid = req.params.tid || null,
mid = req.query.mid,
floor_start = req.query.floor_start,
floor_end = req.query.floor_end,
content = req.query.content || '';
var ent_code = req.session.user.ent_code;
var status = 2;//删除状态为2
var conditions = {
ent_code: ent_code,
thread: tid,
level:1
};
if (content) {
conditions.content = {
$regex: content,
$options: 'i'
};
}
if(floor_start){
conditions.floor = {
$gte:floor_start
};
}
if(floor_end){
conditions.floor = {
$lte:floor_end
};
}
var callback = function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign({
data:result
}, returnCode.SUCCESS));
}
};
var deleteAll= function(condition,callback){
ForumComment.find(conditions).select('_id').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
} else {
var ids=[];
_.forEach(docs,function(doc){
ids.push(doc._id);
});
var chunks=_.chunk(ids, 100);
var tasks = [];
_.forEach(chunks,function(chunk){
tasks.push(function(cb){
batchUpdateCommentStatus(ent_code,chunk,status,function(err,result){
cb(err,result);
});
});
});
async.series(tasks,function(err){
callback(err, true);
});
}
});
};
if (tid && mid) {
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
console.error(err);
callback(err, null);
} else {
//查询对应用户
var user_ids = [];
for (var i in users) {
user_ids.push(users[i]._id);
}
conditions.from = {
$in: user_ids
}
deleteAll(conditions,callback);
}
});
} else if(tid){
deleteAll(conditions,callback);
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//屏蔽帖子的评论(查询结果)
router.post('/threadManagement/threads/:tid/comment/search/closeAll', function(req, res, next) {
var tid = req.params.tid || null,
mid = req.query.mid,
floor_start = req.query.floor_start,
floor_end = req.query.floor_end,
content = req.query.content || '';
var ent_code = req.session.user.ent_code;
var status = 0;//屏蔽的状态为0
var conditions = {
ent_code: ent_code,
thread: tid,
level:1
};
if (content) {
conditions.content = {
$regex: content,
$options: 'i'
};
}
if(floor_start){
conditions.floor = {
$gte:floor_start
};
}
if(floor_end){
conditions.floor = {
$lte:floor_end
};
}
var callback = function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign({
data:result
}, returnCode.SUCCESS));
}
};
var closeAll= function(condition,callback){
ForumComment.find(conditions).select('_id').exec(function(err, docs) {
if (err) {
console.error(err);
callback(err, null);
} else {
var ids=[];
_.forEach(docs,function(doc){
ids.push(doc._id);
});
var chunks=_.chunk(ids, 100);
var tasks = [];
_.forEach(chunks,function(chunk){
tasks.push(function(cb){
batchUpdateCommentStatus(ent_code,chunk,status,function(err,result){
cb(err,result);
});
});
});
async.series(tasks,function(err){
callback(err, true);
});
}
});
};
if (tid && mid) {
forumUserService.searchMembersByMid(mid, function(err, users) {
if (err) {
console.error(err);
callback(err, null);
} else {
//查询对应用户
var user_ids = [];
for (var i in users) {
user_ids.push(users[i]._id);
}
conditions.from = {
$in: user_ids
}
closeAll(conditions,callback);
}
});
} else if(tid){
closeAll(conditions,callback);
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//查询帖子的收藏数
router.get('/threadManagement/threads/:tid/collects', function(req, res, next) {
var tid = req.params.tid || null;
......
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