Authored by 郝肖肖

客服开关走 zookeeper配置

... ... @@ -99,7 +99,6 @@ try {
const errorHanlder = require('./doraemon/middleware/error-handler');
const setPageInfo = require('./doraemon/middleware/set-pageinfo');
const pageCache = require('./doraemon/middleware/page-cache');
const secretSwitch = require('./doraemon/middleware/secret-switch');
// YOHO 前置中间件
app.use(subDomain());
... ... @@ -110,7 +109,6 @@ try {
app.use(user());
app.use(seo());
app.use(setPageInfo());
app.use(secretSwitch());
app.use(pageCache());
require('./dispatch')(app);
... ...
/**
* 设置cache controller
* @author: xiaoxiao<xiaoxiao.hao@yoho.cn>
* @date: 2016/12/21
*/
'use strict';
const cache = global.yoho.cache;
const index = (req, res, next) => {
const param = req.query['com.yohobuy.customerservice.enabled'];
let status = param === 'true';
cache.set('customerServiceSwitch', status, 0).then(result => {
res.json(result);
}).catch(next);
};
module.exports = {
index
};
... ... @@ -10,12 +10,9 @@ const router = require('express').Router(); // eslint-disable-line
const cRoot = './controllers';
const ads = require(`${cRoot}/ads`); // 第三方广告平台对接
const secretSwitch = require(`${cRoot}/secret-switch`);
// Your controller here
router.get('/ads', ads.jump);
router.get('/secret-switch', secretSwitch.index); // 设置cache
module.exports = router;
... ...
... ... @@ -34,7 +34,7 @@ const bindController = require(`${cRoot}/3party-bind`);
// const AddressController = require(`${cRoot}/address`);
// const GiftController = require(`${cRoot}/gift`);
const homeNav = (req, res) => {
const homeNav = (req) => {
return [
{
title: '交易管理',
... ... @@ -56,12 +56,12 @@ const homeNav = (req, res) => {
/* {name: '我的投诉', href: '/home/complaints'}, */
{name: '我的信息', href: '/home/message', count: 0},
{
name: '在线客服',
href: res.locals.customerServiceSwitch ?
{
name: '在线客服',
href: _.get(req.app.locals.pc, 'clientService.new', false) ?
'/service/client' : 'http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&amp;configID=149091&amp;jid=8732423409',
isBlank: true
}
isBlank: true
}
]
},
{
... ... @@ -74,11 +74,11 @@ const homeNav = (req, res) => {
]
}
];
}
};
const getActiveNav = (req, res)=>{
const getActiveNav = (req)=>{
let mHomeNav = _.cloneDeep(homeNav(req, res));
let mHomeNav = _.cloneDeep(homeNav(req));
return mHomeNav.map((item) => {
item.subNav = item.subNav.map((nav) => {
... ... @@ -108,7 +108,7 @@ const getActiveNav = (req, res)=>{
const getHomeNav = (req, res, next) => {
res.locals.path = [{href: helpers.urlFormat('/'), name: 'YOHO!BUY 有货首页'}, {name: '个人中心'}];
res.locals.homeNav = getActiveNav(req, res);
res.locals.homeNav = getActiveNav(req);
res.locals.userThumb = '//img10.static.yhbimg.com/headimg/' +
'2013/11/28/09/01cae078abe5fe320c88cdf4c220212688.gif?imageView/2/w/100/h/100';
next();
... ...
const logger = global.yoho.logger;
const secretSwitch = () => {
return (req, res, next) => {
// 获取客服开关,读cache
global.yoho.cache.get('customerServiceSwitch').then(result => {
Object.assign(res.locals, {
customerServiceSwitch: result || false
});
next();
}).catch((err) => {
logger.error(err);
next();
});
};
};
module.exports = secretSwitch;
... ... @@ -189,7 +189,7 @@
</div>
<div class="left">
<span class="iconfont rgbf">&#xe602;</span>
<a href="{{#if customerServiceSwitch}}/service/client{{else}}http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&amp;configID=149091&amp;jid=8732423409{{/if}}" target="_blank">
<a href="{{#if @root.pc.clientService.new}}/service/client{{else}}http://chat8.live800.com/live800/chatClient/chatbox.jsp?companyID=620092&amp;configID=149091&amp;jid=8732423409{{/if}}" target="_blank">
<span class="red">便捷</span>
<span class="rgbf">在线客服</span>
</a>
... ...