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
1dad89c0
Commit
1dad89c0
authored
Sep 22, 2015
by
黄广星
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
添加后台逻辑删除接口
parent
a2cc8fae
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
232 additions
and
202 deletions
+232
-202
forumThread.js
app/controllers/admin/forumThread.js
+232
-202
No files found.
app/controllers/admin/forumThread.js
View file @
1dad89c0
...
...
@@ -49,10 +49,10 @@ router.post('/thread/create', function(req, res, next) {
ent_code
=
req
.
session
.
user
.
ent_code
,
icon
=
req
.
session
.
user
.
headPic
,
nickName
=
req
.
session
.
user
.
name
;
if
(
icon
&&
icon
.
indexOf
(
'http://'
)
==-
1
)
{
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
if
(
icon
&&
icon
.
indexOf
(
'http://'
)
==
-
1
)
{
if
(
process
.
env
.
NODE_ENV
===
'production'
)
{
icon
=
'http://fs.wxpai.cn/'
+
icon
;
}
else
{
}
else
{
icon
=
'http://dev.fs.wxpai.cn/'
+
icon
;
}
}
...
...
@@ -77,21 +77,21 @@ router.post('/thread/create', function(req, res, next) {
//更新后台对应用户信息
var
isUpdate
=
false
,
updateObj
=
{};
if
(
icon
)
{
if
(
!
user
.
icon
||
user
.
icon
!=
icon
)
{
if
(
icon
)
{
if
(
!
user
.
icon
||
user
.
icon
!=
icon
)
{
isUpdate
=
true
;
updateObj
.
icon
=
icon
;
}
}
if
(
nickName
)
{
if
(
!
nickName
||
!
user
.
nickName
||
user
.
nickName
!=
nickName
)
{
isUpdate
=
true
;
if
(
nickName
)
{
if
(
!
nickName
||
!
user
.
nickName
||
user
.
nickName
!=
nickName
)
{
isUpdate
=
true
;
updateObj
.
nickName
=
nickName
;
}
}
if
(
isUpdate
)
{
user
.
update
(
updateObj
,
function
(
err
,
data
)
{
if
(
err
)
console
.
log
(
err
);
if
(
isUpdate
)
{
user
.
update
(
updateObj
,
function
(
err
,
data
)
{
if
(
err
)
console
.
log
(
err
);
});
}
//创建帖子
...
...
@@ -112,7 +112,7 @@ router.post('/thread/create', function(req, res, next) {
//创建后台对应用户
var
entity
=
{
uid
:
uid
,
ent_code
:
ent_code
,
ent_code
:
ent_code
,
nickName
:
nickName
,
icon
:
icon
};
...
...
@@ -157,22 +157,25 @@ router.get('/thread/:tid/get', function(req, res, next) {
}
});
},
function
(
thread
,
callback
)
{
if
(
thread
&&
thread
.
info
&&
thread
.
info
.
_id
){
forumTagService
.
getAllTag
({
ent_code
:
req
.
session
.
user
.
ent_code
,
info
:
thread
.
info
.
_id
},
1
,
100
,
function
(
err
,
results
)
{
function
(
thread
,
callback
)
{
if
(
thread
&&
thread
.
info
&&
thread
.
info
.
_id
)
{
forumTagService
.
getAllTag
({
ent_code
:
req
.
session
.
user
.
ent_code
,
info
:
thread
.
info
.
_id
},
1
,
100
,
function
(
err
,
results
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
[
thread
,
results
]);
callback
(
null
,
[
thread
,
results
]);
}
});
}
else
{
callback
(
null
,[
thread
]);
}
else
{
callback
(
null
,
[
thread
]);
}
},
function
(
datas
,
callback
)
{
forumUserService
.
getUserByUid
(
uid
,
function
(
err
,
results
)
{
function
(
datas
,
callback
)
{
forumUserService
.
getUserByUid
(
uid
,
function
(
err
,
results
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
...
...
@@ -186,8 +189,8 @@ router.get('/thread/:tid/get', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
isSameAuthor
=
false
;
if
(
results
[
0
].
from
&&
results
[
0
].
from
.
uid
)
{
if
(
!
isNaN
(
results
[
0
].
from
.
uid
))
{
if
(
results
[
0
].
from
&&
results
[
0
].
from
.
uid
)
{
if
(
!
isNaN
(
results
[
0
].
from
.
uid
))
{
isSameAuthor
=
true
;
}
}
...
...
@@ -225,8 +228,8 @@ router.post('/thread/:tid/update', function(req, res, next) {
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
!
isNaN
(
req
.
body
.
status
))
{
forumAboutMEService
.
updateThreadStatus
(
thread
.
_id
,
thread
.
status
)
if
(
!
isNaN
(
req
.
body
.
status
))
{
forumAboutMEService
.
updateThreadStatus
(
thread
.
_id
,
thread
.
status
)
}
res
.
json
({
message
:
"success"
,
...
...
@@ -256,6 +259,24 @@ router.post('/thread/:tid/delete', function(req, res, next) {
}
});
//逻辑删除文章
router
.
post
(
'/thread/:tid/disable'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
logicDeleteThreadById
(
tid
,
function
(
err
,
flag
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumAboutMEService
.
updateThreadStatus
(
tid
,
3
);
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//文章置顶
router
.
post
(
'/thread/:tid/:fid/top'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
//文章ID
...
...
@@ -295,28 +316,28 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
var
tid
=
req
.
params
.
tid
,
fid
=
req
.
params
.
fid
,
ent_code
=
req
.
session
.
user
.
ent_code
,
mid
=
req
.
body
.
mid
;
//板块ID
mid
=
req
.
body
.
mid
;
//板块ID
if
(
tid
&&
fid
)
{
forumThreadService
.
updateRecommendByThreadId
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
mid
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
tid
,
function
(
err
,
flag
){
if
(
err
)
{
if
(
mid
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
tid
,
function
(
err
,
flag
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
flag
)
{
}
else
{
if
(
flag
)
{
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
httpService
.
sendRequest
(
ent_code
,
mid
,
'thread_recomment'
);
}
else
{
httpService
.
sendRequest
(
ent_code
,
mid
,
'thread_recomment'
);
res
.
json
(
returnCode
.
SUCCESS
);
}
}
});
}
else
{
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
}
...
...
@@ -358,7 +379,9 @@ router.get('/threads/list', function(req, res, next) {
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
,
status
:{
$ne
:
3
}
status
:
{
$ne
:
3
}
};
if
(
infoId
)
{
conditions
.
info
=
infoId
;
...
...
@@ -380,15 +403,15 @@ router.get('/threads/list', function(req, res, next) {
$options
:
'i'
}
}
if
(
type
)
{
if
(
type
)
{
conditions
.
type
=
type
;
}
if
(
status
)
{
if
(
status
)
{
conditions
.
status
=
status
;
}
if
(
nickName
)
{
if
(
nickName
)
{
forumThreadService
.
getAllThreadByFidAndNickName
(
nickName
,
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -406,7 +429,7 @@ router.get('/threads/list', function(req, res, next) {
}
}
});
}
else
{
}
else
{
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -445,8 +468,11 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
// $ne: 2
// } //过滤被删除的数据,status 为 2 表示删除
};
if
(
content
){
conditions
.
content
=
{
$regex
:
content
,
$options
:
'i'
};
if
(
content
)
{
conditions
.
content
=
{
$regex
:
content
,
$options
:
'i'
};
}
if
(
tid
)
{
//获取最新5条评论
...
...
@@ -456,20 +482,20 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
asyncTasks
=
[];
_
.
forEach
(
results
.
items
,
function
(
e
)
{
asyncTasks
.
push
(
function
(
cb
){
if
(
e
.
level
==
1
)
{
cb
(
null
,
e
);
}
else
{
forumCommentService
.
getCommentParent
(
e
.
_id
,
function
(
err
,
p_comment
)
{
_
.
forEach
(
results
.
items
,
function
(
e
)
{
asyncTasks
.
push
(
function
(
cb
)
{
if
(
e
.
level
==
1
)
{
cb
(
null
,
e
);
}
else
{
forumCommentService
.
getCommentParent
(
e
.
_id
,
function
(
err
,
p_comment
)
{
var
comment
=
e
.
toObject
();
comment
.
floor
=
p_comment
.
floor
;
cb
(
null
,
comment
);
cb
(
null
,
comment
);
});
}
});
});
async
.
parallel
(
asyncTasks
,
function
(
err
,
items
)
{
async
.
parallel
(
asyncTasks
,
function
(
err
,
items
)
{
results
.
items
=
items
;
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
...
...
@@ -489,7 +515,7 @@ router.get('/thread/:tid/comment/list/:floor', function(req, res, next) {
ent_code
:
req
.
session
.
user
.
ent_code
,
thread
:
tid
,
level
:
'1'
,
floor
:
floor
floor
:
floor
};
if
(
tid
&&
floor
)
{
...
...
@@ -499,23 +525,23 @@ router.get('/thread/:tid/comment/list/:floor', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
asyncTasks
=
[];
if
(
results
.
items
&&
results
.
items
[
0
]
&&
results
.
items
[
0
].
comments
.
length
>
0
)
{
if
(
results
.
items
&&
results
.
items
[
0
]
&&
results
.
items
[
0
].
comments
.
length
>
0
)
{
var
items
=
[
results
.
items
[
0
]];
_
.
forEach
(
results
.
items
[
0
].
comments
,
function
(
e
)
{
_
.
forEach
(
results
.
items
[
0
].
comments
,
function
(
e
)
{
var
subComment
=
e
.
toObject
();
subComment
.
floor
=
results
.
items
[
0
].
floor
;
if
(
content
)
{
if
(
subComment
.
content
.
indexOf
(
content
)
!=
-
1
)
{
if
(
content
)
{
if
(
subComment
.
content
.
indexOf
(
content
)
!=
-
1
)
{
items
.
push
(
subComment
);
}
}
else
{
}
else
{
items
.
push
(
subComment
);
}
});
results
.
items
=
items
;
results
.
total
=
items
.
length
;
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
else
{
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
}
...
...
@@ -531,43 +557,45 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
var
status
=
req
.
body
.
status
;
if
(
cid
)
{
async
.
waterfall
([
function
(
callback
){
function
(
callback
)
{
//获取评论实例
forumCommentService
.
getCommentById
(
cid
,
callback
);
forumCommentService
.
getCommentById
(
cid
,
callback
);
},
function
(
comment
,
callback
)
{
function
(
comment
,
callback
)
{
//更新评论状态
forumCommentService
.
updateCommentStatusById
(
cid
,
status
,
function
(
err
,
update
)
{
callback
(
err
,
comment
);
forumCommentService
.
updateCommentStatusById
(
cid
,
status
,
function
(
err
,
update
)
{
callback
(
err
,
comment
);
});
},
function
(
comment
,
callback
)
{
function
(
comment
,
callback
)
{
//是否删除评论
if
(
status
==
2
)
{
if
(
status
==
2
)
{
//一级评论
if
(
comment
.
level
==
1
)
{
if
(
comment
.
level
==
1
)
{
var
commentList
=
result
.
comments
;
var
comments
=
forumThreadService
.
remove
(
commentList
,
cid
);
forumThreadService
.
updateThreadById
(
comment
.
thread
,
{
comments
:
comments
,
$inc
:
{
comment_count
:
-
1
}
comments
:
comments
,
$inc
:
{
comment_count
:
-
1
}
},
function
(
err
,
result
)
{
callback
(
err
);
});
}
else
{
}
else
{
forumThreadService
.
updateThreadCommentCount
(
comment
.
thread
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
);
}
else
{
}
else
{
// 更新评论的子评论列表
forumCommentService
.
getCommentParent
(
cid
,
function
(
err
,
p_comment
)
{
if
(
err
||
!
p_comment
)
{
forumCommentService
.
getCommentParent
(
cid
,
function
(
err
,
p_comment
)
{
if
(
err
||
!
p_comment
)
{
callback
(
err
||
'comment not exist'
);
}
else
{
}
else
{
var
commentList
=
p_comment
.
comments
;
var
comments
=
forumCommentService
.
remove
(
commentList
,
cid
);
forumCommentService
.
updateCommentById
(
p_comment
.
_id
,
{
comments
:
comments
comments
:
comments
},
function
(
err
,
update
)
{
callback
(
err
);
});
...
...
@@ -576,21 +604,21 @@ router.post('/thread/comment/update/:cid', function(req, res, next) {
}
});
}
}
else
{
if
(
comment
&&
comment
.
level
==
1
)
{
forumAboutMEService
.
updateCommentLevel1Status
(
comment
.
_id
,
status
);
}
else
{
if
(
comment
&&
comment
.
level
==
1
)
{
forumAboutMEService
.
updateCommentLevel1Status
(
comment
.
_id
,
status
);
}
if
(
comment
&&
comment
.
level
==
2
)
{
forumAboutMEService
.
updateCommentLevel2Status
(
comment
.
_id
,
status
);
if
(
comment
&&
comment
.
level
==
2
)
{
forumAboutMEService
.
updateCommentLevel2Status
(
comment
.
_id
,
status
);
}
callback
();
}
}
],
function
(
err
,
restult
)
{
if
(
err
)
{
],
function
(
err
,
restult
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
...
...
@@ -626,7 +654,7 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumAboutMEService
.
saveCommentLevel2BySearch
(
tid
,
cid
,
replayComment_id
);
forumAboutMEService
.
saveCommentLevel2BySearch
(
tid
,
cid
,
replayComment_id
);
res
.
json
(
returnCode
.
SUCCESS
);
}
});
...
...
@@ -693,9 +721,9 @@ router.post('/thread/comment/add', function(req, res, next) {
function
(
callback
)
{
forumUserService
.
getUserByUid
(
uid
,
callback
);
},
function
(
user
,
callback
)
{
function
(
user
,
callback
)
{
//获取发表人
if
(
!
user
)
{
if
(
!
user
)
{
var
userentity
=
{
uid
:
uid
,
nickName
:
req
.
session
.
user
.
name
,
...
...
@@ -709,16 +737,18 @@ router.post('/thread/comment/add', function(req, res, next) {
callback
();
}
});
}
else
{
}
else
{
var
icon
=
req
.
session
.
user
.
headPic
;
if
(
icon
)
{
if
(
icon
.
indexOf
(
'http://'
)
==
-
1
)
{
icon
=
req
.
host
!=
'piplus.wxpai.cn'
?
'http://img3.wxpai.cn/'
+
icon
:
'http://img2.wxpai.cn/'
+
icon
;
if
(
icon
)
{
if
(
icon
.
indexOf
(
'http://'
)
==
-
1
)
{
icon
=
req
.
host
!=
'piplus.wxpai.cn'
?
'http://img3.wxpai.cn/'
+
icon
:
'http://img2.wxpai.cn/'
+
icon
;
}
if
(
icon
&&
(
!
user
.
icon
||
user
.
icon
!==
icon
))
{
if
(
icon
&&
(
!
user
.
icon
||
user
.
icon
!==
icon
))
{
forumUserService
.
updateUserById
(
user
.
_id
,{
icon
:
icon
},
function
(
err
){
if
(
err
){
forumUserService
.
updateUserById
(
user
.
_id
,
{
icon
:
icon
},
function
(
err
)
{
if
(
err
)
{
console
.
log
(
err
);
}
});
...
...
@@ -729,39 +759,39 @@ router.post('/thread/comment/add', function(req, res, next) {
callback
();
}
},
function
(
callback
){
function
(
callback
)
{
//获取楼层
if
(
entity
.
level
==
1
)
{
if
(
entity
.
level
==
1
)
{
var
conditions
=
{
thread
:
entity
.
thread
,
level
:
'1'
thread
:
entity
.
thread
,
level
:
'1'
}
forumCommentService
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
callback
(
err
);
}
else
{
if
(
count
)
{
if
(
count
)
{
entity
.
floor
=
count
+
1
;
}
else
{
}
else
{
entity
.
floor
=
1
;
}
callback
();
}
});
}
else
{
}
else
{
callback
();
}
},
function
(
callback
){
function
(
callback
)
{
// 添加评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
comment
)
{
if
(
err
)
{
callback
(
err
);
}
else
{
forumThreadService
.
getById
(
tid
,
function
(
err
,
thread
)
{
if
(
entity
.
level
==
1
)
{
forumAboutMEService
.
saveCommentLevel1
(
thread
,
comment
);
forumThreadService
.
getById
(
tid
,
function
(
err
,
thread
)
{
if
(
entity
.
level
==
1
)
{
forumAboutMEService
.
saveCommentLevel1
(
thread
,
comment
);
}
var
comments
=
thread
.
comments
;
var
array
=
[];
...
...
@@ -780,7 +810,7 @@ router.post('/thread/comment/add', function(req, res, next) {
errorcode
:
0
,
errormsg
:
'请求成功'
}
callback
(
null
,
returnData
);
callback
(
null
,
returnData
);
});
});
}
...
...
@@ -843,57 +873,57 @@ router.post('/thread/:tid/updateComments', function(req, res, next) {
// });
});
var
checkOpenIds
=
function
(
openIds
,
openId
)
{
var
checkOpenIds
=
function
(
openIds
,
openId
)
{
var
restult
=
false
;
for
(
var
i
=
0
;
i
<
openIds
.
length
;
i
+=
1
)
{
if
(
openIds
[
i
]
==
openId
)
{
for
(
var
i
=
0
;
i
<
openIds
.
length
;
i
+=
1
)
{
if
(
openIds
[
i
]
==
openId
)
{
restult
=
true
;
break
;
}
}
return
restult
;
};
var
getSubSpreadPaths
=
function
(
openIds
,
c
,
pvs
,
cb
)
{
var
getSubSpreadPaths
=
function
(
openIds
,
c
,
pvs
,
cb
)
{
c
.
children
=
[];
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
)
{
if
(
pvs
[
i
].
source
.
uid
==
c
.
openId
)
{
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
)
{
if
(
pvs
[
i
].
source
.
uid
==
c
.
openId
)
{
var
flag
=
false
;
for
(
var
j
=
0
;
j
<
c
.
children
.
length
;
j
+=
1
)
{
if
(
c
.
children
[
j
].
openId
==
pvs
[
i
].
open_id
)
{
for
(
var
j
=
0
;
j
<
c
.
children
.
length
;
j
+=
1
)
{
if
(
c
.
children
[
j
].
openId
==
pvs
[
i
].
open_id
)
{
flag
=
true
;
break
;
}
}
if
(
!
flag
&&
!
checkOpenIds
(
openIds
,
pvs
[
i
].
open_id
))
{
if
(
!
flag
&&
!
checkOpenIds
(
openIds
,
pvs
[
i
].
open_id
))
{
c
.
children
.
push
({
openId
:
pvs
[
i
].
open_id
,
nickName
:
pvs
[
i
].
user
.
displayName
||
'未知'
,
name
:
pvs
[
i
].
user
.
nickName
||
'未知'
openId
:
pvs
[
i
].
open_id
,
nickName
:
pvs
[
i
].
user
.
displayName
||
'未知'
,
name
:
pvs
[
i
].
user
.
nickName
||
'未知'
});
openIds
.
push
(
pvs
[
i
].
open_id
);
}
}
}
var
new_pvs
=
[];
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
)
{
if
(
pvs
[
i
].
source
.
uid
!==
c
.
openId
)
{
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
)
{
if
(
pvs
[
i
].
source
.
uid
!==
c
.
openId
)
{
new_pvs
.
push
(
pvs
[
i
]);
}
}
pvs
=
new_pvs
;
if
(
c
.
children
.
length
>
0
)
{
if
(
c
.
children
.
length
>
0
)
{
var
thenTask
=
[];
_
.
forEach
(
c
.
children
,
function
(
c
)
{
thenTask
.
push
(
function
(
scb
)
{
getSubSpreadPaths
(
openIds
,
c
,
pvs
,
scb
);
_
.
forEach
(
c
.
children
,
function
(
c
)
{
thenTask
.
push
(
function
(
scb
)
{
getSubSpreadPaths
(
openIds
,
c
,
pvs
,
scb
);
});
})
then
.
parallel
(
thenTask
).
then
(
function
(
cont
,
childrens
)
{
then
.
parallel
(
thenTask
).
then
(
function
(
cont
,
childrens
)
{
c
.
children
=
childrens
;
cb
(
null
,
c
);
cb
(
null
,
c
);
});
}
else
{
cb
(
null
,
c
);
}
else
{
cb
(
null
,
c
);
}
};
// 更新文章评论
...
...
@@ -902,49 +932,49 @@ router.get('/thread/:tid/spreadchain', function(req, res, next) {
ent_code
=
req
.
session
.
user
.
ent_code
;
var
openIds
=
[];
then
.
parallel
([
function
(
cont
){
function
(
cont
)
{
ForumThread
.
findOne
({
_id
:
tid
,
ent_code
:
ent_code
}).
populate
(
'from'
).
exec
(
function
(
err
,
doc
)
{
cont
(
err
,
doc
);
_id
:
tid
,
ent_code
:
ent_code
}).
populate
(
'from'
).
exec
(
function
(
err
,
doc
)
{
cont
(
err
,
doc
);
});
},
function
(
cont
){
function
(
cont
)
{
ForumPVLog
.
find
({
thread
:
tid
,
ent_code
:
ent_code
}).
sort
(
'source created'
).
populate
(
'user source'
).
exec
(
function
(
err
,
docs
)
{
cont
(
err
,
docs
);
thread
:
tid
,
ent_code
:
ent_code
}).
sort
(
'source created'
).
populate
(
'user source'
).
exec
(
function
(
err
,
docs
)
{
cont
(
err
,
docs
);
});
}
]).
then
(
function
(
cont
,
results
)
{
]).
then
(
function
(
cont
,
results
)
{
var
thread
=
results
[
0
],
pvs
=
results
[
1
];
var
data
=
{
openId
:
thread
.
from
.
uid
,
name
:
thread
.
from
.
nickName
,
nickName
:
thread
.
from
.
displayName
,
children
:
[]
openId
:
thread
.
from
.
uid
,
name
:
thread
.
from
.
nickName
,
nickName
:
thread
.
from
.
displayName
,
children
:
[]
}
//获取一级传播
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
)
{
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
)
{
var
pv
=
pvs
[
i
];
if
(
!
pv
.
source
)
{
if
(
!
pv
.
source
)
{
var
flag
=
false
;
for
(
var
j
=
0
;
j
<
data
.
children
.
length
;
j
+=
1
)
{
for
(
var
j
=
0
;
j
<
data
.
children
.
length
;
j
+=
1
)
{
var
c
=
data
.
children
[
j
];
if
(
c
.
openId
===
pv
.
open_id
)
{
if
(
c
.
openId
===
pv
.
open_id
)
{
flag
=
true
;
break
;
}
}
if
(
!
flag
&&
pv
.
open_id
!==
data
.
openId
&&
!
checkOpenIds
(
openIds
,
pv
.
open_id
))
{
if
(
!
flag
&&
pv
.
open_id
!==
data
.
openId
&&
!
checkOpenIds
(
openIds
,
pv
.
open_id
))
{
data
.
children
.
push
({
openId
:
pv
.
open_id
,
nickName
:
pv
.
user
.
displayName
||
'未知'
,
name
:
pv
.
user
.
nickName
||
'未知'
openId
:
pv
.
open_id
,
nickName
:
pv
.
user
.
displayName
||
'未知'
,
name
:
pv
.
user
.
nickName
||
'未知'
});
openIds
.
push
(
pv
.
open_id
);
}
...
...
@@ -952,29 +982,29 @@ router.get('/thread/:tid/spreadchain', function(req, res, next) {
}
//获取非一级传播
var
new_pvs
=
[];
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
)
{
if
(
pvs
[
i
].
source
&&
pvs
[
i
].
source
.
uid
!==
data
.
openId
&&
pvs
[
i
].
open_id
!==
data
.
openId
)
{
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
)
{
if
(
pvs
[
i
].
source
&&
pvs
[
i
].
source
.
uid
!==
data
.
openId
&&
pvs
[
i
].
open_id
!==
data
.
openId
)
{
new_pvs
.
push
(
pvs
[
i
]);
}
}
pvs
=
new_pvs
;
//递归其他传播
var
thenTask
=
[];
_
.
forEach
(
data
.
children
,
function
(
c
)
{
thenTask
.
push
(
function
(
cb
){
getSubSpreadPaths
(
openIds
,
c
,
pvs
,
cb
);
_
.
forEach
(
data
.
children
,
function
(
c
)
{
thenTask
.
push
(
function
(
cb
)
{
getSubSpreadPaths
(
openIds
,
c
,
pvs
,
cb
);
});
})
then
.
parallel
(
thenTask
).
then
(
function
(
cont
,
childrens
)
{
then
.
parallel
(
thenTask
).
then
(
function
(
cont
,
childrens
)
{
data
.
children
=
childrens
;
var
rs
=
{
data
:
data
data
:
data
}
openIds
=
[];
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
});
}).
fail
(
function
(
cont
,
err
)
{
}).
fail
(
function
(
cont
,
err
)
{
console
.
error
(
err
);
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