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
9172e7e9
Commit
9172e7e9
authored
Aug 27, 2015
by
陈志良
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
717640fb
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
180 additions
and
0 deletions
+180
-0
forumThread.js
app/controllers/mobile/forumThread.js
+168
-0
forumCommentService.js
app/service/forumCommentService.js
+12
-0
No files found.
app/controllers/mobile/forumThread.js
View file @
9172e7e9
...
@@ -614,7 +614,175 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
...
@@ -614,7 +614,175 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
}
}
});
});
});
});
//新增文章评论
router
.
post
(
'/thread/:tid/comment/create/new'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
newCommentId
=
null
;
forumLimitActionRefService
.
checkLimitActionProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
isProhibition
){
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'comment'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
var
content
=
req
.
body
.
content
;
if
(
content
)
{
//评论不能为空
//2.获取论坛文章
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
var
floor
=
1
;
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
content
:
content
,
ip
:
req
.
ip
,
thread
:
thread
,
level
:
'1'
,
floor
:
floor
};
var
conditions
=
{
thread
:
thread
.
_id
,
level
:
'1'
};
forumCommentService
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
// callback(null, count);
if
(
count
){
entity
.
floor
=
count
+
1
;
}
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
newComment
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
newCommentId
=
newComment
.
_id
;
var
comments
=
thread
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
items
&&
comments
.
items
.
length
>
0
)
{
array
=
comments
.
items
;
}
array
.
push
(
newComment
.
_id
);
forumThreadService
.
updateThreadById
(
tid
,
{
comments
:
array
},
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
});
}
});
},
function
(
callback
)
{
//3.更新文章统计数据(评论数)
if
(
thread
)
{
forumThreadService
.
updateThreadCommentCountInc
(
tid
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
if
(
!
flag
){
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment'
);
}
}
});
async
.
parallel
([
function
(
callback
)
{
//获取创建评论
var
conditions
=
{
thread
:
tid
,
level
:
'1'
};
forumCommentService
.
getPopulateCommentById
(
newCommentId
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
doc
);
}
});
},
function
(
callback
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
results
[
0
];
var
result
=
_
.
assign
(
rs
,
returnCode
.
SUCCESS
);
res
.
json
(
result
);
}
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
}
});
});
//新建文章评论的子评论
//新建文章评论的子评论
router
.
post
(
'/thread/:tid/comment/:cid/create'
,
function
(
req
,
res
,
next
)
{
router
.
post
(
'/thread/:tid/comment/:cid/create'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
...
...
app/service/forumCommentService.js
View file @
9172e7e9
...
@@ -288,4 +288,16 @@ exports.getCommentParent = function(cid,callback){
...
@@ -288,4 +288,16 @@ exports.getCommentParent = function(cid,callback){
ForumComment
.
findOne
({
comments
:{
$in
:[
cid
]}},
function
(
err
,
doc
){
ForumComment
.
findOne
({
comments
:{
$in
:[
cid
]}},
function
(
err
,
doc
){
callback
(
err
,
doc
);
callback
(
err
,
doc
);
});
});
};
//根据ID获取评论
exports
.
getPopulateCommentById
=
function
(
cid
,
callback
){
ForumComment
.
findById
({
_id
:
cid
}).
populate
({
path
:
'from to'
,
select
:
'uid nickName icon'
}).
exec
(
function
(
err
,
c
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
null
,
null
);
}
else
{
callback
(
null
,
c
);
}
});
};
};
\ No newline at end of file
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