Commit 742dca0d authored by 陈家荣's avatar 陈家荣

Merge branch 'development' of git.wxpai.cn:scrmgroup/pisns-forum-api into development

parents 065902a8 50bc31e2
...@@ -44,6 +44,18 @@ router.get('/complaints/getComplaints', function(req, res, next) { ...@@ -44,6 +44,18 @@ router.get('/complaints/getComplaints', function(req, res, next) {
}); });
}); });
//在获取举报详细
router.get('/complaints/:complaintid/detail', function(req, res, next) {
var complaintid = req.params.complaintid;
ForumComplaintService.getDetailByComplaintid(complaintid,function(err,result){
if(err){
res.json(returnCode.BUSY);
}else{
res.json(_.assign({result:result}, returnCode.SUCCESS));
}
});
});
//删除黑名单根据id //删除黑名单根据id
router.get('/complaints/:id/del', function(req, res, next) { router.get('/complaints/:id/del', function(req, res, next) {
var id = req.params.id; var id = req.params.id;
......
...@@ -30,7 +30,9 @@ router.post('/thread/create', function(req, res, next) { ...@@ -30,7 +30,9 @@ router.post('/thread/create', function(req, res, next) {
var rs = {}; var rs = {};
req.body.ent_code = req.session.user.ent_code; req.body.ent_code = req.session.user.ent_code;
if(!req.body.share){
delete req.body.share;
}
var uid = req.session.user.id; var uid = req.session.user.id;
// var uid='12345'; // var uid='12345';
if (req.body.pid) { if (req.body.pid) {
...@@ -81,7 +83,9 @@ router.post('/thread/create', function(req, res, next) { ...@@ -81,7 +83,9 @@ router.post('/thread/create', function(req, res, next) {
} }
}); });
} }
}); } } });
}
}
}); });
}); });
...@@ -113,9 +117,20 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -113,9 +117,20 @@ router.get('/thread/:tid/get', function(req, res, next) {
if (err) { if (err) {
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
rs.data = results[0];
rs.tagList = results[1]; if (results[0].pid) {
res.json(_.assign(rs, returnCode.SUCCESS)); forumThreadService.getById(results[0].pid, function(err, parentThread) {
rs.data = results[0];
rs.tagList = results[1];
rs.parentThread = parentThread;
res.json(_.assign(rs, returnCode.SUCCESS));
});
} else {
rs.data = results[0];
rs.tagList = results[1];
res.json(_.assign(rs, returnCode.SUCCESS));
}
} }
}); });
} else { } else {
...@@ -210,6 +225,7 @@ router.get('/threads/list', function(req, res, next) { ...@@ -210,6 +225,7 @@ router.get('/threads/list', function(req, res, next) {
var infoId = req.query.infoId; var infoId = req.query.infoId;
var tagId = req.query.tagId; var tagId = req.query.tagId;
var pid = req.query.pid; var pid = req.query.pid;
var content = req.query.content;
var conditions = { var conditions = {
ent_code: req.session.user.ent_code, ent_code: req.session.user.ent_code,
level: 1 level: 1
...@@ -228,12 +244,28 @@ router.get('/threads/list', function(req, res, next) { ...@@ -228,12 +244,28 @@ router.get('/threads/list', function(req, res, next) {
conditions.level = 2; conditions.level = 2;
} }
if (content) {
conditions.content = {
$regex: content,
$options: 'i'
}
}
forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, null, function(err, results) { forumThreadService.getAllThreadByFid(conditions, pageNo, pageSize, null, function(err, results) {
if (err) { if (err) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
} else { } else {
res.json(_.assign(results, returnCode.SUCCESS));
if (results.items.length>0 &&results.items[0].pid) {
forumThreadService.getById(results.items[0].pid, function(err, parentThread) {
res.json(_.assign({
parentThread: parentThread
}, results, returnCode.SUCCESS));
});
} else {
res.json(_.assign(results, returnCode.SUCCESS));
}
} }
}); });
}); });
...@@ -364,7 +396,14 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) { ...@@ -364,7 +396,14 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
}); });
// 更新评论对象 // 更新评论对象
// result.comment_count+=1; // 回复评论+1 // result.comment_count+=1; // 回复评论+1
forumCommentService.updateCommentById(cid, {$push:{comments:replayComment_id},$inc:{comment_count:1}}, function(err, result) { forumCommentService.updateCommentById(cid, {
$push: {
comments: replayComment_id
},
$inc: {
comment_count: 1
}
}, function(err, result) {
if (err) { if (err) {
console.error(err); console.error(err);
res.json(returnCode.BUSY); res.json(returnCode.BUSY);
...@@ -473,7 +512,7 @@ router.post('/thread/comment/add', function(req, res, next) { ...@@ -473,7 +512,7 @@ router.post('/thread/comment/add', function(req, res, next) {
res.json(returnCode.WRONG_PARAM); res.json(returnCode.WRONG_PARAM);
} }
// 测试环境 // 测试环境
// entity.from = '55015675868b65a028187c49'; // entity.from = '55015675868b65a028187c49';
......
...@@ -19,28 +19,54 @@ exports.getForumComplaintPageList=function(condition,pageNo,pageSize,callback){ ...@@ -19,28 +19,54 @@ exports.getForumComplaintPageList=function(condition,pageNo,pageSize,callback){
var skip = (pageNo - 1) * pageSize; var skip = (pageNo - 1) * pageSize;
skip = skip >0 ? skip :0; skip = skip >0 ? skip :0;
var limit = pageSize; var limit = pageSize;
ForumComplaint.find(_condition) ForumComplaint.distinct('complaintId',_condition)
.populate('complaintTo').populate('complaintFrom').limit(limit) .exec(function (err, complaints) {
.skip(skip).sort('-created').exec(function(err,complaints){
if(err){ if(err){
console.error(err); console.error(err);
return callback && callback(err,null); return callback && callback(err,null);
} }
obj.total=count; if(!complaints || complaints.length<=0){
return callback && callback(null,obj);
}
obj.total=count;
obj.pageNo=pageNo; obj.pageNo=pageNo;
obj.pageSize=pageSize; obj.pageSize=pageSize;
obj.items=complaints; var real_items= complaints.slice(skip,skip+limit);
return callback && callback(null,obj); var tasks = [];
var pushTask = function(i){
var con={complaintId:real_items[i]};
tasks.push(function(cb){
ForumComplaint.find(con)
.populate('complaintTo').exec(function(err,complaints){
if(!err && complaints && complaints.length>0){
var complaint=complaints[0];
if(complaint &&
'function' === typeof complaint.toObject){
complaint = complaint.toObject();
}
complaint.sum=complaints.length;
cb(null,complaint);
}
});
});
};
for(var i=0,len=real_items.length;i<len;i=i+1){
pushTask(i);
}
async.parallel(tasks,function(err, results) {
obj.items=results || [];
return callback && callback(null,obj);
});
}); });
}; };
ForumComplaint.count(_condition, function (err, count) { ForumComplaint.distinct('complaintId',_condition).exec(function (err, result) {
if(err){ if(err){
return callback && callback(err,null); return callback && callback(err,null);
} }
if(!!!count){ if(!result || result.length<=0){
return callback && callback(null,obj); return callback && callback(null,obj);
} }
return search(count); return search(result.length);
}); });
}; };
...@@ -142,4 +168,15 @@ exports.removeComplaintById = function(id,callback){ ...@@ -142,4 +168,15 @@ exports.removeComplaintById = function(id,callback){
} }
return callback && callback(null,result); return callback && callback(null,result);
}); });
} };
\ No newline at end of file
exports.getDetailByComplaintid = function(complaintid,callback){
ForumComplaint.find({complaintId:complaintid})
.populate('complaintTo').populate('complaintFrom')
.exec(function(err,complaints){
if (err) {
return callback && callback(err,null);
}
return callback && callback(null,complaints);
});
};
\ 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