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
656e7786
Commit
656e7786
authored
Oct 28, 2015
by
刘文胜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
11111
parent
13cf76cf
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
264 additions
and
46 deletions
+264
-46
forumInfo.js
app/controllers/admin/forumInfo.js
+47
-4
forumNotice.js
app/controllers/admin/forumNotice.js
+128
-29
forumTag.js
app/controllers/admin/forumTag.js
+49
-10
forumInfoService.js
app/service/forumInfoService.js
+13
-3
forumTagService.js
app/service/forumTagService.js
+27
-0
No files found.
app/controllers/admin/forumInfo.js
View file @
656e7786
...
@@ -225,13 +225,56 @@ router.get('/infos/list', function(req, res, next) {
...
@@ -225,13 +225,56 @@ router.get('/infos/list', function(req, res, next) {
});
});
//板块上移
//板块上移
router
.
put
(
'/infos/moveUP/:id'
,
function
(
req
,
res
,
next
)
{
router
.
put
(
'/infos/moveUP/:id
/:order
'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
var
id
=
req
.
params
.
id
;
forumInfoService
.
updateInfoIdx
(
id
,
function
(
err
,
result
){
var
idx
=
req
.
params
.
order
;
if
(
err
||
!
result
){
var
groupId
=
req
.
body
.
groupId
||
null
;
var
infoName
=
req
.
body
.
infoName
||
null
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
order_idx
:{
$gte
:
idx
}
};
if
(
groupId
){
conditions
.
group
=
groupId
;
}
if
(
infoName
){
conditions
.
name
=
{
$regex
:
infoName
,
$options
:
'i'
};
}
forumInfoService
.
getAllOrderIDX
(
conditions
,
function
(
err
,
results
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
return
res
.
json
(
returnCode
.
BUSY
);
}
}
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
var
index
=-
1
;
_
.
forEach
(
results
,
function
(
r
,
i
){
if
(
r
.
_id
.
toString
()
===
id
.
toString
()){
index
=
i
;
}
});
if
(
index
===
-
1
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
preObj
=
results
[
index
-
1
];
if
(
!
preObj
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
preidx
=
preObj
.
order_idx
;
if
(
preidx
.
toString
()
===
idx
.
toString
()){
preidx
=
Number
(
preidx
)
+
1
;
}
forumInfoService
.
updateInfoIdx
(
id
,
preidx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
forumInfoService
.
updateInfoIdx
(
preObj
.
_id
,
idx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
});
});
});
});
});
});
...
...
app/controllers/admin/forumNotice.js
View file @
656e7786
...
@@ -31,6 +31,29 @@ function getPageInfo(pageNo,pageSize,count){
...
@@ -31,6 +31,29 @@ function getPageInfo(pageNo,pageSize,count){
};
};
}
}
function
updateNoticIdx
(
id
,
idx
,
callback
){
Notice
.
update
(
{
_id
:
id
},
{
order_idx
:
idx
},
null
,
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
true
);
}
});
}
function
getAllOrderIDX
(
condition
,
sort
,
callback
){
Notice
.
find
(
condition
).
select
(
'_id order_idx'
).
sort
(
sort
).
exec
(
function
(
err
,
results
){
//分页查询
if
(
err
){
return
callback
&&
callback
(
err
);
}
return
callback
&&
callback
(
false
,
results
);
});
}
function
queryList
(
condition
,
sort
,
pageNo
,
pageSize
,
callback
){
function
queryList
(
condition
,
sort
,
pageNo
,
pageSize
,
callback
){
condition
=
condition
||
{};
condition
=
condition
||
{};
sort
=
sort
||
{};
sort
=
sort
||
{};
...
@@ -72,22 +95,6 @@ function update(obj,callback){
...
@@ -72,22 +95,6 @@ function update(obj,callback){
});
});
}
}
//上移
router
.
put
(
'/notice/moveUP/:id'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
Notice
.
update
(
{
_id
:
id
},
{
$inc
:
{
order_idx
:
1
}},
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
){
if
(
err
){
return
res
.
json
({
err
:
err
});
}
else
{
res
.
json
({
result
:
true
});
}
});
});
router
.
post
(
'/notice'
,
function
(
req
,
res
,
next
)
{
router
.
post
(
'/notice'
,
function
(
req
,
res
,
next
)
{
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
var
notice
=
new
Notice
(
req
.
body
);
var
notice
=
new
Notice
(
req
.
body
);
...
@@ -116,25 +123,13 @@ router.post('/notice/search', function(req, res, next) {
...
@@ -116,25 +123,13 @@ router.post('/notice/search', function(req, res, next) {
title
=
req
.
body
.
title
,
title
=
req
.
body
.
title
,
label
=
req
.
body
.
label
,
label
=
req
.
body
.
label
,
plate
=
req
.
body
.
plate
,
plate
=
req
.
body
.
plate
,
//createtime=req.body.createtime;
sort
=
req
.
body
.
sort
,
begin_time
=
req
.
body
.
begin_time
,
begin_time
=
req
.
body
.
begin_time
,
end_time
=
req
.
body
.
end_time
,
end_time
=
req
.
body
.
end_time
,
top
=
req
.
body
.
top
,
top
=
req
.
body
.
top
,
status
=
req
.
body
.
status
,
status
=
req
.
body
.
status
,
finished
=
req
.
body
.
finished
;
finished
=
req
.
body
.
finished
;
var
_condition
=
{
ent_code
:
req
.
session
.
user
.
ent_code
},
_sort
=
{};
var
_condition
=
{
ent_code
:
req
.
session
.
user
.
ent_code
},
_sort
=
{
top
:
-
1
,
order_idx
:
-
1
,
createtime
:
-
1
};
//如果sort为空
if
(
!
sort
)
{
_sort
=
{
top
:
-
1
,
order_idx
:
-
1
,
createtime
:
-
1
};
}
if
(
sort
){
_sort
[
sort
]
=
-
1
;
//降序
// console.log("改了排序");
//_sort = {top:-1,createtime:-1};
}
if
(
title
){
if
(
title
){
_condition
.
title
=
new
RegExp
(
title
,
'i'
);
_condition
.
title
=
new
RegExp
(
title
,
'i'
);
...
@@ -202,6 +197,110 @@ router.post('/notice/search', function(req, res, next) {
...
@@ -202,6 +197,110 @@ router.post('/notice/search', function(req, res, next) {
});
});
});
});
//上移
router
.
put
(
'/notice/moveUP/:id/:order'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
var
idx
=
req
.
params
.
order
;
var
type
=
req
.
body
.
type
,
title
=
req
.
body
.
title
,
label
=
req
.
body
.
label
,
plate
=
req
.
body
.
plate
,
begin_time
=
req
.
body
.
begin_time
,
end_time
=
req
.
body
.
end_time
,
top
=
req
.
body
.
top
,
status
=
req
.
body
.
status
,
finished
=
req
.
body
.
finished
;
var
_condition
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
order_idx
:{
$gte
:
idx
}},
_sort
=
{
top
:
-
1
,
order_idx
:
-
1
,
createtime
:
-
1
};
if
(
title
){
_condition
.
title
=
new
RegExp
(
title
,
'i'
);
}
if
(
label
){
_condition
.
label
=
new
RegExp
(
label
,
'i'
);
}
if
(
begin_time
){
if
(
!!!
_condition
.
createtime
){
_condition
.
createtime
=
{};
}
var
gte
=
'$gte'
;
_condition
.
createtime
[
gte
]
=
begin_time
;
}
if
(
end_time
){
if
(
!!!
_condition
.
createtime
){
_condition
.
createtime
=
{};
}
var
lte
=
'$lte'
;
_condition
.
createtime
[
lte
]
=
end_time
;
}
try
{
if
(
!!
type
){
_condition
.
type
=
Number
(
type
);
}
}
catch
(
err
){
delete
_condition
.
type
;
}
try
{
if
(
!!
top
){
_condition
.
top
=
Number
(
top
);
}
}
catch
(
err
){
delete
_condition
.
top
;
}
try
{
if
(
!!
status
){
_condition
.
status
=
Number
(
status
);
}
}
catch
(
err
){
delete
_condition
.
status
;
}
try
{
if
(
!!
finished
){
_condition
.
finished
=
Number
(
finished
);
}
}
catch
(
err
){
delete
_condition
.
finished
;
}
if
(
!!
plate
){
_condition
.
plate
=
plate
;
}
getAllOrderIDX
(
_condition
,
_sort
,
function
(
err
,
results
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
index
=-
1
;
_
.
forEach
(
results
,
function
(
r
,
i
){
if
(
r
.
_id
.
toString
()
===
id
.
toString
()){
index
=
i
;
}
});
if
(
index
===
-
1
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
preObj
=
results
[
index
-
1
];
if
(
!
preObj
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
preidx
=
preObj
.
order_idx
;
if
(
preidx
.
toString
()
===
idx
.
toString
()){
preidx
=
Number
(
preidx
)
+
1
;
}
updateNoticIdx
(
id
,
preidx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
updateNoticIdx
(
preObj
.
_id
,
idx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
});
});
});
});
router
.
get
(
'/notice/:id'
,
function
(
req
,
res
,
next
)
{
router
.
get
(
'/notice/:id'
,
function
(
req
,
res
,
next
)
{
Notice
.
findById
(
req
.
params
.
id
,
function
(
err
,
result
){
Notice
.
findById
(
req
.
params
.
id
,
function
(
err
,
result
){
if
(
err
){
if
(
err
){
...
...
app/controllers/admin/forumTag.js
View file @
656e7786
...
@@ -96,19 +96,58 @@ router.get('/tag/:tid/get', function(req, res, next) {
...
@@ -96,19 +96,58 @@ router.get('/tag/:tid/get', function(req, res, next) {
});
});
//上移
//上移
router
.
put
(
'/tag/moveUP/:id'
,
function
(
req
,
res
,
next
)
{
router
.
put
(
'/tag/moveUP/:id
/:order
'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
var
id
=
req
.
params
.
id
;
ForumTag
.
update
(
var
idx
=
req
.
params
.
order
;
{
_id
:
id
},
var
tagName
=
req
.
query
.
tagName
||
''
;
{
$inc
:
{
order_idx
:
1
}},
var
info
=
req
.
query
.
info
||
''
;
{
w
:
1
,
safe
:
true
},
function
(
err
,
result
){
var
conditions
=
{
if
(
err
){
ent_code
:
req
.
session
.
user
.
ent_code
,
return
res
.
json
({
err
:
err
});
order_idx
:{
$gte
:
idx
}
}
else
{
};
res
.
json
({
result
:
true
});
if
(
tagName
){
conditions
.
title
=
{
$regex
:
tagName
,
$options
:
'i'
};
}
if
(
info
){
conditions
.
info
=
info
;
}
forumTagService
.
getAllOrderIDX
(
conditions
,
function
(
err
,
results
){
if
(
err
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
index
=-
1
;
_
.
forEach
(
results
,
function
(
r
,
i
){
if
(
r
.
_id
.
toString
()
===
id
.
toString
()){
index
=
i
;
}
}
});
});
if
(
index
===
-
1
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
preObj
=
results
[
index
-
1
];
if
(
!
preObj
){
return
res
.
json
(
returnCode
.
BUSY
);
}
var
preidx
=
preObj
.
order_idx
;
if
(
preidx
.
toString
()
===
idx
.
toString
()){
preidx
=
Number
(
preidx
)
+
1
;
}
forumTagService
.
updateTagIdx
(
id
,
preidx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
forumTagService
.
updateTagIdx
(
preObj
.
_id
,
idx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
});
});
});
});
});
//查询所有标签
//查询所有标签
...
...
app/service/forumInfoService.js
View file @
656e7786
...
@@ -89,6 +89,16 @@ exports.getAllByGid= function(conditions,pageNo,pageSize,callback) {
...
@@ -89,6 +89,16 @@ exports.getAllByGid= function(conditions,pageNo,pageSize,callback) {
});
});
};
};
exports
.
getAllOrderIDX
=
function
(
conditions
,
callback
){
ForumInfo
.
find
(
conditions
).
select
(
'_id order_idx'
).
sort
({
order_idx
:
-
1
}).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
docs
);
}
});
};
//更新板块浏览数
//更新板块浏览数
exports
.
updateInfoPvCount
=
function
(
fid
,
callback
){
exports
.
updateInfoPvCount
=
function
(
fid
,
callback
){
ForumInfo
.
update
(
ForumInfo
.
update
(
...
@@ -106,11 +116,11 @@ exports.updateInfoPvCount=function(fid,callback){
...
@@ -106,11 +116,11 @@ exports.updateInfoPvCount=function(fid,callback){
};
};
//上移
//上移
exports
.
updateInfoIdx
=
function
(
fid
,
callback
){
exports
.
updateInfoIdx
=
function
(
fid
,
idx
,
callback
){
ForumInfo
.
update
(
ForumInfo
.
update
(
{
_id
:
fid
},
{
_id
:
fid
},
{
$inc
:
{
order_idx
:
1
}
},
{
order_idx
:
idx
},
{
w
:
1
,
safe
:
true
}
,
null
,
function
(
err
,
result
){
function
(
err
,
result
){
if
(
err
){
if
(
err
){
console
.
error
(
err
);
console
.
error
(
err
);
...
...
app/service/forumTagService.js
View file @
656e7786
...
@@ -89,3 +89,30 @@ exports.getAllTag= function(conditions,pageNo,pageSize,callback) {
...
@@ -89,3 +89,30 @@ exports.getAllTag= function(conditions,pageNo,pageSize,callback) {
});
});
};
};
exports
.
getAllOrderIDX
=
function
(
conditions
,
callback
){
ForumTag
.
find
(
conditions
).
select
(
'_id order_idx'
).
sort
({
order_idx
:
-
1
}).
exec
(
function
(
err
,
docs
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
docs
);
}
});
};
//修改序号
exports
.
updateTagIdx
=
function
(
id
,
idx
,
callback
){
ForumTag
.
update
(
{
_id
:
id
},
{
order_idx
:
idx
},
null
,
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
true
);
}
});
};
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