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
467e5e14
Commit
467e5e14
authored
Apr 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
646033df
fda25b63
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
747 additions
and
283 deletions
+747
-283
forumThread.js
app/controllers/admin/forumThread.js
+474
-258
forumInfo.js
app/controllers/mobile/forumInfo.js
+3
-2
forumShare.js
app/controllers/mobile/forumShare.js
+176
-1
forumTag.js
app/controllers/mobile/forumTag.js
+1
-1
forumThread.js
app/controllers/mobile/forumThread.js
+8
-5
forumPVLog.js
app/models/forumPVLog.js
+7
-3
forumUVLog.js
app/models/forumUVLog.js
+7
-3
forumCommentService.js
app/service/forumCommentService.js
+20
-3
forumThreadService.js
app/service/forumThreadService.js
+38
-4
httpService.js
app/service/httpService.js
+2
-1
user.js
app/utils/user.js
+11
-2
No files found.
app/controllers/admin/forumThread.js
View file @
467e5e14
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumThread
=
mongoose
.
model
(
'ForumThread'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
);
var
forumPraiseLogService
=
require
(
'../../service/forumPraiseLogService'
);
var
forumShareLogService
=
require
(
'../../service/forumShareLogService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumTagService
=
require
(
'../../service/forumTagService'
);
var
forumUserService
=
require
(
'../../service/forumUserService'
);
var
forumThreadService
=
require
(
'../../service/forumThreadService'
);
var
forumRolePermissionService
=
require
(
'../../service/forumRolePermissionService'
);
var
forumPraiseLogService
=
require
(
'../../service/forumPraiseLogService'
);
var
forumShareLogService
=
require
(
'../../service/forumShareLogService'
);
var
forumCommentService
=
require
(
'../../service/forumCommentService'
);
var
forumTagService
=
require
(
'../../service/forumTagService'
);
var
forumUserService
=
require
(
'../../service/forumUserService'
);
var
userUtil
=
require
(
'../../utils/user'
);
var
async
=
require
(
'async'
);
var
httpService
=
require
(
'../../service/httpService'
);
var
userUtil
=
require
(
'../../utils/user'
);
var
async
=
require
(
'async'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
app
.
use
(
'/admin/forum'
,
router
);
};
...
...
@@ -26,167 +28,175 @@ module.exports = function(app) {
//新增论坛文章
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
var
uid
=
req
.
session
.
user
.
id
;
// var uid='12345';
if
(
req
.
body
.
pid
){
req
.
body
.
level
=
2
;
}
async
.
waterfall
([
function
(
callback
){
forumUserService
.
getUserByUid
(
uid
,
callback
);
}
],
function
(
err
,
user
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
user
){
req
.
body
.
from
=
user
.
_id
;
forumThreadService
.
createThread
(
req
.
body
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
entity
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
var
entity
=
{
uid
:
uid
,
nickName
:
req
.
session
.
user
.
name
,
icon
:
req
.
session
.
user
.
headPic
};
forumUserService
.
createUser
(
entity
,
function
(
err
,
doc
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
req
.
body
.
from
=
doc
.
_id
;
forumThreadService
.
createThread
(
req
.
body
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
entity
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
}
});
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
var
uid
=
req
.
session
.
user
.
id
;
// var uid='12345';
if
(
req
.
body
.
pid
)
{
req
.
body
.
level
=
2
;
}
async
.
waterfall
([
function
(
callback
)
{
forumUserService
.
getUserByUid
(
uid
,
callback
);
}
],
function
(
err
,
user
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
user
)
{
req
.
body
.
from
=
user
.
_id
;
forumThreadService
.
createThread
(
req
.
body
,
function
(
err
,
entity
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
entity
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
var
entity
=
{
uid
:
uid
,
nickName
:
req
.
session
.
user
.
name
,
icon
:
req
.
session
.
user
.
headPic
};
forumUserService
.
createUser
(
entity
,
function
(
err
,
doc
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
req
.
body
.
from
=
doc
.
_id
;
forumThreadService
.
createThread
(
req
.
body
,
function
(
err
,
entity
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
entity
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
});
}
}
});
});
//获取目标论坛文章
router
.
get
(
'/thread/:tid/get'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
rs
=
{};
if
(
tid
)
{
async
.
parallel
([
function
(
callback
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
},
function
(
callback
)
{
forumTagService
.
getAllTag
(
req
.
session
.
user
.
ent_code
,
1
,
100
,
function
(
err
,
results
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
results
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
results
[
0
];
rs
.
tagList
=
results
[
1
];
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
||
null
;
var
rs
=
{};
if
(
tid
)
{
async
.
parallel
([
function
(
callback
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
},
function
(
callback
)
{
forumTagService
.
getAllTag
(
req
.
session
.
user
.
ent_code
,
1
,
100
,
function
(
err
,
results
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
results
);
}
});
}
],
function
(
err
,
results
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
results
[
0
];
rs
.
tagList
=
results
[
1
];
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//更新文章状态、如:屏蔽
router
.
post
(
'/thread/:tid/update'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
var
fatherTitle
=
req
.
body
.
father
;
delete
req
.
body
.
father
;
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
){
forumThreadService
.
updateThreadById
(
tid
,
req
.
body
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
({
message
:
"success"
,
data
:
thread
,
title
:
fatherTitle
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
;
var
fatherTitle
=
req
.
body
.
father
;
delete
req
.
body
.
father
;
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
)
{
forumThreadService
.
updateThreadById
(
tid
,
req
.
body
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
({
message
:
"success"
,
data
:
thread
,
title
:
fatherTitle
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//删除文章
router
.
post
(
'/thread/:tid/delete'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
deleteThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
deleteThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//文章置顶
router
.
post
(
'/thread/:tid/:fid/top'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
//文章ID
var
fid
=
req
.
params
.
fid
;
//板块ID
if
(
tid
&&
fid
)
{
forumThreadService
.
updateTopByThreadId
(
fid
,
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
;
//文章ID
var
fid
=
req
.
params
.
fid
;
//板块ID
if
(
tid
&&
fid
)
{
forumThreadService
.
updateTopByThreadId
(
fid
,
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//文章取消置顶
router
.
post
(
'/thread/:tid/:fid/unTop'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
//文章ID
var
fid
=
req
.
params
.
fid
;
//板块ID
if
(
tid
&&
fid
)
{
forumThreadService
.
updateUnTopByThreadId
(
fid
,
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
tid
=
req
.
params
.
tid
;
//文章ID
var
fid
=
req
.
params
.
fid
;
//板块ID
if
(
tid
&&
fid
)
{
forumThreadService
.
updateUnTopByThreadId
(
fid
,
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
/**
...
...
@@ -197,135 +207,341 @@ router.post('/thread/:tid/:fid/unTop', function(req, res, next) {
* @return {[type]}
*/
router
.
get
(
'/threads/list'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
infoId
=
req
.
query
.
infoId
;
var
tagId
=
req
.
query
.
tagId
;
var
pid
=
req
.
query
.
pid
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
var
infoId
=
req
.
query
.
infoId
;
var
tagId
=
req
.
query
.
tagId
;
var
pid
=
req
.
query
.
pid
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
};
if
(
infoId
)
{
conditions
.
info
=
infoId
;
if
(
infoId
)
{
conditions
.
info
=
infoId
;
}
if
(
tagId
){
conditions
.
tag
=
{
$in
:[
tagId
]};
if
(
tagId
)
{
conditions
.
tag
=
{
$in
:
[
tagId
]
};
}
if
(
pid
)
{
conditions
.
pid
=
pid
;
conditions
.
level
=
2
;
if
(
pid
)
{
conditions
.
pid
=
pid
;
conditions
.
level
=
2
;
}
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
null
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
});
//评论列表
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
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
thread
:
tid
,
level
:
'1'
,
status
:{
$ne
:
2
}
//过滤被删除的数据,status 为 2 表示删除
};
if
(
tid
){
//获取最新5条评论
forumCommentService
.
getAllComment
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
){
if
(
err
){
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
thread
:
tid
,
level
:
'1'
,
status
:
{
$ne
:
2
}
//过滤被删除的数据,status 为 2 表示删除
};
if
(
tid
)
{
//获取最新5条评论
forumCommentService
.
getAllComment
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
log
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
// 更新评论状态
router
.
post
(
'/thread/comment/update/:cid'
,
function
(
req
,
res
,
next
){
var
cid
=
req
.
params
.
cid
||
null
;
var
status
=
req
.
body
.
status
;
if
(
cid
){
forumCommentService
.
updateCommentStatusById
(
cid
,
status
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
router
.
post
(
'/thread/comment/update/:cid'
,
function
(
req
,
res
,
next
)
{
var
cid
=
req
.
params
.
cid
||
null
;
var
status
=
req
.
body
.
status
;
var
tid
=
req
.
body
.
tid
;
var
comment_count
=
req
.
body
.
comment_count
;
var
level
=
req
.
body
.
level
;
var
parent_cid
=
req
.
body
.
parent_cid
;
if
(
cid
)
{
forumCommentService
.
updateCommentStatusById
(
cid
,
status
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
// 如果是删除
if
(
status
==
2
)
{
if
(
level
==
1
)
{
// 如果删除的是一级评论
// 获取评论的评论列表,并移除cid评论
forumThreadService
.
getById
(
tid
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
result
.
comment_count
-=
1
;
var
commentList
=
result
.
comments
;
result
.
comments
=
forumThreadService
.
remove
(
commentList
,
cid
);
forumThreadService
.
updateThreadById
(
tid
,
result
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
}
else
{
// 删除子评论
// 更新文章评论 - 1
forumThreadService
.
updateThreadCommentCount
(
tid
,
comment_count
-
1
,
function
(
err
,
result
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
});
// 更新评论的子评论列表
if
(
parent_cid
)
{
forumCommentService
.
getCommentById
(
parent_cid
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
commentList
=
result
.
comments
;
result
.
comments
=
forumCommentService
.
remove
(
commentList
,
cid
);
forumCommentService
.
updateCommentById
(
parent_cid
,
result
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
})
};
}
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
// 更新回复评论
router
.
post
(
'/thread/comment/update/:cid/comments'
,
function
(
req
,
res
,
next
){
var
cid
=
req
.
params
.
cid
||
null
;
var
replayComment_id
=
req
.
body
.
replayComment_id
;
// 获取评论的子评论列表
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
commentList
=
result
.
comments
;
result
.
comments
.
push
(
replayComment_id
);
forumCommentService
.
updateCommentById
(
cid
,
result
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
router
.
post
(
'/thread/comment/update/:cid/comments'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
body
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
replayComment_id
=
req
.
body
.
replayComment_id
;
// 获取评论的子评论列表
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
// 更新文章评论 + 1
forumThreadService
.
updateThreadCommentCountInc
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
});
// 更新评论对象
result
.
comments
.
push
(
replayComment_id
);
// 添加子评论ID
// result.comment_count+=1; // 回复评论+1
forumCommentService
.
updateCommentById
(
cid
,
result
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
});
// 更新评论的子评论列表
router
.
post
(
'/thread/comment/update/:cid/comments'
,
function
(
req
,
res
,
next
)
{
var
cid
=
req
.
params
.
cid
||
null
;
var
replayComment_id
=
req
.
body
.
replayComment_id
;
// 获取评论的子评论列表
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
commentList
=
result
.
comments
;
result
.
comments
.
push
(
replayComment_id
);
forumCommentService
.
updateCommentById
(
cid
,
result
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
});
//添加评论
router
.
post
(
'/thread/comment/add'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
body
.
tid
||
null
;
var
entity
=
req
.
body
;
entity
.
created
=
new
Date
();
entity
.
ent_code
=
req
.
session
.
user
.
ent_code
;
// entity.from = req.session.mobileForumUser.userId; // 正式环境
entity
.
from
=
'55015675868b65a028187c49'
;
// 测试环境
if
(
tid
){
// 添加评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
returnData
=
{
// returnCode.SUCCESS,
comment
:
result
}
res
.
json
(
returnData
);
}
});
}
});
\ No newline at end of file
var
tid
=
req
.
body
.
tid
||
null
;
var
entity
=
req
.
body
;
var
ip
=
getClientIP
(
req
);
entity
.
created
=
new
Date
();
entity
.
ent_code
=
req
.
session
.
user
.
ent_code
;
entity
.
ip
=
ip
;
var
uid
=
req
.
session
.
user
.
id
;
// 正式环境
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserService
.
getUserByUid
(
uid
,
callback
);
}
],
function
(
err
,
user
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
user
)
{
entity
.
from
=
user
.
_id
;
// 添加评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
returnData
=
{
comment
:
result
,
errorcode
:
0
,
errormsg
:
'请求成功'
}
res
.
json
(
returnData
);
}
});
}
else
{
var
userentity
=
{
uid
:
uid
,
nickName
:
req
.
session
.
user
.
name
,
icon
:
req
.
session
.
user
.
headPic
};
forumUserService
.
createUser
(
userentity
,
function
(
err
,
doc
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
entity
.
from
=
doc
.
_id
;
// 添加评论
forumCommentService
.
createComment
(
entity
,
function
(
err
,
result
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
returnData
=
{
comment
:
result
,
errorcode
:
0
,
errormsg
:
'请求成功'
}
res
.
json
(
returnData
);
}
});
}
});
}
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
// 测试环境
// entity.from = '55015675868b65a028187c49';
// if (tid) {
// // 添加评论
// forumCommentService.createComment(entity, function(err, result) {
// if (err) {
// res.json(returnCode.BUSY);
// } else {
// var returnData = {
// comment: result,
// errorcode: 0,
// errormsg: '请求成功'
// }
// res.json(returnData);
// }
// });
// }
});
// 更新文章评论
router
.
post
(
'/thread/:tid/updateComments'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
body
.
cid
||
null
;
// 获取评论的子评论列表
forumThreadService
.
getById
(
tid
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
result
.
comments
.
push
(
cid
);
result
.
comment_count
+=
1
;
forumThreadService
.
updateThreadById
(
tid
,
result
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
});
});
var
getClientIP
=
function
(
req
)
{
var
ipAddress
;
var
headers
=
req
.
headers
;
var
forwardedIpsStr
=
headers
[
'x-real-ip'
]
||
headers
[
'x-forwarded-for'
];
if
(
forwardedIpsStr
)
{
ipAddress
=
forwardedIpsStr
;
}
else
{
ipAddress
=
null
;
}
if
(
!
ipAddress
)
{
ipAddress
=
req
.
connection
.
remoteAddress
;
}
return
ipAddress
;
};
app/controllers/mobile/forumInfo.js
View file @
467e5e14
...
...
@@ -41,7 +41,8 @@ router.post('/info/create', function(req, res, next) {
router
.
get
(
'/info/:fid/get'
,
function
(
req
,
res
,
next
)
{
var
fid
=
req
.
params
.
fid
||
null
;
if
(
fid
)
{
httpService
.
createLog
(
req
,
fid
,
2
);
var
source
=
req
.
session
.
mobileForumUser
.
source
;
httpService
.
createLog
(
req
,
source
,
fid
,
2
);
async
.
waterfall
([
function
(
callback
)
{
//更新浏览数
...
...
@@ -133,7 +134,7 @@ router.get('/info/:fid/threads', function(req, res, next) {
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
fid
=
req
.
params
.
fid
;
var
sort
=
'top -topTime -created'
var
sort
=
'
-
top -topTime -created'
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
level
:
1
...
...
app/controllers/mobile/forumShare.js
View file @
467e5e14
...
...
@@ -17,8 +17,8 @@ module.exports = function(app) {
app
.
use
(
'/v1/forum'
,
router
);
};
function
write
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
)
{
link
=
config
.
service
+
link
+
"&mid="
+
mid
;
res
.
writeHead
(
200
,
{
'Content-Type'
:
'text/javascript'
,
'Cache-Control'
:
'no-cache'
,
...
...
@@ -74,3 +74,178 @@ function getWX(res, title, desc, link, imgUrl, mid,ent_code, id,type,forumThread
}
//微信分享接口
router
.
get
(
'/:ent_code/share.js'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
var
type
=
req
.
query
.
type
;
var
id
=
req
.
query
.
id
;
var
uId
=
req
.
session
.
mobileForumUser
.
userId
;
var
mid
=
0
;
if
(
req
.
session
.
openUser
&&
req
.
session
.
openUser
.
mid
)
{
mid
=
req
.
session
.
openUser
.
mid
;
}
var
ent_code
=
req
.
params
.
ent_code
;
var
link
=
'/app/forum/'
+
ent_code
+
'/index?pageUrl='
;
if
(
type
)
{
//板块微信接口
if
(
type
===
'Info'
)
{
then
(
function
(
cont
)
{
forumShareConfigService
.
getByKey
(
ent_code
,
'share'
,
function
(
err
,
result
)
{
var
title
=
''
,
desc
=
''
,
imgUrl
=
''
;
if
(
result
)
{
result
=
result
.
meta_value
;
for
(
var
i
=
0
;
i
<
result
.
length
;
i
++
)
{
if
(
result
[
i
].
type
===
'info'
)
{
title
=
result
[
i
].
title
;
desc
=
result
[
i
].
desc
;
imgUrl
=
result
[
i
].
imgUrl
;
}
}
if
(
id
)
{
link
=
link
+
'index&infoId='
+
id
;
}
else
{
link
=
link
+
'index'
;
}
link
=
link
+
'&uId='
+
uId
;
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
id
,
type
,
null
);
}
else
{
cont
(
err
);
}
});
}).
fail
(
function
(
cont
,
err
)
{
console
.
error
(
err
);
res
.
json
({
result
:
false
,
code
:
'10002'
});
});
}
else
if
(
!
id
)
{
console
.
error
(
"ID不能为空"
);
res
.
json
({
message
:
'ID不能为空'
,
result
:
false
,
code
:
'10002'
});
}
else
if
(
type
===
'Thread'
)
{
then
(
function
(
cont
)
{
//获得文章
forumThreadService
.
getById
(
id
,
function
(
err
,
result
)
{
if
(
result
)
{
cont
(
null
,
result
);
}
else
{
cont
(
err
);
}
});
}).
then
(
function
(
cont
,
result
)
{
//如果没有share值则用默认值
if
(
!
result
.
share
||
result
.
share_type
==
2
)
{
forumShareConfigService
.
getByKey
(
ent_code
,
'share'
,
function
(
err
,
sc
)
{
var
title
=
''
,
desc
=
''
,
imgUrl
=
''
;
if
(
sc
)
{
if
(
result
.
type
===
1
||
(
result
.
type
===
2
&&
result
.
level
===
2
))
{
link
=
link
+
'thread&infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
}
else
if
(
result
.
type
===
2
&&
result
.
level
===
1
)
{
link
=
link
+
'topicList&infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
}
else
if
(
result
.
type
===
3
)
{
link
=
link
+
'photoList&infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
}
//1、文章 2、话题 3、照片墙
sc
=
sc
.
meta_value
;
for
(
var
i
=
0
;
i
<
sc
.
length
;
i
++
)
{
if
(
result
.
type
===
1
||
(
result
.
type
===
2
&&
result
.
level
===
2
))
{
if
(
sc
[
i
].
type
===
'article'
)
{
title
=
sc
[
i
].
title
;
desc
=
sc
[
i
].
desc
;
imgUrl
=
sc
[
i
].
imgUrl
;
}
}
else
if
(
result
.
type
===
2
&&
result
.
level
===
1
)
{
if
(
sc
[
i
].
type
===
'topic'
)
{
title
=
sc
[
i
].
title
;
desc
=
sc
[
i
].
desc
;
imgUrl
=
sc
[
i
].
imgUrl
;
}
}
else
if
(
result
.
type
===
3
)
{
if
(
sc
[
i
].
type
===
'photo'
)
{
title
=
sc
[
i
].
title
;
desc
=
sc
[
i
].
desc
;
imgUrl
=
sc
[
i
].
imgUrl
;
}
}
}
link
=
link
+
'&uId='
+
uId
;
getWX
(
res
,
title
,
desc
,
link
,
imgUrl
,
mid
,
ent_code
,
result
.
_id
,
type
,
result
);
}
else
{
cont
(
err
);
}
});
}
else
{
//如果有分享设置,则返回分享设置
forumShareService
.
getById
(
result
.
share
,
function
(
err
,
forumShare
)
{
//1、文章 2、话题 3、照片墙
if
(
result
.
type
===
1
||
(
result
.
type
===
2
&&
result
.
level
===
2
))
{
link
=
link
+
'thread&infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
//key = 'article';
}
else
if
(
result
.
type
===
2
&&
result
.
level
===
1
)
{
link
=
link
+
'topicList&infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
//key = 'topic';
}
else
if
(
result
.
type
===
3
)
{
link
=
link
+
'photoList&infoId='
+
result
.
info
+
'&ent_code='
+
ent_code
+
'&id='
+
result
.
_id
;
//key = 'photo';
}
link
=
link
+
'&uId='
+
uId
;
getWX
(
res
,
forumShare
.
title
,
forumShare
.
description
,
link
,
forumShare
.
icon
,
mid
,
ent_code
,
result
.
_id
,
type
,
result
);
});
}
}).
fail
(
function
(
cont
,
err
)
{
console
.
error
(
err
);
res
.
json
({
result
:
false
,
code
:
'10002'
});
});
}
}
else
{
res
.
json
({
result
:
false
,
code
:
'10002'
});
}
});
//微信分享接口
router
.
get
(
'/:ent_code/timeline'
,
function
(
req
,
res
,
next
)
{
var
mid
=
req
.
session
.
openUser
.
mid
,
action
=
'share_timeline'
,
ent_code
=
req
.
session
.
user
.
ent_code
;
httpService
.
sendRequest
(
ent_code
,
mid
,
action
);
res
.
status
(
200
).
end
();
});
app/controllers/mobile/forumTag.js
View file @
467e5e14
...
...
@@ -58,7 +58,7 @@ router.get('/tag/:tid/threads', function(req, res, next) {
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
tid
=
req
.
params
.
tid
;
var
sort
=
'tag_top -tag_topTime -created'
;
var
sort
=
'
-
tag_top -tag_topTime -created'
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
};
...
...
app/controllers/mobile/forumThread.js
View file @
467e5e14
...
...
@@ -175,15 +175,16 @@ router.get('/thread/:tid/get', function(req, res, next) {
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
//文章类型 1、文章 2、话题 3、照片墙
var
info_id
=
thread
.
info
.
_id
,
pid
=
thread
.
pid
;
pid
=
thread
.
pid
,
source
=
req
.
session
.
mobileForumUser
.
source
;
if
(
thread
.
type
==
1
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
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
,
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
,
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
,
info_id
,
3
,
3
,
tid
);
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
3
,
tid
);
}
...
...
@@ -690,6 +691,8 @@ 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
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
...
...
app/models/forumPVLog.js
View file @
467e5e14
...
...
@@ -45,11 +45,15 @@ var ForumPVLogSchema = new Schema({
index
:
true
},
p_thread
:
{
//父文章ID
type
:
Number
,
index
:
true
type
:
String
,
index
:
true
,
ref
:
'forumThread'
},
source
:
{
//分享者
type
:
String
type
:
String
,
require
:
true
,
index
:
true
,
ref
:
'ForumUser'
},
ip
:
{
//IP地址
type
:
String
...
...
app/models/forumUVLog.js
View file @
467e5e14
...
...
@@ -45,11 +45,15 @@ var ForumUVLogSchema = new Schema({
index
:
true
},
p_thread
:
{
//父文章ID
type
:
Number
,
index
:
true
type
:
String
,
index
:
true
,
ref
:
'forumThread'
},
source
:
{
//分享者
type
:
String
type
:
String
,
require
:
true
,
index
:
true
,
ref
:
'ForumUser'
},
ip
:
{
//IP地址
type
:
String
...
...
app/service/forumCommentService.js
View file @
467e5e14
...
...
@@ -38,7 +38,6 @@ exports.updateCommentStatusById=function(cid,status,callback){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
console
.
log
(
result
);
callback
(
null
,
null
);
}
});
...
...
@@ -51,7 +50,6 @@ exports.updateCommentById=function(cid,entity,callback){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
console
.
log
(
result
);
callback
(
null
,
null
);
}
});
...
...
@@ -84,6 +82,7 @@ function countAll(conditions,callback) {
//获取全部列表数据
exports
.
getAllComment
=
function
(
conditions
,
pageNo
,
pageSize
,
callback
)
{
countAll
(
conditions
,
function
(
err
,
count
){
if
(
err
){
console
.
error
(
err
);
...
...
@@ -91,7 +90,7 @@ exports.getAllComment= function(conditions,pageNo,pageSize,callback) {
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
console
.
log
(
"count:"
+
count
);
ForumComment
.
find
(
conditions
).
populate
(
'from'
).
populate
(
'to'
).
limit
(
limit
).
skip
(
skip
).
sort
(
'-created'
).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
...
...
@@ -199,3 +198,21 @@ exports.updateCommentCount=function(cid,callback){
}
});
};
// 查找数组元素下标
function
indexOf
(
array
,
val
)
{
for
(
var
i
=
0
;
i
<
array
.
length
;
i
++
)
{
if
(
array
[
i
]
==
val
)
return
i
;
}
return
-
1
;
};
// 删除数组指定值
exports
.
remove
=
function
(
array
,
val
)
{
var
index
=
indexOf
(
array
,
val
);
if
(
index
>
-
1
)
{
array
.
splice
(
index
,
1
);
}
return
array
;
};
\ No newline at end of file
app/service/forumThreadService.js
View file @
467e5e14
...
...
@@ -254,9 +254,9 @@ exports.getThreadById = function(tid, callback) {
//根据ID更新文章
exports
.
updateThreadById
=
function
(
tid
,
entity
,
callback
)
{
var
shareEntity
=
entity
.
share
;
if
(
entity
.
share
&&
entity
.
share
.
_id
)
{
if
(
entity
.
share
&&
entity
.
share
.
_id
)
{
entity
.
share
=
entity
.
share
.
_id
;
}
else
{
}
else
{
entity
.
share
=
''
;
}
if
(
entity
.
share
)
{
...
...
@@ -283,7 +283,7 @@ exports.updateThreadById = function(tid, entity, callback) {
});
}
else
{
if
(
shareEntity
&&
(
shareEntity
.
title
||
shareEntity
.
description
||
shareEntity
.
icon
))
{
if
(
shareEntity
&&
(
shareEntity
.
title
||
shareEntity
.
description
||
shareEntity
.
icon
))
{
shareEntity
.
ent_code
=
entity
.
ent_code
;
var
forumShare
=
new
ForumShare
(
shareEntity
);
...
...
@@ -650,7 +650,7 @@ exports.updateThreadShareCount = function(threadId, callback) {
};
//更新文章评论数
exports
.
updateThreadCommentCount
=
function
(
threadId
,
callback
)
{
exports
.
updateThreadCommentCount
Inc
=
function
(
threadId
,
callback
)
{
ForumThread
.
update
({
_id
:
threadId
},
{
...
...
@@ -671,6 +671,23 @@ exports.updateThreadCommentCount = function(threadId, callback) {
});
};
//更新文章评论数
exports
.
updateThreadCommentCount
=
function
(
threadId
,
comment_count
,
callback
)
{
ForumThread
.
update
({
_id
:
threadId
},
{
'comment_count'
:
comment_count
},
null
,
function
(
err
,
result
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
};
//更新文章浏览数
exports
.
updateThreadPvCount
=
function
(
threadId
,
callback
)
{
ForumThread
.
update
({
...
...
@@ -692,3 +709,20 @@ exports.updateThreadPvCount = function(threadId, callback) {
}
});
};
// 查找数组元素下标
function
indexOf
(
array
,
val
)
{
for
(
var
i
=
0
;
i
<
array
.
length
;
i
++
)
{
if
(
array
[
i
]
==
val
)
return
i
;
}
return
-
1
;
};
// 删除数组指定值
exports
.
remove
=
function
(
array
,
val
)
{
var
index
=
indexOf
(
array
,
val
);
if
(
index
>
-
1
)
{
array
.
splice
(
index
,
1
);
}
return
array
;
};
app/service/httpService.js
View file @
467e5e14
...
...
@@ -50,10 +50,11 @@ var getClientIP = function(req) {
return
ipAddress
;
};
exports
.
createLog
=
function
(
req
,
info
,
type
,
thread_type
,
thread
,
p_thread
)
{
exports
.
createLog
=
function
(
req
,
source
,
info
,
type
,
thread_type
,
thread
,
p_thread
)
{
var
logObj
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
source
:
source
,
mid
:
req
.
session
.
openUser
.
mid
,
open_id
:
req
.
session
.
mobileForumUser
.
openId
,
user
:
req
.
session
.
mobileForumUser
.
userId
,
...
...
app/utils/user.js
View file @
467e5e14
...
...
@@ -3,8 +3,8 @@
var
forumUserService
=
require
(
'../service/forumUserService'
);
exports
.
getMobileUser
=
function
(
req
){
//
return req.session.mobileForumUser.userId;
return
'55015675868b65a028187c49'
;
return
req
.
session
.
mobileForumUser
.
userId
;
//
return '55015675868b65a028187c49';
}
exports
.
getOpenId
=
function
(
req
){
...
...
@@ -24,6 +24,10 @@ exports.identifyUser=function() {
userId
:
doc
.
_id
,
openId
:
doc
.
uid
};
if
(
req
.
session
.
source
){
req
.
session
.
mobileForumUser
.
source
=
req
.
session
.
source
;
delete
req
.
session
.
source
;
}
next
(
null
);
}
else
{
if
(
req
.
session
.
tmpOpenId
){
...
...
@@ -44,6 +48,11 @@ exports.identifyUser=function() {
userId
:
doc
.
_id
,
openId
:
doc
.
uid
};
if
(
req
.
session
.
source
){
req
.
session
.
mobileForumUser
.
source
=
req
.
session
.
source
;
delete
req
.
session
.
source
;
}
next
(
null
);
}
});
...
...
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