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
2d9cb4e1
Commit
2d9cb4e1
authored
Aug 27, 2015
by
strong
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Notice' into SANDBOX
parents
b2fe2300
ac543813
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
592 additions
and
34 deletions
+592
-34
forumNotice.js
app/controllers/admin/forumNotice.js
+188
-0
commentTips.js
app/controllers/mobile/commentTips.js
+43
-0
forumNotice.js
app/controllers/mobile/forumNotice.js
+189
-0
forumNotice.js
app/models/forumNotice.js
+82
-0
commentTips.js
app/utils/commentTips.js
+41
-0
config.js
config/config.js
+31
-32
express.js
config/express.js
+18
-2
No files found.
app/controllers/admin/forumNotice.js
0 → 100644
View file @
2d9cb4e1
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
),
thenjs
=
require
(
'thenjs'
);
var
mongoose
=
require
(
'mongoose'
);
var
Notice
=
mongoose
.
model
(
'ForumNotice'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/admin/forum'
,
router
);
};
function
getPageInfo
(
pageNo
,
pageSize
,
count
){
var
skip
,
limit
;
pageNo
=
pageNo
||
1
;
pageSize
=
pageSize
||
10
;
skip
=
(
pageNo
-
1
)
*
pageSize
;
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
if
(
skip
>
count
/
2
&&
pageNo
>
10000
)
{
skip
=
limit
>
pageSize
?
(
count
-
skip
-
pageSize
)
:
0
;
}
if
(
skip
<
0
){
skip
=
0
;
}
return
{
pageNo
:
pageNo
,
pageSize
:
pageSize
,
skip
:
skip
,
limit
:
limit
};
}
function
queryList
(
condition
,
sort
,
pageNo
,
pageSize
,
callback
){
condition
=
condition
||
{};
sort
=
sort
||
{};
thenjs
(
function
(
cont
){
Notice
.
find
(
condition
).
count
(
function
(
err
,
count
){
if
(
err
){
return
cont
&&
cont
(
err
);
}
if
(
!!!
count
){
return
callback
&&
callback
(
false
,{
data
:[],
total
:
0
});
}
cont
(
null
,
count
,
getPageInfo
(
pageNo
,
pageSize
,
count
));
});
})
.
then
(
function
(
cont
,
count
,
pageInfo
){
Notice
.
find
(
condition
).
sort
(
sort
).
limit
(
pageInfo
.
limit
).
skip
(
pageInfo
.
skip
).
exec
(
function
(
err
,
results
){
//分页查询
if
(
err
){
return
callback
&&
callback
({
err
:
err
});
}
return
callback
&&
callback
(
false
,{
data
:
results
,
total
:
count
});
});
})
.
fail
(
function
(
cont
,
err
){
console
.
log
(
err
);
return
callback
&&
callback
({
err
:
err
});
});
}
function
update
(
obj
,
callback
){
if
(
!!!
obj
||
!!!
obj
.
id
){
return
callback
&&
callback
({
err
:
'参数错误!'
});
}
var
id
=
obj
.
_id
;
Notice
.
findByIdAndUpdate
(
id
,
obj
,
function
(
err
,
notice
){
if
(
err
){
return
callback
&&
callback
(
err
);
}
return
callback
&&
callback
({
result
:
true
});
});
}
router
.
post
(
'/notice'
,
function
(
req
,
res
,
next
)
{
req
.
body
.
ent_code
=
req
.
session
.
user
.
ent_code
;
var
notice
=
new
Notice
(
req
.
body
);
notice
.
save
(
function
(
err
){
if
(
err
){
return
res
.
json
({
err
:
err
});
}
res
.
json
({
result
:
true
});
});
});
router
.
post
(
'/notice/update'
,
function
(
req
,
res
,
next
)
{
update
(
req
.
body
,
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
err
);
}
return
res
.
json
(
result
);
});
});
router
.
post
(
'/notice/search'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
body
.
pageNo
,
pageSize
=
req
.
body
.
pageSize
,
type
=
req
.
body
.
type
,
title
=
req
.
body
.
title
,
label
=
req
.
body
.
label
,
plate
=
req
.
body
.
plate
,
sort
=
req
.
body
.
sort
,
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
},
_sort
=
{};
if
(
sort
){
_sort
[
sort
]
=
-
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
;
}
queryList
(
_condition
,
_sort
,
pageNo
,
pageSize
,
function
(
err
,
result
){
console
.
log
(
err
);
if
(
err
){
return
res
.
json
(
err
);
}
return
res
.
json
(
result
);
});
});
router
.
get
(
'/notice/:id'
,
function
(
req
,
res
,
next
)
{
Notice
.
findById
(
req
.
params
.
id
,
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
err
);
}
return
res
.
json
(
result
);
});
});
\ No newline at end of file
app/controllers/mobile/commentTips.js
0 → 100644
View file @
2d9cb4e1
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
commentTips
=
require
(
'../../utils/commentTips'
),
_
=
require
(
'lodash'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
router
.
get
(
'/commentTips'
,
function
(
req
,
res
,
next
)
{
var
openId
=
req
.
session
.
openUser
.
openId
;
commentTips
.
get
(
openId
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
UNCHECK_ERROR
(
err
));
}
else
{
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
}
});
});
router
.
put
(
'/commentTips'
,
function
(
req
,
res
,
next
)
{
var
openId
=
req
.
session
.
openUser
.
openId
;
commentTips
.
incrTips
(
openId
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
UNCHECK_ERROR
(
err
));
}
else
{
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
}
});
});
router
.
put
(
'/commentTips/del'
,
function
(
req
,
res
,
next
)
{
var
openId
=
req
.
session
.
openUser
.
openId
;
commentTips
.
clear
(
openId
,
function
(
err
,
result
){
if
(
err
){
res
.
json
(
returnCode
.
UNCHECK_ERROR
(
err
));
}
else
{
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
}
});
});
\ No newline at end of file
app/controllers/mobile/forumNotice.js
0 → 100644
View file @
2d9cb4e1
'use strict'
;
var
express
=
require
(
'express'
),
router
=
express
.
Router
(),
returnCode
=
require
(
'../../utils/returnCode'
),
_
=
require
(
'lodash'
),
thenjs
=
require
(
'thenjs'
);
var
mongoose
=
require
(
'mongoose'
);
var
Notice
=
mongoose
.
model
(
'ForumNotice'
);
module
.
exports
=
function
(
app
)
{
app
.
use
(
'/v1/forum'
,
router
);
};
function
getPageInfo
(
pageNo
,
pageSize
,
count
){
var
skip
,
limit
;
pageNo
=
pageNo
||
1
;
pageSize
=
pageSize
||
10
;
skip
=
(
pageNo
-
1
)
*
pageSize
;
limit
=
count
-
skip
>
pageSize
?
pageSize
:
(
count
-
skip
);
if
(
skip
>
count
/
2
&&
pageNo
>
10000
)
{
skip
=
limit
>
pageSize
?
(
count
-
skip
-
pageSize
)
:
0
;
}
if
(
skip
<
0
){
skip
=
0
;
}
return
{
pageNo
:
pageNo
,
pageSize
:
pageSize
,
skip
:
skip
,
limit
:
limit
};
}
function
queryList
(
condition
,
sort
,
pageNo
,
pageSize
,
callback
){
condition
=
condition
||
{};
sort
=
sort
||
{};
thenjs
(
function
(
cont
){
Notice
.
find
(
condition
).
count
(
function
(
err
,
count
){
if
(
err
){
return
cont
&&
cont
(
err
);
}
if
(
!!!
count
){
return
callback
&&
callback
(
false
,{
data
:[],
total
:
0
});
}
cont
(
null
,
count
,
getPageInfo
(
pageNo
,
pageSize
,
count
));
});
})
.
then
(
function
(
cont
,
count
,
pageInfo
){
Notice
.
find
(
condition
).
sort
(
sort
).
limit
(
pageInfo
.
limit
).
skip
(
pageInfo
.
skip
).
exec
(
function
(
err
,
results
){
//分页查询
if
(
err
){
return
callback
&&
callback
({
err
:
err
});
}
return
callback
&&
callback
(
false
,{
data
:
results
,
total
:
count
});
});
})
.
fail
(
function
(
cont
,
err
){
console
.
log
(
err
);
return
callback
&&
callback
({
err
:
err
});
});
}
/*
status = 1
and
finished = 0
and
startdate 小于等于当前时间
and
indate大于等于当前时间
然后按top降序 startdate 降序
*/
// exports.newestMsg = function(req,res) {
// var pageNo=req.query.pageNo,
// pageSize=req.query.pageSize;
// var curdate = new Date(),
// _condition = {status:1,finished:0,
// startdate:{$lte:curdate},
// indate:{$gte:curdate},
// },_sort = {top:-1,startdate:-1};
// queryList(_condition,_sort,pageNo,pageSize,function(err,result){
// console.log(err);
// if(err){
// return res.json(err);
// }
// return res.json(result);
// });
// };
/*20150422修改消息的规则
根据type =2 为消息
*/
router
.
get
(
'/notice/newestMsg'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
,
pageSize
=
req
.
query
.
pageSize
,
plate
=
req
.
query
.
plate
;
var
_condition
=
{
status
:
1
,
type
:
2
,
ent_code
:
req
.
session
.
user
.
ent_code
},
_sort
=
{
top
:
-
1
,
createtime
:
-
1
};
if
(
plate
){
_condition
.
$or
=
[{
plate
:
plate
},{
plate
:
null
}];
}
else
{
_condition
.
plate
=
null
;
}
queryList
(
_condition
,
_sort
,
pageNo
,
pageSize
,
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
err
);
}
return
res
.
json
(
result
);
});
});
/*
status = 1
and
finished = 0
and
startdate 小于等于当前时间
and
indate大于等于当前时间
然后按top降序 startdate 降序
*/
router
.
get
(
'/notice/newestAct'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
,
pageSize
=
req
.
query
.
pageSize
,
plate
=
req
.
query
.
plate
;
var
curdate
=
new
Date
(),
_condition
=
{
status
:
1
,
finished
:
0
,
type
:
1
,
ent_code
:
req
.
session
.
user
.
ent_code
,
startdate
:{
$lte
:
curdate
},
indate
:{
$gte
:
curdate
},
},
_sort
=
{
top
:
-
1
,
startdate
:
-
1
};
if
(
plate
){
_condition
.
$or
=
[{
plate
:
plate
},{
plate
:
null
}];
}
else
{
_condition
.
plate
=
null
;
}
console
.
log
(
_condition
);
queryList
(
_condition
,
_sort
,
pageNo
,
pageSize
,
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
err
);
}
return
res
.
json
(
result
);
});
});
/*
status = 1
finished = 1
or
status = 1
finished = 0
indate < 当前时间
然后按top降序 indate 降序
*/
router
.
get
(
'/notice/oldAct'
,
function
(
req
,
res
,
next
)
{
var
pageNo
=
req
.
query
.
pageNo
,
pageSize
=
req
.
query
.
pageSize
,
plate
=
req
.
query
.
plate
,
curdate
=
new
Date
(),
_condition
=
{
status
:
1
,
type
:
1
,
ent_code
:
req
.
session
.
user
.
ent_code
,
$or
:[{
indate
:{
$lt
:
curdate
}},{
finished
:
1
}]},
_sort
=
{
top
:
-
1
,
indate
:
-
1
};
if
(
plate
){
_condition
.
$or
=
[{
plate
:
plate
},{
plate
:
null
}];
}
else
{
_condition
.
plate
=
null
;
}
queryList
(
_condition
,
_sort
,
pageNo
,
pageSize
,
function
(
err
,
result
){
if
(
err
){
return
res
.
json
(
err
);
}
return
res
.
json
(
result
);
});
});
router
.
get
(
'/notice/:id'
,
function
(
req
,
res
,
next
)
{
var
id
=
req
.
params
.
id
||
req
.
query
.
id
;
if
(
!!!
id
){
return
res
.
json
({
err
:
'不存在的资源'
});
}
Notice
.
findOne
({
_id
:
id
,
status
:
1
},
function
(
err
,
result
){
if
(
err
){
return
res
.
json
({
err
:
err
});
}
if
(
!!!
result
){
return
res
.
json
({
err
:
'不存在的资源'
});
}
return
res
.
json
(
result
);
});
});
\ No newline at end of file
app/models/forumNotice.js
0 → 100644
View file @
2d9cb4e1
'use strict'
;
var
mongoose
=
require
(
'mongoose'
),
Schema
=
mongoose
.
Schema
;
//话题广场,板块
var
ForumNoticeSchema
=
new
Schema
({
ent_code
:
{
//企业号
type
:
Number
,
default
:
''
,
index
:
true
},
plate
:
{
//所属板块
type
:
Schema
.
Types
.
ObjectId
,
require
:
true
,
index
:
true
,
ref
:
'ForumInfo'
},
type
:{
//1/2 活动 消息
type
:
Number
,
default
:
1
,
index
:
true
},
label
:
{
//标签
type
:
String
,
require
:
true
,
default
:
''
},
title
:
{
//标题
type
:
String
,
require
:
true
},
desc
:
{
//描述
type
:
String
,
require
:
true
},
content
:{
type
:
String
,
//正文
require
:
false
},
readnum
:{
//阅读数
type
:
Number
,
default
:
0
},
creater
:
{
//创建人
type
:
String
,
require
:
true
},
startdate
:
{
//开始时间,默认当前时间
type
:
Date
,
default
:
''
},
indate
:
{
//有效期限,不填就默认永久
type
:
Date
,
default
:
''
},
createtime
:
{
//创建时间,当前时间
type
:
Date
,
default
:
Date
.
now
},
top
:
{
// 置顶0/1 默认0
type
:
Number
,
default
:
0
,
index
:
true
},
status
:
{
//是否显示 0/1 隐藏/显示
type
:
Number
,
require
:
true
,
default
:
1
,
index
:
true
},
finished
:
{
//是否结束 0/1 否/是
type
:
Number
,
require
:
true
,
default
:
0
,
index
:
true
}
},
{
'collection'
:
'pisns_forum_notice'
});
module
.
exports
=
mongoose
.
model
(
'ForumNotice'
,
ForumNoticeSchema
);
\ No newline at end of file
app/utils/commentTips.js
0 → 100644
View file @
2d9cb4e1
'use strict'
;
var
redis
=
global
.
redis
;
var
prefix
=
'comment-tips-'
;
function
getKey
(
openId
){
return
prefix
+
openId
;
}
exports
.
clear
=
function
(
openId
,
callback
){
var
key
=
getKey
(
openId
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
}
redis
.
del
(
key
,
function
(
error
,
res
){
return
callback
&&
callback
(
error
,
!!
res
);
});
};
exports
.
incrTips
=
function
(
openId
,
callback
){
var
key
=
getKey
(
openId
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
}
redis
.
incr
(
key
,
function
(
error
,
res
){
return
callback
&&
callback
(
error
,
!!
res
);
});
};
exports
.
get
=
function
(
openId
,
callback
){
var
key
=
getKey
(
openId
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
}
redis
.
get
(
key
,
function
(
error
,
res
){
return
callback
&&
callback
(
error
,
res
||
0
);
});
};
\ No newline at end of file
config/config.js
View file @
2d9cb4e1
...
...
@@ -26,14 +26,14 @@ var config = {
devCDNURL
:
'http://dev.fs.wxpai.cn/'
},
sessionStore
:
{
password
:
''
,
password
:
'
future123456
'
,
port
:
6379
,
host
:
'115.29.177.177'
,
db
:
2
}
},
sandbox
:
{
test
:
{
root
:
rootPath
,
app
:
{
name
:
'pisns-forum-api'
...
...
@@ -63,36 +63,35 @@ var config = {
},
production
:
{
root
:
rootPath
,
app
:
{
name
:
'pisns-forum-api'
},
service
:
'http://piplu
s.wxpai.cn'
,
port
:
3011
,
root
:
rootPath
,
app
:
{
name
:
'pisns-forum-api'
},
service
:
'http://pisn
s.wxpai.cn'
,
port
:
3011
,
mongodb
:
{
uri
:
'mongodb://10.173.224.92,10.173.226.96,10.173.227.160/pisns-forum'
,
username
:
'future'
,
password
:
'future123456'
,
dbname
:
'pisns-forum'
,
replset
:
'hdp'
,
poolSize
:
50
},
ossConfig
:
{
accessKeyId
:
'ezpP6LGjecQW6zJC'
,
accessKeySecret
:
'1iqc1bkwZCVjK7oFUYdGm6e0xOL4mF'
,
bucketNameProd
:
'pisns-oss-res'
,
bucketNameDev
:
'pisns-oss-dev'
,
prodCDNURL
:
'http://fs.wxpai.cn/'
,
devCDNURL
:
'http://dev.fs.wxpai.cn/'
},
sessionStore
:
{
password
:
'a39131f8d598429f:GuangZhouhdp123'
,
port
:
6379
,
host
:
'a39131f8d598429f.m.cnhza.kvstore.aliyuncs.com'
,
db
:
2
}
}
mongodb
:
{
uri
:
'mongodb://10.173.226.96:27017/pisns-forum'
,
username
:
'future'
,
password
:
'future123456'
,
dbname
:
'pisns-forum'
,
poolSize
:
50
},
ossConfig
:
{
accessKeyId
:
'ezpP6LGjecQW6zJC'
,
accessKeySecret
:
'1iqc1bkwZCVjK7oFUYdGm6e0xOL4mF'
,
bucketNameProd
:
'pisns-oss-res'
,
bucketNameDev
:
'pisns-oss-dev'
,
prodCDNURL
:
'http://fs.wxpai.cn/'
,
devCDNURL
:
'http://dev.fs.wxpai.cn/'
},
sessionStore
:
{
password
:
'future123456'
,
port
:
6379
,
host
:
'10.168.27.179'
,
db
:
2
}
}
};
module
.
exports
=
config
[
env
];
module
.
exports
=
config
[
env
];
\ No newline at end of file
config/express.js
View file @
2d9cb4e1
...
...
@@ -60,8 +60,24 @@ module.exports = function(app, config) {
res
.
header
(
'Access-Control-Max-Age'
,
7200
);
next
();
});
if
(
app
.
get
(
'env'
)
===
'development'
){
app
.
use
(
function
(
req
,
res
,
next
)
{
if
(
!
req
.
session
.
user
)
{
req
.
session
.
user
=
{
ent_code
:
100001
};
}
if
(
!
req
.
session
.
openUser
)
{
req
.
session
.
openUser
=
{
openId
:
'1111'
,
integral
:
'100'
,
exp
:
'100'
};
}
next
(
null
);
});
}
//设置创建用户中间件
app
.
use
(
'/v1/forum/*'
,
forumUser
.
identifyUser
());
...
...
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