Authored by lijing

Merge branch 'master' into feature/grow

... ... @@ -40,6 +40,8 @@ app.locals.startTime = moment().format('YYYYMMDDHH');
// 全局注册library
yohoLib.global(config);
const logger = global.yoho.logger;
// zookeeper
if (config.zookeeperServer) {
require('yoho-zookeeper')(config.zookeeperServer, 'wap', app.locals.wap = {}, global.yoho.cache);
... ... @@ -52,6 +54,23 @@ app.set('etag', false);
app.enable('trust proxy');
const safeStringify = require('fast-safe-stringify');
// 循环对象检测
app.set('json replacer', function(key, value) {
if (!key) {
let safeStr = safeStringify(value) || '{}';
if (/\[Circular\]/.test(safeStr)) {
logger.error('stringify error:', value);
}
return JSON.parse(safeStr);
}
return value;
});
// 请求限制中间件
if (!app.locals.devEnv) {
app.use(require('./doraemon/middleware/limiter'));
... ... @@ -60,8 +79,6 @@ if (!app.locals.devEnv) {
// 指定libray目录
global.utils = path.resolve('./utils');
const logger = global.yoho.logger;
// 访问域名层级
app.set('subdomain offset', 3);
... ...
... ... @@ -349,7 +349,7 @@ exports.receiveCoupon = (receiveData, uid) => {
break;
default:
returnData = {
msg: '领券失败!',
msg: result.message || '领券失败!',
status: false
};
break;
... ...
... ... @@ -14,7 +14,7 @@
{{#content.floors}}
{{#isEqualOr type 'sidebar'}}
{{! 侧悬浮}}
<div id="sidebar" pageid="{{param.sidebarPageId}}"></div>
<div id="sidebar" pageid="{{param.sidebarPageId}}"></div>
{{/isEqualOr}}
{{#isEqualOr type '' 'common_floor' 'fix'}}
{{! 普通楼层 顶悬浮}}
... ... @@ -84,12 +84,12 @@
{{/repeat}}
</div>
{{/isEqualOr}}
{{#isEqualOr type 'productGroup'}}
{{! 商品池}}
<div class="product-container item{{numOfOneRow}}" {{#if proBgImg}}style="background:url({{image2 proBgImg q=60}})repeat;"{{/if}}>
<div class="product-container item{{numOfOneRow}}" {{#if proBgImg}}style="background:url({{image2 proBgImg q=60}}) repeat;background-size:100%;"{{/if}}>
<div class="product-source" condition='{{stringify searchCondition}}' fp="{{getAnalysis ../this @index}}"
{{#unless defaultPros.length}}
{{#unless defaultPros.length}}
{{#if searchCondition.item}}
cloneitem="{{searchCondition.item}}"
{{else}}
... ... @@ -130,7 +130,7 @@
<img class="brand-img lazy" data-original="{{image2 ../brandImg q=60}}">
</a>
{{/if}}
</div>
</div>
{{/defaultPros}}
{{else}}
<div class="feature-product-info novisible">
... ... @@ -158,7 +158,7 @@
{{#if brandImg}}
<a class="second-part {{#isEqualOr showBrandUrl '1'}}product-brand{{else}}product-detail{{/isEqualOr}}" href=''>
<div class="brand-div">
<span class="brand-name" {{#if fontColor}}style="color:{{fontColor}};"{{/if}}></span>
<span class="brand-name" {{#if fontColor}}style="color:{{fontColor}};"{{/if}}></span>
</div>
<img class="brand-img" src="{{image2 brandImg q=60}}">
</a>
... ... @@ -171,6 +171,6 @@
{{/component}}
</div>
{{/isEqualOr}}
{{/content.floors}}
{{/content.floors}}
{{/unless}}
</div>
\ No newline at end of file
</div>
... ...
... ... @@ -103,7 +103,7 @@ const getResources = (params, options) => {
let list = {};
let productSkns = [];
if (result.code !== 200) {
if (result && result.code !== 200) {
return data;
}
... ...
... ... @@ -319,7 +319,7 @@ const getRepayRecord = (req, res, next) => {
recordData: result
});
} else {
res.json();
res.send('');
}
}).catch((err) => {
_serverCrash(res, {
... ...
... ... @@ -233,7 +233,7 @@ const order = (params) => {
code: 200
}).then(result => {
if (result.data) {
if (result && result.data) {
Object.assign(finalResult, {cancelReason: result.data});
}
... ...
... ... @@ -74,8 +74,7 @@ exports.validate = (req, res, next) => {
captchaShow: true
};
logger.info(`captcha validate result${
captchaInput.toString() === captchaCode},user:${captchaInput};server:${captchaCode}`);
logger.info(`captcha validate result${(captchaInput && captchaInput.toString()) === captchaCode},user:${captchaInput};server:${captchaCode}`); // eslint-disable-line
_.set(req.session, 'captchaValidCount', errorCount - 1);
... ...
... ... @@ -33,6 +33,11 @@ const _getUserProfile = (uid) => {
uid: uid
}, {
cache: true
}).catch(function() {
return {
code: 200,
data: {}
};
});
};
... ...
... ... @@ -224,6 +224,11 @@ const _getUserProfile = (uid, params) => {
uid: uid
}, {
cache: true
}).catch(function() {
return {
code: 200,
data: {}
};
});
};
... ...
... ... @@ -88,7 +88,7 @@
<div class="margin-bottom"></div>
{{/if}}
{{/isEqual}}
{{#isEqual module_type 'RecommentProduct'}}
{{#isEqual module_type 'AppRecommendProduct'}}
<div class="index-goods-container" data-type="{{../type}}" data-skns="{{../skns}}" data-order="{{../order}}"></div>
{{#if ../isModuleMargin}}
<div class="margin-bottom"></div>
... ...
... ... @@ -18,7 +18,7 @@ exports.page = (req, res, next) => {
userApi.profile(req.user.uid)
.then(userinfo => {
userinfo = userinfo.data;
userinfo = userinfo.data || {};
res.render('chat/index', {
module: 'service',
... ... @@ -30,7 +30,7 @@ exports.page = (req, res, next) => {
imSocket: global.yoho.config.domains.imSocket,
userData: {
encrypteduid: crypto.encryption(null, uid + ''),
avatar: helpers.image(userinfo.head_ico, 100, 100),
avatar: userinfo.head_ico ? helpers.image(userinfo.head_ico, 100, 100) : '',
uname: userinfo.profile_name
}
});
... ...
... ... @@ -56,12 +56,12 @@ const qaDetail = (params) => {
// 根据子id,父id,关键字,匹配问题详情
if (params.keyword) {
// 从搜索列表进入,有关键字
// 从搜索列表进入,有关键字
if (result && result[1] && result[1].data) {
let keyList = result[1].data.helper_list;
_.forEach(keyList, function(val) {
if (val.id === params.sonId) {
if (parseInt(val.id, 10) === parseInt(params.sonId, 10)) {
resu = {
caption: val.caption,
content: val.content
... ... @@ -70,11 +70,11 @@ const qaDetail = (params) => {
});
}
} else {
// 常见问题没有parentId
// 常见问题没有parentId
if (result && result[0] && result[0].data) {
if (!params.parentId) {
_.forEach(result[0].data.faqs, function(val) {
if (val.id === params.sonId) {
if (parseInt(val.id, 10) === parseInt(params.sonId, 10)) {
resu = {
caption: val.caption,
content: val.content
... ... @@ -83,10 +83,10 @@ const qaDetail = (params) => {
});
} else {
_.forEach(result[0].data.categorys, function(val) {
if (val.id === params.parentId) {
if (parseInt(val.id, 10) === parseInt(params.parentId, 10)) {
_.forEach(val.contentItems, function(item) {
if (item.id === params.sonId) {
if (parseInt(item.id, 10) === parseInt(params.sonId, 10)) {
resu = {
caption: item.caption,
content: item.content
... ...
... ... @@ -48,7 +48,9 @@ module.exports = () => {
yoho.channel = channel;
// 判断请求是否来自app
yoho.isApp = req.query.app_version || req.query.appVersion || req.cookies.app_version;
yoho.isApp = (req.query.app_version && req.query.app_version !== 'false') ||
(req.query.appVersion && req.query.appVersion !== 'false') ||
req.cookies.app_version;
yoho.isWechat = /micromessenger/i.test(req.get('User-Agent') || '');
yoho.isWeibo = ua.indexOf('weibo') !== -1;
yoho.isqq = /MQQBrowser/i.test(req.get('User-Agent') || '');
... ...
... ... @@ -6,33 +6,36 @@ const authcode = require('../../utils/authcode');
module.exports = () => {
return (req, res, next) => {
// 从 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session.LOGIN_UID)) {
// 调用接口传参时切勿使用toString获得字符串
req.user.uid = {
toString: () => {
return req.session.LOGIN_UID;
},
sessionKey: req.session.SESSION_KEY
};
let userData = _.get(req.session, 'USER', {});
_.merge(req.user, userData);
}
if (!req.yoho.isApp) {
// 从 SESSION 中获取到当前登录用户的 UID
if (req.session && _.isNumber(req.session.LOGIN_UID)) {
// 调用接口传参时切勿使用toString获得字符串
req.user.uid = {
toString: () => {
return _.parseInt(req.session.LOGIN_UID);
},
sessionKey: req.session.SESSION_KEY
};
let userData = _.get(req.session, 'USER', {});
// session 没有读取到的时候,从 cookie 读取 UID
if (!req.user.uid && req.cookies._UID) {
let sessionKey = req.cookies._SESSION_KEY && authcode(req.cookies._SESSION_KEY, '_SESSION_KEY', 2592000000);
_.merge(req.user, userData);
}
// 调用接口传参时切勿使用toString获得字符串
req.user.uid = {
toString: () => {
return cookie.getUid(req);
},
sessionKey
};
}
// session 没有读取到的时候,从 cookie 读取 UID
if (!req.user.uid && req.cookies._UID) {
let sessionKey = req.cookies._SESSION_KEY &&
authcode(req.cookies._SESSION_KEY, '_SESSION_KEY', 2592000000);
// 调用接口传参时切勿使用toString获得字符串
req.user.uid = {
toString: () => {
return _.parseInt(cookie.getUid(req));
},
sessionKey
};
}
}
if (!req.user.uid &&
req.cookies.app_uid &&
req.cookies.app_uid !== '0' &&
... ...
... ... @@ -32,6 +32,7 @@
"connect-multiparty": "^2.0.0",
"cookie-parser": "^1.4.3",
"express": "^4.14.1",
"fast-safe-stringify": "^1.1.13",
"feed": "^1.0.2",
"geetest": "^4.1.1",
"lodash": "^4.17.4",
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-03-23 11:31:51
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-25 11:45:13
* @Last Modified time: 2017-05-02 11:17:31
*/
/** *****************
... ... @@ -95,7 +95,7 @@ $.each($goodsContainer, function(index, elem) {
let $result = $(result);
lazyLoad($result.find('img[class=lazy]'));
$(elem).html(result);
$(elem).html($result);
}
});
});
... ...
... ... @@ -263,7 +263,7 @@ exports.processFilter = (list, options) => {
title: '折扣',
dataId: 'key',
subsName: 'name',
firstSub: '0.1,0.9',
firstSub: '0,1',
dataType: 'p_d',
sortNum: '7'
},
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2017-03-23 11:02:31
* @Last Modified by: Targaryen
* @Last Modified time: 2017-04-26 16:33:07
* @Last Modified time: 2017-05-02 11:09:37
*/
/* 红人店铺数据处理 */
... ... @@ -174,14 +174,14 @@ const _tools = {
},
/**
* 商品列表
* 推荐商品列表
* @param {*} moduleData
*/
recommentProduct(moduleData) {
appRecommendProduct(moduleData) {
let displayType = _.parseInt(_.get(moduleData, 'properties.displayType', 0));
let result = {
module_type: 'RecommentProduct',
module_type: 'AppRecommendProduct',
type: displayType
};
... ... @@ -206,10 +206,7 @@ const _tools = {
break;
}
return {
module_type: 'RecommentProduct',
skns: skns,
};
return result;
}
};
... ... @@ -256,8 +253,8 @@ const floor = (decoratorsData) => {
case 'SknList':
skns = _.get(value, 'module_data.data').join(',');
break;
case 'RecommentProduct':
decorators.push(_tools.recommentProduct(value.module_data));
case 'AppRecommendProduct':
decorators.push(_tools.appRecommendProduct(value.module_data));
break;
default:
break;
... ...