Commit da9fb3fb authored by 张淼's avatar 张淼

1

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