Commit b394d955 authored by 陈志良's avatar 陈志良

社区分享设置更新

parent a2cc8fae
...@@ -80,12 +80,10 @@ router.get('/:ent_code/share.js', function(req, res, next) { ...@@ -80,12 +80,10 @@ router.get('/:ent_code/share.js', function(req, res, next) {
id = req.query.id, id = req.query.id,
uId= req.session.mobileForumUser.userId, uId= req.session.mobileForumUser.userId,
ent_code = req.params.ent_code, ent_code = req.params.ent_code,
mid = 0, mid = req.session.openUser.mid,
link = '/app/forum/' + ent_code + '/index?pageUrl=', link = '/app/forum/' + ent_code + '/index?pageUrl=',
share_log = {}; share_log = {};
if (req.session.openUser && req.session.openUser.mid) { var title = '',desc = '',imgUrl = '';
mid = req.session.openUser.mid;
}
delete req.session.mobileForumUser.share_log; delete req.session.mobileForumUser.share_log;
//板块微信接口 //板块微信接口
if(!type || !id){ if(!type || !id){
...@@ -101,47 +99,20 @@ router.get('/:ent_code/share.js', function(req, res, next) { ...@@ -101,47 +99,20 @@ router.get('/:ent_code/share.js', function(req, res, next) {
console.error(err); console.error(err);
res.json(_.assign({result:false},returnCode.BUSY)); res.json(_.assign({result:false},returnCode.BUSY));
return; return;
}else{
if(forumInfo.share_type == 1){
var shareInfo = forumInfo.share || {};
title = shareInfo.title,desc = shareInfo.description,imgUrl = shareInfo.icon;
link = link + 'index&infoId='+ id+'&uId='+uId;
getWX(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
return;
}else{
//默认分享设置
title = forumInfo.name,desc = forumInfo.description,imgUrl = forumInfo.icon;
getWX(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
}
} }
if(forumInfo.share_type == 1){
var shareInfo = forumInfo.share || {};
var title = shareInfo.title || '',
desc = shareInfo.description || '',
imgUrl = shareInfo.icon || '';
link = link + 'index&infoId='+ id+'&uId='+uId;
getWX(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
return;
}else{
//默认分享设置 //查询板块默认分享设置
forumShareConfigService.getByKey(ent_code, 'share', function(err, result) {
if(err){
console.error(err);
res.json(_.assign({result:false},returnCode.BUSY));
}else{
var title = '',desc = '',imgUrl = '';
if (result) {
//匹配板块默认分享设置
result = result.meta_value;
_.forEach(result,function(e){
if (e.type === 'info') {
title = e.title;
desc = e.desc;
imgUrl = e.imgUrl;
return;
}
});
link = link + 'index&infoId='+ id+'&uId='+uId;
getWX(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
}else{
//没找到板块默认分享设置
console.error('info默认分享设置不存在');
res.json(_.assign({result:false},returnCode.DATA_NOTEXITS));
}
}
});
}
}); });
}else if (type === 'Thread') { }else if (type === 'Thread') {
share_log.type = 3; share_log.type = 3;
share_log.thread = id; share_log.thread = id;
...@@ -160,38 +131,43 @@ router.get('/:ent_code/share.js', function(req, res, next) { ...@@ -160,38 +131,43 @@ router.get('/:ent_code/share.js', function(req, res, next) {
//组装分享路径与判断分享类型 //组装分享路径与判断分享类型
//判断分享类型 1、文章 2、话题 3、照片墙 //判断分享类型 1、文章 2、话题 3、照片墙
var share_type = ''; var share_type = '';
if (thread.type === 1 || (thread.type === 2 && thread.level === 2)) { switch(thread.type){
link = link + 'thread&infoId=' + thread.info + '&ent_code=' + ent_code + '&id=' + thread._id; case 1:
share_type = 'article'; link += 'thread';
} else if (thread.type === 2 && thread.level === 1) { share_type = 'article';
link = link + 'topicList&infoId=' + thread.info + '&ent_code=' + ent_code + '&id=' + thread._id; title = thread.info.name;
share_type = 'topic'; break;
} else if (thread.type === 3) { case 2:
link = link + 'photoList&infoId=' + thread.info + '&ent_code=' + ent_code + '&id=' + thread._id; if(thread.level === 2){
share_type = 'photo'; link += 'thread';
share_type = 'article';
title = thread.info.name;
}else{
link += 'topicList';
share_type = 'topic';
title = thread.pid.name;
}
break;
case 3:
if(thread.level === 2){
link += 'thread';
share_type = 'article';
title = thread.info.name;
}else{
link += 'photoList';
share_type = 'photo';
title = thread.pid.name;
}
break;
} }
link = link +'&uId='+uId; var baseParamsUrl = '&infoId=' + thread.info + '&ent_code=' + ent_code + '&id=' + thread._id + '&uId='+uId;
link += baseParamsUrl;
desc = thread.content.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"");
imgUrl = thread.from.displayIcon || thread.from.icon || thread.info.icon;
//获取分享设置 //获取分享设置
if (!thread.share || thread.share_type==1) { if (!thread.share || thread.share_type==1) {
//获取默认文章分享设置 //获取默认文章分享
forumShareConfigService.getByKey(ent_code, 'share', function(err, sc) { getWX(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
var title = '',desc = '',imgUrl = '';
if(err || !sc){
cont(err || share_type+'默认分享设置不存在');
}else{
sc = sc.meta_value;
//设置分享信息
_.forEach(sc,function(e){
if(share_type === e.type){
title = e.title;
desc = e.desc;
imgUrl = e.imgUrl;
return;
}
});
getWX(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
}
});
} else { } else {
//获取个性化文章分享设置 //获取个性化文章分享设置
forumShareService.getById(thread.share, function(err, forumShare) { forumShareService.getById(thread.share, function(err, forumShare) {
...@@ -291,20 +267,20 @@ function getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,forumThre ...@@ -291,20 +267,20 @@ function getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,forumThre
ent_code:ent_code ent_code:ent_code
}); });
} }
//微信分享接口 //微信分享接口V3
router.get('/sharev2.js', function(req, res, next) { router.get('/sharev2.js', function(req, res, next) {
var rs = {}, var rs = {},
type = req.query.type, type = req.query.type,
id = req.query.id, id = req.query.id,
uId= req.session.mobileForumUser.userId, uId= req.session.mobileForumUser.userId,
ent_code = req.session.user.ent_code, ent_code = req.session.user.ent_code,
mid = 0, mid = req.session.openUser.mid,
link = '/app/forum/' + ent_code + '/v2?pageUrl=', link = '/app/forum/' + ent_code + '/v2?pageUrl=',
share_log = {}; share_log = {};
if (req.session.openUser && req.session.openUser.mid) {
mid = req.session.openUser.mid;
}
delete req.session.mobileForumUser.share_log; delete req.session.mobileForumUser.share_log;
var title = '',desc = '',imgUrl = '';
//板块微信接口 //板块微信接口
if(!type || !id){ if(!type || !id){
console.error('请求参数错误') console.error('请求参数错误')
...@@ -318,46 +294,17 @@ router.get('/sharev2.js', function(req, res, next) { ...@@ -318,46 +294,17 @@ router.get('/sharev2.js', function(req, res, next) {
if (err) { if (err) {
console.error(err); console.error(err);
res.json(_.assign({result:false},returnCode.BUSY)); res.json(_.assign({result:false},returnCode.BUSY));
return;
}
if(forumInfo.share_type == 1){
var shareInfo = forumInfo.share || {};
var title = shareInfo.title || '',
desc = shareInfo.description || '',
imgUrl = shareInfo.icon || '';
link = link + 'index&infoId='+ id+'&uId='+uId;
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
return;
}else{ }else{
//默认分享设置 //查询板块默认分享设置 if(forumInfo.share_type && forumInfo.share_type == 1){
forumShareConfigService.getByKey(ent_code, 'share', function(err, result) { var shareInfo = forumInfo.share || {};
if(err){ title = shareInfo.title,desc = shareInfo.description,imgUrl = shareInfo.icon;
console.error(err); link = link + 'index&infoId='+ id+'&uId='+uId;
res.json(_.assign({result:false},returnCode.BUSY)); getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
}else{ }else{
var title = '',desc = '',imgUrl = ''; title = forumInfo.name,desc = forumInfo.description,imgUrl = forumInfo.icon;
if (result) { getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
//匹配板块默认分享设置 }
result = result.meta_value;
_.forEach(result,function(e){
if (e.type === 'info') {
title = e.title;
desc = e.desc;
imgUrl = e.imgUrl;
return;
}
});
link = link + 'index&infoId='+ id+'&uId='+uId;
getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
}else{
//没找到板块默认分享设置
console.error('info默认分享设置不存在');
res.json(_.assign({result:false},returnCode.DATA_NOTEXITS));
}
}
});
} }
}); });
}else if (type === 'Thread') { }else if (type === 'Thread') {
...@@ -365,61 +312,59 @@ router.get('/sharev2.js', function(req, res, next) { ...@@ -365,61 +312,59 @@ router.get('/sharev2.js', function(req, res, next) {
share_log.thread = id; share_log.thread = id;
then(function(cont) { then(function(cont) {
//获得文章 //获得文章
forumThreadService.getById(id,cont); forumThreadService.getThreadByIdSimple({_id:id},cont);
}).then(function(cont, thread) { }).then(function(cont, thread) {
if(!thread){ if(!thread){
//文章个性化分享设置不存在 //文章不存在
console.error('分享文章不存在'); cont('分享文章不存在');
res.json(_.assign({result:false},returnCode.DATA_NOTEXITS));
}else{ }else{
share_log.p_thread = thread.pid; share_log.p_thread = thread.pid;
share_log.info = thread.info; share_log.info = thread.info._id || thread.info;
share_log.thread_type = thread.pid?4:thread.type; share_log.thread_type = thread.pid?4:thread.type;
//组装分享路径与判断分享类型 //组装分享路径与判断分享类型
//判断分享类型 1、文章 2、话题 3、照片墙 var baseParamsUrl = '&infoId=' + thread.info._id + '&ent_code=' + ent_code + '&tId=' + thread._id +'&uId='+uId;
var share_type = ''; var share_type = '';
if (thread.type === 1 ) { switch(thread.type){
link = link + 'detail&infoId=' + thread.info + '&ent_code=' + ent_code + '&tId=' + thread._id; case 1://文章
share_type = 'article'; link = link + 'detail';
}else if(thread.type === 2 && thread.level === 2){ share_type = 'article';
link = link + 'photoDetail&infoId=' + thread.info + '&ent_code=' + ent_code + '&tId=' + thread._id; title = thread.info.name;
share_type = 'photo'; break;
}else if (thread.type === 2 && thread.level === 1) { case 2://话题
link = link + 'topic&infoId=' + thread.info + '&ent_code=' + ent_code + '&tId=' + thread._id; if(thread.level === 2){
share_type = 'topic'; link += 'detail';
} else if (thread.type === 3) { share_type = 'article';
link = link + 'photoWall&infoId=' + thread.info + '&ent_code=' + ent_code + '&tId=' + thread._id; title = thread.pid.name;
share_type = 'photo'; }else if(thread.level === 1){
link += 'topic';
share_type = 'topic';
title = thread.title;
}
break;
case 3://照片墙
if(thread.level === 2){
link += 'photoDetail';
share_type = 'photo';
title = thread.pid.name;
}else if(thread.level === 1){
link += 'photoWall';
share_type = 'photo';
title = thread.title;
}
break;
} }
link = link +'&uId='+uId; desc = thread.content.replace(/<\/?.+?>/g,"").replace(/&nbsp;/g,"");
imgUrl = thread.from.displayIcon || thread.from.icon || thread.info.icon;
link += baseParamsUrl;
//获取分享设置 //获取分享设置
if (!thread.share || thread.share_type==1) { if (!thread.share || thread.share_type==1) {
//获取默认文章分享设置 //文章默认分享
forumShareConfigService.getByKey(ent_code, 'share', function(err, sc) { getWXV2(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
var title = '',desc = '',imgUrl = '';
if(err || !sc){
cont(err || share_type+'默认分享设置不存在');
}else{
sc = sc.meta_value;
//设置分享信息
_.forEach(sc,function(e){
if(share_type === e.type){
title = e.title;
desc = e.desc;
imgUrl = e.imgUrl;
return;
}
});
getWXV2(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
}
});
} else { } else {
//获取个性化文章分享设置 //获取个性化文章分享设置
forumShareService.getById(thread.share, function(err, forumShare) { forumShareService.getById(thread.share, function(err, forumShare) {
if(err || !forumShare){ if(err || !forumShare){
//文章个性化分享设置不存在 getWXV2(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
console.error(err || '文章个性化分享设置不存在');
res.json(_.assign({result:false},returnCode.DATA_NOTEXITS));
}else{ }else{
getWXV2(res, forumShare.title, forumShare.description, link, forumShare.icon, mid,ent_code,thread._id,type,thread); getWXV2(res, forumShare.title, forumShare.description, link, forumShare.icon, mid,ent_code,thread._id,type,thread);
} }
...@@ -432,4 +377,145 @@ router.get('/sharev2.js', function(req, res, next) { ...@@ -432,4 +377,145 @@ router.get('/sharev2.js', function(req, res, next) {
}); });
} }
req.session.mobileForumUser.share_log = share_log; req.session.mobileForumUser.share_log = share_log;
}); });
\ No newline at end of file //微信分享接口V2
// router.get('/sharev2.js', function(req, res, next) {
// var rs = {},
// type = req.query.type,
// id = req.query.id,
// uId= req.session.mobileForumUser.userId,
// ent_code = req.session.user.ent_code,
// mid = 0,
// link = '/app/forum/' + ent_code + '/v2?pageUrl=',
// share_log = {};
// if (req.session.openUser && req.session.openUser.mid) {
// mid = req.session.openUser.mid;
// }
// delete req.session.mobileForumUser.share_log;
// //板块微信接口
// if(!type || !id){
// console.error('请求参数错误')
// res.json(_.assign({result:false},returnCode.WRONG_PARAM));
// }else if (type === 'Info') {
// //分享记录对象
// share_log.type = 2;
// share_log.info = id;
// forumInfoService.getInfoById(id, function(err, forumInfo) {
// if (err) {
// console.error(err);
// res.json(_.assign({result:false},returnCode.BUSY));
// return;
// }
// if(forumInfo.share_type == 1){
// var shareInfo = forumInfo.share || {};
// var title = shareInfo.title || '',
// desc = shareInfo.description || '',
// imgUrl = shareInfo.icon || '';
// link = link + 'index&infoId='+ id+'&uId='+uId;
// getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
// return;
// }else{
// //默认分享设置 //查询板块默认分享设置
// forumShareConfigService.getByKey(ent_code, 'share', function(err, result) {
// if(err){
// console.error(err);
// res.json(_.assign({result:false},returnCode.BUSY));
// }else{
// var title = '',desc = '',imgUrl = '';
// if (result) {
// //匹配板块默认分享设置
// result = result.meta_value;
// _.forEach(result,function(e){
// if (e.type === 'info') {
// title = e.title;
// desc = e.desc;
// imgUrl = e.imgUrl;
// return;
// }
// });
// link = link + 'index&infoId='+ id+'&uId='+uId;
// getWXV2(res, title, desc, link, imgUrl, mid,ent_code, id,type,null);
// }else{
// //没找到板块默认分享设置
// console.error('info默认分享设置不存在');
// res.json(_.assign({result:false},returnCode.DATA_NOTEXITS));
// }
// }
// });
// }
// });
// }else if (type === 'Thread') {
// share_log.type = 3;
// share_log.thread = id;
// then(function(cont) {
// //获得文章
// forumThreadService.getById(id,cont);
// }).then(function(cont, thread) {
// if(!thread){
// //文章不存在
// cont('分享文章不存在');
// }else{
// share_log.p_thread = thread.pid;
// share_log.info = thread.info;
// share_log.thread_type = thread.pid?4:thread.type;
// //组装分享路径与判断分享类型
// //判断分享类型 1、文章 2、话题 3、照片墙
// var share_type = '';
// if (thread.type === 1 ) {
// link = link + 'detail&infoId=' + thread.info + '&ent_code=' + ent_code + '&tId=' + thread._id;
// share_type = 'article';
// }else if(thread.type === 2 && thread.level === 2){
// link = link + 'photoDetail&infoId=' + thread.info + '&ent_code=' + ent_code + '&tId=' + thread._id;
// share_type = 'photo';
// }else if (thread.type === 2 && thread.level === 1) {
// link = link + 'topic&infoId=' + thread.info + '&ent_code=' + ent_code + '&tId=' + thread._id;
// share_type = 'topic';
// } else if (thread.type === 3) {
// link = link + 'photoWall&infoId=' + thread.info + '&ent_code=' + ent_code + '&tId=' + thread._id;
// share_type = 'photo';
// }
// link = link +'&uId='+uId;
// //获取分享设置
// if (!thread.share || thread.share_type==1) {
// //获取默认文章分享设置
// forumShareConfigService.getByKey(ent_code, 'share', function(err, sc) {
// var title = '',desc = '',imgUrl = '';
// if(err || !sc){
// cont(err || share_type+'默认分享设置不存在');
// }else{
// sc = sc.meta_value;
// //设置分享信息
// _.forEach(sc,function(e){
// if(share_type === e.type){
// title = e.title;
// desc = e.desc;
// imgUrl = e.imgUrl;
// return;
// }
// });
// getWXV2(res, title, desc, link, imgUrl, mid,ent_code,thread._id,type,thread);
// }
// });
// } else {
// //获取个性化文章分享设置
// forumShareService.getById(thread.share, function(err, forumShare) {
// if(err || !forumShare){
// //文章个性化分享设置不存在
// console.error(err || '文章个性化分享设置不存在');
// res.json(_.assign({result:false},returnCode.DATA_NOTEXITS));
// }else{
// getWXV2(res, forumShare.title, forumShare.description, link, forumShare.icon, mid,ent_code,thread._id,type,thread);
// }
// });
// }
// }
// }).fail(function(cont, err) {
// console.error(err);
// res.json(_.assign({result:false},returnCode.WRONG_PARAM));
// });
// }
// req.session.mobileForumUser.share_log = share_log;
// });
\ No newline at end of file
...@@ -262,6 +262,12 @@ exports.getThreadById = function(tid, callback) { ...@@ -262,6 +262,12 @@ exports.getThreadById = function(tid, callback) {
}); });
}; };
//根据ID获取文章 //根据ID获取文章
exports.getThreadByIdSimple = function(conditions, callback) {
ForumThread.findOne(conditions).populate('from info share pid').exec(function(err, doc) {
callback(err, doc);
});
};
//根据ID获取文章
exports.getThreadByIdNoLimit = function(tid, callback) { exports.getThreadByIdNoLimit = function(tid, callback) {
async.parallel([ async.parallel([
function(cb) { function(cb) {
......
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