Commit da9fb3fb authored by 张淼's avatar 张淼

1

parent a7287daf
...@@ -47,7 +47,7 @@ exports.getThreadById=function(tid,callback){ ...@@ -47,7 +47,7 @@ exports.getThreadById=function(tid,callback){
thread:tid, thread:tid,
level:'1' level:'1'
}; };
//获取最新5条评论 //获取最新10条评论
forumCommentService.getAllComment(conditions,1,10,function(err,results){ forumCommentService.getAllComment(conditions,1,10,function(err,results){
if(err){ if(err){
console.log(err); console.log(err);
...@@ -58,30 +58,65 @@ exports.getThreadById=function(tid,callback){ ...@@ -58,30 +58,65 @@ exports.getThreadById=function(tid,callback){
}); });
}, },
function(cb){ function(cb){
//获取话题子文章列表
var conditions={ var conditions={
ent_code:req.session.user.ent_code, pid:tid,
pdi:tid type:2
}; };
getAllThreadByFidHelp(conditions,1,10,function(err,threads){ getAllThreadByFidHelp(conditions,1,10,null,function(err,threads){
if(err){ if(err){
console.error(err); console.error(err);
callback(err,null); cb(err,null);
}else{ }else{
callback(null,threads); cb(null,threads);
} }
}); });
} },
function(cb){
//获取照片墙最新文章列表
var conditions={
pid:tid,
type:3
};
getAllThreadByFidHelp(conditions,1,10,'-created',function(err,threads){
if(err){
console.error(err);
cb(err,null);
}else{
cb(null,threads);
}
});
},
function(cb){
//获取照片墙最热文章列表
var conditions={
pid:tid,
type:3
};
getAllThreadByFidHelp(conditions,1,10,'-praise_count',function(err,threads){
if(err){
console.error(err);
cb(err,null);
}else{
cb(null,threads);
}
});
},
],function(err,results){ ],function(err,results){
if(err){ if(err){
callback(err,null); callback(err,null);
}else{ }else{
var thread=results[0]; var thread=results[0];
var comments=results[1]; var comments=results[1];
var subThreads=results[2]; var subThreads=results[2]||[];//话题子文章列表
// console.log(thread); var latestPhotos=results[3]||[];//最新照片墙列表
var hotPhotos=results[4]||[];//最热照片墙列表
var threadObj=thread.toObject(); var threadObj=thread.toObject();
threadObj.comments=comments; threadObj.comments=comments;
threadObj.subThreads=subThreads; threadObj.subThreads=subThreads;
threadObj.latestPhotos=latestPhotos;
threadObj.hotPhotos=hotPhotos;
callback(null,threadObj); callback(null,threadObj);
} }
}); });
...@@ -202,7 +237,7 @@ exports.getAllCountByFid=function(conditions,callback){ ...@@ -202,7 +237,7 @@ exports.getAllCountByFid=function(conditions,callback){
countAllByFid(conditions,callback); countAllByFid(conditions,callback);
} }
function getAllThreadByFidHelp(conditions,pageNo,pageSize,callback){ function getAllThreadByFidHelp(conditions,pageNo,pageSize,sort,callback){
countAllByFid(conditions,function(err,count){ countAllByFid(conditions,function(err,count){
if(err){ if(err){
console.error(err); console.error(err);
...@@ -210,8 +245,11 @@ function getAllThreadByFidHelp(conditions,pageNo,pageSize,callback){ ...@@ -210,8 +245,11 @@ function getAllThreadByFidHelp(conditions,pageNo,pageSize,callback){
}else{ }else{
var skip = (pageNo - 1) * pageSize; var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip); var limit = count - skip > pageSize ? pageSize : (count - skip);
var sortBy='-top -created';
ForumThread.find(conditions).populate('from').populate('info').populate({path:'tag'}).populate({path:'comments',options:{limit:5,sort:'-created'}, select:'from to created content'}).limit(limit).skip(skip).sort('-top -created').exec(function(err, docs) { if(sort){
sortBy=sort;
}
ForumThread.find(conditions).populate('from').populate('info').populate({path:'tag'}).populate({path:'comments',options:{limit:5,sort:'-created'}, select:'from to created content'}).limit(limit).skip(skip).sort(sortBy).exec(function(err, docs) {
if (err) { if (err) {
console.error(err); console.error(err);
callback(err,null); callback(err,null);
...@@ -231,7 +269,7 @@ function getAllThreadByFidHelp(conditions,pageNo,pageSize,callback){ ...@@ -231,7 +269,7 @@ function getAllThreadByFidHelp(conditions,pageNo,pageSize,callback){
}); });
async.parallel(asyncTasks, function(err, results) { async.parallel(asyncTasks, function(err, results) {
if (err) { if (err) {
console.log(err); console.error(err);
callback(null, null); callback(null, null);
} else { } else {
callback(null,obj); callback(null,obj);
...@@ -248,8 +286,8 @@ function getAllThreadByFidHelp(conditions,pageNo,pageSize,callback){ ...@@ -248,8 +286,8 @@ function getAllThreadByFidHelp(conditions,pageNo,pageSize,callback){
} }
//获取全部列表数据 //获取全部列表数据
exports.getAllThreadByFid= function(conditions,pageNo,pageSize,callback) { exports.getAllThreadByFid= function(conditions,pageNo,pageSize,sort,callback) {
getAllThreadByFidHelp(conditions,pageNo,pageSize,callback); getAllThreadByFidHelp(conditions,pageNo,pageSize,sort,callback);
}; };
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶) //根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
......
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