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
277c2858
Commit
277c2858
authored
Dec 14, 2015
by
陈家荣
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
增加荣誉头衔管理功能
parent
e0b6068c
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
354 additions
and
79 deletions
+354
-79
forumHonorTitle.js
app/controllers/admin/forumHonorTitle.js
+172
-0
forumMember.js
app/controllers/admin/forumMember.js
+23
-0
forumHonorTitle.js
app/models/forumHonorTitle.js
+40
-0
forumHonorTitleService.js
app/service/forumHonorTitleService.js
+118
-0
forumUserService.js
app/service/forumUserService.js
+1
-79
No files found.
app/controllers/admin/forumHonorTitle.js
0 → 100644
View file @
277c2858
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
ForumHonorTitle
=
mongoose
.
model
(
'ForumHonorTitle'
);
var
forumHonorTitleService
=
require
(
'../../service/forumHonorTitleService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
};
//新增
router
.
post
(
'/honorTitle/create'
,
function
(
req
,
res
,
next
)
{
var
rs
=
{};
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
forumHonorTitleService
.
create
(
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
.
post
(
'/honorTitle/:id/delete'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
if
(
id
){
forumHonorTitleService
.
deleteById
(
id
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//更新
router
.
post
(
'/honorTitle/:id/update'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
var
entity
=
req
.
body
;
if
(
id
&&
entity
){
forumHonorTitleService
.
updateById
(
id
,
entity
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//获取
router
.
get
(
'/honorTitle/:id/get'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
||
null
;
var
rs
=
{};
if
(
id
)
{
forumHonorTitleService
.
getById
(
id
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
rs
.
data
=
entity
;
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//直接修改序号
router
.
put
(
'/honorTitle/orderIDX/:id/:order'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
var
idx
=
req
.
params
.
order
;
forumHonorTitleService
.
updateIdx
(
id
,
idx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
});
});
//上移
router
.
put
(
'/honorTitle/moveUP/:id/:order'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
var
idx
=
req
.
params
.
order
;
var
titleName
=
req
.
query
.
titleName
||
''
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
};
if
(
tagName
){
conditions
.
title
=
{
$regex
:
titleName
,
$options
:
'i'
};
}
forumHonorTitleService
.
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
;
}
forumHonorTitleService
.
updateIdx
(
id
,
preidx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
forumHonorTitleService
.
updateIdx
(
preObj
.
_id
,
idx
,
function
(
err
,
result
){
if
(
err
||
!
result
){
return
res
.
json
(
returnCode
.
BUSY
);
}
return
res
.
json
(
_
.
assign
({
data
:
true
},
returnCode
.
SUCCESS
));
});
});
});
});
//查询所有
router
.
get
(
'/honorTitle/list'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
,
pageSize
=
req
.
query
.
pageSize
||
10
,
titleName
=
req
.
query
.
titleName
||
''
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
};
if
(
titleName
){
conditions
.
title
=
{
$regex
:
titleName
,
$options
:
'i'
};
}
forumHonorTitleService
.
getAll
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
});
app/controllers/admin/forumMember.js
View file @
277c2858
...
@@ -65,6 +65,11 @@ router.post('/member/searchMembers', function(req, res, next) {
...
@@ -65,6 +65,11 @@ router.post('/member/searchMembers', function(req, res, next) {
if
(
search
.
status
)
{
if
(
search
.
status
)
{
q
.
status
=
search
.
status
;
q
.
status
=
search
.
status
;
}
}
if
(
search
.
honorTitleId
)
{
q
.
honorTitles
=
{
$in
:
[
search
.
honorTitleId
]
};
}
forumUserService
.
searchMembersAndLimitActions
(
pageNo
,
pageSize
,
q
,
function
(
err
,
results
)
{
forumUserService
.
searchMembersAndLimitActions
(
pageNo
,
pageSize
,
q
,
function
(
err
,
results
)
{
if
(
err
)
{
if
(
err
)
{
console
.
error
(
err
);
console
.
error
(
err
);
...
@@ -136,3 +141,21 @@ router.get('/member/getMidByUid/:uid', function(req, res, next) {
...
@@ -136,3 +141,21 @@ router.get('/member/getMidByUid/:uid', function(req, res, next) {
});
});
}
}
});
});
//更新
router
.
post
(
'/member/:mid/update'
,
function
(
req
,
res
,
next
)
{
var
mid
=
req
.
params
.
mid
;
var
entity
=
req
.
body
;
if
(
mid
&&
entity
){
forumUserService
.
updateUserById
(
mid
,
entity
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
\ No newline at end of file
app/models/forumHonorTitle.js
0 → 100644
View file @
277c2858
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
//荣誉头衔
var
ForumHonorTitleSchema
=
new
Schema
({
ent_code
:
{
type
:
Number
,
require
:
true
,
index
:
true
},
title
:
{
//荣誉头衔标题
type
:
String
,
require
:
true
,
},
icon
:
{
//荣誉头衔图片
type
:
String
},
order_idx
:
{
//荣誉头衔排序
type
:
Number
,
require
:
true
,
default
:
0
},
status
:
{
//荣誉头衔状态,1启用,0停用
type
:
Number
,
require
:
true
,
default
:
1
},
created
:
{
type
:
Date
,
required
:
true
,
default
:
Date
.
now
}
},
{
'collection'
:
'pisns_forum_honor_title'
});
module
.
exports
=
mongoose
.
model
(
'ForumHonorTitle'
,
ForumHonorTitleSchema
);
\ No newline at end of file
app/service/forumHonorTitleService.js
0 → 100644
View file @
277c2858
'use strict'
;
var
mongoose
=
require
(
'mongoose'
);
var
ForumHonorTitle
=
mongoose
.
model
(
'ForumHonorTitle'
);
//创建
exports
.
create
=
function
(
entity
,
callback
){
var
forum
=
new
ForumHonorTitle
(
entity
);
forum
.
save
(
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
doc
);
}
});
};
//根据ID获取
exports
.
getById
=
function
(
tid
,
callback
){
ForumHonorTitle
.
findById
(
tid
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
doc
);
}
});
};
//根据ID更新
exports
.
updateById
=
function
(
tid
,
entity
,
callback
){
ForumHonorTitle
.
update
({
_id
:
tid
},
entity
,
null
,
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
};
//根据ID删除
exports
.
deleteById
=
function
(
tid
,
callback
){
ForumHonorTitle
.
remove
({
_id
:
tid
},
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
};
//获取数量
function
countAll
(
conditions
,
callback
)
{
ForumHonorTitle
.
count
(
conditions
,
function
(
err
,
count
)
{
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
count
);
}
});
}
//获取全部列表数据
exports
.
getAll
=
function
(
conditions
,
pageNo
,
pageSize
,
callback
)
{
countAll
(
conditions
,
function
(
err
,
count
){
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumHonorTitle
.
find
(
conditions
,
null
,
{
skip
:
skip
,
limit
:
limit
,
sort
:{
order_idx
:
1
}},
function
(
err
,
docs
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
var
obj
=
{};
obj
.
total
=
count
;
obj
.
pageNo
=
pageNo
;
obj
.
pageSize
=
pageSize
;
obj
.
items
=
docs
;
callback
(
null
,
obj
);
}
});
}
});
};
exports
.
getAllOrderIDX
=
function
(
conditions
,
callback
){
ForumHonorTitle
.
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
.
updateIdx
=
function
(
id
,
idx
,
callback
){
ForumHonorTitle
.
update
(
{
_id
:
id
},
{
order_idx
:
idx
},
null
,
function
(
err
,
result
){
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
true
);
}
});
};
app/service/forumUserService.js
View file @
277c2858
...
@@ -125,7 +125,7 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
...
@@ -125,7 +125,7 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
}).
then
(
function
(
cont
,
count
)
{
}).
then
(
function
(
cont
,
count
)
{
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
var
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
ForumUser
.
find
(
q
).
skip
(
skip
).
limit
(
limit
).
sort
(
'-created'
).
exec
(
function
(
err
,
docs
)
{
ForumUser
.
find
(
q
).
skip
(
skip
).
limit
(
limit
).
sort
(
'-created'
).
populate
(
'honorTitles'
).
exec
(
function
(
err
,
docs
)
{
cont
(
err
,
count
,
docs
);
cont
(
err
,
count
,
docs
);
});
});
}).
then
(
function
(
cont
,
count
,
members
)
{
}).
then
(
function
(
cont
,
count
,
members
)
{
...
@@ -197,81 +197,3 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
...
@@ -197,81 +197,3 @@ exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
});
});
};
};
//查询用户和行为限制信息
// exports.searchMembersAndLimitActions=function(pageNo, pageSize, q, callback){
// then(function(cont) {
// ForumUser.find(q).count(cont);
// }).then(function(cont, count) {
// var skip = (pageNo - 1) * pageSize;
// var limit = count - skip > pageSize ? pageSize : (count - skip);
// ForumUser.find(q).skip(skip).limit(limit).sort('-created').exec(function(err, docs) {
// cont(err, count, docs);
// });
// }).then(function(cont, count, members) {
// forumLimitActionConfigService.getAllLimitActionConfig(function(err, configs) {
// cont(err, count, members, configs);
// });
// }).then(function(cont, count, members, configs) {
// if (count > 0 && configs.length > 0) {
// var asyncTasks = [];
// members.forEach(function(member) {
// asyncTasks.push(function(callback) {
// forumLimitActionRefService.getLimitActionRefByMIdAndEntCode(member._id, member.ent_code, function(err, forumLimitActionRef) {
// if (err) {
// console.error(err);
// callback(null, null);
// } else {
// if(forumLimitActionRef){
// var limit_actions = forumLimitActionRef.limit_actions;
// var array = [];
// for (var i = 0; i < limit_actions.length; i += 1) {
// var limit_action = limit_actions[i];
// for(var k = 0; k < configs.length; k+=1){
// if(limit_action.limit_action_type === configs[k].code){
// array.push(configs[k].name);
// break;
// }
// }
// }
// member = member.toObject();
// member.limitActions = array;
// callback(null, member);
// }else{
// callback(null, member);
// }
// }
// });
// });
// });
// async.parallel(asyncTasks, function(err, results) {
// if (err) {
// console.log(err);
// callback(null, null);
// } else {
// // callback(null, results);
// var rsJson = {
// result: true,
// total: count,
// datas: results
// };
// callback(null, rsJson);
// }
// });
// } else {
// var rsJson = {
// result: true,
// total: count,
// datas: members
// };
// callback(null, rsJson);
// }
// }).fail(function(cont, err) {
// console.error(err);
// var rsJson = {
// result: false,
// err: err
// };
// callback(err, rsJson);
// });
// };
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