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
6463fd2d
Commit
6463fd2d
authored
Mar 22, 2016
by
陈家荣
1
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
意见管理
parent
ab917852
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
312 additions
and
1 deletion
+312
-1
forumSuggestion.js
app/controllers/admin/forumSuggestion.js
+119
-0
fourmSuggestion.js
app/controllers/mobile/fourmSuggestion.js
+38
-0
forumSuggestion.js
app/models/forumSuggestion.js
+41
-0
forumSuggestionService.js
app/service/forumSuggestionService.js
+105
-0
forumUserService.js
app/service/forumUserService.js
+8
-0
cacheable.js
app/utils/cacheable.js
+1
-1
No files found.
app/controllers/admin/forumSuggestion.js
0 → 100644
View file @
6463fd2d
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
);
var
mongoose
=
require
(
'mongoose'
);
var
forumSuggestionService
=
require
(
'../../service/forumSuggestionService'
);
var
forumUserService
=
require
(
'../../service/forumUserService'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
};
//获取
router
.
get
(
'/suggestion/:id/get'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
||
null
;
if
(
id
)
{
forumSuggestionService
.
getById
(
id
,
function
(
err
,
entity
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
rs
=
{
data
:
entity
};
res
.
json
(
_
.
assign
(
rs
,
returnCode
.
SUCCESS
));
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//屏蔽
router
.
post
(
'/suggestion/:id/shield'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
;
if
(
id
){
forumSuggestionService
.
findOneAndUpdate
({
_id
:
id
},{
status
:
2
},
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
(
'/suggestion/searchList'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
||
1
,
pageSize
=
req
.
query
.
pageSize
||
10
,
title
=
req
.
query
.
title
||
''
,
content
=
req
.
query
.
content
||
''
,
mid
=
req
.
query
.
mid
||
''
,
nickName
=
req
.
query
.
nickName
||
''
;
var
conditions
=
{
ent_code
:
req
.
session
.
user
.
ent_code
,
status
:
1
};
if
(
title
){
conditions
.
title
=
{
$regex
:
title
,
$options
:
'i'
};
}
if
(
content
){
conditions
.
content
=
{
$regex
:
content
,
$options
:
'i'
};
}
if
(
nickName
||
mid
){
//先找出用户
var
q
=
{};
if
(
nickName
){
q
.
nickName
=
{
$regex
:
nickName
,
$options
:
'i'
}
}
if
(
mid
){
q
.
mid
=
mid
;
}
forumUserService
.
searchMembersWithFields
(
q
,
"_id"
,
null
,
function
(
err
,
docs
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
var
ids
=
[];
_
.
forEach
(
docs
,
function
(
e
)
{
ids
.
push
(
e
.
_id
);
});
conditions
.
from
=
{
$in
:
ids
}
forumSuggestionService
.
getAll
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
}
else
{
forumSuggestionService
.
getAll
(
conditions
,
pageNo
,
pageSize
,
function
(
err
,
results
){
if
(
err
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
_
.
assign
(
results
,
returnCode
.
SUCCESS
));
}
});
}
});
\ No newline at end of file
app/controllers/mobile/fourmSuggestion.js
0 → 100644
View file @
6463fd2d
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
moment
=
require
(
'moment'
),
mongoose
=
require
(
'mongoose'
),
_
=
require
(
'lodash'
),
then
=
require
(
'thenjs'
);
var
forumSuggestionService
=
require
(
'../../service/forumSuggestionService'
);
var
user
=
require
(
'../../utils/user'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
//新增
router
.
post
(
'/suggestion/create'
,
function
(
req
,
res
,
next
)
{
var
userId
=
user
.
getMobileUser
(
req
);
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
object
=
req
.
body
;
object
.
from
=
userId
;
object
.
ent_code
=
ent_code
;
if
(
userId
&&
object
){
forumSuggestionService
.
create
(
object
,
function
(
err
,
doc
){
if
(
err
)
{
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
\ No newline at end of file
app/models/forumSuggestion.js
0 → 100644
View file @
6463fd2d
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
//建议
var
ForumSuggestionSchema
=
new
Schema
({
ent_code
:
{
type
:
Number
,
require
:
true
,
index
:
true
},
from
:
{
//发消息者
type
:
Schema
.
Types
.
ObjectId
,
require
:
true
,
index
:
true
,
ref
:
'ForumUser'
},
title
:
{
//标题
type
:
String
,
require
:
true
},
content
:
{
//话题内容
type
:
String
},
status
:
{
//状态,1显示,2屏蔽,3 删除
type
:
Number
,
require
:
true
,
default
:
1
},
created
:
{
type
:
Date
,
required
:
true
,
default
:
Date
.
now
}
},
{
'collection'
:
'pisns_forum_suggestion'
});
module
.
exports
=
mongoose
.
model
(
'ForumSuggestion'
,
ForumSuggestionSchema
);
\ No newline at end of file
app/service/forumSuggestionService.js
0 → 100644
View file @
6463fd2d
'use strict'
;
var
mongoose
=
require
(
'mongoose'
);
var
Suggestion
=
mongoose
.
model
(
'ForumSuggestion'
);
//创建
exports
.
create
=
function
(
entity
,
callback
){
var
forum
=
new
Suggestion
(
entity
);
forum
.
save
(
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
doc
);
}
});
};
//根据ID获取
exports
.
getById
=
function
(
id
,
callback
){
Suggestion
.
findById
(
id
,
function
(
err
,
doc
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
doc
);
}
});
};
//根据条件更新
// exports.update=function(condition,entity,callback){
// Suggestion.update(condition, entity,null,function(err,result){
// if (err) {
// console.error(err);
// callback(err,null);
// } else {
// callback(null,null);
// }
// });
// };
//根据ID删除
exports
.
deleteById
=
function
(
tid
,
callback
){
Suggestion
.
remove
({
_id
:
tid
},
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
null
);
}
});
};
//更新
exports
.
findOneAndUpdate
=
function
(
condition
,
entity
,
callback
){
Suggestion
.
findOneAndUpdate
(
condition
,
entity
,
null
,
function
(
err
,
result
){
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
result
);
}
});
};
//获取数量
function
countAll
(
conditions
,
callback
)
{
Suggestion
.
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
);
Suggestion
.
find
(
conditions
).
populate
({
path
:
'from'
,
select
:
'mid nickName icon'
}).
skip
(
skip
).
limit
(
limit
).
sort
({
created
:
-
1
}).
exec
(
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
);
}
});
}
});
};
\ No newline at end of file
app/service/forumUserService.js
View file @
6463fd2d
...
@@ -372,4 +372,12 @@ exports.searchMembersAndFields = function(pageNo, pageSize, q, fields, callback)
...
@@ -372,4 +372,12 @@ exports.searchMembersAndFields = function(pageNo, pageSize, q, fields, callback)
};
};
callback
(
err
,
rsJson
);
callback
(
err
,
rsJson
);
});
});
};
//查询用户信息,只查某些字段
exports
.
searchMembersWithFields
=
function
(
q
,
fields
,
sort
,
callback
)
{
ForumUser
.
find
(
q
).
select
(
fields
).
sort
(
sort
).
exec
(
function
(
err
,
docs
)
{
callback
(
err
,
docs
);
});
};
};
\ No newline at end of file
app/utils/cacheable.js
View file @
6463fd2d
...
@@ -81,7 +81,7 @@ function withCache(dur, keyBuilder, fn) {
...
@@ -81,7 +81,7 @@ function withCache(dur, keyBuilder, fn) {
fromCache
(
dur
,
key
,
function
(
err
,
datas
)
{
fromCache
(
dur
,
key
,
function
(
err
,
datas
)
{
if
(
err
)
return
cb
(
err
);
if
(
err
)
return
cb
(
err
);
if
(
datas
)
{
// cache hit
if
(
datas
)
{
// cache hit
console
.
log
(
'cache hit'
);
//
console.log('cache hit');
cb
.
apply
(
null
,
datas
);
cb
.
apply
(
null
,
datas
);
}
else
{
// cache missed
}
else
{
// cache missed
console
.
log
(
'cache missed'
);
console
.
log
(
'cache missed'
);
...
...
strong
@strong
mentioned in commit
e237bf17
·
Mar 22, 2016
mentioned in commit
e237bf17
mentioned in commit e237bf17079ce213c885b4b62bcb27795bc0b9af
Toggle commit list
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