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
47910bdf
Commit
47910bdf
authored
Mar 27, 2015
by
张淼
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1
parent
590f5d04
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
96 additions
and
94 deletions
+96
-94
forumTag.js
app/controllers/mobile/forumTag.js
+0
-2
forumThread.js
app/controllers/mobile/forumThread.js
+41
-70
forumThread.js
app/models/forumThread.js
+10
-8
forumUser.js
app/models/forumUser.js
+5
-0
forumThreadService.js
app/service/forumThreadService.js
+40
-14
No files found.
app/controllers/mobile/forumTag.js
View file @
47910bdf
...
...
@@ -16,8 +16,6 @@ module.exports = function(app) {
app
.
use
(
'/v1/forum'
,
router
);
};
//查询所有标签
router
.
get
(
'/tag/list'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
...
...
app/controllers/mobile/forumThread.js
View file @
47910bdf
...
...
@@ -23,7 +23,34 @@ module.exports = function(app) {
};
//---------------------文章表单操作---------------------------------
function
create
(
req
,
callback
){
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
req
.
body
.
from
=
user
.
getMobileUser
(
req
);
//-----------处理前端上传图片开始
//格式为['http://imageurl','http://imageurl'],
//转换为[{urlFileName:'http://imageUrL'},{urlFileName:'http://imageUrL'}]
var
images
=
req
.
body
.
images
;
if
(
images
){
var
array
=
[];
for
(
var
i
=
0
;
i
<
images
.
length
;
i
=
i
+
1
){
array
.
push
({
urlFileName
:
images
[
i
]
});
}
req
.
body
.
images
=
array
;
}
//-----------处理前端上传图片结束
forumThreadService
.
createThread
(
req
.
body
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
entity
);
}
});
}
//新增论坛文章
router
.
post
(
'/thread/create'
,
function
(
req
,
res
,
next
)
{
...
...
@@ -35,32 +62,12 @@ router.post('/thread/create', function(req, res, next) {
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
//有操作权限
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
req
.
body
.
from
=
user
.
getMobileUser
(
req
);
// console.log(req.body);
//-----------处理前端上传图片开始
//格式为['http://imageurl','http://imageurl'],
//转换为[{urlFileName:'http://imageUrL'},{urlFileName:'http://imageUrL'}]
var
images
=
req
.
body
.
images
;
if
(
images
){
var
array
=
[];
for
(
var
i
=
0
;
i
<
images
.
length
;
i
=
i
+
1
){
array
.
push
({
urlFileName
:
images
[
i
]
});
}
req
.
body
.
images
=
array
;
}
//-----------处理前端上传图片结束
forumThreadService
.
createThread
(
req
.
body
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
create
(
req
,
function
(
err
,
thread
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
{
'id'
:
entity
.
_id
};
}
else
{
var
rs
=
{};
rs
.
data
=
{
'id'
:
thread
.
_id
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
...
...
@@ -71,59 +78,32 @@ router.post('/thread/create', function(req, res, next) {
});
});
/**
* [description]
* @param {[type]}
* @param {[type]}
* @param {[type]}
* @return {[type]}
*/
router
.
get
(
'/threads/list'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
status
:
1
};
forumThreadService
.
getAllThreadByFid
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
});
//获取目标论坛文章
router
.
get
(
'/thread/:tid/get'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
if
(
tid
){
async
.
waterfall
([
function
(
callback
){
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
forumThreadService
.
updateThreadPvCount
(
tid
,
function
(
err
,
doc
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
// console.log(thread);
callback
(
null
,
thread
);
callback
(
null
,
null
);
}
});
},
function
(
thread
,
callback
){
var
pv_count
=
thread
.
pv_count
+
1
;
thread
.
pv_count
=
pv_count
;
forumThreadService
.
updateThreadById
(
tid
,{
pv_count
:
pv_count
},
function
(
err
,
doc
){
function
(
data
,
callback
){
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
){
if
(
err
){
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
}
}
,
],
function
(
err
,
thread
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{};
...
...
@@ -332,22 +312,12 @@ router.post('/thread/:tid/share', function(req, res, next) {
});
//新增文章评论
/**
**输入:
tid:文章id
pId:评论父id
comment:评论内容
**输出:
操作结果
**/
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'
;
console
.
log
(
'===========integral:'
+
integral
);
console
.
log
(
'===========exp:'
+
exp
);
//1.检查是否有权限
forumRolePermissionService
.
checkRolePermiss
(
req
.
session
.
user
.
ent_code
,
'comment'
,
integral
,
exp
,
function
(
err
,
result
){
if
(
err
){
...
...
@@ -462,7 +432,6 @@ router.post('/thread/:tid/comment/create', function(req, res, next) {
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
}
else
{
console
.
log
(
'no permiss'
);
res
.
json
(
returnCode
.
ACTION_NOT_PERMISSION
);
}
}
...
...
@@ -485,6 +454,7 @@ router.post('/thread/:tid/comment/:cid/create', function(req, res, next) {
//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
){
//有操作权限
...
...
@@ -578,6 +548,7 @@ router.post('/thread/:tid/comment/:cid/delete', function(req, res, next) {
if
(
tid
&&
cid
){
forumCommentService
.
getCommentById
(
cid
,
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
if
(
result
){
...
...
app/models/forumThread.js
View file @
47910bdf
...
...
@@ -25,21 +25,23 @@ var ForumThreadSchema = new Schema({
type
:
String
,
require
:
true
},
type
:{
//文章类型 1、文章 2、
照片墙 3、话题
type
:{
//文章类型 1、文章 2、
话题 3、照片墙
type
:
Number
,
require
:
true
},
pid
:{
//文章父ID
type
:
Schema
.
Types
.
ObjectId
,
ref
:
'ForumThread'
level
:{
//文章等级(1级在列表页显示 2级是归属于话题、照片墙的文章)
type
:
Number
,
require
:
true
,
default
:
1
},
pid
:{
type
:
Schema
.
Types
.
ObjectId
},
content
:
{
//话题内容
type
:
String
,
require
:
true
type
:
String
},
icon
:
{
//话题图标
type
:
String
,
require
:
true
type
:
String
},
order_idx
:
{
//论坛排序
type
:
Number
,
...
...
app/models/forumUser.js
View file @
47910bdf
...
...
@@ -32,6 +32,11 @@ var ForumUserSchema = new Schema({
require
:
true
,
default
:
0
},
address
:
{
//地址
country
:{
type
:
String
,
default
:
''
},
province
:{
type
:
String
,
default
:
''
},
city
:{
type
:
String
,
default
:
''
},
},
status
:
{
//用户状态1,正常,2黑名单
type
:
Number
,
require
:
true
,
...
...
app/service/forumThreadService.js
View file @
47910bdf
...
...
@@ -36,16 +36,6 @@ exports.getThreadById=function(tid,callback){
if
(
docs
&&
docs
.
length
>
0
)
{
thread
=
docs
[
0
];
cb
(
null
,
thread
);
// populateComment(thread, function(err,results){
// if (err) {
// console.log(err);
// cb(null, null);
// } else {
// var threadObj = thread.toObject();
// threadObj.comments = results;
// cb(null,threadObj);
// }
// });
}
else
{
cb
(
null
,
thread
);
}
...
...
@@ -53,7 +43,7 @@ exports.getThreadById=function(tid,callback){
});
},
function
(
cb
){
var
conditions
=
{
var
conditions
=
{
thread
:
tid
,
level
:
'1'
};
...
...
@@ -66,6 +56,20 @@ exports.getThreadById=function(tid,callback){
cb
(
null
,
results
);
}
});
},
function
(
cb
){
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
pdi
:
tid
};
getAllThreadByFidHelp
(
conditions
,
1
,
10
,
function
(
err
,
threads
){
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
threads
);
}
});
}
],
function
(
err
,
results
){
if
(
err
){
...
...
@@ -73,9 +77,11 @@ exports.getThreadById=function(tid,callback){
}
else
{
var
thread
=
results
[
0
];
var
comments
=
results
[
1
];
var
subThreads
=
results
[
2
];
// console.log(thread);
var
threadObj
=
thread
.
toObject
();
threadObj
.
comments
=
comments
;
threadObj
.
subThreads
=
subThreads
;
callback
(
null
,
threadObj
);
}
});
...
...
@@ -196,8 +202,7 @@ exports.getAllCountByFid=function(conditions,callback){
countAllByFid
(
conditions
,
callback
);
}
//获取全部列表数据
exports
.
getAllThreadByFid
=
function
(
conditions
,
pageNo
,
pageSize
,
callback
)
{
function
getAllThreadByFidHelp
(
conditions
,
pageNo
,
pageSize
,
callback
){
countAllByFid
(
conditions
,
function
(
err
,
count
){
if
(
err
){
console
.
error
(
err
);
...
...
@@ -240,6 +245,11 @@ exports.getAllThreadByFid= function(conditions,pageNo,pageSize,callback) {
});
}
});
}
//获取全部列表数据
exports
.
getAllThreadByFid
=
function
(
conditions
,
pageNo
,
pageSize
,
callback
)
{
getAllThreadByFidHelp
(
conditions
,
pageNo
,
pageSize
,
callback
);
};
//根据板块ID更新板块下的top为0,并把当前文章的top设为1(置顶)
...
...
@@ -291,7 +301,7 @@ exports.updateThreadShareCount=function(threadId,callback){
});
};
//更新文章
分享
数
//更新文章
评论
数
exports
.
updateThreadCommentCount
=
function
(
threadId
,
callback
){
ForumThread
.
update
(
{
_id
:
threadId
},
...
...
@@ -306,3 +316,19 @@ exports.updateThreadCommentCount=function(threadId,callback){
}
});
};
//更新文章浏览数
exports
.
updateThreadPvCount
=
function
(
threadId
,
callback
){
ForumThread
.
update
(
{
_id
:
threadId
},
{
$inc
:
{
pv_count
:
1
}},
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
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