Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
P
pisns-forum-api
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
scrmGroup
pisns-forum-api
Commits
aa700ba2
Commit
aa700ba2
authored
Oct 10, 2015
by
陈志良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
评论下载
parent
e2c8aa70
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
135 additions
and
123 deletions
+135
-123
forumThread.js
app/controllers/admin/forumThread.js
+135
-123
No files found.
app/controllers/admin/forumThread.js
View file @
aa700ba2
'use strict'
;
//插件
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
),
then
=
require
(
'thenjs'
),
moment
=
require
(
'moment'
),
nodeExcel
=
require
(
'excel-export'
);
var
mongoose
=
require
(
'mongoose'
);
nodeExcel
=
require
(
'excel-export'
),
mongoose
=
require
(
'mongoose'
),
async
=
require
(
'async'
);
//模型
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
),
ForumPVLog
=
mongoose
.
model
(
'ForumPVLog'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
);
var
forumPraiseLogService
=
require
(
'../../service/forumPraiseLogService'
);
var
forumShareLogService
=
require
(
'../../service/forumShareLogService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumTagService
=
require
(
'../../service/forumTagService'
);
var
forumUserService
=
require
(
'../../service/forumUserService'
);
//服务
var
forumThreadService
=
require
(
'../../service/forumThreadService'
),
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
),
forumPraiseLogService
=
require
(
'../../service/forumPraiseLogService'
),
forumShareLogService
=
require
(
'../../service/forumShareLogService'
),
forumCommentService
=
require
(
'../../service/forumCommentService'
),
forumTagService
=
require
(
'../../service/forumTagService'
),
forumUserService
=
require
(
'../../service/forumUserService'
),
// var forumLimitActionRefService = require('../../service/forumLimitActionRefService');
var
forumLimitOperationService
=
require
(
'../../service/forumLimitOperationService'
);
var
forumAboutMEService
=
require
(
'../../service/forumAboutMEService'
);
var
httpService
=
require
(
'../../service/httpService'
);
forumLimitOperationService
=
require
(
'../../service/forumLimitOperationService'
),
forumAboutMEService
=
require
(
'../../service/forumAboutMEService'
),
httpService
=
require
(
'../../service/httpService'
);
var
userUtil
=
require
(
'../../utils/user'
);
var
async
=
require
(
'async'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
...
...
@@ -1020,121 +1023,130 @@ router.get('/thread/:tid/spreadchain', function(req, res, next) {
// 导出文章评论内容
router
.
get
(
'/thread/:tid/exportComments'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
ent_code
=
req
.
query
.
ent_code
||
null
;
if
(
tid
&&
ent_code
){
var
conditions
=
{
ent_code
:
ent_code
,
thread
:
tid
,
level
:
1
};
//查询所有评论
forumCommentService
.
getAllCommentByThread
(
conditions
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//查询每个一级评论点赞
var
asyncTasks
=
[];
_
.
forEach
(
results
,
function
(
e
)
{
asyncTasks
.
push
(
function
(
cb
)
{
if
(
e
.
level
!=
1
)
{
cb
(
null
,
e
);
}
else
{
var
con
=
{
ent_code
:
ent_code
,
thread
:
tid
,
type
:
2
,
comment
:
e
.
_id
}
forumPraiseLogService
.
queryPraiseLogV2
(
con
,
function
(
err
,
results
){
if
(
err
){
console
.
log
(
err
);
cb
(
null
,
e
);
}
else
{
if
(
results
){
var
praiseNames
=
[];
var
praiseOpenIds
=
[];
_
.
forEach
(
results
,
function
(
e2
)
{
praiseNames
.
push
(
e2
.
user
.
nickName
||
'游客'
);
praiseOpenIds
.
push
(
e2
.
user
.
uid
);
});
e
.
praiseNames
=
praiseNames
;
e
.
praiseOpenIds
=
praiseOpenIds
;
e
.
praiseCount
=
results
.
length
;
}
cb
(
null
,
e
);
var
tid
=
req
.
params
.
tid
||
null
,
ent_code
=
req
.
query
.
ent_code
||
null
;
then
(
function
(
cont
){
if
(
tid
&&
ent_code
){
var
conditions
=
{
ent_code
:
ent_code
,
thread
:
tid
,
level
:
1
};
//查询所有评论
forumCommentService
.
getAllCommentByThread
(
conditions
,
function
(
err
,
docs
)
{
cont
(
err
,
docs
);
});
}
else
{
cont
(
'params error'
);
}
}).
then
(
function
(
cont
,
comments
){
//获取点赞信息
var
asyncTasks
=
[];
_
.
forEach
(
comments
,
function
(
e
)
{
asyncTasks
.
push
(
function
(
cb
)
{
var
conditions
=
{
ent_code
:
ent_code
,
thread
:
tid
,
type
:
2
,
comment
:
e
.
_id
}
forumPraiseLogService
.
queryPraiseLogV2
(
conditions
,
function
(
err
,
results
){
if
(
err
){
console
.
log
(
err
);
cb
(
null
,
e
);
}
else
{
if
(
results
){
var
praiseNames
=
[];
var
praiseOpenIds
=
[];
_
.
forEach
(
results
,
function
(
e2
)
{
if
(
e2
.
user
){
praiseNames
.
push
(
e2
.
user
.
nickName
||
'游客'
);
praiseOpenIds
.
push
(
e2
.
user
.
uid
);
}
});
e
.
praiseNames
=
praiseNames
;
e
.
praiseOpenIds
=
praiseOpenIds
;
e
.
praiseCount
=
results
.
length
;
}
});
});
async
.
parallel
(
asyncTasks
,
function
(
err
,
items
)
{
//表头
var
conf
=
{};
conf
.
cols
=
[
{
caption
:
'楼层'
,
type
:
'string'
},
{
caption
:
'发布时间'
,
type
:
'Date'
},
{
caption
:
'openId'
,
type
:
'string'
},
{
caption
:
'会员名'
,
type
:
'string'
},
{
caption
:
'内容'
,
type
:
'string'
},
{
caption
:
'点赞数'
,
type
:
'number'
},
{
caption
:
'点赞人'
,
type
:
'string'
},
{
caption
:
'点赞人openId'
,
type
:
'string'
}
];
//内容
var
rows
=
[];
for
(
var
i
=
items
.
length
-
1
;
i
>=
0
;
i
--
)
{
var
comment
=
items
[
i
];
var
floor
=
comment
.
floor
,
time
=
date_format
(
comment
.
created
),
openId
=
comment
.
from
.
uid
||
''
,
nickName
=
comment
.
from
.
nickName
||
'游客'
,
content
=
comment
.
content
||
''
,
praiseCount
=
comment
.
praiseCount
||
0
,
praiseNames
=
''
,
praiseOpenIds
=
''
;
if
(
comment
.
praiseNames
){
praiseNames
=
comment
.
praiseNames
.
toString
();
praiseOpenIds
=
comment
.
praiseOpenIds
.
toString
();
}
var
this_row
=
[
floor
+
''
,
time
,
openId
,
nickName
,
content
,
praiseCount
,
praiseNames
,
praiseOpenIds
];
rows
.
push
(
this_row
);
if
(
comment
.
comments
.
length
>
0
){
for
(
var
k
=
0
;
k
<
comment
.
comments
.
length
;
k
++
)
{
var
sub_comment
=
comment
.
comments
[
k
];
var
time
=
date_format
(
sub_comment
.
created
);
var
openId
=
sub_comment
.
from
.
uid
||
''
;
var
nickName
=
sub_comment
.
from
.
nickName
||
'游客'
;
var
content
=
sub_comment
.
content
||
''
;
var
this_row
=
[
'回复'
,
time
,
openId
,
nickName
,
content
,
null
,
null
,
null
];
rows
.
push
(
this_row
);
};
}
};
conf
.
rows
=
rows
;
var
result
=
nodeExcel
.
execute
(
conf
);
res
.
setHeader
(
'Content-Type'
,
'application/vnd.ms-excel'
);
res
.
setHeader
(
'Content-Disposition'
,
'attachment; filename=commentsReport.xlsx'
);
res
.
end
(
result
,
'binary'
);
cb
(
null
,
e
);
}
});
}
}
);
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
async
.
parallel
(
asyncTasks
,
function
(
err
,
items
)
{
cont
(
err
,
items
);
});
}).
then
(
function
(
cont
,
items
){
//表头
var
conf
=
{};
conf
.
cols
=
[
{
caption
:
'楼层'
,
type
:
'string'
},
{
caption
:
'发布时间'
,
type
:
'Date'
},
{
caption
:
'openId'
,
type
:
'string'
},
{
caption
:
'会员名'
,
type
:
'string'
},
{
caption
:
'内容'
,
type
:
'string'
},
{
caption
:
'点赞数'
,
type
:
'number'
},
{
caption
:
'点赞人'
,
type
:
'string'
},
{
caption
:
'点赞人openId'
,
type
:
'string'
}
];
//内容
var
rows
=
[];
for
(
var
i
=
items
.
length
-
1
;
i
>=
0
;
i
--
)
{
var
comment
=
items
[
i
];
var
floor
=
comment
.
floor
,
time
=
date_format
(
comment
.
created
),
openId
=
''
,
nickName
=
''
,
content
=
comment
.
content
||
''
,
praiseCount
=
comment
.
praiseCount
||
0
,
praiseNames
=
''
,
praiseOpenIds
=
''
;
if
(
comment
.
praiseNames
){
praiseNames
=
comment
.
praiseNames
.
toString
();
praiseOpenIds
=
comment
.
praiseOpenIds
.
toString
();
}
if
(
comment
.
from
){
openId
=
comment
.
from
.
uid
||
''
;
nickName
=
comment
.
from
.
nickName
||
'游客'
;
}
var
this_row
=
[
floor
+
''
,
time
,
openId
,
nickName
,
content
,
praiseCount
,
praiseNames
,
praiseOpenIds
];
rows
.
push
(
this_row
);
if
(
comment
.
comments
.
length
>
0
){
for
(
var
k
=
0
;
k
<
comment
.
comments
.
length
;
k
++
)
{
var
sub_comment
=
comment
.
comments
[
k
];
var
time
=
date_format
(
sub_comment
.
created
),
openId
=
''
,
nickName
=
''
,
content
=
sub_comment
.
content
||
''
,
to
=
''
;
if
(
comment
.
from
){
openId
=
sub_comment
.
from
.
uid
||
''
;
nickName
=
sub_comment
.
from
.
nickName
||
'游客'
;
}
if
(
comment
.
to
){
to
=
sub_comment
.
to
.
nickName
||
'游客'
;
}
var
this_row
=
[
nickName
+
' 回复 '
+
to
,
time
,
openId
,
nickName
,
content
,
0
,
null
,
null
];
rows
.
push
(
this_row
);
};
}
};
conf
.
rows
=
rows
;
var
result
=
nodeExcel
.
execute
(
conf
);
res
.
setHeader
(
'Content-Type'
,
'application/vnd.ms-excel'
);
res
.
setHeader
(
'Content-Disposition'
,
'attachment; filename=commentsReport.xlsx'
);
res
.
end
(
result
,
'binary'
);
}).
fail
(
function
(
cont
,
err
){
console
.
error
(
err
);
if
(
err
===
'params error'
){
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
else
{
res
.
json
(
returnCode
.
BUSY
);
}
});
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment