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
c65c3a02
Commit
c65c3a02
authored
May 16, 2016
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
111
parent
2f157241
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
227 additions
and
7 deletions
+227
-7
forumThreadManagement.js
app/controllers/admin/forumThreadManagement.js
+211
-5
forumThreadService.js
app/service/forumThreadService.js
+16
-2
No files found.
app/controllers/admin/forumThreadManagement.js
View file @
c65c3a02
...
...
@@ -9,10 +9,13 @@ var router = require('express').Router(),
async
=
require
(
'async'
);
//模型
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
),
ForumComment
=
mongoose
.
model
(
'ForumComment'
),
ForumPVLog
=
mongoose
.
model
(
'ForumPVLog'
);
//服务
var
forumThreadService
=
require
(
'../../service/forumThreadService'
),
forumUserService
=
require
(
'../../service/forumUserService'
);
forumUserService
=
require
(
'../../service/forumUserService'
),
forumCommentService
=
require
(
'../../service/forumCommentService'
),
forumAboutMEService
=
require
(
'../../service/forumAboutMEService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
...
...
@@ -20,7 +23,7 @@ module.exports = function(app) {
//格式化日期 (格式:年-月-日)
function
date_format
(
date
)
{
return
moment
(
date
).
format
(
'YYYY-MM-DD
hh
:mm:ss'
);
return
moment
(
date
).
format
(
'YYYY-MM-DD
HH
:mm:ss'
);
}
//文章列表
...
...
@@ -147,9 +150,7 @@ router.get('/threadManagement/threads/statistics', function(req, res, next) {
var
begin_time
=
req
.
query
.
begin_time
;
var
end_time
=
req
.
query
.
end_time
;
var
tab
=
req
.
query
.
tab
;
//全部,官方贴,推荐贴,置顶帖,加精贴,活动贴,屏蔽贴
var
sortBy
=
{
//默认排序
created
:
-
1
};
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
,
...
...
@@ -407,3 +408,208 @@ router.post('/threadManagement/threads/batchdel', function(req, res, next) {
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
});
});
function
updateComemntStatus
(
ent_code
,
id
,
status
,
cb
){
if
(
!
ent_code
||
!
id
){
return
cb
&&
cb
(
null
,
true
);
}
var
cid
=
id
;
async
.
waterfall
([
function
(
callback
)
{
//获取评论实例
forumCommentService
.
getCommentById
(
cid
,
callback
);
},
function
(
comment
,
callback
)
{
//更新评论状态
forumCommentService
.
updateCommentStatusById
(
cid
,
status
,
function
(
err
,
update
)
{
callback
(
err
,
comment
);
});
},
function
(
comment
,
callback
)
{
if
(
comment
&&
comment
.
level
==
1
)
{
forumAboutMEService
.
updateCommentLevel1Status
(
comment
.
_id
,
status
);
}
if
(
comment
&&
comment
.
level
==
2
)
{
forumAboutMEService
.
updateCommentLevel2Status
(
comment
.
_id
,
status
);
}
//是否删除评论
if
(
status
==
2
)
{
if
(
comment
.
level
==
1
)
{
//一级评论,需要移除文章的comments里的cid,并且评论数-1
forumThreadService
.
updateThreadById
(
comment
.
thread
,
{
$pull
:{
comments
:
cid
},
$inc
:
{
comment_count
:
-
1
}
},
function
(
err
,
result
)
{
if
(
err
){
console
.
log
(
err
);
}
callback
();
});
}
else
{
//二级评论,移除父级评论的comments里的cid
forumCommentService
.
getCommentParent
(
cid
,
function
(
err
,
p_comment
)
{
if
(
err
||
!
p_comment
){
console
.
log
(
err
);
}
else
{
forumCommentService
.
updateCommentById
(
p_comment
.
_id
,
{
$pull
:{
comments
:
cid
},
$inc
:
{
comment_count
:
-
1
}
},
function
(
err
,
update
)
{
if
(
err
){
console
.
log
(
err
);
}
});
}
callback
();
});
}
}
else
{
callback
();
}
}
],
function
(
err
,
restult
)
{
if
(
err
)
{
console
.
error
(
err
);
}
cb
(
err
,
!!!
err
);
});
}
function
batchUpdateCommentStatus
(
ent_code
,
ids
,
status
,
callback
){
if
(
!
ent_code
||
!
ids
){
return
callback
&&
callback
(
'参数错误'
);
}
var
tasks
=
[];
_
.
forEach
(
ids
,
function
(
id
){
task
.
push
(
function
(
cb
){
updateComemntStatus
(
ent_code
,
id
,
status
,
function
(
err
,
result
){
cb
();
})
});
});
async
.
parallel
(
tasks
,
function
(
err
,
results
){
return
callback
&&
callback
(
err
,
!!!
err
);
});
}
//批量屏蔽帖子的评论
router
.
post
(
'/threadManagement/threads/:id/comment/batchclose'
,
function
(
req
,
res
,
next
)
{
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
id
=
req
.
params
.
id
;
//帖子id
var
ids
=
req
.
body
.
ids
;
//评论id数组
var
closed_status
=
0
;
if
(
!
ent_code
||
!
id
||
!
ids
){
return
res
.
json
(
returnCode
.
BUSY
);
}
//获取有效的评论id数组
ForumComment
.
find
({
ent_code
:
ent_code
,
thread
:
id
,
_id
:{
$in
:
ids
}}).
select
(
'_id'
).
exec
(
function
(
err
,
docs
)
{
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
if
(
!
docs
||
docs
.
length
==
0
){
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
}
var
available_ids
=
[];
_
.
forEach
(
docs
,
function
(
doc
){
available_ids
.
push
(
doc
.
_id
);
});
batchUpdateCommentStatus
(
ent_code
,
available_ids
,
closed_status
,
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
});
});
});
//批量删除帖子的评论
router
.
post
(
'/threadManagement/threads/:id/comment/batchdel'
,
function
(
req
,
res
,
next
)
{
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
id
=
req
.
params
.
id
;
//帖子id
var
ids
=
req
.
body
.
ids
;
//评论id数组
var
delete_status
=
2
;
if
(
!
ent_code
||
!
id
||
!
ids
){
return
res
.
json
(
returnCode
.
BUSY
);
}
//获取有效的评论id数组
ForumComment
.
find
({
ent_code
:
ent_code
,
thread
:
id
,
_id
:{
$in
:
ids
}}).
select
(
'_id'
).
exec
(
function
(
err
,
docs
)
{
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
if
(
!
docs
||
docs
.
length
==
0
){
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
}
var
available_ids
=
[];
_
.
forEach
(
docs
,
function
(
doc
){
available_ids
.
push
(
doc
.
_id
);
});
batchUpdateCommentStatus
(
ent_code
,
available_ids
,
delete_status
,
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
});
});
});
//查询评论列表
router
.
get
(
'/threadManagement/threads/:tid/comment/search'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
,
pageNo
=
req
.
query
.
pageNo
||
1
,
pageSize
=
req
.
query
.
pageSize
||
10
,
mid
=
req
.
query
.
mid
,
floor_start
=
req
.
query
.
floor_start
,
floor_end
=
req
.
query
.
floor_end
,
content
=
req
.
query
.
content
||
''
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
thread
:
tid
,
level
:
1
,
};
if
(
content
)
{
conditions
.
content
=
{
$regex
:
content
,
$options
:
'i'
};
}
if
(
floor_start
){
conditions
.
floor
=
{
$gte
:
floor_start
};
}
if
(
floor_end
){
conditions
.
floor
=
{
$lte
:
floor_end
};
}
if
(
tid
&&
mid
)
{
forumCommentService
.
getCommentListByMid
(
mid
,
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
if
(
tid
){
forumCommentService
.
getAllComment
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
app/service/forumThreadService.js
View file @
c65c3a02
...
...
@@ -6,6 +6,7 @@ var ForumShare = mongoose.model('ForumShare');
var
forumUserService
=
require
(
'./forumUserService'
);
var
forumCommentService
=
require
(
'./forumCommentService'
);
var
forumAboutMEService
=
require
(
'./forumAboutMEService'
);
var
async
=
require
(
'async'
);
var
then
=
require
(
'thenjs'
);
...
...
@@ -1142,14 +1143,27 @@ exports.updateThreadRaiseCount = function(threadId, callback) {
//批量屏蔽帖子
exports
.
batchClose
=
function
(
ent_code
,
ids
,
callback
)
{
update
({
ent_code
:
ent_code
,
_id
:
{
$in
:
ids
}},
{
$set
:{
status
:
0
}},
{
multi
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
var
status_closed
=
0
;
update
({
ent_code
:
ent_code
,
_id
:
{
$in
:
ids
}},
{
status
:
status_closed
},
{
multi
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
callback
(
err
,
!!!
err
);
if
(
!
err
){
_
.
forEach
(
ids
,
function
(
id
){
forumAboutMEService
.
updateThreadStatus
(
id
,
status_closed
);
});
}
});
};
//批量删除
exports
.
batchLogicDelete
=
function
(
ent_code
,
ids
,
callback
)
{
update
({
ent_code
:
ent_code
,
_id
:
{
$in
:
ids
}},
{
$set
:{
status
:
3
}},
{
multi
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
var
status_deleted
=
3
;
update
({
ent_code
:
ent_code
,
_id
:
{
$in
:
ids
}},
{
status
:
status_deleted
},
{
multi
:
true
},
'updateRedisRecommentThreads'
,
function
(
err
,
result
)
{
callback
(
err
,
!!!
err
);
if
(
!
err
){
_
.
forEach
(
ids
,
function
(
id
){
forumAboutMEService
.
updateThreadStatus
(
id
,
status_deleted
);
});
}
});
};
...
...
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