Commit 18abca5d authored by 陈家荣's avatar 陈家荣

子话题最新查询接口

parent b94dc9c6
...@@ -506,8 +506,6 @@ router.post('/thread/create', function(req, res, next) { ...@@ -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 = {}; var rs = {};
rs.data = { rs.data = {
'id': thread._id 'id': thread._id
...@@ -525,32 +523,35 @@ router.post('/thread/create', function(req, res, next) { ...@@ -525,32 +523,35 @@ router.post('/thread/create', function(req, res, next) {
}); });
}); });
//获取目标论坛文章 //获取文章
router.get('/thread/:tid/get', function(req, res, next) { router.get('/thread/:tid/get', function(req, res, next) {
var tid = req.params.tid || null; var tid = req.params.tid || null;
var ent_code = req.session.user.ent_code; var ent_code = req.session.user.ent_code;
if (tid) { if (tid) {
async.waterfall([ async.waterfall([
function(callback) { function(callback) {
forumThreadService.getThreadById(tid, function(err, thread) { forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙 //文章类型 1、文章 2、话题 3、照片墙
if (err || !thread) { if (err) {
callback(err, null); callback(err, null);
} else { } else {
callback(null, thread); callback(null, thread);
} }
var info_id = thread.info._id, if(thread && thread.info){
pid = thread.pid, var info_id = thread.info._id,
source = req.session.mobileForumUser.source; pid = thread.pid,
if (thread.type == 1 && thread.level == 1) { source = req.session.mobileForumUser.source;
httpService.createLog(req, source, info_id, 3, 1, tid); if (thread.type == 1 && thread.level == 1) {
} else if (thread.type == 1 && thread.level == 2) { httpService.createLog(req, source, info_id, 3, 1, tid);
httpService.createLog(req, source, info_id, 3, 4, tid, pid); } else if (thread.type == 1 && thread.level == 2) {
} else if (thread.type == 2 && thread.level == 1) { httpService.createLog(req, source, info_id, 3, 4, tid, pid);
httpService.createLog(req, source, info_id, 3, 2, tid); } else if (thread.type == 2 && thread.level == 1) {
} else if (thread.type == 3 && thread.level == 1) { httpService.createLog(req, source, info_id, 3, 2, tid);
httpService.createLog(req, source, info_id, 3, 3, tid); } else if (thread.type == 3 && thread.level == 1) {
} httpService.createLog(req, source, info_id, 3, 3, tid);
}
}
}); });
forumThreadService.updateThreadPvCount(tid, function(err, doc) { forumThreadService.updateThreadPvCount(tid, function(err, doc) {
if (err) { if (err) {
...@@ -616,7 +617,7 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -616,7 +617,7 @@ router.get('/thread/:tid/get', function(req, res, next) {
} }
}); });
//获取目标论坛文章 //获取文章
router.get('/thread/photo/:pid/get', function(req, res, next) { router.get('/thread/photo/:pid/get', function(req, res, next) {
var pid = req.params.pid || null, var pid = req.params.pid || null,
userId = user.getMobileUser(req); userId = user.getMobileUser(req);
...@@ -677,36 +678,6 @@ router.post('/thread/:tid/delete', function(req, res, next) { ...@@ -677,36 +678,6 @@ router.post('/thread/:tid/delete', function(req, res, next) {
} }
}); });
//文章点赞
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);
});
} else {
res.json(returnCode.WRONG_PARAM);
}
});
//文章点赞和取消点赞 //文章点赞和取消点赞
router.post('/thread/:tid/praiseOrCancelPraise', function(req, res, next) { router.post('/thread/:tid/praiseOrCancelPraise', function(req, res, next) {
var userId = req.session.mobileForumUser.userId; var userId = req.session.mobileForumUser.userId;
...@@ -1469,39 +1440,6 @@ router.get('/thread/:tid/comment/list/byFloor', function(req, res, next) { ...@@ -1469,39 +1440,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) { router.post('/thread/:tid/comment/:cid/praiseOrCancelPraise', function(req, res, next) {
var userId = req.session.mobileForumUser.userId; var userId = req.session.mobileForumUser.userId;
...@@ -1574,9 +1512,7 @@ router.get('/thread/:tid/topics', function(req, res, next) { ...@@ -1574,9 +1512,7 @@ router.get('/thread/:tid/topics', function(req, res, next) {
$ne: 3 $ne: 3
} }
}; };
if (tid) { if (tid) {
async.waterfall([ async.waterfall([
function(callback) { function(callback) {
forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) { forumUserThreadControlService.getUserThreadControlById(user.getMobileUser(req), function(err, doc) {
...@@ -1985,4 +1921,89 @@ router.get('/thread/getThreadWithNotPopulateComment/hot', function(req, res, nex ...@@ -1985,4 +1921,89 @@ 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){ //最热
}
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
...@@ -191,9 +191,6 @@ exports.findCommentByPage = function(pageNo, pageSize, q, callback) { ...@@ -191,9 +191,6 @@ exports.findCommentByPage = function(pageNo, pageSize, q, callback) {
}); });
}; };
//创建文章 //创建文章
exports.createThread = function(entity, callback) { exports.createThread = function(entity, callback) {
if (!entity.share) { if (!entity.share) {
...@@ -231,6 +228,18 @@ exports.createThread = function(entity, callback) { ...@@ -231,6 +228,18 @@ exports.createThread = function(entity, callback) {
} }
}; };
//根据ID获取文章,选择字段
exports.getByIdSelectyField = function(id, fields, callback) {
ForumThread.findOne({_id: id}).select(fields).exec(function(err,result){
if (err) {
console.error(err);
callback(err, null);
} else {
callback(null, result);
}
});
}
//根据ID获取文章记录,不查评论,子话题 //根据ID获取文章记录,不查评论,子话题
exports.getById = function(id, callback) { exports.getById = function(id, callback) {
ForumThread.findOne({ ForumThread.findOne({
...@@ -257,7 +266,6 @@ exports.getByConditions = function(conditions, callback) { ...@@ -257,7 +266,6 @@ exports.getByConditions = function(conditions, callback) {
} }
//根据ID获取文章 //根据ID获取文章
exports.getThreadById = function(tid, callback) { exports.getThreadById = function(tid, callback) {
ForumThread.findOne({_id: tid}).populate('from','uid mid nickName icon exp').populate('info','name icon').populate('share').exec(function(err, doc) { ForumThread.findOne({_id: tid}).populate('from','uid mid nickName icon exp').populate('info','name icon').populate('share').exec(function(err, doc) {
if (err) { if (err) {
console.error(err); console.error(err);
...@@ -273,7 +281,6 @@ exports.getThreadById = function(tid, callback) { ...@@ -273,7 +281,6 @@ exports.getThreadById = function(tid, callback) {
var conditions = { var conditions = {
thread: tid, thread: tid,
level: '1' level: '1'
// status:1
}; };
//获取最新10条评论 //获取最新10条评论
forumCommentService.getAllComment(conditions, 1, 10, function(err, results) { forumCommentService.getAllComment(conditions, 1, 10, function(err, results) {
...@@ -1149,7 +1156,6 @@ exports.remove = function(array,val) { ...@@ -1149,7 +1156,6 @@ exports.remove = function(array,val) {
return array; return array;
}; };
function getAllThreadByFidAndUserHelp(user_ids, conditions, pageNo, pageSize, sort, callback) { function getAllThreadByFidAndUserHelp(user_ids, conditions, pageNo, pageSize, sort, callback) {
conditions.from = { conditions.from = {
"$in" : user_ids "$in" : user_ids
...@@ -1231,7 +1237,6 @@ exports.getAllThreadByFidAndMid = function(mid, conditions, pageNo, pageSize, so ...@@ -1231,7 +1237,6 @@ exports.getAllThreadByFidAndMid = function(mid, conditions, pageNo, pageSize, so
}); });
} }
//更新文章 //更新文章
exports.updateThread = function(condition, entity, callback) { exports.updateThread = function(condition, entity, callback) {
ForumThread.findOneAndUpdate(condition, entity, function(err, doc){ ForumThread.findOneAndUpdate(condition, entity, function(err, doc){
...@@ -1256,8 +1261,6 @@ exports.updateByIdWithOptions = function(condition, entity, options, callback) { ...@@ -1256,8 +1261,6 @@ exports.updateByIdWithOptions = function(condition, entity, options, callback) {
}); });
}; };
//查询列表数据,不获取评论,话题获取参与用户 //查询列表数据,不获取评论,话题获取参与用户
exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize, sort, callback) { exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize, sort, callback) {
countAllByFid(conditions, function(err, count) { countAllByFid(conditions, function(err, count) {
...@@ -1318,4 +1321,5 @@ exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize, ...@@ -1318,4 +1321,5 @@ exports.getThreadWithNotPopulateComment = function(conditions, pageNo, pageSize,
} }
}); });
}; };
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment