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
be521c4b
Commit
be521c4b
authored
Jul 23, 2015
by
陈志良
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'development' of git.wxpai.cn:scrmgroup/pisns-forum-api into development
parents
7a3eb34a
82382f48
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
561 additions
and
317 deletions
+561
-317
forumIdentifyUser.js
app/controllers/admin/forumIdentifyUser.js
+41
-5
forumLimitActionRef.js
app/controllers/admin/forumLimitActionRef.js
+0
-17
forumThread.js
app/controllers/admin/forumThread.js
+13
-1
forumShare.js
app/controllers/mobile/forumShare.js
+32
-6
forumThread.js
app/controllers/mobile/forumThread.js
+336
-242
forumLimitActionRefService.js
app/service/forumLimitActionRefService.js
+135
-46
returnCode.js
app/utils/returnCode.js
+4
-0
No files found.
app/controllers/admin/forumIdentifyUser.js
View file @
be521c4b
...
...
@@ -5,6 +5,7 @@ var express = require('express'),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
moment
=
require
(
'moment'
);
var
forumUserService
=
require
(
'../../service/forumUserService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
httpService
=
require
(
'../../service/httpService'
);
...
...
@@ -18,10 +19,27 @@ module.exports = function(app) {
app
.
use
(
'/admin/forum'
,
router
);
};
//格式化日期 (格式:年-月-日)
function
date_format
(
date
)
{
return
moment
(
date
).
format
(
'YYYY-MM-DD'
);
}
//判断时间是否在指定范围
function
compareTime
(
now
,
begin_time
,
end_time
)
{
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
);
}
}
var
checkLimitAction
=
function
(
req
,
res
)
{
var
mid
=
req
.
session
.
mobileForumUser
.
userId
;
if
(
mid
){
req
.
session
.
mobileForumUser
.
limit_action
=
[];
var
array
=
[];
forumLimitActionRefService
.
getLimitActionRefByMid
(
mid
,
function
(
err
,
forumLimitActionRef
){
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -38,9 +56,10 @@ var checkLimitAction = function(req, res) {
result
:
flag
,
code
:
limit_action
.
limit_action_type
}
req
.
session
.
mobileForumUser
.
limit_actions
.
push
(
obj
);
res
.
json
(
'success'
);
array
.
push
(
obj
);
}
req
.
session
.
mobileForumUser
.
limit_actions
=
array
;
res
.
json
(
'success'
);
}
else
{
req
.
session
.
mobileForumUser
.
limit_actions
=
null
;
res
.
json
(
'success'
);
...
...
@@ -92,9 +111,26 @@ router.post('/user/identifyUser',function(req,res,next){
});
//微信分享带来用户
router
.
get
(
'/user/from/share'
,
function
(
req
,
res
,
next
)
{
var
mid
=
req
.
query
.
mid
,
action
=
req
.
query
.
action
,
ent_code
=
req
.
query
.
ent_code
;
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
flag
){
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
}
}
});
// httpService.sendRequest(ent_code,mid,action);
// res.status(200).end();
});
\ No newline at end of file
app/controllers/admin/forumLimitActionRef.js
View file @
be521c4b
...
...
@@ -13,23 +13,6 @@ module.exports = function(app) {
app
.
use
(
'/admin/forum'
,
router
);
};
//格式化日期 (格式:年-月-日)
// function date_format(date) {
// return moment(date).format('YYYY-MM-DD');
// }
//判断时间是否在指定范围
// function compareTime(now, begin_time, end_time) {
// 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);
// }
// }
//新增或更新论坛行为限制
router
.
post
(
'/limitActionRef/createOrUpdate'
,
function
(
req
,
res
,
next
)
{
var
ent_code
=
req
.
session
.
user
.
ent_code
;
...
...
app/controllers/admin/forumThread.js
View file @
be521c4b
...
...
@@ -238,7 +238,19 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
mid
){
httpService
.
sendRequest
(
ent_code
,
mid
,
'thread_recomment'
);
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
isProhibition
){
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
httpService
.
sendRequest
(
ent_code
,
mid
,
'thread_recomment'
);
res
.
json
(
returnCode
.
SUCCESS
);
}
}
});
}
res
.
json
(
returnCode
.
SUCCESS
);
}
...
...
app/controllers/mobile/forumShare.js
View file @
be521c4b
...
...
@@ -216,9 +216,22 @@ router.get('/:ent_code/share/timeline', function(req, res, next) {
var
mid
=
req
.
session
.
openUser
.
mid
,
action
=
'share_timeline'
,
ent_code
=
req
.
session
.
user
.
ent_code
;
httpService
.
createShareLog
(
req
,
1
);
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
flag
){
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
httpService
.
createShareLog
(
req
,
1
);
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
}
}
});
});
//微信分享单人接口
...
...
@@ -226,7 +239,20 @@ router.get('/:ent_code/share/singlemessage', function(req, res, next) {
var
mid
=
req
.
session
.
openUser
.
mid
,
action
=
'share_singlemessage'
,
ent_code
=
req
.
session
.
user
.
ent_code
;
httpService
.
createShareLog
(
req
,
2
);
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
flag
){
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
httpService
.
createShareLog
(
req
,
2
);
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
}
}
});
});
app/controllers/mobile/forumThread.js
View file @
be521c4b
...
...
@@ -13,6 +13,7 @@ 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
httpService
=
require
(
'../../service/httpService'
);
...
...
@@ -130,27 +131,49 @@ router.get('/thread/searchComment', function(req, res, next) {
//新增论坛文章
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
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
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
//有操作权限
create
(
req
,
function
(
err
,
thread
)
{
var
mid
=
req
.
session
.
openUser
.
mid
;
forumLimitActionRefService
.
checkLimitActionProhibitionOfSpeech
(
mid
,
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
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'post'
);
var
rs
=
{};
rs
.
data
=
{
'id'
:
thread
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
if
(
result
)
{
//有操作权限
create
(
req
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
if
(
!
flag
){
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'post'
);
}
}
});
// httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'post');
var
rs
=
{};
rs
.
data
=
{
'id'
:
thread
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
});
...
...
@@ -244,6 +267,7 @@ router.post('/thread/:tid/delete', function(req, res, next) {
//文章点赞
router
.
post
(
'/thread/:tid/raise'
,
function
(
req
,
res
,
next
)
{
var
mid
=
req
.
session
.
openUser
.
mid
;
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
...
...
@@ -306,7 +330,19 @@ router.post('/thread/:tid/raise', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'thread_praise'
);
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
if
(
!
flag
){
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'thread_praise'
);
}
}
});
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -408,257 +444,304 @@ router.post('/thread/:tid/share', function(req, res, next) {
//新增文章评论
router
.
post
(
'/thread/:tid/comment/create'
,
function
(
req
,
res
,
next
)
{
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
{
var
comments
=
thread
.
comments
;
// console.log('=========');
// console.log(comments);
// console.log('=========');
var
array
=
[];
if
(
comments
&&
comments
.
items
&&
comments
.
items
.
length
>
0
)
{
array
=
comments
.
items
;
var
mid
=
req
.
session
.
openUser
.
mid
;
forumLimitActionRefService
.
checkLimitActionProhibitionOfSpeech
(
mid
,
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
{
var
comments
=
thread
.
comments
;
// console.log('=========');
// console.log(comments);
// console.log('=========');
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
);
}
});
}
});
}
array
.
push
(
newComment
.
_id
);
forumThreadService
.
updateThreadById
(
tid
,
{
comments
:
array
},
function
(
err
,
result
)
{
});
},
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
(
callback
)
{
//3.更新文章统计数据(评论数)
if
(
thread
)
{
forumThreadService
.
updateThreadCommentCountInc
(
tid
,
function
(
err
,
results
)
{
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
callback
(
null
,
null
);
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
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
)
{
//获取最新5条评论
var
conditions
=
{
thread
:
tid
,
level
:
'1'
};
forumCommentService
.
getAllComment
(
conditions
,
1
,
5
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
results
);
}
});
},
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
.
comments
=
results
[
0
].
items
;
rs
.
commentCount
=
results
[
1
].
comment_count
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment'
);
async
.
parallel
([
function
(
callback
)
{
//获取最新5条评论
var
conditions
=
{
thread
:
tid
,
level
:
'1'
};
forumCommentService
.
getAllComment
(
conditions
,
1
,
5
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
results
);
}
});
},
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
.
comments
=
results
[
0
].
items
;
rs
.
commentCount
=
results
[
1
].
comment_count
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
});
});
//新建文章评论的子评论
router
.
post
(
'/thread/:tid/comment/:cid/create'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
req
.
body
.
from
=
user
.
getMobileUser
(
req
);
var
mid
=
req
.
session
.
openUser
.
mid
;
forumLimitActionRefService
.
checkLimitActionProhibitionOfSpeech
(
mid
,
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
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
var
exp
=
req
.
session
.
openUser
.
exp
||
0
;
var
destination
=
req
.
body
.
destination
||
'1'
;
req
.
body
.
from
=
user
.
getMobileUser
(
req
);
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'reply'
,
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.获取论坛评论
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
comment
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
to
:
req
.
body
.
to
,
content
:
content
,
ip
:
req
.
ip
,
thread
:
tid
,
level
:
'2'
};
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
newComment
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
var
comments
=
comment
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
length
>
0
)
{
array
=
comments
;
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'reply'
,
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.获取论坛评论
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
comment
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
async
.
parallel
([
function
(
callback
)
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
to
:
req
.
body
.
to
,
content
:
content
,
ip
:
req
.
ip
,
thread
:
tid
,
level
:
'2'
};
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
newComment
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
var
comments
=
comment
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
length
>
0
)
{
array
=
comments
;
}
array
.
push
(
newComment
.
_id
);
forumCommentService
.
updateCommentById
(
cid
,
{
comments
:
array
},
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
newComment
);
}
});
}
});
},
function
(
callback
)
{
forumCommentService
.
updateCommentCount
(
cid
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
array
.
push
(
newComment
.
_id
);
forumCommentService
.
updateCommentById
(
cid
,
{
comments
:
array
},
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
newComment
);
}
});
}
});
},
function
(
callback
)
{
forumCommentService
.
updateCommentCount
(
cid
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'reply'
);
ForumComment
.
populate
(
results
[
0
],
{
path
:
'from to'
,
select
:
'uid nickName icon comments'
},
function
(
err
,
c
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
if
(
!
flag
){
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'reply'
);
}
}
});
var
rs
=
{};
rs
.
data
=
results
[
0
];
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
// res.json(returnCode.SUCCESS);
}
});
// httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'reply');
ForumComment
.
populate
(
results
[
0
],
{
path
:
'from to'
,
select
:
'uid nickName icon comments'
},
function
(
err
,
c
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
results
[
0
];
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
// res.json(returnCode.SUCCESS);
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
});
});
//更改评论状态为3(删除)
...
...
@@ -773,7 +856,7 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
router
.
post
(
'/thread/:tid/comment/:cid/raise'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
mid
=
req
.
session
.
openUser
.
mid
;
if
(
tid
&&
cid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
...
...
@@ -831,7 +914,18 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment_praise'
);
forumLimitActionRefService
.
checkLimitActionProhibitionAddIntegral
(
mid
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
if
(
!
flag
){
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment_praise'
);
}
}
});
//返回点赞总数
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
doc
)
{
if
(
err
)
{
...
...
app/service/forumLimitActionRefService.js
View file @
be521c4b
...
...
@@ -4,6 +4,50 @@ var ForumLimitActionRef = mongoose.model('ForumLimitActionRef');
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
countAll
(
conditions
,
callback
)
{
ForumLimitActionRef
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
count
);
}
});
}
//获取单个行为限制
function
getLimitActionRef
(
mid
,
callback
){
ForumLimitActionRef
.
findOne
({
mid
:
mid
},
function
(
err
,
role
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
role
);
}
});
}
//创建或更新论坛行为限制
exports
.
createOrUpdateLimitActionRef
=
function
(
conditions
,
entity
,
callback
){
...
...
@@ -44,7 +88,8 @@ exports.createLimitActionRef=function(entity,callback){
}
});
};
//根据MID获取论坛角色
//根据MID和EntCode获取
exports
.
getLimitActionRefByMIdAndEntCode
=
function
(
mid
,
ent_code
,
callback
){
ForumLimitActionRef
.
findOne
({
mid
:
mid
,
ent_code
:
ent_code
},
function
(
err
,
role
)
{
if
(
err
)
{
...
...
@@ -56,8 +101,9 @@ exports.getLimitActionRefByMIdAndEntCode=function(mid,ent_code,callback){
});
};
//根据MID获取
exports
.
getLimitActionRefByMid
=
function
(
mid
,
callback
){
ForumLimitActionRef
.
findOne
({
mid
:
mid
}
,
function
(
err
,
role
)
{
getLimitActionRef
(
mid
,
function
(
err
,
role
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -67,53 +113,32 @@ exports.getLimitActionRefByMid=function(mid,callback){
});
};
//根据ID获取
论坛角色
exports
.
getLimitActionRefById
=
function
(
rid
,
callback
){
ForumLimitActionRef
.
findById
(
rid
,
function
(
err
,
role
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
role
);
}
});
};
//根据ID获取
//
exports.getLimitActionRefById=function(rid,callback){
//
ForumLimitActionRef.findById(rid, function(err, role) {
//
if (err) {
//
console.error(err);
//
callback(err,null);
//
} else {
//
callback(null,role);
//
}
//
});
//
};
//根据ID更新论坛角色
exports
.
updateLimitActionRefById
=
function
(
rid
,
entity
,
callback
){
ForumLimitActionRef
.
update
({
_id
:
rid
},
entity
,
null
,
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
};
//根据ID更新论坛角色
exports
.
deleteLimitActionRefById
=
function
(
rid
,
callback
){
ForumLimitActionRef
.
remove
({
_id
:
rid
},
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
};
//根据ID删除
// exports.deleteLimitActionRefById=function(rid,callback){
// ForumLimitActionRef.remove({ _id: rid},function(err,result){
// if (err) {
// console.error(err);
// callback(err,null);
// } else {
// callback(null,null);
// }
// });
// };
//获取数量
function
countAll
(
conditions
,
callback
)
{
ForumLimitActionRef
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
count
);
}
});
}
//获取全部列表数据
exports
.
getAllLimitActionRef
=
function
(
conditions
,
callback
)
{
...
...
@@ -135,3 +160,67 @@ exports.getAllLimitActionRef= function(conditions,callback) {
}
});
};
//检查用户是否被禁言
exports
.
checkLimitActionProhibitionOfSpeech
=
function
(
mid
,
callback
)
{
if
(
mid
){
var
isProhibition
=
false
;
getLimitActionRef
(
mid
,
function
(
err
,
forumLimitActionRef
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
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
];
if
(
limit_action
.
limit_action_type
==
'forum_prohibition_of_speech'
){
isProhibition
=
compareTime
(
new
Date
(),
limit_action
.
begin_time
,
limit_action
.
end_time
);
break
;
}
}
callback
(
null
,
isProhibition
);
}
else
{
callback
(
null
,
isProhibition
);
}
}
});
}
else
{
callback
(
null
,
isProhibition
);
}
};
//检查用户是否被禁加积分
exports
.
checkLimitActionProhibitionAddIntegral
=
function
(
mid
,
callback
)
{
if
(
mid
){
var
isProhibition
=
false
;
getLimitActionRef
(
mid
,
function
(
err
,
forumLimitActionRef
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
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
];
if
(
limit_action
.
limit_action_type
==
'forum_not_add_integral'
){
isProhibition
=
compareTime
(
new
Date
(),
limit_action
.
begin_time
,
limit_action
.
end_time
);
break
;
}
}
callback
(
null
,
isProhibition
);
}
else
{
callback
(
null
,
isProhibition
);
}
}
});
}
else
{
callback
(
null
,
isProhibition
);
}
};
\ No newline at end of file
app/utils/returnCode.js
View file @
be521c4b
...
...
@@ -38,6 +38,10 @@ module.exports = {
errorcode
:
10006
,
errormsg
:
'不能重复点赞'
},
PROHIBITION_OF_SPEECH
:
{
errorcode
:
10007
,
errormsg
:
'已被禁言'
},
UNCHECK_ERROR
:
function
(
msg
){
return
{
errorcode
:
9999
,
...
...
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