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
34a8c73f
Commit
34a8c73f
authored
Sep 06, 2015
by
strong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'mycomment_remould'
parents
a5496225
e03e5cbd
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
861 additions
and
103 deletions
+861
-103
forumIdentifyUser.js
app/controllers/admin/forumIdentifyUser.js
+126
-49
forumLimitOperation.js
app/controllers/admin/forumLimitOperation.js
+110
-0
forumLimitOperationLog.js
app/controllers/admin/forumLimitOperationLog.js
+31
-0
forumThread.js
app/controllers/admin/forumThread.js
+4
-2
forumInfo.js
app/controllers/mobile/forumInfo.js
+58
-3
forumShare.js
app/controllers/mobile/forumShare.js
+4
-3
forumThread.js
app/controllers/mobile/forumThread.js
+14
-12
forumLimitOperation.js
app/models/forumLimitOperation.js
+57
-0
forumLimitOperationLog.js
app/models/forumLimitOperationLog.js
+49
-0
forumCommentService.js
app/service/forumCommentService.js
+51
-0
forumLimitOperationLogService.js
app/service/forumLimitOperationLogService.js
+74
-0
forumLimitOperationService.js
app/service/forumLimitOperationService.js
+169
-0
forumUserService.js
app/service/forumUserService.js
+114
-34
No files found.
app/controllers/admin/forumIdentifyUser.js
View file @
34a8c73f
...
...
@@ -9,8 +9,11 @@ var moment = require('moment');
var
forumUserService
=
require
(
'../../service/forumUserService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
forumLimitActionRefService
=
require
(
'../../service/forumLimitActionRefService'
);
var
forumLimitActionConfigService
=
require
(
'../../service/forumLimitActionConfigService'
);
// var forumLimitActionRefService=require('../../service/forumLimitActionRefService');
// var forumLimitActionConfigService=require('../../service/forumLimitActionConfigService');
var
forumLimitOperationService
=
require
(
'../../service/forumLimitOperationService'
);
var
async
=
require
(
'async'
);
...
...
@@ -83,7 +86,7 @@ router.get('/user/from/share', function(req, res, next) {
action
=
req
.
query
.
action
,
ent_code
=
req
.
query
.
ent_code
;
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
...
...
@@ -101,64 +104,138 @@ router.get('/user/from/share', function(req, res, next) {
// res.status(200).end();
});
//检查用户权限
//检查用户权限
旧版
router
.
post
(
'/user/checkLimitAction'
,
function
(
req
,
res
,
next
)
{
var
entity
=
req
.
body
;
var
userId
=
entity
.
mid
;
if
(
userId
){
forumLimitActionConfigService
.
getAllLimitActionConfig
(
function
(
err
,
configs
){
if
(
err
){
var
array
=
[];
var
configs
=
[{
code
:
'forum_prohibition_of_speech'
},{
code
:
'forum_not_add_integral'
}];
forumLimitOperationService
.
getLimitOperationByUserId
(
userId
,
function
(
err
,
forumLimitOperation
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
array
=
[];
forumLimitActionRefService
.
getLimitActionRefByMid
(
userId
,
function
(
err
,
forumLimitActionRef
){
if
(
err
)
{
console
.
error
(
err
);
var
returnObject
=
{
errcode
:
'success'
,
configs
:
configs
,
data
:
array
}
res
.
json
(
returnObject
);
}
else
{
// 获取到用户行为限制记录
if
(
forumLimitActionRef
){
var
limit_actions
=
forumLimitActionRef
.
limit_actions
;
for
(
var
i
=
0
;
i
<
limit_actions
.
length
;
i
+=
1
)
{
var
limit_action
=
limit_actions
[
i
];
var
flag
=
compareTime
(
new
Date
(),
limit_action
.
begin_time
,
limit_action
.
end_time
);
//把flag和limit_action_type 放进session
var
obj
=
{
result
:
flag
,
code
:
limit_action
.
limit_action_type
}
array
.
push
(
obj
);
}
var
returnObject
=
{
errcode
:
'success'
,
configs
:
configs
,
data
:
array
}
res
.
json
(
returnObject
);
}
else
{
var
returnObject
=
{
errcode
:
'success'
,
configs
:
configs
,
data
:[]
}
res
.
json
(
returnObject
);
var
returnObject
=
{
errcode
:
'-1'
,
errmsg
:
err
,
configs
:
configs
,
data
:
array
}
res
.
json
(
returnObject
);
}
else
{
// 获取到用户行为限制记录
if
(
forumLimitOperation
){
var
limit_actions
=
forumLimitOperation
.
limit_actions
;
for
(
var
i
=
0
;
i
<
limit_actions
.
length
;
i
+=
1
)
{
var
limit_action
=
limit_actions
[
i
];
var
flag
=
compareTime
(
new
Date
(),
limit_action
.
begin_time
,
limit_action
.
end_time
);
//把flag和limit_action_type 放进session
var
code
=
''
;
switch
(
limit_action
.
limit_type
)
{
case
1
:
code
=
'forum_prohibition_of_speech'
;
break
;
case
2
:
code
=
'forum_not_add_integral'
;
break
;
}
}
});
var
obj
=
{
result
:
flag
,
code
:
code
}
array
.
push
(
obj
);
}
var
returnObject
=
{
errcode
:
'success'
,
configs
:
configs
,
data
:
array
}
res
.
json
(
returnObject
);
}
else
{
var
returnObject
=
{
errcode
:
'success'
,
configs
:
configs
,
data
:[]
}
res
.
json
(
returnObject
);
}
}
});
}
else
{
var
returnObject
=
{
errcode
:
'
success
'
,
configs
:
configs
,
errcode
:
'
-1
'
,
errmsg
:
'参数错误'
,
data
:[]
}
res
.
json
(
returnObject
);
}
});
//检查用户权限
// router.post('/user/checkLimitAction', function(req, res, next) {
// var entity=req.body;
// var userId = entity.mid;
// if(userId){
// forumLimitActionConfigService.getAllLimitActionConfig(function(err,configs){
// if(err){
// console.error(err);
// res.json(returnCode.BUSY);
// }else{k
// var array = [];
// forumLimitActionRefService.getLimitActionRefByMid(userId,function(err,forumLimitActionRef){
// if (err) {
// console.error(err);
// var returnObject = {
// errcode:'success',
// configs:configs,
// data:array
// }
// res.json(returnObject);
// } else {
// // 获取到用户行为限制记录
// if(forumLimitActionRef){
// var limit_actions = forumLimitActionRef.limit_actions;
// for (var i = 0; i < limit_actions.length; i += 1) {
// var limit_action = limit_actions[i];
// var flag = compareTime(new Date(), limit_action.begin_time, limit_action.end_time);
// //把flag和limit_action_type 放进session
// var obj = {
// result : flag,
// code : limit_action.limit_action_type
// }
// array.push(obj);
// }
// var returnObject = {
// errcode:'success',
// configs:configs,
// data:array
// }
// res.json(returnObject);
// }else{
// var returnObject = {
// errcode:'success',
// configs:configs,
// data:[]
// }
// res.json(returnObject);
// }
// }
// });
// }
// });
// }else{
// var returnObject = {
// errcode:'success',
// configs:configs,
// data:[]
// }
// res.json(returnObject);
// }
// });
app/controllers/admin/forumLimitOperation.js
0 → 100644
View file @
34a8c73f
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
moment
=
require
(
'moment'
);
var
async
=
require
(
'async'
);
var
then
=
require
(
'thenjs'
);
var
forumLimitOperationService
=
require
(
'../../service/forumLimitOperationService'
);
var
forumLimitOperationLogService
=
require
(
'../../service/forumLimitOperationLogService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
};
//新增或更新论坛行为限制
router
.
post
(
'/limitOperation/createOrUpdate'
,
function
(
req
,
res
,
next
)
{
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
userId
=
req
.
body
.
userId
;
var
selects
=
req
.
body
.
selects
;
var
limit_actions
=
[];
if
(
selects
){
// 封装操作
for
(
var
i
in
selects
){
var
begin_time
=
moment
(
new
Date
()).
format
(
'YYYY-MM-DD'
);
var
end_time
=
moment
(
new
Date
()).
add
(
selects
[
i
].
days
,
'days'
).
format
(
'YYYY-MM-DD'
);
var
obj
=
{
limit_reason
:
selects
[
i
].
limit_reason
,
limit_type
:
selects
[
i
].
limit_type
,
begin_time
:
new
Date
(
begin_time
),
end_time
:
new
Date
(
end_time
),
days
:
selects
[
i
].
days
}
limit_actions
.
push
(
obj
);
}
}
//封装实体
var
forumLimiOperation
=
{
ent_code
:
ent_code
,
userId
:
userId
,
limit_actions
:
limit_actions
}
async
.
parallel
([
function
(
callback
)
{
//创建或更新
forumLimitOperationService
.
createOrUpdateLimitOperation
({
userId
:
userId
,
ent_code
:
ent_code
,
status
:
1
},
forumLimiOperation
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
result
);
}
});
},
function
(
callback
)
{
for
(
var
i
in
limit_actions
){
var
obj
=
{
ent_code
:
ent_code
,
userId
:
userId
,
limit_reason
:
limit_actions
[
i
].
limit_reason
,
limit_type
:
limit_actions
[
i
].
limit_type
,
begin_time
:
limit_actions
[
i
].
begin_time
,
end_time
:
limit_actions
[
i
].
end_time
,
days
:
limit_actions
[
i
].
days
,
}
forumLimitOperationLogService
.
createOperationLog
(
obj
,
function
(
err
,
doc
){
// console.log('save log');
});
}
callback
();
}
],
function
done
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{
data
:
results
[
0
]
}
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
});
//根据userId获取论坛行为限制
router
.
get
(
'/limitOperation/get/:userId'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
params
.
userId
;
if
(
userId
)
{
forumLimitOperationService
.
getLimitOperationByUserId
(
userId
,
function
(
err
,
forumLimitOperation
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
forumLimitOperation
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
app/controllers/admin/forumLimitOperationLog.js
0 → 100644
View file @
34a8c73f
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
forumLimitOperationLogService
=
require
(
'../../service/forumLimitOperationLogService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
};
//根据userId获取论坛行为限制
router
.
get
(
'/limitOperationLogs/get/:userId'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
userId
=
req
.
params
.
userId
;
if
(
userId
)
{
forumLimitOperationLogService
.
getAllLimitAction
(
userId
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
app/controllers/admin/forumThread.js
View file @
34a8c73f
...
...
@@ -14,7 +14,9 @@ var forumShareLogService = require('../../service/forumShareLogService');
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumTagService
=
require
(
'../../service/forumTagService'
);
var
forumUserService
=
require
(
'../../service/forumUserService'
);
var
forumLimitActionRefService
=
require
(
'../../service/forumLimitActionRefService'
);
// var forumLimitActionRefService = require('../../service/forumLimitActionRefService');
var
forumLimitOperationService
=
require
(
'../../service/forumLimitOperationService'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
userUtil
=
require
(
'../../utils/user'
);
...
...
@@ -264,7 +266,7 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
mid
){
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
tid
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
tid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
...
...
app/controllers/mobile/forumInfo.js
View file @
34a8c73f
...
...
@@ -403,7 +403,7 @@ router.get('/info/myThreads', function(req, res, next) {
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-
created
'
,
function
(
err
,
results
)
{
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-
praise_count
'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
...
...
@@ -437,6 +437,61 @@ router.get('/info/myComments', function(req, res, next) {
});
});
//获取跟我相关的评论列表
router
.
get
(
'/info/:tid/comment/list'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
id
=
user
.
getMobileUser
(
req
);
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
thread
:
tid
,
//5539fa026cf87854c87be3c9
level
:
'1'
};
if
(
!
tid
){
return
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
forumCommentService
.
getAllCommentByThread
(
conditions
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
docs
=
[];
if
(
results
&&
results
.
length
>
0
){
results
.
forEach
(
function
(
doc
,
i
){
//过滤与自己无关的评论
if
(
doc
.
from
.
_id
!=
id
&&
doc
.
thread
.
from
!=
id
){
//文章和一级评论的作者不是自己
if
(
doc
.
comments
&&
doc
.
comments
.
length
>
0
){
//有子评论
var
comments
=
[];
doc
.
comments
.
forEach
(
function
(
comment
,
j
){
console
.
log
((
comment
.
from
&&
comment
.
from
.
_id
==
id
),(
comment
.
to
&&
comment
.
to
.
_id
==
id
),
id
);
if
((
comment
.
from
&&
comment
.
from
.
_id
==
id
)
||
(
comment
.
to
&&
comment
.
to
.
_id
==
id
)){
//二级评论的作者 或 被评论者是自己
comments
.
push
(
comment
);
}
});
if
(
comments
.
length
>
0
){
doc
.
comments
=
comments
;
docs
.
push
(
doc
);
}
}
}
else
{
//文章或一级评论的作者是自己那么所有的子评论都不用过滤
docs
.
push
(
doc
);
}
});
}
var
obj
=
{};
obj
.
total
=
docs
.
length
;
obj
.
pageNo
=
pageNo
;
obj
.
pageSize
=
pageSize
;
obj
.
items
=
docs
.
slice
((
pageNo
-
1
>=
0
?
pageNo
-
1
:
0
)
*
pageSize
,
pageSize
);
console
.
log
(
obj
.
items
);
res
.
json
(
_
.
assign
(
obj
,
returnCode
.
SUCCESS
));
}
});
});
//搜索文章列表
router
.
get
(
'/info/:fid/serachThreads'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
||
null
;
...
...
@@ -483,7 +538,7 @@ router.get('/info/:fid/serachThreads', function(req, res, next) {
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-
created
'
,
function
(
err
,
results
)
{
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-
praise_count
'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
...
...
@@ -567,7 +622,7 @@ router.get('/info/myAttend', function(req, res, next) {
});
cont
(
null
,
threadIds
);
}
else
{
res
.
json
(
_
.
assign
({
items
:[],
total
:
0
},
returnCode
.
SUCCESS
));
res
.
json
(
_
.
assign
({
data
:[],
total
:
0
},
returnCode
.
SUCCESS
));
}
}
});
...
...
app/controllers/mobile/forumShare.js
View file @
34a8c73f
...
...
@@ -12,7 +12,8 @@ var forumThreadService = require('../../service/forumThreadService'),
config
=
require
(
'../../../config/config'
),
httpService
=
require
(
'../../service/httpService'
),
forumInfoService
=
require
(
'../../service/forumInfoService'
),
forumLimitActionRefService
=
require
(
'../../service/forumLimitActionRefService'
);
// forumLimitActionRefService = require('../../service/forumLimitActionRefService'),
forumLimitOperationService
=
require
(
'../../service/forumLimitOperationService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
...
...
@@ -220,7 +221,7 @@ router.get('/:ent_code/share/timeline', function(req, res, next) {
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
...
...
@@ -243,7 +244,7 @@ router.get('/:ent_code/share/singlemessage', function(req, res, next) {
ent_code
=
req
.
session
.
user
.
ent_code
;
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
...
...
app/controllers/mobile/forumThread.js
View file @
34a8c73f
...
...
@@ -13,7 +13,8 @@ var forumPraiseLogService = require('../../service/forumPraiseLogService');
var
forumShareLogService
=
require
(
'../../service/forumShareLogService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumUserThreadControlService
=
require
(
'../../service/forumUserThreadControlService'
);
var
forumLimitActionRefService
=
require
(
'../../service/forumLimitActionRefService'
);
// var forumLimitActionRefService = require('../../service/forumLimitActionRefService');
var
forumLimitOperationService
=
require
(
'../../service/forumLimitOperationService'
);
var
forumThreadAttendService
=
require
(
'../../service/forumThreadAttendService'
);
var
commentTips
=
require
(
'../../utils/commentTips'
);
var
httpService
=
require
(
'../../service/httpService'
);
...
...
@@ -159,27 +160,28 @@ router.get('/thread/searchComment', function(req, res, next) {
//新增论坛文章
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionOfSpeech
(
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
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'create'
,
integral
,
exp
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
create
(
req
,
function
(
err
,
thread
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
...
...
@@ -380,7 +382,7 @@ router.post('/thread/:tid/raise', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
...
...
@@ -494,7 +496,7 @@ router.post('/thread/:tid/share', function(req, res, next) {
//新增文章评论
router
.
post
(
'/thread/:tid/comment/add'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
...
...
@@ -600,7 +602,7 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
...
...
@@ -643,7 +645,7 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
//新增文章评论
router
.
post
(
'/thread/:tid/comment/create'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
...
...
@@ -748,7 +750,7 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
...
...
@@ -817,7 +819,7 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
//新建文章评论的子评论
router
.
post
(
'/thread/:tid/comment/:cid/create'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
...
...
@@ -900,7 +902,7 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
...
...
@@ -1110,7 +1112,7 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimit
ActionRefService
.
checkLimitAc
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
forumLimit
OperationService
.
checkLimitOpera
tionProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
...
...
app/models/forumLimitOperation.js
0 → 100644
View file @
34a8c73f
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
//行为限制表
var
ForumLimitOperationSchema
=
new
Schema
({
ent_code
:
{
type
:
Number
,
index
:
true
,
require
:
true
},
userId
:
{
//forumUser id
type
:
String
,
index
:
true
,
unique
:
true
,
require
:
true
},
uid
:
{
//用户ID,这里直接存放用户的openId
type
:
String
,
require
:
false
},
status
:
{
//状态,1启用,0禁用
type
:
Number
,
require
:
true
,
default
:
1
},
limit_actions
:
[{
limit_reason
:
{
//原因
type
:
String
,
default
:
''
},
limit_type
:
{
//限制类型, 1 禁言, 2 不加积分
type
:
Number
,
default
:
0
},
begin_time
:
{
//开始时间
type
:
Date
},
end_time
:
{
//结束时间
type
:
Date
},
days
:{
//限制天数
type
:
Number
,
require
:
false
}
}],
created
:
{
type
:
Date
,
required
:
true
,
default
:
Date
.
now
}
},
{
'collection'
:
'pisns_forum_limit_operation'
});
module
.
exports
=
mongoose
.
model
(
'ForumLimitOperation'
,
ForumLimitOperationSchema
);
app/models/forumLimitOperationLog.js
0 → 100644
View file @
34a8c73f
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
//行为限制日志
var
ForumLimitOperationLogSchema
=
new
Schema
({
ent_code
:
{
type
:
Number
,
require
:
true
,
index
:
true
},
userId
:
{
//forumUser id
type
:
String
,
index
:
true
,
require
:
true
},
mid
:
{
//会员ID
type
:
Number
,
require
:
true
,
index
:
false
},
limit_reason
:
{
//原因
type
:
String
,
default
:
''
},
limit_type
:
{
//限制类型, 1 禁言, 2 不加积分
type
:
String
,
default
:
''
},
begin_time
:
{
//开始时间
type
:
Date
},
end_time
:
{
//结束时间
type
:
Date
},
days
:{
//限制天数
type
:
Number
,
require
:
false
},
created
:
{
type
:
Date
,
required
:
true
,
default
:
Date
.
now
}
},
{
'collection'
:
'pisns_forum_limit_operation_log'
});
module
.
exports
=
mongoose
.
model
(
'ForumLimitOperationLog'
,
ForumLimitOperationLogSchema
);
\ No newline at end of file
app/service/forumCommentService.js
View file @
34a8c73f
...
...
@@ -392,4 +392,55 @@ exports.getMyComment = function(conditions,pageNo,pageSize,callback){
});
}
});
};
//获取全部列表数据
exports
.
getAllCommentByThread
=
function
(
conditions
,
callback
)
{
countAll
(
conditions
,
function
(
err
,
count
){
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
ForumComment
.
find
(
conditions
).
populate
({
path
:
'thread'
,
select
:
'from'
}).
populate
({
path
:
'from to'
,
select
:
'_id uid nickName icon'
}).
sort
(
'-created'
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
if
(
docs
&&
docs
.
length
>
0
)
{
var
asyncTasks
=
[];
docs
.
forEach
(
function
(
doc
){
asyncTasks
.
push
(
function
(
callback
)
{
populateComment
(
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
{
callback
(
null
,
results
);
}
});
}
else
{
callback
(
null
,
null
);
}
}
});
}
});
};
\ No newline at end of file
app/service/forumLimitOperationLogService.js
0 → 100644
View file @
34a8c73f
'use strict'
;
var
mongoose
=
require
(
'mongoose'
);
var
forumLimitOperationLog
=
mongoose
.
model
(
'ForumLimitOperationLog'
);
var
async
=
require
(
'async'
);
var
then
=
require
(
'thenjs'
);
var
moment
=
require
(
'moment'
);
//获取数量
function
countAll
(
conditions
,
callback
)
{
forumLimitOperationLog
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
count
);
}
});
}
//创建行为限制log
exports
.
createOperationLog
=
function
(
entity
,
callback
)
{
var
forum
=
new
forumLimitOperationLog
(
entity
);
forum
.
save
(
function
(
err
,
forum
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
forum
);
}
});
};
//获取全部列表数据
exports
.
getAllLimitOperationLog
=
function
(
conditions
,
callback
)
{
forumLimitOperationLog
.
find
(
conditions
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
docs
);
}
});
};
//分页获取全部列表数据
exports
.
getAllLimitAction
=
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
);
forumLimitOperationLog
.
find
(
conditions
).
skip
(
skip
).
limit
(
limit
).
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
.
data
=
docs
;
callback
(
null
,
obj
);
}
});
}
});
};
\ No newline at end of file
app/service/forumLimitOperationService.js
0 → 100644
View file @
34a8c73f
'use strict'
;
var
mongoose
=
require
(
'mongoose'
);
var
forumLimitOperation
=
mongoose
.
model
(
'ForumLimitOperation'
);
var
async
=
require
(
'async'
);
var
then
=
require
(
'thenjs'
);
var
moment
=
require
(
'moment'
);
//格式化日期 (格式:年-月-日)
function
date_format
(
date
)
{
return
moment
(
date
).
format
(
'YYYY-MM-DD'
);
}
//判断时间是否在指定范围
function
compareTime
(
now
,
begin_time
,
end_time
)
{
// 禁言中 true
now
=
date_format
(
now
);
begin_time
=
date_format
(
begin_time
);
end_time
=
date_format
(
end_time
);
if
(
moment
(
now
).
isSame
(
begin_time
)
||
moment
(
now
).
isSame
(
end_time
))
{
//如果等于开始时间或者结束时间
return
true
;
}
else
{
return
moment
(
now
).
isBetween
(
begin_time
,
end_time
);
}
}
//获取单个行为限制
function
getLimitOperation
(
userId
,
callback
){
forumLimitOperation
.
findOne
({
userId
:
userId
},
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
doc
);
}
});
}
//创建或更新论坛行为限制
exports
.
createOrUpdateLimitOperation
=
function
(
conditions
,
entity
,
callback
){
forumLimitOperation
.
findOneAndUpdate
(
conditions
,
{
limit_actions
:
entity
.
limit_actions
},
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
if
(
!
doc
){
var
forum
=
new
forumLimitOperation
(
entity
);
forum
.
save
(
function
(
err
,
forum
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
forum
);
}
});
}
else
{
callback
(
null
,
doc
);
}
}
});
};
//根据userId获取
exports
.
getLimitOperationByUserId
=
function
(
userId
,
callback
){
getLimitOperation
(
userId
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
//判断是否在用,过期的赋为空
if
(
doc
){
var
limit_actions
=
doc
.
limit_actions
;
for
(
var
i
=
limit_actions
.
length
-
1
;
i
>=
0
;
i
-=
1
)
{
var
limit_action
=
limit_actions
[
i
];
if
(
limit_action
.
begin_time
&&
limit_action
.
end_time
){
var
begin_time
=
new
Date
(
limit_action
.
begin_time
).
getTime
(),
ent_time
=
new
Date
(
limit_action
.
end_time
).
getTime
(),
now
=
new
Date
().
getTime
();
if
(
now
>
ent_time
){
limit_actions
.
splice
(
i
,
1
);
}
}
}
}
callback
(
null
,
doc
);
}
});
};
//检查用户是否被禁言
exports
.
checkLimitOperationProhibitionOfSpeech
=
function
(
userId
,
callback
)
{
if
(
userId
){
var
isProhibition
=
false
;
getLimitOperation
(
userId
,
function
(
err
,
forumLimitOperation
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
// 获取到用户行为限制记录
if
(
forumLimitOperation
){
var
limit_actions
=
forumLimitOperation
.
limit_actions
;
for
(
var
i
=
0
;
i
<
limit_actions
.
length
;
i
+=
1
)
{
var
limit_action
=
limit_actions
[
i
];
if
(
limit_action
.
limit_type
===
1
){
if
(
limit_action
.
begin_time
&&
limit_action
.
end_time
){
var
begin_time
=
new
Date
(
limit_action
.
begin_time
).
getTime
(),
ent_time
=
new
Date
(
limit_action
.
end_time
).
getTime
(),
now
=
new
Date
().
getTime
();
if
(
now
>=
begin_time
&&
now
<=
ent_time
){
isProhibition
=
true
;
break
;
}
}
}
}
callback
(
null
,
isProhibition
);
}
else
{
callback
(
null
,
isProhibition
);
}
}
});
}
else
{
callback
(
null
,
isProhibition
);
}
};
//检查用户是否被禁加积分
exports
.
checkLimitOperationProhibitionAddIntegral
=
function
(
userId
,
callback
)
{
var
isProhibition
=
false
;
if
(
userId
){
getLimitOperation
(
userId
,
function
(
err
,
forumLimitOperation
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
// 获取到用户行为限制记录
if
(
forumLimitOperation
){
var
limit_actions
=
forumLimitOperation
.
limit_actions
;
for
(
var
i
=
0
;
i
<
limit_actions
.
length
;
i
+=
1
)
{
var
limit_action
=
limit_actions
[
i
];
if
(
limit_action
.
limit_type
===
2
){
if
(
limit_action
.
begin_time
&&
limit_action
.
end_time
){
var
begin_time
=
new
Date
(
limit_action
.
begin_time
).
getTime
(),
ent_time
=
new
Date
(
limit_action
.
end_time
).
getTime
(),
now
=
new
Date
().
getTime
();
if
(
now
>=
begin_time
&&
now
<=
ent_time
){
isProhibition
=
true
;
break
;
}
}
}
}
callback
(
null
,
isProhibition
);
}
else
{
callback
(
null
,
isProhibition
);
}
}
});
}
else
{
callback
(
null
,
isProhibition
);
}
};
\ No newline at end of file
app/service/forumUserService.js
View file @
34a8c73f
...
...
@@ -3,8 +3,11 @@ var mongoose = require('mongoose');
var
ForumUser
=
mongoose
.
model
(
'ForumUser'
);
var
then
=
require
(
'thenjs'
);
var
async
=
require
(
'async'
);
var
forumLimitActionRefService
=
require
(
'../service/forumLimitActionRefService'
);
var
forumLimitActionConfigService
=
require
(
'../service/forumLimitActionConfigService'
);
// var forumLimitActionRefService = require('../service/forumLimitActionRefService');
// var forumLimitActionConfigService = require('../service/forumLimitActionConfigService');
var
forumLimitOperationService
=
require
(
'../service/forumLimitOperationService'
);
//创建用户
exports
.
createUser
=
function
(
entity
,
callback
){
var
forum
=
new
ForumUser
(
entity
);
...
...
@@ -87,6 +90,23 @@ exports.searchMembers=function(pageNo, pageSize, q, callback){
});
};
//根据nickName查询用户
exports
.
searchMembersByNickName
=
function
(
nickName
,
callback
){
var
name
=
{
$or
:
[
{
nickName
:
{
$regex
:
nickName
,
$options
:
'i'
}},
{
displayName
:
{
$regex
:
nickName
,
$options
:
'i'
}}
]
};
ForumUser
.
find
(
name
).
exec
(
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
result
);
}
});
};
//查询用户和行为限制信息
exports
.
searchMembersAndLimitActions
=
function
(
pageNo
,
pageSize
,
q
,
callback
){
then
(
function
(
cont
)
{
...
...
@@ -98,30 +118,31 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
cont
(
err
,
count
,
docs
);
});
}).
then
(
function
(
cont
,
count
,
members
)
{
forumLimitActionConfigService
.
getAllLimitActionConfig
(
function
(
err
,
configs
)
{
cont
(
err
,
count
,
members
,
configs
);
});
}).
then
(
function
(
cont
,
count
,
members
,
configs
)
{
if
(
count
>
0
&&
configs
.
length
>
0
)
{
if
(
count
>
0
)
{
var
asyncTasks
=
[];
members
.
forEach
(
function
(
member
)
{
asyncTasks
.
push
(
function
(
callback
)
{
forumLimit
ActionRefService
.
getLimitActionRefByMIdAndEntCode
(
member
.
_id
,
member
.
ent_code
,
function
(
err
,
forumLimitActionRef
)
{
forumLimit
OperationService
.
getLimitOperationByUserId
(
member
.
_id
,
function
(
err
,
forumLimitOperation
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
null
,
null
);
}
else
{
if
(
forumLimit
ActionRef
){
var
limit_actions
=
forumLimit
ActionRef
.
limit_actions
;
if
(
forumLimit
Operation
){
var
limit_actions
=
forumLimit
Operation
.
limit_actions
;
var
array
=
[];
for
(
var
i
=
0
;
i
<
limit_actions
.
length
;
i
+=
1
)
{
var
limit_action
=
limit_actions
[
i
];
for
(
var
k
=
0
;
k
<
configs
.
length
;
k
+=
1
){
if
(
limit_action
.
limit_action_type
===
configs
[
k
].
code
){
array
.
push
(
configs
[
k
].
name
);
break
;
}
}
var
name
=
''
;
switch
(
limit_action
.
limit_type
)
{
case
1
:
name
=
'禁言'
;
break
;
case
2
:
name
=
'不加积分'
;
break
;
}
array
.
push
(
name
);
}
member
=
member
.
toObject
();
member
.
limitActions
=
array
;
...
...
@@ -138,7 +159,6 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
console
.
log
(
err
);
callback
(
null
,
null
);
}
else
{
// callback(null, results);
var
rsJson
=
{
result
:
true
,
total
:
count
,
...
...
@@ -166,21 +186,81 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
});
};
//查询用户和行为限制信息
// exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
// then(function(cont) {
// ForumUser.find(q).count(cont);
// }).then(function(cont, count) {
// var skip = (pageNo - 1) * pageSize;
// var limit = count - skip > pageSize ? pageSize : (count - skip);
// ForumUser.find(q).skip(skip).limit(limit).sort('-created').exec(function(err, docs) {
// cont(err, count, docs);
// });
// }).then(function(cont, count, members) {
// forumLimitActionConfigService.getAllLimitActionConfig(function(err, configs) {
// cont(err, count, members, configs);
// });
// }).then(function(cont, count, members, configs) {
// if (count > 0 && configs.length > 0) {
// var asyncTasks = [];
// members.forEach(function(member) {
// asyncTasks.push(function(callback) {
// forumLimitActionRefService.getLimitActionRefByMIdAndEntCode(member._id, member.ent_code, function(err, forumLimitActionRef) {
// if (err) {
// console.error(err);
// callback(null, null);
// } else {
// if(forumLimitActionRef){
// var limit_actions = forumLimitActionRef.limit_actions;
// var array = [];
// for (var i = 0; i < limit_actions.length; i += 1) {
// var limit_action = limit_actions[i];
// for(var k = 0; k < configs.length; k+=1){
// if(limit_action.limit_action_type === configs[k].code){
// array.push(configs[k].name);
// break;
// }
// }
// }
// member = member.toObject();
// member.limitActions = array;
// callback(null, member);
// }else{
// callback(null, member);
// }
// }
// });
// });
// });
// async.parallel(asyncTasks, function(err, results) {
// if (err) {
// console.log(err);
// callback(null, null);
// } else {
// // callback(null, results);
// var rsJson = {
// result: true,
// total: count,
// datas: results
// };
// callback(null, rsJson);
// }
// });
//根据nickName查询用户
exports
.
searchMembersByNickName
=
function
(
nickName
,
callback
){
var
name
=
{
$or
:
[
{
nickName
:
{
$regex
:
nickName
,
$options
:
'i'
}},
{
displayName
:
{
$regex
:
nickName
,
$options
:
'i'
}}
]
};
ForumUser
.
find
(
name
).
exec
(
function
(
err
,
result
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
result
);
}
});
};
\ No newline at end of file
// } else {
// var rsJson = {
// result: true,
// total: count,
// datas: members
// };
// callback(null, rsJson);
// }
// }).fail(function(cont, err) {
// console.error(err);
// var rsJson = {
// result: false,
// err: err
// };
// callback(err, rsJson);
// });
// };
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