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
64ac73cb
Commit
64ac73cb
authored
Oct 12, 2015
by
黄广星
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
等级
parent
41212c6d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
548 additions
and
461 deletions
+548
-461
forumAboutMe.js
app/controllers/mobile/forumAboutMe.js
+30
-24
forumInfo.js
app/controllers/mobile/forumInfo.js
+196
-175
forumThread.js
app/controllers/mobile/forumThread.js
+322
-262
No files found.
app/controllers/mobile/forumAboutMe.js
View file @
64ac73cb
...
...
@@ -2,9 +2,11 @@
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
user
=
require
(
'../../utils/user'
),
util
=
require
(
'../../utils/util'
),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
forumAboutMEService
=
require
(
'../../service/forumAboutMEService'
);
var
forumAboutMEService
=
require
(
'../../service/forumAboutMEService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
...
...
@@ -13,15 +15,17 @@ module.exports = function(app) {
router
.
get
(
'/aboutme/me2other'
,
function
(
req
,
res
,
next
)
{
var
userId
=
user
.
getMobileUser
(
req
);
var
entcode
=
req
.
session
.
user
.
ent_code
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
console
.
log
(
userId
);
console
.
log
(
entcode
);
forumAboutMEService
.
me2other
(
entcode
,
userId
,
pageNo
,
pageSize
,
function
(
err
,
result
)
{
if
(
err
)
{
forumAboutMEService
.
me2other
(
entcode
,
userId
,
pageNo
,
pageSize
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
UNCHECK_ERROR
(
err
));
}
else
{
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
}
else
{
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
result
.
items
,
function
(){
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
});
}
});
});
...
...
@@ -29,15 +33,17 @@ router.get('/aboutme/me2other', function(req, res, next) {
router
.
get
(
'/aboutme/other2me'
,
function
(
req
,
res
,
next
)
{
var
userId
=
user
.
getMobileUser
(
req
);
var
entcode
=
req
.
session
.
user
.
ent_code
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
console
.
log
(
userId
);
console
.
log
(
entcode
);
forumAboutMEService
.
other2me
(
entcode
,
userId
,
pageNo
,
pageSize
,
function
(
err
,
result
)
{
if
(
err
)
{
forumAboutMEService
.
other2me
(
entcode
,
userId
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
UNCHECK_ERROR
(
err
));
}
else
{
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
}
else
{
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
(){
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
}
});
});
...
...
@@ -45,12 +51,12 @@ router.get('/aboutme/other2me', function(req, res, next) {
router
.
get
(
'/aboutme/he2other/:id/:entcode'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
params
.
id
;
var
entcode
=
req
.
params
.
entcode
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
forumAboutMEService
.
me2other
(
entcode
,
userId
,
pageNo
,
pageSize
,
function
(
err
,
result
)
{
if
(
err
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
forumAboutMEService
.
me2other
(
entcode
,
userId
,
pageNo
,
pageSize
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
UNCHECK_ERROR
(
err
));
}
else
{
}
else
{
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
}
});
...
...
@@ -59,13 +65,13 @@ router.get('/aboutme/he2other/:id/:entcode', function(req, res, next) {
router
.
get
(
'/aboutme/other2he/:id/:entcode'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
params
.
id
;
var
entcode
=
req
.
params
.
entcode
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
forumAboutMEService
.
other2me
(
entcode
,
userId
,
pageNo
,
pageSize
,
function
(
err
,
result
)
{
if
(
err
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
forumAboutMEService
.
other2me
(
entcode
,
userId
,
pageNo
,
pageSize
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
UNCHECK_ERROR
(
err
));
}
else
{
}
else
{
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
}
});
});
\ No newline at end of file
});
app/controllers/mobile/forumInfo.js
View file @
64ac73cb
...
...
@@ -3,6 +3,7 @@ var express = require('express'),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
then
=
require
(
'thenjs'
),
util
=
require
(
'../../utils/util'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
...
...
@@ -10,8 +11,8 @@ var ForumInfo = mongoose.model('ForumInfo');
var
forumInfoService
=
require
(
'../../service/forumInfoService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumUserThreadControlService
=
require
(
'../../service/forumUserThreadControlService'
);
var
forumTagService
=
require
(
'../../service/forumTagService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumTagService
=
require
(
'../../service/forumTagService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumThreadAttendService
=
require
(
'../../service/forumThreadAttendService'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
redisPraiseLog
=
require
(
'../../utils/redisPraiseLog'
);
...
...
@@ -28,7 +29,9 @@ module.exports = function(app) {
router
.
get
(
'/info/list/all'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
var
ent_code
=
req
.
session
.
user
.
ent_code
;
forumInfoService
.
getAllByGid
({
ent_code
:
ent_code
},
1
,
100
,
function
(
err
,
datas
)
{
forumInfoService
.
getAllByGid
({
ent_code
:
ent_code
},
1
,
100
,
function
(
err
,
datas
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
...
...
@@ -62,7 +65,7 @@ router.get('/info/:fid/get', function(req, res, next) {
var
fid
=
req
.
params
.
fid
||
null
;
if
(
fid
)
{
var
source
=
req
.
session
.
mobileForumUser
.
source
;
httpService
.
createLog
(
req
,
source
,
fid
,
2
);
httpService
.
createLog
(
req
,
source
,
fid
,
2
);
async
.
waterfall
([
function
(
callback
)
{
//更新浏览数
...
...
@@ -159,7 +162,7 @@ router.get('/info/:fid/threads', function(req, res, next) {
var
conditions
=
{
ent_code
:
ent_code
,
level
:
1
,
status
:
1
status
:
1
};
if
(
fid
)
{
conditions
.
info
=
fid
;
...
...
@@ -194,21 +197,23 @@ router.get('/info/:fid/threads', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//判断是否已经点赞
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
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
;
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
()
{
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
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
));
});
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
}
});
...
...
@@ -230,7 +235,9 @@ router.get('/info/:fid/hotThreads', function(req, res, next) {
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
,
info
:
fid
,
status
:{
$ne
:
3
}
status
:
{
$ne
:
3
}
};
if
(
fid
)
{
...
...
@@ -285,7 +292,9 @@ router.get('/info/:fid/photoThreads', function(req, res, next) {
level
:
1
,
info
:
fid
,
type
:
3
,
status
:{
$ne
:
3
}
status
:
{
$ne
:
3
}
};
if
(
fid
)
{
...
...
@@ -374,6 +383,7 @@ router.get('/info/:fid/myThreads', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
...
...
@@ -392,45 +402,48 @@ router.get('/info/myThreads', function(req, res, next) {
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
from
:
user
.
getMobileUser
(
req
),
status
:
1
status
:
1
};
async
.
waterfall
([
function
(
callback
)
{
callback
();
// forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// if (doc) {
// callback(null, doc);
// } else {
// callback(null, null);
// }
// }
// });
function
(
callback
)
{
callback
();
// forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
// if (err) {
// callback(err, null);
// } else {
// if (doc) {
// callback(null, doc);
// } else {
// callback(null, null);
// }
// }
// });
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
],
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
)
{
conditions
.
_id
=
{
$nin
:
result
.
thread
};
}
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-created'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//获取子话题数据
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
'-created'
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
()
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
});
}
});
}
});
});
//获取他的文章列表
...
...
@@ -474,7 +487,9 @@ router.get('/info/hisThreads/:id', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
()
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
}
});
}
...
...
@@ -486,74 +501,74 @@ router.get('/info/myComments', function(req, res, next) {
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
id
=
user
.
getMobileUser
(
req
);
var
id
=
user
.
getMobileUser
(
req
);
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
status
:
1
,
//$or:[{from: id},{to: id}]
to
:
id
status
:
1
,
//$or:[{from: id},{to: id}]
to
:
id
};
forumCommentService
.
getMyComment
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
});
//获取跟我相关的评论列表
router
.
get
(
'/info/: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
pageSize
=
req
.
query
.
pageSize
||
10
;
var
id
=
user
.
getMobileUser
(
req
);
var
id
=
user
.
getMobileUser
(
req
);
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
thread
:
tid
,
//5539fa026cf87854c87be3c9
thread
:
tid
,
//5539fa026cf87854c87be3c9
level
:
'1'
};
if
(
!
tid
)
{
return
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
forumCommentService
.
getAllCommentByThread
(
conditions
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
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
)
{
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
);
res
.
json
(
_
.
assign
(
obj
,
returnCode
.
SUCCESS
));
}
});
if
(
!
tid
)
{
return
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
forumCommentService
.
getAllCommentByThread
(
conditions
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
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
)
{
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
);
res
.
json
(
_
.
assign
(
obj
,
returnCode
.
SUCCESS
));
}
});
});
//搜索文章列表
...
...
@@ -565,7 +580,7 @@ router.get('/info/:fid/serachThreads', function(req, res, next) {
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
conditions
=
{
ent_code
:
ent_code
,
status
:
1
,
status
:
1
,
info
:
fid
};
...
...
@@ -609,21 +624,24 @@ router.get('/info/:fid/serachThreads', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//判断是否已经点赞
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
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
;
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
results
.
items
,
function
()
{
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
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
));
});
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
}
});
}
...
...
@@ -644,11 +662,11 @@ router.get('/info/:fid/tags', function(req, res, next) {
info
:
fid
};
if
(
fid
)
{
forumTagService
.
getAllTag
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
forumTagService
.
getAllTag
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
...
...
@@ -662,16 +680,16 @@ router.get('/info/:fid/mobileList', function(req, res, next) {
var
fid
=
req
.
params
.
fid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
type
:
1
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
type
:
1
};
if
(
fid
)
{
forumTagService
.
getAllTag
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
forumTagService
.
getAllTag
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
...
...
@@ -686,52 +704,55 @@ router.get('/info/myAttend', function(req, res, next) {
var
pageNo
=
req
.
query
.
pageNo
,
pageSize
=
req
.
query
.
pageSize
;
var
total
=
0
;
then
(
function
(
cont
){
var
conditions
=
{
attend
:
user_id
}
forumThreadAttendService
.
findMyAttentByPage
(
conditions
,
pageNo
,
pageSize
,
'-updated'
,
function
(
err
,
attends
){
if
(
err
){
cont
(
err
);
}
else
{
if
(
attends
&&
attends
.
datas
.
length
>
0
){
total
=
attends
.
total
;
var
threadIds
=
[];
_
.
forEach
(
attends
.
datas
,
function
(
a
){
threadIds
.
push
(
a
.
thread
);
});
cont
(
null
,
threadIds
);
}
else
{
res
.
json
(
_
.
assign
({
data
:[],
total
:
0
},
returnCode
.
SUCCESS
));
}
then
(
function
(
cont
)
{
var
conditions
=
{
attend
:
user_id
}
forumThreadAttendService
.
findMyAttentByPage
(
conditions
,
pageNo
,
pageSize
,
'-updated'
,
function
(
err
,
attends
)
{
if
(
err
)
{
cont
(
err
);
}
else
{
if
(
attends
&&
attends
.
datas
.
length
>
0
)
{
total
=
attends
.
total
;
var
threadIds
=
[];
_
.
forEach
(
attends
.
datas
,
function
(
a
)
{
threadIds
.
push
(
a
.
thread
);
});
cont
(
null
,
threadIds
);
}
else
{
res
.
json
(
_
.
assign
({
data
:
[],
total
:
0
},
returnCode
.
SUCCESS
));
}
});
}).
then
(
function
(
cont
,
threadIds
){
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
cont
(
err
,
doc
,
threadIds
);
});
}).
then
(
function
(
cont
,
results
,
threadIds
){
var
conditions
=
{};
if
(
results
){
conditions
.
_id
=
{
$in
:
threadIds
}
});
}).
then
(
function
(
cont
,
threadIds
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
cont
(
err
,
doc
,
threadIds
);
});
}).
then
(
function
(
cont
,
results
,
threadIds
)
{
var
conditions
=
{};
if
(
results
)
{
conditions
.
_id
=
{
$in
:
threadIds
// $nin:results
}
}
else
{
conditions
.
_id
=
{
$in
:
threadIds
}
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
''
,
function
(
err
,
threads
)
{
cont
(
err
,
threads
);
});
}).
then
(
function
(
cont
,
threads
){
threads
.
total
=
total
;
res
.
json
(
_
.
assign
(
threads
,
returnCode
.
SUCCESS
));
}).
then
(
function
(
cont
){
}).
fail
(
function
(
cont
,
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
})
}
else
{
conditions
.
_id
=
{
$in
:
threadIds
}
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
''
,
function
(
err
,
threads
)
{
cont
(
err
,
threads
);
});
}).
then
(
function
(
cont
,
threads
)
{
threads
.
total
=
total
;
res
.
json
(
_
.
assign
(
threads
,
returnCode
.
SUCCESS
));
}).
then
(
function
(
cont
)
{
}).
fail
(
function
(
cont
,
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
})
});
app/controllers/mobile/forumThread.js
View file @
64ac73cb
...
...
@@ -2,6 +2,7 @@
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
util
=
require
(
'../../utils/util'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
...
...
@@ -26,7 +27,6 @@ module.exports = function(app) {
app
.
use
(
'/v1/forum'
,
router
);
};
function
create
(
req
,
callback
)
{
var
entity
=
req
.
body
;
...
...
@@ -58,19 +58,24 @@ function create(req, callback) {
entity
.
images
=
array
;
}
//-----------处理前端上传图片结束
if
(
entity
.
pid
&&
entity
.
type
==
3
){
forumThreadService
.
getByConditions
({
type
:
3
,
level
:
'2'
,
pid
:
entity
.
pid
,
from
:
entity
.
from
},
function
(
err
,
doc
){
if
(
doc
){
if
(
entity
.
pid
&&
entity
.
type
==
3
)
{
forumThreadService
.
getByConditions
({
type
:
3
,
level
:
'2'
,
pid
:
entity
.
pid
,
from
:
entity
.
from
},
function
(
err
,
doc
)
{
if
(
doc
)
{
var
update
=
{
$set
:{
images
:
entity
.
images
,
content
:
entity
.
content
$set
:
{
images
:
entity
.
images
,
content
:
entity
.
content
}
};
forumThreadService
.
updateThreadById
(
doc
.
_id
,
update
,
function
(
err
,
updatedDoc
)
{
callback
(
err
,
entity
);
forumThreadService
.
updateThreadById
(
doc
.
_id
,
update
,
function
(
err
,
updatedDoc
)
{
callback
(
err
,
entity
);
});
}
else
{
}
else
{
forumThreadService
.
createThread
(
entity
,
function
(
err
,
entity
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -81,7 +86,7 @@ function create(req, callback) {
});
}
});
}
else
{
}
else
{
forumThreadService
.
createThread
(
entity
,
function
(
err
,
entity
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -89,7 +94,7 @@ function create(req, callback) {
}
else
{
callback
(
null
,
entity
);
}
});
});
}
}
...
...
@@ -128,7 +133,7 @@ router.get('/thread/searchThread', function(req, res, next) {
//文章评论
router
.
get
(
'/thread/searchComment'
,
function
(
req
,
res
,
next
)
{
//参数
var
pageNo
=
req
.
query
.
pageNo
,
pageSize
=
req
.
query
.
pageSize
,
...
...
@@ -140,10 +145,10 @@ router.get('/thread/searchComment', function(req, res, next) {
var
q
=
{
ent_code
:
ent_code
,
// status: status,
from
:
req
.
session
.
mobileForumUser
.
from
from
:
req
.
session
.
mobileForumUser
.
from
};
forumThreadService
.
findCommentByPage
(
pageNo
,
pageSize
,
q
,
function
(
err
,
result
)
{
forumThreadService
.
findCommentByPage
(
pageNo
,
pageSize
,
q
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
}
...
...
@@ -161,14 +166,14 @@ router.get('/thread/searchComment', function(req, res, next) {
//新增论坛文章
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
forumLimitOperationService
.
checkLimitOperationProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
if
(
err
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
isProhibition
)
{
}
else
{
if
(
isProhibition
)
{
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
}
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
)
{
...
...
@@ -183,11 +188,11 @@ router.post('/thread/create', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumAboutMEService
.
saveThread
(
thread
);
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
)
{
if
(
err
)
{
console
.
error
(
err
);
}
else
{
if
(
!
flag
)
{
}
else
{
if
(
!
flag
)
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'post'
);
}
}
...
...
@@ -234,19 +239,20 @@ router.get('/thread/:tid/get', function(req, res, next) {
pid
=
thread
.
pid
,
source
=
req
.
session
.
mobileForumUser
.
source
;
if
(
thread
.
type
==
1
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
1
,
tid
);
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
1
,
tid
);
}
else
if
(
thread
.
type
==
1
&&
thread
.
level
==
2
)
{
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
4
,
tid
,
pid
);
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
4
,
tid
,
pid
);
}
else
if
(
thread
.
type
==
2
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
2
,
tid
);
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
2
,
tid
);
}
else
if
(
thread
.
type
==
3
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
3
,
tid
);
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
3
,
tid
);
}
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
...
...
@@ -256,23 +262,52 @@ router.get('/thread/:tid/get', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//判断是否已经点赞
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
function
(
error
,
docs
){
if
(
thread
.
toObject
){
thread
=
thread
.
toObject
();
var
threads
=
[];
threads
.
push
(
thread
);
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
threads
,
function
()
{
if
(
threads
&&
threads
.
length
>
0
)
{
thread
=
threads
[
0
];
}
//console.log(thread);
//console.log(thread.type == 2 && thread.level == 1&&thread.subThreads.items.length>0);
if
(
thread
.
type
==
2
&&
thread
.
level
==
1
&&
thread
.
subThreads
.
items
.
length
>
0
)
{
//console.log(thread.subThreads);
util
.
loadLevel
(
req
.
session
.
user
.
ent_code
,
thread
.
subThreads
.
items
,
function
()
{
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
function
(
error
,
docs
)
{
if
(
thread
.
toObject
)
{
thread
=
thread
.
toObject
();
}
thread
.
isPraise
=
false
;
for
(
var
k
=
docs
.
length
-
1
;
k
>=
0
;
k
--
)
{
if
(
thread
.
_id
==
docs
[
k
])
{
thread
.
isPraise
=
true
;
break
;
}
};
var
rs
=
{};
rs
.
data
=
thread
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
});
});
}
else
{
redisPraiseLog
.
get
(
ent_code
,
user
.
getMobileUser
(
req
),
'thread'
,
function
(
error
,
docs
)
{
if
(
thread
.
toObject
)
{
thread
=
thread
.
toObject
();
}
thread
.
isPraise
=
false
;
for
(
var
k
=
docs
.
length
-
1
;
k
>=
0
;
k
--
)
{
if
(
thread
.
_id
==
docs
[
k
])
{
thread
.
isPraise
=
true
;
break
;
}
};
var
rs
=
{};
rs
.
data
=
thread
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
});
}
thread
.
isPraise
=
false
;
for
(
var
k
=
docs
.
length
-
1
;
k
>=
0
;
k
--
)
{
if
(
thread
.
_id
==
docs
[
k
]){
thread
.
isPraise
=
true
;
break
;
}
};
var
rs
=
{};
rs
.
data
=
thread
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
});
}
});
}
else
{
...
...
@@ -285,7 +320,12 @@ router.get('/thread/photo/:pid/get', function(req, res, next) {
var
pid
=
req
.
params
.
pid
||
null
,
userId
=
req
.
session
.
mobileForumUser
.
userId
;;
if
(
pid
)
{
forumThreadService
.
getByConditions
({
type
:
3
,
level
:
'2'
,
pid
:
pid
,
from
:
userId
},
function
(
err
,
thread
){
forumThreadService
.
getByConditions
({
type
:
3
,
level
:
'2'
,
pid
:
pid
,
from
:
userId
},
function
(
err
,
thread
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
...
...
@@ -293,7 +333,7 @@ router.get('/thread/photo/:pid/get', function(req, res, next) {
var
rs
=
{};
rs
.
data
=
thread
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
...
...
@@ -308,8 +348,8 @@ router.post('/thread/:tid/update', function(req, res, next) {
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
!
isNaN
(
req
.
body
.
status
))
{
forumAboutMEService
.
updateThreadStatus
(
thread
.
_id
,
thread
.
status
)
if
(
!
isNaN
(
req
.
body
.
status
))
{
forumAboutMEService
.
updateThreadStatus
(
thread
.
_id
,
thread
.
status
)
}
res
.
json
(
returnCode
.
SUCCESS
);
}
...
...
@@ -377,7 +417,7 @@ router.post('/thread/:tid/raise', function(req, res, next) {
}
},
function
(
callback
)
{
if
(
doc
)
{
//如果已存在,更新为点赞日志
if
(
doc
)
{
//如果已存在,更新为点赞日志
forumPraiseLogService
.
updatePraiseLog
(
doc
.
_id
,
0
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
...
...
@@ -385,7 +425,7 @@ router.post('/thread/:tid/raise', function(req, res, next) {
callback
(
null
,
null
);
}
});
}
else
{
//不存在,创建点赞日志
}
else
{
//不存在,创建点赞日志
var
entity
=
{
ent_code
:
ent_code
,
user
:
user
.
getMobileUser
(
req
),
...
...
@@ -393,7 +433,7 @@ router.post('/thread/:tid/raise', function(req, res, next) {
ip
:
req
.
ip
,
comment
:
null
,
type
:
1
,
status
:
0
status
:
0
};
//4.创建点赞日志
forumPraiseLogService
.
createPraiseLog
(
entity
,
function
(
err
,
result
)
{
...
...
@@ -421,12 +461,12 @@ router.post('/thread/:tid/raise', function(req, res, next) {
// });
//更新点赞redis
redisPraiseLog
.
get
(
ent_code
,
userId
,
'thread'
,
function
(
error
,
docs
)
{
redisPraiseLog
.
get
(
ent_code
,
userId
,
'thread'
,
function
(
error
,
docs
)
{
var
list
=
docs
;
list
.
push
(
tid
);
redisPraiseLog
.
set
(
ent_code
,
userId
,
'thread'
,
list
,
function
()
{});
redisPraiseLog
.
set
(
ent_code
,
userId
,
'thread'
,
list
,
function
()
{});
});
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -513,17 +553,17 @@ router.post('/thread/:tid/cancelRaise', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//更新点赞redis
redisPraiseLog
.
get
(
ent_code
,
userId
,
'thread'
,
function
(
error
,
docs
)
{
redisPraiseLog
.
get
(
ent_code
,
userId
,
'thread'
,
function
(
error
,
docs
)
{
var
list
=
docs
;
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
)
{
if
(
list
[
i
].
toString
()
==
tid
){
list
.
splice
(
i
,
1
);
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
)
{
if
(
list
[
i
].
toString
()
==
tid
)
{
list
.
splice
(
i
,
1
);
break
;
}
}
redisPraiseLog
.
set
(
ent_code
,
userId
,
'thread'
,
list
,
function
()
{});
}
}
redisPraiseLog
.
set
(
ent_code
,
userId
,
'thread'
,
list
,
function
()
{});
});
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -626,14 +666,14 @@ 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
;
forumLimitOperationService
.
checkLimitOperationProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
if
(
err
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
isProhibition
)
{
}
else
{
if
(
isProhibition
)
{
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
}
else
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
...
...
@@ -645,118 +685,118 @@ router.post('/thread/:tid/comment/add', function(req, res, next) {
// 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
)
{
callback
(
err
,
null
);
}
else
{
// callback(null, count);
if
(
count
){
entity
.
floor
=
count
+
1
;
// 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
)
{
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
{
try
{
if
(
user
.
getMobileUser
(
req
).
toString
()
!=
thread
.
from
.
_id
.
toString
())
{
//文章的作者不等于评论的作者才增加消息数
commentTips
.
incrTips
(
req
.
session
.
user
.
ent_code
,
thread
.
from
.
_id
);
forumThreadAttendService
.
threadAttend
(
thread
.
_id
,
user
.
getMobileUser
(
req
),
function
(
err
)
{});
}
//4.创建文章评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
newComment
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
try
{
if
(
user
.
getMobileUser
(
req
).
toString
()
!=
thread
.
from
.
_id
.
toString
()){
//文章的作者不等于评论的作者才增加消息数
commentTips
.
incrTips
(
req
.
session
.
user
.
ent_code
,
thread
.
from
.
_id
);
forumThreadAttendService
.
threadAttend
(
thread
.
_id
,
user
.
getMobileUser
(
req
),
function
(
err
){});
}
}
catch
(
e
){
console
.
log
(
e
);
}
forumAboutMEService
.
saveCommentLevel1
(
thread
,
newComment
);
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
,
newComment
);
}
else
{
callback
(
null
,
newComment
);
}
});
}
});
}
catch
(
e
)
{
console
.
log
(
e
);
}
});
},
function
(
callback
)
{
//3.更新文章统计数据(评论数)
if
(
thread
)
{
forumThreadService
.
updateThreadCommentCountInc
(
tid
,
function
(
err
,
results
)
{
forumAboutMEService
.
saveCommentLevel1
(
thread
,
newComment
);
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
,
n
ull
);
callback
(
err
,
n
ewComment
);
}
else
{
callback
(
null
,
n
ull
);
callback
(
null
,
n
ewComment
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
}
],
function
(
err
,
results
)
{
});
}
});
},
function
(
callback
)
{
//3.更新文章统计数据(评论数)
if
(
thread
)
{
forumThreadService
.
updateThreadCommentCountInc
(
tid
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
callback
(
err
,
null
);
}
else
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
){
console
.
error
(
err
);
}
else
{
if
(
!
flag
){
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment'
);
}
}
});
forumCommentService
.
getPopulateCommentById
(
results
[
0
].
_id
,
function
(
err
,
c
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
c
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
callback
(
null
,
null
);
}
});
}
else
{
callback
(
'cannot find thread by id'
,
null
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
],
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
)
{
if
(
err
)
{
console
.
error
(
err
);
}
else
{
if
(
!
flag
)
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment'
);
}
}
});
forumCommentService
.
getPopulateCommentById
(
results
[
0
].
_id
,
function
(
err
,
c
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
rs
.
data
=
c
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
// } else {
// res.json(returnCode.ACTION_NOT_PERMISSION);
// }
...
...
@@ -772,14 +812,14 @@ 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
;
forumLimitOperationService
.
checkLimitOperationProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
if
(
err
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
isProhibition
)
{
}
else
{
if
(
isProhibition
)
{
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
}
else
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
)
{
var
integral
=
req
.
session
.
openUser
.
integral
||
0
;
...
...
@@ -822,7 +862,7 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
callback
(
err
,
null
);
}
else
{
// callback(null, count);
if
(
count
)
{
if
(
count
)
{
entity
.
floor
=
count
+
1
;
}
//4.创建文章评论
...
...
@@ -830,16 +870,16 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
try
{
if
(
user
.
getMobileUser
(
req
).
toString
()
!=
thread
.
from
.
_id
.
toString
()){
//文章的作者不等于评论的作者才增加消息数
commentTips
.
incrTips
(
req
.
session
.
user
.
ent_code
,
thread
.
from
.
_id
);
forumThreadAttendService
.
threadAttend
(
thread
.
_id
,
user
.
getMobileUser
(
req
),
function
(
err
)
{});
try
{
if
(
user
.
getMobileUser
(
req
).
toString
()
!=
thread
.
from
.
_id
.
toString
())
{
//文章的作者不等于评论的作者才增加消息数
commentTips
.
incrTips
(
req
.
session
.
user
.
ent_code
,
thread
.
from
.
_id
);
forumThreadAttendService
.
threadAttend
(
thread
.
_id
,
user
.
getMobileUser
(
req
),
function
(
err
)
{});
}
}
catch
(
e
)
{
}
catch
(
e
)
{
console
.
log
(
e
);
}
forumAboutMEService
.
saveCommentLevel1
(
thread
,
newComment
);
forumAboutMEService
.
saveCommentLevel1
(
thread
,
newComment
);
var
comments
=
thread
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
items
&&
comments
.
items
.
length
>
0
)
{
...
...
@@ -880,11 +920,11 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
)
{
if
(
err
)
{
console
.
error
(
err
);
}
else
{
if
(
!
flag
)
{
}
else
{
if
(
!
flag
)
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'comment'
);
}
}
...
...
@@ -949,14 +989,14 @@ 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
;
forumLimitOperationService
.
checkLimitOperationProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
){
if
(
err
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionOfSpeech
(
userId
,
function
(
err
,
isProhibition
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
if
(
isProhibition
)
{
}
else
{
if
(
isProhibition
)
{
res
.
json
(
returnCode
.
PROHIBITION_OF_SPEECH
);
}
else
{
}
else
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
if
(
tid
&&
cid
)
{
...
...
@@ -995,15 +1035,15 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
try
{
if
(
user
.
getMobileUser
(
req
).
toString
()
!=
req
.
body
.
to
.
toString
()){
//被评论人 和评论人不是同一个
commentTips
.
incrTips
(
req
.
session
.
user
.
ent_code
,
req
.
body
.
to
);
forumThreadAttendService
.
threadAttend
(
tid
,
user
.
getMobileUser
(
req
),
function
(
err
)
{});
try
{
if
(
user
.
getMobileUser
(
req
).
toString
()
!=
req
.
body
.
to
.
toString
())
{
//被评论人 和评论人不是同一个
commentTips
.
incrTips
(
req
.
session
.
user
.
ent_code
,
req
.
body
.
to
);
forumThreadAttendService
.
threadAttend
(
tid
,
user
.
getMobileUser
(
req
),
function
(
err
)
{});
}
}
catch
(
e
)
{
console
.
log
(
e
);
}
catch
(
e
)
{
console
.
log
(
e
);
}
forumAboutMEService
.
saveCommentLevel2
(
tid
,
comment
,
newComment
);
forumAboutMEService
.
saveCommentLevel2
(
tid
,
comment
,
newComment
);
var
comments
=
comment
.
comments
;
var
array
=
[];
if
(
comments
&&
comments
.
length
>
0
)
{
...
...
@@ -1037,11 +1077,11 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
){
if
(
err
)
{
forumLimitOperationService
.
checkLimitOperationProhibitionAddIntegral
(
userId
,
function
(
err
,
flag
)
{
if
(
err
)
{
console
.
error
(
err
);
}
else
{
if
(
!
flag
)
{
}
else
{
if
(
!
flag
)
{
httpService
.
sendRequest
(
req
.
session
.
user
.
ent_code
,
req
.
session
.
openUser
.
mid
,
'reply'
);
}
}
...
...
@@ -1081,26 +1121,26 @@ router.post('/thread/:tid/comment/:cid/disable', function(req, res, next) {
tid
=
req
.
params
.
tid
,
cid
=
req
.
params
.
cid
;
if
(
tid
&&
cid
)
{
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
comment
)
{
if
(
comment
&&
user_id
)
{
if
(
comment
.
from
.
toString
()
==
user_id
.
toString
())
{
forumCommentService
.
changeStatus
(
cid
,
2
,
function
(
err
,
update
)
{
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
comment
)
{
if
(
comment
&&
user_id
)
{
if
(
comment
.
from
.
toString
()
==
user_id
.
toString
())
{
forumCommentService
.
changeStatus
(
cid
,
2
,
function
(
err
,
update
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
comment
&&
comment
.
level
==
1
)
{
forumAboutMEService
.
updateCommentLevel1Status
(
comment
.
_id
,
2
);
if
(
comment
&&
comment
.
level
==
1
)
{
forumAboutMEService
.
updateCommentLevel1Status
(
comment
.
_id
,
2
);
}
if
(
comment
&&
comment
.
level
==
2
)
{
forumAboutMEService
.
updateCommentLevel2Status
(
comment
.
_id
,
2
);
if
(
comment
&&
comment
.
level
==
2
)
{
forumAboutMEService
.
updateCommentLevel2Status
(
comment
.
_id
,
2
);
}
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
else
{
}
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
...
...
@@ -1155,8 +1195,8 @@ router.post('/thread/:tid/comment/:cid/delete', function(req, res, next) {
//评论列表
router
.
get
(
'/thread/:tid/comment/list'
,
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
tid
=
req
.
params
.
tid
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
...
...
@@ -1175,20 +1215,22 @@ router.get('/thread/:tid/comment/list', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//判断是否已经点赞
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
;
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
));
});
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
}
});
...
...
@@ -1232,21 +1274,23 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//判断是否已经点赞
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
;
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
));
});
results
.
total
=
count
;
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
});
}
});
...
...
@@ -1298,7 +1342,7 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
});
},
function
(
callback
)
{
if
(
doc
)
{
if
(
doc
)
{
//4.更新点赞日志
forumPraiseLogService
.
updatePraiseLog
(
doc
.
_id
,
0
,
function
(
err
,
result
)
{
if
(
err
)
{
...
...
@@ -1307,7 +1351,7 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
callback
(
null
,
null
);
}
});
}
else
{
}
else
{
var
entity
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
user
:
user
.
getMobileUser
(
req
),
...
...
@@ -1315,7 +1359,7 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
ip
:
req
.
ip
,
comment
:
cid
,
type
:
2
,
status
:
0
status
:
0
};
//4.创建点赞日志
forumPraiseLogService
.
createPraiseLog
(
entity
,
function
(
err
,
result
)
{
...
...
@@ -1343,13 +1387,13 @@ router.post('/thread/:tid/comment/:cid/raise', function(req, res, next) {
// });
//更新点赞redis
redisPraiseLog
.
get
(
ent_code
,
userId
,
'comment'
,
function
(
error
,
docs
)
{
redisPraiseLog
.
get
(
ent_code
,
userId
,
'comment'
,
function
(
error
,
docs
)
{
var
list
=
docs
;
list
.
push
(
cid
);
redisPraiseLog
.
set
(
ent_code
,
userId
,
'comment'
,
list
,
function
()
{});
redisPraiseLog
.
set
(
ent_code
,
userId
,
'comment'
,
list
,
function
()
{});
});
//返回点赞总数
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
doc
)
{
if
(
err
)
{
...
...
@@ -1433,16 +1477,16 @@ router.post('/thread/:tid/comment/:cid/cancelRaise', function(req, res, next) {
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
//更新点赞redis
redisPraiseLog
.
get
(
ent_code
,
userId
,
'comment'
,
function
(
error
,
docs
)
{
//更新点赞redis
redisPraiseLog
.
get
(
ent_code
,
userId
,
'comment'
,
function
(
error
,
docs
)
{
var
list
=
docs
;
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
)
{
if
(
list
[
i
].
toString
()
==
cid
){
list
.
splice
(
i
,
1
);
for
(
var
i
=
0
;
i
<
list
.
length
;
i
++
)
{
if
(
list
[
i
].
toString
()
==
cid
)
{
list
.
splice
(
i
,
1
);
break
;
}
}
redisPraiseLog
.
set
(
ent_code
,
userId
,
'comment'
,
list
,
function
()
{});
}
}
redisPraiseLog
.
set
(
ent_code
,
userId
,
'comment'
,
list
,
function
()
{});
});
//返回点赞总数
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
doc
)
{
...
...
@@ -1464,7 +1508,7 @@ router.post('/thread/:tid/comment/:cid/cancelRaise', function(req, res, next) {
}
}
});
}
}
}
});
...
...
@@ -1525,7 +1569,9 @@ router.get('/thread/:tid/topics', function(req, res, next) {
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
2
,
status
:{
$ne
:
3
}
status
:
{
$ne
:
3
}
};
if
(
tid
)
{
...
...
@@ -1580,8 +1626,15 @@ router.get('/thread/:tid/latestPhotos', function(req, res, next) {
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
3
,
status
:{
$ne
:
3
},
images
:
{
$exists
:
true
,
$not
:
{
$size
:
0
}}
status
:
{
$ne
:
3
},
images
:
{
$exists
:
true
,
$not
:
{
$size
:
0
}
}
};
if
(
tid
)
{
...
...
@@ -1635,8 +1688,15 @@ router.get('/thread/:tid/hotPhotos', function(req, res, next) {
ent_code
:
req
.
session
.
user
.
ent_code
,
pid
:
tid
,
type
:
3
,
status
:{
$ne
:
3
},
images
:
{
$exists
:
true
,
$not
:
{
$size
:
0
}}
status
:
{
$ne
:
3
},
images
:
{
$exists
:
true
,
$not
:
{
$size
:
0
}
}
};
if
(
tid
)
{
...
...
@@ -1686,21 +1746,21 @@ router.post('/thread/:tid/disable', function(req, res, next) {
var
user_id
=
user
.
getMobileUser
(
req
);
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
thread
.
from
&&
user_id
)
{
if
(
thread
.
from
.
_id
.
toString
()
==
user_id
.
toString
())
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
thread
.
from
&&
user_id
)
{
if
(
thread
.
from
.
_id
.
toString
()
==
user_id
.
toString
())
{
forumThreadService
.
logicDeleteThreadById
(
tid
,
function
(
err
,
flag
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
forumAboutMEService
.
updateThreadStatus
(
tid
,
3
);
forumAboutMEService
.
updateThreadStatus
(
tid
,
3
);
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
}
else
{
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
else
{
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
})
...
...
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