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
1b50346c
Commit
1b50346c
authored
Mar 10, 2016
by
strong
Browse files
Options
Browse Files
Download
Plain Diff
Merge commit '
fd749970
' into SANDBOX
parents
720ed72c
fd749970
Changes
4
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
543 additions
and
355 deletions
+543
-355
forumThread.js
app/controllers/admin/forumThread.js
+56
-26
forumThread.js
app/controllers/mobile/forumThread.js
+115
-94
forumThreadService.js
app/service/forumThreadService.js
+317
-184
redisThreadList.js
app/utils/redisThreadList.js
+55
-51
No files found.
app/controllers/admin/forumThread.js
View file @
1b50346c
...
...
@@ -322,7 +322,7 @@ router.post('/thread/:tid/:fid/unTop', function(req, res, next) {
}
});
//文章
推荐
//文章
加精
router
.
post
(
'/thread/:tid/:fid/recommend'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
,
fid
=
req
.
params
.
fid
,
...
...
@@ -364,7 +364,7 @@ router.post('/thread/:tid/:fid/recommend', function(req, res, next) {
}
});
//文章取消
推荐
//文章取消
加精
router
.
post
(
'/thread/:tid/:fid/unRecommend'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
//文章ID
var
fid
=
req
.
params
.
fid
;
//板块ID
...
...
@@ -398,6 +398,9 @@ router.get('/threads/list', function(req, res, next) {
var
eventStatus
=
req
.
query
.
eventStatus
;
var
recommend_threads
=
req
.
query
.
recommend_threads
;
//推荐帖子
var
top_threads
=
req
.
query
.
top_threads
;
//置顶帖子
var
begin_time
=
req
.
query
.
begin_time
;
var
end_time
=
req
.
query
.
end_time
;
var
title
=
req
.
query
.
title
;
var
sortBy
=
{
top
:
-
1
,
top_order_idx
:
-
1
,
...
...
@@ -476,6 +479,22 @@ router.get('/threads/list', function(req, res, next) {
conditions
[
'event.eventEndTime'
]
=
{
$gt
:
today
};
}
}
if
(
begin_time
&&
end_time
){
conditions
.
created
=
{
$gte
:
begin_time
,
$lte
:
end_time
};
}
else
if
(
end_time
){
conditions
.
created
=
{
$lte
:
end_time
};
}
else
if
(
begin_time
){
conditions
.
created
=
{
$gte
:
begin_time
};
}
if
(
title
)
{
conditions
.
title
=
{
$regex
:
title
,
$options
:
'i'
}
}
if
(
mid
)
{
forumThreadService
.
getAllThreadByFidAndMid
(
mid
,
conditions
,
pageNo
,
pageSize
,
sortBy
,
function
(
err
,
results
)
{
if
(
err
)
{
...
...
@@ -536,11 +555,17 @@ router.get('/threads/list', function(req, res, next) {
//直接修改序号
function
updateThreadTopIdx
(
id
,
idx
,
callback
){
ForumThread
.
update
(
{
_id
:
id
},
{
top_order_idx
:
idx
},
null
,
function
(
err
,
result
){
// ForumThread.update({_id:id},{ top_order_idx: idx },
// null,
// function(err,result){
// if(err){
// console.error(err);
// callback(err,null);
// }else{
// callback(null,true);
// }
// });
forumThreadService
.
updateThread
({
_id
:
id
},
{
top_order_idx
:
idx
},
function
(
err
,
doc
)
{
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
@@ -550,11 +575,16 @@ function updateThreadTopIdx(id,idx,callback){
});
}
function
updateThreadNewRecommendIdx
(
id
,
idx
,
callback
){
ForumThread
.
update
(
{
_id
:
id
},
{
new_recommend_order_idx
:
idx
},
null
,
function
(
err
,
result
){
// ForumThread.update({_id:id},{ new_recommend_order_idx: idx },null, function(err,result){
// if(err){
// console.error(err);
// callback(err,null);
// }else{
// callback(null,true);
// }
// });
forumThreadService
.
updateThread
({
_id
:
id
},
{
new_recommend_order_idx
:
idx
},
function
(
err
,
doc
)
{
if
(
err
){
console
.
error
(
err
);
callback
(
err
,
null
);
...
...
app/controllers/mobile/forumThread.js
View file @
1b50346c
...
...
@@ -506,8 +506,6 @@ router.post('/thread/create', function(req, res, next) {
}
}
});
// httpService.sendRequest(req.session.user.ent_code, req.session.openUser.mid, 'post');
var
rs
=
{};
rs
.
data
=
{
'id'
:
thread
.
_id
...
...
@@ -525,20 +523,22 @@ router.post('/thread/create', function(req, res, next) {
});
});
//获取
目标论坛
文章
//获取文章
router
.
get
(
'/thread/:tid/get'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumThreadService
.
getThreadById
(
tid
,
function
(
err
,
thread
)
{
//文章类型 1、文章 2、话题 3、照片墙
if
(
err
||
!
thread
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
if
(
thread
&&
thread
.
info
){
var
info_id
=
thread
.
info
.
_id
,
pid
=
thread
.
pid
,
source
=
req
.
session
.
mobileForumUser
.
source
;
...
...
@@ -551,6 +551,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
}
else
if
(
thread
.
type
==
3
&&
thread
.
level
==
1
)
{
httpService
.
createLog
(
req
,
source
,
info_id
,
3
,
3
,
tid
);
}
}
});
forumThreadService
.
updateThreadPvCount
(
tid
,
function
(
err
,
doc
)
{
if
(
err
)
{
...
...
@@ -616,7 +617,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
}
});
//获取
目标论坛
文章
//获取文章
router
.
get
(
'/thread/photo/:pid/get'
,
function
(
req
,
res
,
next
)
{
var
pid
=
req
.
params
.
pid
||
null
,
userId
=
user
.
getMobileUser
(
req
);
...
...
@@ -665,43 +666,16 @@ router.post('/thread/:tid/update', function(req, res, next) {
router
.
post
(
'/thread/:tid/delete'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
;
if
(
tid
)
{
forumThreadService
.
deleteThreadById
(
tid
,
function
(
err
,
thread
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
SUCCESS
);
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//注销此方法
//文章点赞
router
.
post
(
'/thread/:tid/raise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
mid
=
req
.
session
.
openUser
.
mid
;
var
tid
=
req
.
params
.
tid
||
null
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
)
{
raiseOrcancelRaise
(
req
,
ent_code
,
tid
,
userId
,
function
(
result
){
res
.
json
(
result
);
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//文章取消点赞
router
.
post
(
'/thread/:tid/cancelRaise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
mid
=
req
.
session
.
openUser
.
mid
;
var
tid
=
req
.
params
.
tid
||
null
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
)
{
raiseOrcancelRaise
(
req
,
ent_code
,
tid
,
userId
,
function
(
result
){
res
.
json
(
result
);
});
// forumThreadService.deleteThreadById(tid, function(err, thread) {
// if (err) {
// res.json(returnCode.BUSY);
// } else {
// res.json(returnCode.SUCCESS);
// }
// });
res
.
json
(
returnCode
.
BUSY
);
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
...
...
@@ -1469,39 +1443,6 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) {
}
});
//评论点赞
router
.
post
(
'/thread/:tid/comment/:cid/raise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
mid
=
req
.
session
.
openUser
.
mid
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
&&
cid
)
{
conmentRaiseOrcancelRaise
(
req
,
ent_code
,
tid
,
cid
,
userId
,
function
(
result
){
res
.
json
(
result
);
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//评论取消点赞
router
.
post
(
'/thread/:tid/comment/:cid/cancelRaise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
var
tid
=
req
.
params
.
tid
||
null
;
var
cid
=
req
.
params
.
cid
||
null
;
var
mid
=
req
.
session
.
openUser
.
mid
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
if
(
tid
&&
cid
)
{
conmentRaiseOrcancelRaise
(
req
,
ent_code
,
tid
,
cid
,
userId
,
function
(
result
){
res
.
json
(
result
);
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
//评论点赞和取消点赞
router
.
post
(
'/thread/:tid/comment/:cid/praiseOrCancelPraise'
,
function
(
req
,
res
,
next
)
{
var
userId
=
req
.
session
.
mobileForumUser
.
userId
;
...
...
@@ -1574,9 +1515,7 @@ router.get('/thread/:tid/topics', function(req, res, next) {
$ne
:
3
}
};
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
...
...
@@ -1820,8 +1759,6 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
var
infoId
=
req
.
query
.
infoId
||
null
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
skip
=
(
pageNo
-
1
)
*
pageSize
;
var
redis_type
=
'_thread_essence'
;
var
sort
=
{
new_recommend
:
-
1
,
new_recommend_order_idx
:
-
1
,
...
...
@@ -1850,7 +1787,6 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
}]
};
if
((
pageNo
*
pageSize
)
>
redisThreadList
.
getThreadRedisCount
()
||
infoId
){
if
(
infoId
){
conditions
.
info
=
infoId
;
...
...
@@ -1869,10 +1805,10 @@ router.get('/thread/getThreadWithEssence', function(req, res, next) {
});
}
else
{
//更新推荐列表redis
redisThreadList
.
get
(
ent_code
,
""
,
redis_type
,
function
(
error
,
docs
)
{
redisThreadList
.
get
(
ent_code
,
function
(
error
,
docs
)
{
var
results
=
JSON
.
parse
(
docs
);
if
(
results
.
items
==
null
||
results
.
items
.
length
<=
0
){
//如果不存在,继续重新获取
redisThreadList
.
getRedisEsenceThreads
(
ent_code
,
""
,
redis_type
,
function
(
error
,
docs
){
redisThreadList
.
getRedisEsenceThreads
(
ent_code
,
function
(
error
,
docs
){
if
(
error
){
console
.
error
(
err
);
res
.
json
(
returnCode
.
BUSY
);
...
...
@@ -1986,3 +1922,88 @@ router.get('/thread/getThreadWithNotPopulateComment/hot', function(req, res, nex
}
});
});
//获取话题下子文章
router
.
get
(
'/thread/:tid/get/subThreads/:type'
,
function
(
req
,
res
,
next
)
{
var
tid
=
req
.
params
.
tid
||
null
;
var
type
=
req
.
params
.
type
||
null
;
var
pageNo
=
req
.
query
.
pageNo
||
1
;
var
pageSize
=
req
.
query
.
pageSize
||
10
;
var
ent_code
=
req
.
session
.
user
.
ent_code
;
var
rs
=
{};
var
conditions
=
{
ent_code
:
ent_code
,
pid
:
tid
,
type
:
2
,
status
:
{
$ne
:
3
}
};
var
sort
=
null
;
//排序条件
if
(
type
==
1
){
//最新
sort
=
'-created'
;
}
else
if
(
type
==
2
){
//最热
sort
=
'-praise_count -comment_count'
;
}
if
(
tid
)
{
async
.
waterfall
([
function
(
callback
)
{
forumThreadService
.
getByIdSelectyField
(
tid
,
'type'
,
function
(
err
,
thread
)
{
if
(
err
)
{
callback
(
err
,
null
);
}
else
{
callback
(
null
,
thread
);
}
});
},
function
(
thread
,
callback
)
{
forumUserThreadControlService
.
getUserThreadControlById
(
user
.
getMobileUser
(
req
),
function
(
err
,
doc
)
{
if
(
err
)
{
callback
(
err
,
null
,
null
);
}
else
{
if
(
doc
)
{
callback
(
null
,
thread
,
doc
);
}
else
{
callback
(
null
,
thread
,
null
);
}
}
});
},
function
(
thread
,
doc
,
callback
)
{
if
(
thread
.
type
==
2
)
{
//查询子列表
if
(
doc
)
{
conditions
.
_id
=
{
$nin
:
doc
.
thread
};
}
//获取子话题数据
forumThreadService
.
getThreadWithNotPopulateComment
(
conditions
,
pageNo
,
pageSize
,
sort
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
,
null
);
}
else
{
callback
(
null
,
results
);
}
});
}
else
{
callback
(
null
,
null
);
}
}
],
function
(
err
,
results
)
{
if
(
err
)
{
res
.
json
(
returnCode
.
BUSY
);
}
else
{
util
.
loadLevel
(
ent_code
,
results
.
items
,
function
()
{
handleThreadList
(
req
,
results
,
ent_code
,
function
(
result
){
res
.
json
(
_
.
assign
(
result
,
returnCode
.
SUCCESS
));
});
});
}
});
}
else
{
res
.
json
(
returnCode
.
WRONG_PARAM
);
}
});
\ No newline at end of file
app/service/forumThreadService.js
View file @
1b50346c
This diff is collapsed.
Click to expand it.
app/utils/redisThreadList.js
View file @
1b50346c
'use strict'
;
var
redis
=
global
.
redis
;
var
expire
=
60
*
1
0
;
var
expire
=
60
*
3
0
;
//缓存数量
var
ThreadRedisCount
=
50
;
...
...
@@ -12,6 +12,10 @@ var forumThreadService=require('../service/forumThreadService');
var
redisPraiseLog
=
require
(
'./redisPraiseLog'
);
var
util
=
require
(
'./util'
);
var
RefreshFlag
=
true
;
var
tyhread_redis_salt
=
'_tyhread_redis_salt'
;
var
sort
=
{
new_recommend
:
-
1
,
new_recommend_order_idx
:
-
1
,
...
...
@@ -25,13 +29,13 @@ var sort = {
created
:
-
1
};
function
getKey
(
ent_code
,
keyID
,
type
){
var
key
=
ent_code
+
keyID
+
type
;
function
getKey
(
ent_code
,
salt
){
var
key
=
ent_code
+
salt
;
return
key
;
}
function
setToRedis
(
ent_code
,
keyID
,
type
,
value
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
function
setToRedis
(
ent_code
,
salt
,
value
){
var
key
=
getKey
(
ent_code
,
salt
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
'error'
...
...
@@ -42,8 +46,37 @@ function setToRedis(ent_code,keyID,type,value){
});
}
exports
.
get
=
function
(
ent_code
,
keyID
,
type
,
callback
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
function
getEsenceThreads
(
ent_code
,
salt
,
callback
){
var
today
=
new
Date
();
var
conditions
=
{
ent_code
:
ent_code
,
level
:
1
,
status
:
1
,
new_recommend
:
1
,
$or
:
[{
isEvent
:
0
},
{
isEvent
:
null
},
{
isEvent
:
1
,
'event.eventStartTime'
:
{
$lte
:
today
}
}]
};
forumThreadService
.
getThreadWithNotPopulateComment
(
conditions
,
1
,
ThreadRedisCount
,
sort
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
);
}
else
{
util
.
loadLevel
(
ent_code
,
results
.
items
,
function
()
{
setToRedis
(
ent_code
,
salt
,
JSON
.
stringify
(
results
));
callback
(
null
);
});
}
});
};
exports
.
get
=
function
(
ent_code
,
callback
){
var
key
=
getKey
(
ent_code
,
tyhread_redis_salt
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
...
...
@@ -51,7 +84,7 @@ exports.get=function(ent_code,keyID,type,callback){
redis
.
get
(
key
,
function
(
error
,
res
){
if
(
!
res
){
//不存在,先获取再返回
getEsenceThreads
(
ent_code
,
keyID
,
type
,
function
(
err
){
getEsenceThreads
(
ent_code
,
tyhread_redis_salt
,
function
(
err
){
redis
.
get
(
key
,
function
(
error
,
res
){
return
callback
&&
callback
(
error
,
res
.
split
(
","
));
});
...
...
@@ -62,8 +95,8 @@ exports.get=function(ent_code,keyID,type,callback){
});
};
exports
.
set
=
function
(
ent_code
,
keyID
,
type
,
value
,
callback
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
exports
.
set
=
function
(
ent_code
,
salt
,
value
,
callback
){
var
key
=
getKey
(
ent_code
,
salt
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
...
...
@@ -74,8 +107,8 @@ exports.set=function(ent_code,keyID,type,value,callback){
});
};
exports
.
clear
=
function
(
ent_code
,
keyID
,
type
,
callback
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
exports
.
clear
=
function
(
ent_code
,
salt
,
callback
){
var
key
=
getKey
(
ent_code
,
salt
);
if
(
!
redis
){
console
.
log
(
'redis error'
);
return
callback
&&
callback
(
'error'
);
...
...
@@ -85,53 +118,24 @@ exports.clear = function(ent_code,keyID,type,callback){
});
};
function
getEsenceThreads
(
ent_code
,
keyID
,
type
,
callback
){
var
today
=
new
Date
();
var
conditions
=
{
ent_code
:
ent_code
,
level
:
1
,
status
:
1
,
new_recommend
:
1
,
$or
:
[{
isEvent
:
0
},
{
isEvent
:
null
},
{
isEvent
:
1
,
'event.eventStartTime'
:
{
$lte
:
today
}
}]
};
forumThreadService
.
getThreadWithNotPopulateComment
(
conditions
,
1
,
ThreadRedisCount
,
sort
,
function
(
err
,
results
)
{
if
(
err
)
{
console
.
error
(
err
);
callback
(
err
);
}
else
{
util
.
loadLevel
(
ent_code
,
results
.
items
,
function
()
{
setToRedis
(
ent_code
,
keyID
,
type
,
JSON
.
stringify
(
results
));
callback
(
null
);
});
}
});
};
//获取缓存列表
exports
.
getRedisEsenceThreads
=
function
(
ent_code
,
keyID
,
type
,
callback
){
var
key
=
getKey
(
ent_code
,
keyID
,
type
);
getEsenceThreads
(
ent_code
,
keyID
,
type
,
function
(
err
){
exports
.
getRedisEsenceThreads
=
function
(
ent_code
,
callback
){
var
key
=
getKey
(
ent_code
,
tyhread_redis_salt
);
getEsenceThreads
(
ent_code
,
tyhread_redis_salt
,
function
(
err
){
redis
.
get
(
key
,
function
(
error
,
res
){
return
callback
&&
callback
(
error
,
res
.
split
(
","
));
});
});
};
//更新缓存列表
/*exports.updateRedisEsenceThreads = function(ent_code,keyID,type,callback){
getEsenceThreads(ent_code, keyID,type, function(err){
callback();
});
};*/
//获取缓存数值
exports
.
getThreadRedisCount
=
function
(){
return
ThreadRedisCount
;
};
//更新缓存列表
exports
.
updateRedisEsenceThreads
=
function
(
ent_code
){
if
(
RefreshFlag
){
getEsenceThreads
(
ent_code
,
tyhread_redis_salt
,
function
(
err
){});
}
};
\ No newline at end of file
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