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
3ed356ae
Commit
3ed356ae
authored
Mar 11, 2016
by
strong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'master' into SANDBOX
parents
fa46f642
4589ac08
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
275 additions
and
68 deletions
+275
-68
forumThread.js
app/controllers/admin/forumThread.js
+18
-63
forumShare.js
app/controllers/mobile/forumShare.js
+2
-0
forumThread.js
app/controllers/mobile/forumThread.js
+142
-1
forumCommentService.js
app/service/forumCommentService.js
+106
-0
forumThreadService.js
app/service/forumThreadService.js
+1
-1
user.js
app/utils/user.js
+6
-3
No files found.
app/controllers/admin/forumThread.js
View file @
3ed356ae
...
@@ -617,7 +617,6 @@ router.put('/recommend_threads/orderIDX/:id/:order', function(req, res, next) {
...
@@ -617,7 +617,6 @@ router.put('/recommend_threads/orderIDX/:id/:order', function(req, res, next) {
});
});
//评论列表
//评论列表
router
.
get
(
'/thread/:tid/comment/list'
,
function
(
req
,
res
,
next
)
{
router
.
get
(
'/thread/:tid/comment/list'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
...
@@ -649,10 +648,24 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
...
@@ -649,10 +648,24 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
if
(
e
.
level
==
1
)
{
if
(
e
.
level
==
1
)
{
cb
(
null
,
e
);
cb
(
null
,
e
);
}
else
{
}
else
{
forumCommentService
.
getCommentParent
(
e
.
_id
,
function
(
err
,
p_comment
)
{
forumCommentService
.
getCommentParent
(
new
mongoose
.
Types
.
ObjectId
(
e
.
_id
),
function
(
err
,
p_comment
)
{
if
(
p_comment
&&
p_comment
.
floor
){
var
comment
=
e
.
toObject
();
var
comment
=
e
.
toObject
();
comment
.
floor
=
p_comment
.
floor
;
comment
.
floor
=
p_comment
.
floor
;
cb
(
null
,
comment
);
cb
(
null
,
comment
);
}
else
if
(
p_comment
&&
!
p_comment
.
floor
){
//上一级没有楼层就再查上一级的评论
forumCommentService
.
getCommentParent
(
new
mongoose
.
Types
.
ObjectId
(
p_comment
.
_id
),
function
(
err
,
p_p_comment
)
{
if
(
p_comment
){
var
comment
=
e
.
toObject
();
comment
.
floor
=
p_p_comment
.
floor
;
cb
(
null
,
comment
);
}
else
{
cb
(
null
,
e
);
}
});
}
else
{
cb
(
null
,
e
);
}
});
});
}
}
});
});
...
@@ -917,16 +930,6 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
...
@@ -917,16 +930,6 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
var
tid
=
req
.
body
.
tid
||
null
;
var
tid
=
req
.
body
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
replayComment_id
=
req
.
body
.
replayComment_id
;
var
replayComment_id
=
req
.
body
.
replayComment_id
;
// 获取评论的子评论列表
// 更新文章评论 + 1
forumThreadService
.
updateThreadCommentCountInc
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
console
.
error
(
err
);
}
});
// 更新评论对象
// result.comment_count+=1; // 回复评论+1
forumCommentService
.
updateCommentById
(
cid
,
{
forumCommentService
.
updateCommentById
(
cid
,
{
$push
:
{
$push
:
{
comments
:
replayComment_id
comments
:
replayComment_id
...
@@ -945,53 +948,6 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
...
@@ -945,53 +948,6 @@ router.post('/thread/comment/update/:cid/comments', function(req, res, next) {
});
});
});
});
// 更新评论的子评论列表
router
.
post
(
'/thread/comment/update/:cid/comments'
,
function
(
req
,
res
,
next
)
{
var
cid
=
req
.
params
.
cid
||
null
;
var
replayComment_id
=
req
.
body
.
replayComment_id
;
forumCommentService
.
updateCommentById
(
cid
,
{
$push
:
{
comments
:
replayComment_id
}
},
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
// 获取评论的子评论列表
// forumCommentService.getCommentById(cid, function(err, result) {
// if (err) {
// console.error(err);
// res.json(returnCode.BUSY);
// } else {
// // var commentList = result.comments;
// // result.comments.push(replayComment_id);
// forumCommentService.updateCommentById(cid, {
// $push: {
// comments: replayComment_id
// }
// },
// function(err, result) {
// if (err) {
// console.error(err);
// res.json(returnCode.BUSY);
// } else {
// res.json(returnCode.SUCCESS);
// }
// });
// }
// });
});
//添加评论
//添加评论
router
.
post
(
'/thread/comment/add'
,
function
(
req
,
res
,
next
)
{
router
.
post
(
'/thread/comment/add'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
body
.
tid
||
null
;
var
tid
=
req
.
body
.
tid
||
null
;
...
@@ -1039,7 +995,6 @@ router.post('/thread/comment/add', function(req, res, next) {
...
@@ -1039,7 +995,6 @@ router.post('/thread/comment/add', function(req, res, next) {
});
});
}
}
}
}
entity
.
from
=
user
;
entity
.
from
=
user
;
callback
();
callback
();
}
}
...
...
app/controllers/mobile/forumShare.js
View file @
3ed356ae
...
@@ -507,6 +507,8 @@ router.get('/sharev2.js', function(req, res, next) {
...
@@ -507,6 +507,8 @@ router.get('/sharev2.js', function(req, res, next) {
console
.
error
(
err
);
console
.
error
(
err
);
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
WRONG_PARAM
));
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
WRONG_PARAM
));
});
});
}
else
{
res
.
json
(
_
.
assign
({
result
:
false
},
returnCode
.
WRONG_PARAM
));
}
}
}
}
});
});
\ No newline at end of file
app/controllers/mobile/forumThread.js
View file @
3ed356ae
...
@@ -694,7 +694,7 @@ router.post('/thread/:tid/delete', function(req, res, next) {
...
@@ -694,7 +694,7 @@ router.post('/thread/:tid/delete', function(req, res, next) {
//文章点赞和取消点赞
//文章点赞和取消点赞
router
.
post
(
'/thread/:tid/praiseOrCancelPraise'
,
function
(
req
,
res
,
next
)
{
router
.
post
(
'/thread/:tid/praiseOrCancelPraise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
userId
=
user
.
getMobileUser
(
req
)
;
var
mid
=
req
.
session
.
openUser
.
mid
;
var
mid
=
req
.
session
.
openUser
.
mid
;
var
tid
=
req
.
params
.
tid
||
null
;
var
tid
=
req
.
params
.
tid
||
null
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
...
@@ -1454,6 +1454,147 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) {
...
@@ -1454,6 +1454,147 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) {
}
}
});
});
//不过滤掉已删除的二级评论
router
.
get
(
'/thread/:tid/comment/list/all'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
conditions
=
{
ent_code
:
ent_code
,
thread
:
tid
,
level
:
'1'
};
if
(
tid
)
{
//获取最新5条评论
forumCommentService
.
getAllComment_allstatus
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//判断是否已经点赞
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
()
{
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'comment'
,
function
(
error
,
docs
)
{
_
.
forEach
(
results
.
items
,
function
(
d
,
i
)
{
if
(
results
.
items
[
i
].
toObject
)
{
results
.
items
[
i
]
=
results
.
items
[
i
].
toObject
();
}
results
.
items
[
i
].
isPraise
=
false
;
for
(
var
k
=
docs
.
length
-
1
;
k
>=
0
;
k
--
)
{
if
(
results
.
items
[
i
].
_id
==
docs
[
k
])
{
results
.
items
[
i
].
isPraise
=
true
;
break
;
}
};
});
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//不过滤掉已删除的二级评论
router
.
get
(
'/thread/:tid/comment/list/byFloor/all'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
floor
=
req
.
query
.
floor
||
1
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
countConditions
=
{
ent_code
:
ent_code
,
thread
:
tid
,
level
:
'1'
};
var
conditions
=
{
ent_code
:
ent_code
,
thread
:
tid
,
level
:
'1'
,
floor
:
{
'$gte'
:
floor
-
9
,
'$lte'
:
floor
}
};
if
(
tid
)
{
//获取最新5条评论
forumCommentService
.
count
(
countConditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumCommentService
.
getAllComment_allstatus
(
conditions
,
1
,
10
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//判断是否已经点赞
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
()
{
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'comment'
,
function
(
error
,
docs
)
{
_
.
forEach
(
results
.
items
,
function
(
d
,
i
)
{
if
(
results
.
items
[
i
].
toObject
)
{
results
.
items
[
i
]
=
results
.
items
[
i
].
toObject
();
}
results
.
items
[
i
].
isPraise
=
false
;
for
(
var
k
=
docs
.
length
-
1
;
k
>=
0
;
k
--
)
{
if
(
results
.
items
[
i
].
_id
==
docs
[
k
])
{
results
.
items
[
i
].
isPraise
=
true
;
break
;
}
};
});
results
.
total
=
count
;
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//评论点赞
router
.
post
(
'/thread/:tid/comment/:cid/raise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
mid
=
req
.
session
.
openUser
.
mid
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
&&
cid
)
{
conmentRaiseOrcancelRaise
(
req
,
ent_code
,
tid
,
cid
,
userId
,
function
(
result
){
res
.
json
(
result
);
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//评论取消点赞
router
.
post
(
'/thread/:tid/comment/:cid/cancelRaise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
mid
=
req
.
session
.
openUser
.
mid
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
&&
cid
)
{
conmentRaiseOrcancelRaise
(
req
,
ent_code
,
tid
,
cid
,
userId
,
function
(
result
){
res
.
json
(
result
);
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//评论点赞和取消点赞
//评论点赞和取消点赞
router
.
post
(
'/thread/:tid/comment/:cid/praiseOrCancelPraise'
,
function
(
req
,
res
,
next
)
{
router
.
post
(
'/thread/:tid/comment/:cid/praiseOrCancelPraise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
...
...
app/service/forumCommentService.js
View file @
3ed356ae
...
@@ -616,3 +616,109 @@ exports.getAllCommentByThread = function(conditions, callback) {
...
@@ -616,3 +616,109 @@ exports.getAllCommentByThread = function(conditions, callback) {
}
}
});
});
};
};
/**
* 20160310
* 查询评论列表(包含已删除的二级评论)
*
* **/
exports
.
getAllComment_allstatus
=
function
(
conditions
,
pageNo
,
pageSize
,
callback
)
{
countAll
(
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumComment
.
find
(
conditions
,
listCommentFields
).
populate
(
'from'
,
'uid mid nickName icon exp'
).
populate
(
'to'
,
'uid mid nickName icon exp'
).
limit
(
limit
).
skip
(
skip
).
sort
(
'-created'
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
obj
=
{};
obj
.
total
=
count
;
obj
.
pageNo
=
pageNo
;
obj
.
pageSize
=
pageSize
;
obj
.
items
=
docs
;
if
(
docs
&&
docs
.
length
>
0
)
{
var
asyncTasks
=
[];
docs
.
forEach
(
function
(
doc
)
{
asyncTasks
.
push
(
function
(
callback
)
{
populateComment_allstatus
(
doc
,
function
(
err
,
c
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
var
newobj
=
doc
.
toObject
();
newobj
.
comments
=
(
c
==
null
?
[]
:
c
);
callback
(
null
,
newobj
);
}
});
});
});
async
.
parallel
(
asyncTasks
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
null
,
null
);
}
else
{
obj
.
items
=
results
;
callback
(
null
,
obj
);
}
});
}
else
{
callback
(
null
,
obj
);
}
}
});
}
});
};
//评论
function
populateComment_allstatus
(
doc
,
callback
)
{
if
(
doc
&&
doc
.
comments
.
length
>
0
)
{
var
asyncTasks
=
[];
doc
.
comments
.
forEach
(
function
(
comment
)
{
asyncTasks
.
push
(
function
(
callback
)
{
ForumComment
.
findOne
({
_id
:
comment
}).
populate
({
path
:
'from to'
,
select
:
'uid nickName icon mid'
}).
exec
(
function
(
err
,
c
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
null
,
null
);
}
else
{
if
(
c
)
{
callback
(
null
,
c
);
}
else
{
callback
(
null
);
}
}
});
});
});
async
.
parallel
(
asyncTasks
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
null
,
null
);
}
else
{
var
comments
=
[];
for
(
var
i
=
0
;
i
<
results
.
length
;
i
+=
1
)
{
if
(
results
[
i
])
{
comments
.
push
(
results
[
i
]);
}
}
callback
(
null
,
comments
);
}
});
}
else
{
callback
(
null
,
null
);
}
}
app/service/forumThreadService.js
View file @
3ed356ae
...
@@ -94,7 +94,7 @@ function findOneAndUpdate(condition, entity, afterOperation, callback) {
...
@@ -94,7 +94,7 @@ function findOneAndUpdate(condition, entity, afterOperation, callback) {
ForumThread
.
findOneAndUpdate
(
condition
,
entity
,
function
(
err
,
doc
)
{
ForumThread
.
findOneAndUpdate
(
condition
,
entity
,
function
(
err
,
doc
)
{
callback
(
err
,
doc
);
callback
(
err
,
doc
);
if
(
afterOperation
==
'updateRedisRecommentThreads'
&&
doc
&&
doc
.
new_recommend
==
1
){
//刷新缓存
if
(
afterOperation
==
'updateRedisRecommentThreads'
&&
doc
){
//刷新缓存
redisThreadList
.
updateRedisEsenceThreads
(
doc
.
ent_code
);
redisThreadList
.
updateRedisEsenceThreads
(
doc
.
ent_code
);
}
}
});
});
...
...
app/utils/user.js
View file @
3ed356ae
...
@@ -23,7 +23,8 @@ exports.identifyUser=function() {
...
@@ -23,7 +23,8 @@ exports.identifyUser=function() {
if
(
doc
){
if
(
doc
){
req
.
session
.
mobileForumUser
=
{
req
.
session
.
mobileForumUser
=
{
userId
:
doc
.
_id
,
userId
:
doc
.
_id
,
openId
:
doc
.
uid
openId
:
doc
.
uid
,
mid
:
doc
.
mid
};
};
if
(
req
.
session
.
source
){
if
(
req
.
session
.
source
){
if
(
req
.
session
.
source
!==
req
.
session
.
mobileForumUser
.
userId
){
if
(
req
.
session
.
source
!==
req
.
session
.
mobileForumUser
.
userId
){
...
@@ -41,7 +42,8 @@ exports.identifyUser=function() {
...
@@ -41,7 +42,8 @@ exports.identifyUser=function() {
uid
:
req
.
session
.
openUser
.
openId
,
uid
:
req
.
session
.
openUser
.
openId
,
nickName
:
req
.
session
.
openUser
.
nickName
,
nickName
:
req
.
session
.
openUser
.
nickName
,
icon
:
req
.
session
.
openUser
.
headPic
,
icon
:
req
.
session
.
openUser
.
headPic
,
ent_code
:
req
.
session
.
user
.
ent_code
ent_code
:
req
.
session
.
user
.
ent_code
,
mid
:
req
.
session
.
openUser
.
mid
};
};
forumUserService
.
createUser
(
entity
,
function
(
err
,
doc
){
forumUserService
.
createUser
(
entity
,
function
(
err
,
doc
){
if
(
err
){
if
(
err
){
...
@@ -49,7 +51,8 @@ exports.identifyUser=function() {
...
@@ -49,7 +51,8 @@ exports.identifyUser=function() {
}
else
{
}
else
{
req
.
session
.
mobileForumUser
=
{
req
.
session
.
mobileForumUser
=
{
userId
:
doc
.
_id
,
userId
:
doc
.
_id
,
openId
:
doc
.
uid
openId
:
doc
.
uid
,
mid
:
doc
.
mid
};
};
if
(
req
.
session
.
source
){
if
(
req
.
session
.
source
){
if
(
req
.
session
.
source
!==
req
.
session
.
mobileForumUser
.
userId
){
if
(
req
.
session
.
source
!==
req
.
session
.
mobileForumUser
.
userId
){
...
...
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