Commit a1b4cb97 authored by 陈家荣's avatar 陈家荣

Merge branch 'development' of git.wxpai.cn:scrmgroup/pisns-forum-api into development

parents 3256c22d 7dae0ac7
......@@ -41,7 +41,8 @@ router.post('/info/create', function(req, res, next) {
router.get('/info/:fid/get', function(req, res, next) {
var fid = req.params.fid || null;
if (fid) {
httpService.createLog(req,fid,2);
var source = req.session.mobileForumUser.source;
httpService.createLog(req,source,fid,2);
async.waterfall([
function(callback) {
//更新浏览数
......
......@@ -17,8 +17,8 @@ module.exports = function(app) {
app.use('/v1/forum', router);
};
function write(res, title, desc, link, imgUrl, mid, ent_code) {
link = config.service + link + "&mid=" + mid;
res.writeHead(200, {
'Content-Type': 'text/javascript',
'Cache-Control': 'no-cache',
......@@ -74,3 +74,178 @@ 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 uId= req.session.mobileForumUser.userId;
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) {
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';
}
link = link +'&uId='+uId;
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==2) {
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;
}
}
}
link = link +'&uId='+uId;
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';
}
link = link +'&uId='+uId;
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();
});
......@@ -175,15 +175,16 @@ router.get('/thread/:tid/get', function(req, res, next) {
forumThreadService.getThreadById(tid, function(err, thread) {
//文章类型 1、文章 2、话题 3、照片墙
var info_id = thread.info._id,
pid = thread.pid;
pid = thread.pid,
source = req.session.mobileForumUser.source;
if (thread.type == 1 && thread.level == 1) {
httpService.createLog(req, info_id, 3, 1, tid);
httpService.createLog(req,source,info_id, 3, 1, tid);
} else if (thread.type == 1 && thread.level == 2) {
httpService.createLog(req, info_id, 3, 4, tid, pid);
httpService.createLog(req,source,info_id, 3, 4, tid, pid);
} else if (thread.type == 2 && thread.level == 1) {
httpService.createLog(req, info_id, 3, 2, tid);
httpService.createLog(req,source,info_id, 3, 2, tid);
} else if (thread.type == 3 && thread.level == 1) {
httpService.createLog(req, info_id, 3, 3, tid);
httpService.createLog(req,source,info_id, 3, 3, tid);
}
......
......@@ -45,11 +45,15 @@ var ForumPVLogSchema = new Schema({
index: true
},
p_thread: { //父文章ID
type: Number,
index: true
type: String,
index: true,
ref: 'forumThread'
},
source: { //分享者
type: String
type: String,
require: true,
index: true,
ref: 'ForumUser'
},
ip: { //IP地址
type: String
......
......@@ -45,11 +45,15 @@ var ForumUVLogSchema = new Schema({
index: true
},
p_thread: { //父文章ID
type: Number,
index: true
type: String,
index: true,
ref: 'forumThread'
},
source: { //分享者
type: String
type: String,
require: true,
index: true,
ref: 'ForumUser'
},
ip: { //IP地址
type: String
......
......@@ -50,10 +50,11 @@ var getClientIP = function(req) {
return ipAddress;
};
exports.createLog = function(req,info,type,thread_type,thread,p_thread) {
exports.createLog = function(req,source,info,type,thread_type,thread,p_thread) {
var logObj = {
ent_code: req.session.user.ent_code,
source:source,
mid: req.session.openUser.mid,
open_id: req.session.mobileForumUser.openId,
user: req.session.mobileForumUser.userId,
......
......@@ -3,8 +3,8 @@
var forumUserService=require('../service/forumUserService');
exports.getMobileUser=function(req){
// return req.session.mobileForumUser.userId;
return '55015675868b65a028187c49';
return req.session.mobileForumUser.userId;
// return '55015675868b65a028187c49';
}
exports.getOpenId=function(req){
......@@ -24,6 +24,10 @@ exports.identifyUser=function() {
userId:doc._id,
openId:doc.uid
};
if(req.session.source){
req.session.mobileForumUser.source = req.session.source;
delete req.session.source;
}
next(null);
}else{
if(req.session.tmpOpenId){
......@@ -44,6 +48,11 @@ exports.identifyUser=function() {
userId:doc._id,
openId:doc.uid
};
if(req.session.source){
req.session.mobileForumUser.source = req.session.source;
delete req.session.source;
}
next(null);
}
});
......
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