Authored by 郭成尧

yas-process

... ... @@ -2,7 +2,6 @@
const _ = require('lodash');
const api = global.yoho.API;
const helpers = global.yoho.helpers;
const logger = global.yoho.logger;
const yasProcess = require('../../../utils/yas-process');
const _getProductBySkns = function(productObj, ctx) {
... ... @@ -39,67 +38,6 @@ const _getProductBySkns = function(productObj, ctx) {
};
/**
* openbyStr 处理
*/
const _handleOpenbyParams = (openbyStr, ctx) => {
const paramsKeyStr = 'openby:yohobuy=';
let openByStrNew = '';
let openByParamObj = {};
if (_.isString(openbyStr)) {
openByStrNew = _.replace(openbyStr, paramsKeyStr, '');
} else {
return openbyStr;
}
if (_.isString(openByStrNew)) {
try {
openByParamObj = JSON.parse(openByStrNew);
} catch (error) {
logger.info(`openbyStr json parse err, raw string is ${openByStrNew}`);
}
} else {
return openbyStr;
}
if (!_.isEmpty(openByParamObj)) {
_.assign(openByParamObj, {
from_page_name: yasProcess.getPname(ctx.req),
from_page_param: _.get(ctx, 'req.url', '')
});
openByStrNew = `${paramsKeyStr}${JSON.stringify(openByParamObj)}`;
}
return openByStrNew;
};
/**
* 配置的商品添加参数
*/
const _imageGoodsAddParams = (href, ctx) => {
let finalHref = '';
let paramsSplitArr = href.split('?') || [];
let paramsArr = paramsSplitArr[1].split('&');
let paramsArrNew = [];
let paramsStrNew = '';
paramsArrNew = _.map(paramsArr, param => {
if (_.isString(param) && param.indexOf('openby:yohobuy=') !== -1) {
param = _handleOpenbyParams(param, ctx);
}
return param;
});
paramsStrNew = paramsArrNew.join('&');
finalHref = `${paramsSplitArr[0]}?${paramsStrNew}`;
return finalHref;
};
/**
* 获取店铺组店铺数据
*/
const _getShopGroup = (shopRawData) => {
... ... @@ -183,7 +121,12 @@ class featureModel extends global.yoho.BaseModel {
_.forEach(f.component, component => {
if (component.url && component.url.indexOf('go.productDetail') !== -1) {
component.url = _imageGoodsAddParams(component.url, self.ctx);
component.url = yasProcess.addParamsToGoodsHref({
href: component.url,
fromPageName: yasProcess.getPname(_.get(self, 'ctx.req', {})),
fromPageParam: _.get(self, 'ctx.req.path', '')
});
}
if (component.persenal_enable === '1') {
... ...
... ... @@ -11,6 +11,7 @@ const headerModel = require('../../../doraemon/models/header');
const saleModel = require(`${mRoot}/sale`);
const _ = require('lodash');
const listParamsProcess = require(`${utils}/list-params-process`);
const yasProcess = require(`${utils}/yas-process`);
const channelToAppChannel = (channel) => {
return {
... ... @@ -282,6 +283,20 @@ let search = (req, res, next) => {
};
}
if (params.from === 'seckill' && req.yoho.isApp && _.isArray(result[0])) {
_.forEach(result[0], goods => {
goods.url = yasProcess.addParamsToGoodsHref(goods.url, req);
});
}
_.forEach(result[0], goods => {
goods.url = yasProcess.addParamsToGoodsHref({
href: goods.url,
fromPageName: yasProcess.getPname(req),
fromPageParam: req.get('referer')
});
});
res.render('sale/product', Object.assign({
layout: false,
params: params,
... ...
const _ = require('lodash');
const logger = global.yoho.logger;
const getPname = (req) => {
let userAgent = req.get('User-Agent');
let isiOS = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(userAgent);
... ... @@ -16,6 +19,76 @@ const getPname = (req) => {
return pName;
};
/**
* openbyStr 处理
*/
const _handleOpenbyParams = (params) => {
const paramsKeyStr = 'openby:yohobuy=';
let openByStrNew = '';
let openByParamObj = {};
if (_.isString(params.openbyStr)) {
openByStrNew = _.replace(params.openbyStr, paramsKeyStr, '');
} else {
return params.openbyStr;
}
if (_.isString(openByStrNew)) {
try {
openByParamObj = JSON.parse(openByStrNew);
} catch (error) {
logger.info(`openbyStr json parse err, raw string is ${openByStrNew}`);
}
} else {
return params.openbyStr;
}
if (!_.isEmpty(openByParamObj)) {
_.assign(openByParamObj, {
from_page_name: params.fromPageName,
from_page_param: params.fromPageParam
});
openByStrNew = `${paramsKeyStr}${JSON.stringify(openByParamObj)}`;
}
return openByStrNew;
};
/**
* 配置的商品添加参数
*/
const addParamsToGoodsHref = (params) => {
let finalHref = '';
let paramsSplitArr = params.href.split('?') || [];
let paramsArr = _.has(paramsSplitArr, '1') ? paramsSplitArr[1].split('&') : [];
let paramsArrNew = [];
let paramsStrNew = '';
paramsArrNew = _.map(paramsArr, param => {
if (_.isString(param) && param.indexOf('openby:yohobuy=') !== -1) {
param = _handleOpenbyParams({
openbyStr: param,
fromPageName: params.fromPageName,
fromPageParam: params.fromPageParam
});
}
return param;
});
if (paramsArrNew.length) {
paramsStrNew = paramsArrNew.join('&');
finalHref = `${paramsSplitArr[0]}?${paramsStrNew}`;
} else {
finalHref = params.href;
}
return finalHref;
};
module.exports = {
getPname
getPname,
addParamsToGoodsHref
};
... ...