Commit 84c25b67 authored by 邓军's avatar 邓军

添加论坛帖子按发贴人app分页查询和评论分页查询接口

parent 92ddf72f
...@@ -17,7 +17,6 @@ module.exports = function(app) { ...@@ -17,7 +17,6 @@ module.exports = function(app) {
app.use('/v1/forum', router); app.use('/v1/forum', router);
}; };
function write(res, title, desc, link, imgUrl, mid, ent_code) { function write(res, title, desc, link, imgUrl, mid, ent_code) {
link = config.service + link + "&mid=" + mid; link = config.service + link + "&mid=" + mid;
res.writeHead(200, { res.writeHead(200, {
...@@ -75,179 +74,3 @@ function getWX(res, title, desc, link, imgUrl, mid,ent_code, id,type,forumThread ...@@ -75,179 +74,3 @@ function getWX(res, title, desc, link, imgUrl, mid,ent_code, id,type,forumThread
} }
//微信分享接口
router.get('/:ent_code/share.js', function(req, res, next) {
var rs = {};
var type = req.query.type;
var id = req.query.id;
var mid = 0;
if (req.session.openUser && req.session.openUser.mid) {
mid = req.session.openUser.mid;
}
var ent_code = req.params.ent_code;
var link = '/app/forum/' + ent_code + '/index?pageUrl=';
if (type) {
//板块微信接口
if (type === 'Info') {
then(function(cont) {
forumShareConfigService.getByKey(ent_code, 'share', function(err, result) {
console.log(err);
var title = '',
desc = '',
imgUrl = '';
if (result) {
result = result.meta_value;
for (var i = 0; i < result.length; i++) {
if (result[i].type === 'info') {
title = result[i].title;
desc = result[i].desc;
imgUrl = result[i].imgUrl;
}
}
if (id) {
link = link + 'index&infoId=' + id;
} else {
link = link + 'index';
}
getWX(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
} else {
cont(err);
}
});
}).fail(function(cont, err) {
console.error(err);
res.json({
result: false,
code: '10002'
});
});
} else if (!id) {
console.error("ID不能为空");
res.json({
message: 'ID不能为空',
result: false,
code: '10002'
});
} else if (type === 'Thread') {
then(function(cont) {
//获得文章
forumThreadService.getById(id, function(err, result) {
if (result) {
cont(null, result);
} else {
cont(err);
}
});
}).then(function(cont, result) {
//如果没有share值则用默认值
if (!result.share||result.share_type==1) {
forumShareConfigService.getByKey(ent_code, 'share', function(err, sc) {
var title = '',
desc = '',
imgUrl = '';
if (sc) {
if (result.type === 1 || (result.type === 2 && result.level === 2)) {
link = link + 'thread&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
} else if (result.type === 2 && result.level === 1) {
link = link + 'topicList&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
} else if (result.type === 3) {
link = link + 'photoList&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
}
//1、文章 2、话题 3、照片墙
sc = sc.meta_value;
for (var i = 0; i < sc.length; i++) {
if (result.type === 1 || (result.type === 2 && result.level === 2)) {
if (sc[i].type === 'article') {
title = sc[i].title;
desc = sc[i].desc;
imgUrl = sc[i].imgUrl;
}
} else if (result.type === 2 && result.level === 1) {
if (sc[i].type === 'topic') {
title = sc[i].title;
desc = sc[i].desc;
imgUrl = sc[i].imgUrl;
}
} else if (result.type === 3) {
if (sc[i].type === 'photo') {
title = sc[i].title;
desc = sc[i].desc;
imgUrl = sc[i].imgUrl;
}
}
}
getWX(res, title, desc, link, imgUrl, mid,ent_code,result._id,type,result);
} else {
cont(err);
}
});
} else {
//如果有分享设置,则返回分享设置
forumShareService.getById(result.share, function(err, forumShare) {
//1、文章 2、话题 3、照片墙
if (result.type === 1 || (result.type === 2 && result.level === 2)) {
link = link + 'thread&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
//key = 'article';
} else if (result.type === 2 && result.level === 1) {
link = link + 'topicList&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
//key = 'topic';
} else if (result.type === 3) {
link = link + 'photoList&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
//key = 'photo';
}
getWX(res, forumShare.title, forumShare.description, link, forumShare.icon, mid,ent_code,result._id,type,result);
});
}
}).fail(function(cont, err) {
console.error(err);
res.json({
result: false,
code: '10002'
});
});
}
} else {
res.json({
result: false,
code: '10002'
});
}
});
//微信分享接口
router.get('/:ent_code/timeline', function(req, res, next) {
var mid = req.session.openUser.mid,
action = 'share_timeline',
ent_code = req.session.user.ent_code;
httpService.sendRequest(ent_code,mid,action);
res.status(200).end();
});
...@@ -63,6 +63,71 @@ function create(req, callback) { ...@@ -63,6 +63,71 @@ function create(req, callback) {
}); });
} }
//根据发帖者分页查询话题列表
router.get('/thread/searchThread', function(req, res, next) {
//参数
var pageNo = req.query.pageNo,
pageSize = req.query.pageSize,
from = req.session.mobileForumUser.userId,
status = 1,
ent_code = req.session.user.ent_code;
if (pageNo && pageSize) {
var q = {
ent_code: ent_code,
status: status,
from: from
};
forumThreadService.findThreadByPage(pageNo, pageSize, q, function(err, result) {
if (err) {
console.error(err);
}
res.json(result);
});
} else {
console.error('params error');
res.json({
result: false,
err: 'params error'
});
}
});
//文章评论
router.get('/thread/searchComment', function(req, res, next) {
//参数
var pageNo = req.query.pageNo,
pageSize = req.query.pageSize,
from = req.session.mobileForumUser.userId,
status = 1,
ent_code = req.session.user.ent_code;
if (pageNo && pageSize) {
var q = {
ent_code: ent_code,
status: status,
from:req.session.mobileForumUser.from
};
forumThreadService.findCommentByPage(pageNo, pageSize, q, function(err, result) {
if (err) {
console.error(err);
}
res.json(result);
});
} else {
console.error('params error');
res.json({
result: false,
err: 'params error'
});
}
});
//新增论坛文章 //新增论坛文章
router.post('/thread/create', function(req, res, next) { router.post('/thread/create', function(req, res, next) {
var integral = req.session.openUser.integral || 0; var integral = req.session.openUser.integral || 0;
...@@ -112,13 +177,13 @@ router.get('/thread/:tid/get', function(req, res, next) { ...@@ -112,13 +177,13 @@ router.get('/thread/:tid/get', function(req, res, next) {
var info_id = thread.info._id, var info_id = thread.info._id,
pid = thread.pid; pid = thread.pid;
if (thread.type == 1 && thread.level == 1) { if (thread.type == 1 && thread.level == 1) {
httpService.createLog(req,info_id,3,1,tid); httpService.createLog(req, info_id, 3, 1, tid);
}else if(thread.type == 1 && thread.level == 2){ } else if (thread.type == 1 && thread.level == 2) {
httpService.createLog(req,info_id,3,4,tid,pid); httpService.createLog(req, info_id, 3, 4, tid, pid);
}else if (thread.type == 2 && thread.level == 1) { } else if (thread.type == 2 && thread.level == 1) {
httpService.createLog(req,info_id,3,2,tid); httpService.createLog(req, info_id, 3, 2, tid);
}else if (thread.type == 3 && thread.level == 1) { } else if (thread.type == 3 && thread.level == 1) {
httpService.createLog(req,info_id,3,3,tid); httpService.createLog(req, info_id, 3, 3, tid);
} }
......
...@@ -7,6 +7,69 @@ var ForumShare = mongoose.model('ForumShare'); ...@@ -7,6 +7,69 @@ var ForumShare = mongoose.model('ForumShare');
var forumCommentService = require('./forumCommentService'); var forumCommentService = require('./forumCommentService');
var async = require('async'); var async = require('async');
var then = require('thenjs');
//查询帖子
exports.findThreadByPage = function(pageNo,pageSize,q,callback) {
then(function(cont) {
ForumThread.find(q).populate('from').count(cont);
}).then(function(cont, count) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumThread.find(q).skip(skip).limit(limit).sort('-created').exec(function(err, docs) {
cont(err, count, docs);
});
}).then(function(cont, count, threads) {
var rsJson = {
result: true,
total: count,
datas: threads
};
callback(null,rsJson);
}).fail(function(cont, err) {
console.error(err);
var rsJson = {
result: false,
err: err
};
callback(err,rsJson);
});
};
//查询评论
exports.findCommentByPage = function(pageNo,pageSize,q,callback) {
then(function(cont) {
ForumComment.find(q).populate('from').count(cont);
}).then(function(cont, count) {
var skip = (pageNo - 1) * pageSize;
var limit = count - skip > pageSize ? pageSize : (count - skip);
ForumComment.find(q).skip(skip).limit(limit).sort('-created').populate('from').exec(function(err, docs) {
cont(err, count, docs);
});
}).then(function(cont, count, threads) {
var rsJson = {
result: true,
total: count,
datas: threads
};
callback(null,rsJson);
}).fail(function(cont, err) {
console.error(err);
var rsJson = {
result: false,
err: err
};
callback(err,rsJson);
});
};
//创建文章 //创建文章
exports.createThread = function(entity, callback) { exports.createThread = function(entity, callback) {
......
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