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
ba69d77d
Commit
ba69d77d
authored
Aug 10, 2015
by
陈志良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
fab93375
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
139 additions
and
3 deletions
+139
-3
forumThread.js
app/controllers/admin/forumThread.js
+139
-3
No files found.
app/controllers/admin/forumThread.js
View file @
ba69d77d
...
...
@@ -2,9 +2,11 @@
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
_
=
require
(
'lodash'
),
then
=
require
(
'thenjs'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
),
ForumPVLog
=
mongoose
.
model
(
'ForumPVLog'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
);
var
forumPraiseLogService
=
require
(
'../../service/forumPraiseLogService'
);
...
...
@@ -13,7 +15,6 @@ var forumCommentService = require('../../service/forumCommentService');
var
forumTagService
=
require
(
'../../service/forumTagService'
);
var
forumUserService
=
require
(
'../../service/forumUserService'
);
var
forumLimitActionRefService
=
require
(
'../../service/forumLimitActionRefService'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
userUtil
=
require
(
'../../utils/user'
);
...
...
@@ -792,7 +793,142 @@ router.post('/thread/:tid/updateComments', function(req, res, next) {
// });
});
var
checkOpenIds
=
function
(
openIds
,
openId
){
var
restult
=
false
;
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
){
c
.
children
=
[];
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
){
flag
=
true
;
break
;
}
}
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
||
'未知'
});
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
){
new_pvs
.
push
(
pvs
[
i
]);
}
}
pvs
=
new_pvs
;
if
(
c
.
children
.
length
>
0
){
var
thenTask
=
[];
_
.
forEach
(
c
.
children
,
function
(
c
){
thenTask
.
push
(
function
(
scb
){
getSubSpreadPaths
(
openIds
,
c
,
pvs
,
scb
);
});
})
then
.
parallel
(
thenTask
).
then
(
function
(
cont
,
childrens
){
c
.
children
=
childrens
;
cb
(
null
,
c
);
});
}
else
{
cb
(
null
,
c
);
}
};
// 更新文章评论
router
.
get
(
'/thread/:tid/spreadchain'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
,
ent_code
=
req
.
session
.
user
.
ent_code
;
var
openIds
=
[];
then
.
parallel
([
function
(
cont
){
ForumThread
.
findOne
({
_id
:
tid
,
ent_code
:
ent_code
}).
populate
(
'from'
).
exec
(
function
(
err
,
doc
){
cont
(
err
,
doc
);
});
},
function
(
cont
){
ForumPVLog
.
find
({
thread
:
tid
,
ent_code
:
ent_code
}).
sort
(
'source created'
).
populate
(
'user source'
).
exec
(
function
(
err
,
docs
){
cont
(
err
,
docs
);
});
}
]).
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
:[]
}
//获取一级传播
for
(
var
i
=
0
;
i
<
pvs
.
length
;
i
+=
1
){
var
pv
=
pvs
[
i
];
if
(
!
pv
.
source
){
var
flag
=
false
;
for
(
var
j
=
0
;
j
<
data
.
children
.
length
;
j
+=
1
){
var
c
=
data
.
children
[
j
];
if
(
c
.
openId
===
pv
.
open_id
){
flag
=
true
;
break
;
}
}
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
||
'未知'
});
openIds
.
push
(
pv
.
open_id
);
}
}
}
//获取非一级传播
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
){
new_pvs
.
push
(
pvs
[
i
]);
}
}
pvs
=
new_pvs
;
//递归其他传播
var
thenTask
=
[];
_
.
forEach
(
data
.
children
,
function
(
c
){
thenTask
.
push
(
function
(
cb
){
getSubSpreadPaths
(
openIds
,
c
,
pvs
,
cb
);
});
})
then
.
parallel
(
thenTask
).
then
(
function
(
cont
,
childrens
){
data
.
children
=
childrens
;
var
rs
=
{
data
:
data
}
openIds
=
[];
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
});
}).
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