Commit aa24a261 authored by strong's avatar strong

Merge branch 'SANDBOX'

parents 183b5bab fb4ea06a
......@@ -1027,6 +1027,37 @@ router.get('/thread/:tid/exportComments', function(req, res, next) {
ent_code = req.query.ent_code || null;
then(function(cont){
if(tid && ent_code){
then.parallel([
function(cont2){
forumThreadService.getThreadByIdSimple({_id:tid},function(err,doc){
forumPraiseLogService.queryPraiseLogV2({ent_code:ent_code,thread:tid,type:1}, function(err, results){
if(err){
cont2(err);
}else{
if(results && results.length>0){
var praiseNames = [];
var praiseOpenIds = [];
_.forEach(results, function(e) {
if(e.user){
praiseNames.push(e.user.nickName || '游客');
praiseOpenIds.push(e.user.uid);
}
});
doc = doc.toObject();
doc.praiseNames = praiseNames.toString();
doc.praiseOpenIds = praiseOpenIds.toString();
cont2(null,doc);
}else{
doc = doc.toObject();
doc.praiseNames = '';
doc.praiseOpenIds = '';
cont2(null,doc);
}
}
});
});
},
function(cont2){
var conditions = {
ent_code: ent_code,
thread: tid,
......@@ -1034,12 +1065,19 @@ router.get('/thread/:tid/exportComments', function(req, res, next) {
};
//查询所有评论
forumCommentService.getAllCommentByThread(conditions, function(err, docs) {
cont(err,docs);
cont2(err,docs);
});
}
]).then(function(cont2,datas){
cont(null,datas[0],datas[1]);
}).fail(function(cont2,err){
cont(err);
});
}else{
cont('params error');
}
}).then(function(cont,comments){
}).then(function(cont,thread,comments){
//获取点赞信息
var asyncTasks = [];
_.forEach(comments, function(e) {
......@@ -1052,7 +1090,6 @@ router.get('/thread/:tid/exportComments', function(req, res, next) {
}
forumPraiseLogService.queryPraiseLogV2(conditions, function(err, results){
if(err){
console.log(err);
cb(null, e);
}else{
if(results){
......@@ -1064,9 +1101,8 @@ router.get('/thread/:tid/exportComments', function(req, res, next) {
praiseOpenIds.push(e2.user.uid);
}
});
e.praiseNames = praiseNames;
e.praiseOpenIds = praiseOpenIds;
e.praiseCount = results.length;
e.praiseNames = praiseNames.toString();
e.praiseOpenIds = praiseOpenIds.toString();
}
cb(null, e);
}
......@@ -1074,23 +1110,35 @@ router.get('/thread/:tid/exportComments', function(req, res, next) {
});
});
async.parallel(asyncTasks, function(err, items) {
cont(err,items);
cont(err,thread,items);
});
}).then(function(cont,items){
}).then(function(cont,thread,items){
//表头
var conf = {};
var conf = {},
rows = [];
conf.cols = [
{caption:'楼层', type:'string'},
{caption:'发布时间', type:'Date'},
{caption:'帖子标题', type:'string'},
{caption:'发布时间', type:'string'},
{caption:'发帖人', type:'string'},
{caption:'openId', type:'string'},
{caption:'会员名', type:'string'},
{caption:'内容', type:'string'},
{caption:'点赞数', type:'number'},
{caption:'评论数', type:'number'},
{caption:'转发数', type:'string'},
{caption:'点赞数', type:'string'},
{caption:'点赞人', type:'string'},
{caption:'点赞人openId', type:'string'}
{caption:'点赞点赞人openId', type:'string'}
];
//内容
var rows = [];
//文章内容
var t_title = thread.title == '发话题'?'无标题':thread.title,
t_time = date_format(thread.created),
t_from = thread.from?thread.from.nickName:'游客',
t_from_openId = thread.from?thread.from.uid:'',
t_praiseNames = thread.praiseNames,
t_praiseOpenIds = thread.praiseOpenIds;
rows.push([t_title,t_time,t_from,t_from_openId,thread.content,thread.comment_count,thread.share_count.toString(),thread.praise_count.toString(),t_praiseNames,t_praiseOpenIds]);
rows.push(['','','','','','','','','','']);
rows.push(['楼层','发布时间','openId','会员名', '内容','点赞数','点赞人','点赞人openId','','']);
for (var i = items.length - 1; i >= 0; i--) {
var comment = items[i];
var floor = comment.floor,
......@@ -1110,9 +1158,8 @@ router.get('/thread/:tid/exportComments', function(req, res, next) {
nickName = comment.from.nickName || '游客';
}
var this_row = [floor + '', time,openId, nickName, content, praiseCount, praiseNames,praiseOpenIds];
var this_row = [floor + '', time,openId, nickName, content, praiseCount, praiseNames,praiseOpenIds,null,null];
rows.push(this_row);
if(comment.comments.length > 0){
for (var k = 0; k < comment.comments.length; k++) {
var sub_comment = comment.comments[k];
......@@ -1129,7 +1176,7 @@ router.get('/thread/:tid/exportComments', function(req, res, next) {
if(sub_comment.to){
to = sub_comment.to.nickName || '游客';
}
var this_row = [nickName + ' 回复 ' + to, time,openId, nickName, content, 0, null,null];
var this_row = [nickName + ' 回复 ' + to, time,openId, nickName, content, 0, null,null,null,null];
rows.push(this_row);
};
}
......
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