Commit 5a896156 authored by 张淼's avatar 张淼

1

parent c9f35151
......@@ -195,11 +195,15 @@ router.get('/threads/list', function(req, res, next) {
var pageNo = req.query.pageNo || 1;
var pageSize = req.query.pageSize || 10;
var infoId=req.query.infoId;
var tagId=req.query.tagId;
var conditions={
ent_code:req.session.user.ent_code,
};
if(infoId){
conditions.info=infoId;
}
if(tagId){
conditions.tag={$in:[tagId]};
}
forumThreadService.getAllThreadByFid(conditions,pageNo,pageSize,function(err,results){
if(err){
......
......@@ -40,22 +40,20 @@ router.get('/info/:fid/get', function(req, res, next) {
if (fid) {
async.waterfall([
function(callback){
forumInfoService.getInfoById(fid,function(err,info){
if (err) {
//更新浏览数
forumInfoService.updateInfoPvCount(fid,function(err,result){
if(err){
callback(err,null);
res.json(returnCode.BUSY);
} else {
callback(null,info);
}else{
callback(null,null);
}
});
},
function(info,callback){
var pv_count=info.pv_count+1;
info.pv_count=pv_count;
forumInfoService.updateInfoById(fid,{pv_count:pv_count},function(err,result){
if(err){
function(data,callback){
forumInfoService.getInfoById(fid,function(err,info){
if (err) {
callback(err,null);
}else{
} else {
callback(null,info);
}
});
......
......@@ -163,7 +163,7 @@ router.post('/thread/:tid/raise', function(req, res, next) {
var exp=req.session.openUser.exp||0;
//判断是否已经点赞
forumPraiseLogService.queryPraiseLog(tid,null,user.getMobileUser(),function(err,logs){
forumPraiseLogService.queryPraiseLog(tid,null,user.getMobileUser(),1,function(err,logs){
if(err){
res.json(returnCode.BUSY);
}else{
......@@ -219,7 +219,16 @@ router.post('/thread/:tid/raise', function(req, res, next) {
res.json(returnCode.BUSY);
}else{
httpService.sendRequest(req.session.user.ent_code,user.getOpenId(),tid,'raise');
res.json(returnCode.SUCCESS);
forumThreadService.getThreadById(tid,function(err,doc){
if(err){
console.error(err);
res.json(returnCode.BUSY);
}else{
var rs={};
rs.praise_count=doc.praise_count;
res.json(_.assign(rs,returnCode.SUCCESS));
}
});
}
});
}
......@@ -624,7 +633,7 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
var integral=req.session.openUser.integral||0;
var exp=req.session.openUser.exp||0;
//判断是否已经点赞
forumPraiseLogService.queryPraiseLog(tid,cid,user.getMobileUser(),function(err,logs){
forumPraiseLogService.queryPraiseLog(tid,cid,user.getMobileUser(),2,function(err,logs){
if(err){
res.json(returnCode.BUSY);
}else{
......@@ -647,9 +656,9 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
forumCommentService.updatePraiseCount(cid,function(err,results){
if(err){
console.log(err);
res.json(returnCode.BUSY);
callback(err,null);
}else{
res.json(returnCode.SUCCESS);
callback(null,null);
}
});
},
......@@ -676,7 +685,18 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
res.json(returnCode.BUSY);
}else{
httpService.sendRequest(req.session.user.ent_code,user.getOpenId(),tid,'raise');
res.json(returnCode.SUCCESS);
//返回点赞总数
forumCommentService.getCommentById(cid,function(err,doc){
if(err){
console.error(err);
res.json(returnCode.BUSY);
}else{
var rs={};
rs.praise_count=doc.praise_count;
res.json(_.assign(rs,returnCode.SUCCESS));
}
});
}
});
}
......
......@@ -95,7 +95,7 @@ exports.getAllComment= function(conditions,pageNo,pageSize,callback) {
callback(err,null);
}else{
var newobj = doc.toObject();
newobj.comments = c;
newobj.comments = (c==null?[]:c);
callback(null,newobj);
}
});
......
......@@ -88,3 +88,19 @@ exports.getAllByGid= function(conditions,pageNo,pageSize,callback) {
}
});
};
//更新板块浏览数
exports.updateInfoPvCount=function(fid,callback){
ForumInfo.update(
{_id:fid},
{$inc: { pv_count: 1 }},
{w:1,safe:true},
function(err,result){
if(err){
console.error(err);
callback(err,null);
}else{
callback(null,null);
}
});
};
......@@ -15,10 +15,11 @@ exports.createPraiseLog=function(entity,callback){
});
};
exports.queryPraiseLog=function(tid,cid,user,callback){
exports.queryPraiseLog=function(tid,cid,user,type,callback){
var conditions={
user:user,
thread:tid
thread:tid,
type:type
};
if(cid){
conditions.comment=cid;
......
......@@ -73,13 +73,12 @@ exports.getThreadById=function(tid,callback){
}else{
var thread=results[0];
var comments=results[1];
// console.log(comments);
// console.log(thread);
var threadObj=thread.toObject();
threadObj.comments=comments;
callback(null,threadObj);
}
});
};
//根据ID更新文章
......
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