Commit 03e05b77 authored by 邓军's avatar 邓军

1.增加分享默认配置功能

2.微信分享接口调整
parent ea1dfe8e
...@@ -13,7 +13,7 @@ var then = require('thenjs'); ...@@ -13,7 +13,7 @@ var then = require('thenjs');
//var forumInfoService = require('../../service/forumInfoService'); //var forumInfoService = require('../../service/forumInfoService');
module.exports = function(app) { module.exports = function(app) {
app.use('/forumShare', router); app.use('/forum/share', router);
}; };
function getWX(res, title, desc, link, imgUrl, mid) { function getWX(res, title, desc, link, imgUrl, mid) {
...@@ -44,29 +44,35 @@ router.get('/:ent_code/share.js', function(req, res, next) { ...@@ -44,29 +44,35 @@ router.get('/:ent_code/share.js', function(req, res, next) {
var rs = {}; var rs = {};
var type = req.query.type; var type = req.query.type;
var id = req.query.id; var id = req.query.id;
var mid = req.session.openUser.mid || 0; var mid = 0;
if (req.session.openUser && req.session.openUser.mid) {
mid = req.session.openUser.mid;
}
var ent_code = req.params.ent_code; var ent_code = req.params.ent_code;
var link = '/app/forum/' + ent_code + '/index?pageUrl='; var link = '/app/forum/' + ent_code + '/index?pageUrl=';
if (type) { if (type) {
//板块微信接口 //板块微信接口
if (type === 'Info') { if (type === 'Info') {
then(function(cont) { then(function(cont) {
forumShareConfigService.getByEntCode(ent_code, function(err, result) { forumShareConfigService.getByKey(ent_code, 'share', function(err, result) {
var title = '', var title = '',
desc = '', desc = '',
imgUrl = ''; imgUrl = '';
if (result) { if (result) {
result = result.meta_value;
for (var i = 0; i < result.length; i++) { for (var i = 0; i < result.length; i++) {
if (result[i].meta_key === 'share_info_title') { if (result[i].type === 'info') {
title = result[i].meta_value; title = result[i].title;
} else if (result[i].meta_key === 'share_info_description') { desc = result[i].desc;
desc = result[i].meta_value; imgUrl = result[i].imgUrl;
} else if (result[i].meta_key === 'share_info_icon') {
imgUrl = result[i].meta_value;
} }
} }
if (id) {
link = link + 'index&infoId=' + id; link = link + 'index&infoId=' + id;
} else {
link = link + 'index';
}
getWX(res, title, desc, link, imgUrl, mid); getWX(res, title, desc, link, imgUrl, mid);
} else { } else {
cont(err); cont(err);
...@@ -100,36 +106,60 @@ router.get('/:ent_code/share.js', function(req, res, next) { ...@@ -100,36 +106,60 @@ router.get('/:ent_code/share.js', function(req, res, next) {
//如果没有share值则用默认值 //如果没有share值则用默认值
if (!result.share) { if (!result.share) {
forumShareConfigService.getByEntCode(ent_code, function(err, sc) { forumShareConfigService.getByKey(ent_code, 'share', function(err, sc) {
var title = '', var title = '',
desc = '', desc = '',
imgUrl = ''; imgUrl = '';
if (sc) { if (sc) {
var key = '';
//1、文章 2、话题 3、照片墙
if (result.type === 1 || (result.type === 2 && result.level === 2)) { if (result.type === 1 || (result.type === 2 && result.level === 2)) {
link = link + 'thread&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id; link = link + 'thread&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
key = 'article';
} else if (result.type === 2 && result.level === 1) { } else if (result.type === 2 && result.level === 1) {
link = link + 'topicList&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id; link = link + 'topicList&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
key = 'topic';
} else if (result.type === 3) { } else if (result.type === 3) {
link = link + 'photoList&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id; link = link + 'photoList&infoId=' + result.info + '&ent_code=' + ent_code + '&id=' + result._id;
key = 'photo';
}
}
//1、文章 2、话题 3、照片墙
sc = sc.meta_value;
for (var i = 0; i < sc.length; i++) { for (var i = 0; i < sc.length; i++) {
if (sc[i].meta_key === 'share_' + key + '_title') {
title = sc[i].meta_value; if (result.type === 1 || (result.type === 2 && result.level === 2)) {
} else if (sc[i].meta_key === 'share_' + key + '_description') { console.log('article');
desc = sc[i].meta_value; if (sc[i].type === 'article') {
} else if (sc[i].meta_key === 'share_' + key + '_icon') { console.log(sc[i]);
imgUrl = sc[i].meta_value; 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) {
console.log('photo');
if (sc[i].type === 'photo') {
title = sc[i].title;
desc = sc[i].desc;
imgUrl = sc[i].imgUrl;
}
}
}
console.log(result.type+':'+result.level);
console.log(title + ':' + desc + 'imgUrl');
getWX(res, title, desc, link, imgUrl, mid); getWX(res, title, desc, link, imgUrl, mid);
} else { } else {
cont(err); cont(err);
......
'use strict';
var express = require('express'),
router = express.Router(),
returnCode = require('../../utils/returnCode'),
_ = require('lodash');
var mongoose = require('mongoose');
//var forumThreadService = require('../../service/forumThreadService');
var forumShareConfigService = require('../../service/forumShareConfigService');
//var forumShareService = require('../../service/forumShareService');
//var config = require('../../../config/config');
var then = require('thenjs');
module.exports = function(app) {
app.use('/v1/forum', router);
};
//type:类型(板块,照片墙等); key:类型里面的标题(title,desc等);value:值
function getForumConfig(key, value, ent_code) {
var forumConfig = {};
forumConfig.meta_key = key;
forumConfig.meta_value = value;
forumConfig.ent_code = ent_code;
return forumConfig;
}
//批量创建默认分享设置
router.post('/forumConfig/put', function(req, res, next) {
var model = req.body;
var ent_code = req.session.user.ent_code;
model.ent_code = ent_code;
if (model.ent_code) {
forumShareConfigService.create(model, function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json(_.assign(result, returnCode.SUCCESS));
}
});
} else {
res.json(returnCode.BUSY);
}
});
//初始化默认分享数据
router.get('/forumConfig/getConfig', function(req, res, next) {
var ent_code = req.session.user.ent_code;
forumShareConfigService.getByKey(ent_code, req.query.meta_key, function(err, result) {
if (err) {
console.error(err);
res.json(returnCode.BUSY);
} else {
res.json({message:'success',data:result});
}
});
});
...@@ -8,40 +8,41 @@ var then = require('thenjs'); ...@@ -8,40 +8,41 @@ var then = require('thenjs');
exports.create = function(entity, callback) { exports.create = function(entity, callback) {
var forumShareConfig = new ForumShareConfig(entity); var forumShareConfig = new ForumShareConfig(entity);
ForumShareConfig.findOne({ then(function(cont) {
meta_key: entity.meta_key ForumShareConfig.find({
}, function(err, result) { ent_code: entity.ent_code,
var meta_value = result.meta_value;
for (var i = 0; i < meta_value.length; i += 1) {
for (var j = 0; j < entity.meta_value.length; j += 1) {
if (meta_value[i].type === entity.meta_value[j].type) {
}
}
}
if (result) {
forumShareConfig.update({
meta_key: entity.meta_key meta_key: entity.meta_key
}, entity, null, function(err, result) { }).exec(cont);
console.log(result); }).then(function(cont, config) {
if (err) { if (config.length > 0) {
console.error(err); //更新
callback(err, null); ForumShareConfig.update({
} else { meta_key: entity.meta_key,
callback(null, result); ent_code: entity.ent_code
} }, {
meta_value: entity.meta_value
}, {
multi: false
},
function(affected,result) {
cont(null,result);
}); });
} else { } else {
//增加
forumShareConfig.save(function(err, result) { forumShareConfig.save(function(err, result) {
if (err) { if (err) {
console.error(err); cont(err);
callback(err, null);
} else { } else {
callback(null, result); cont(null,result);
} }
}) });
} }
}) }).then(function(cont,result) {
callback(null, result);
}).fail(function(cont, err) {
console.error(err);
callback(err, 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