...
|
...
|
@@ -2,8 +2,10 @@ |
|
|
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, extraParams) {
|
|
|
const _getProductBySkns = function(productObj, ctx) {
|
|
|
return api.get('', {
|
|
|
productSkn: productObj.defaultSkns,
|
|
|
method: 'h5.product.batch'
|
...
|
...
|
@@ -14,7 +16,7 @@ const _getProductBySkns = function(productObj, extraParams) { |
|
|
if (result && result.data && result.data.product_list && result.code === 200) {
|
|
|
result.data.product_list.forEach(function(val) {
|
|
|
var obj = {
|
|
|
producturl: `//m.yohobuy.com/product/${val.product_skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.product_skn}","from_page_name":"${extraParams.from_page_name}","from_page_param":"${extraParams.from_page_param}"}}`, // eslint-disable-line
|
|
|
producturl: `//m.yohobuy.com/product/${val.product_skn}.html?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":"${val.product_skn}","from_page_name":"${yasProcess.getPname(ctx.req)}","from_page_param":"${_.get(ctx,'req.url', '')}"}}`, // eslint-disable-line
|
|
|
productimg: helpers.image(val.default_images, 213, 284, 2, 60).replace('quality/80', 'quality/60'),
|
|
|
productname: val.product_name,
|
|
|
vipprice: val.vip_price,
|
...
|
...
|
@@ -37,6 +39,67 @@ const _getProductBySkns = function(productObj, extraParams) { |
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 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) => {
|
...
|
...
|
@@ -62,6 +125,8 @@ class featureModel extends global.yoho.BaseModel { |
|
|
super(ctx);
|
|
|
}
|
|
|
index(params) {
|
|
|
const self = this;
|
|
|
|
|
|
return Promise.coroutine(function*() {
|
|
|
if (!params.code) {
|
|
|
return Promise.resolve({});
|
...
|
...
|
@@ -89,13 +154,10 @@ class featureModel extends global.yoho.BaseModel { |
|
|
}
|
|
|
data = data.data;
|
|
|
if (data && data.floors) {
|
|
|
data.floors.forEach(function(f) {
|
|
|
data.floors.forEach(f => {
|
|
|
if (f.component && f.component[0] &&
|
|
|
f.component[0].type === 'productGroup' && f.component[0].defaultSkns) {
|
|
|
sknsArr.push(_getProductBySkns(f.component[0], {
|
|
|
from_page_name: params.from_page_name,
|
|
|
from_page_param: params.from_page_param
|
|
|
}));
|
|
|
sknsArr.push(_getProductBySkns(f.component[0], self.ctx));
|
|
|
|
|
|
f.component[0].newStyle = _.get(f, 'component[0].newStyle') === '1';
|
|
|
}
|
...
|
...
|
@@ -119,7 +181,11 @@ class featureModel extends global.yoho.BaseModel { |
|
|
f.height = _.get(f, 'param.height') / 20;
|
|
|
}
|
|
|
|
|
|
_.forEach(f.component, function(component) {
|
|
|
_.forEach(f.component, component => {
|
|
|
if (component.url && component.url.indexOf('go.productDetail') !== -1) {
|
|
|
component.url = _imageGoodsAddParams(component.url, self.ctx);
|
|
|
}
|
|
|
|
|
|
if (component.persenal_enable === '1') {
|
|
|
f.hide = true; // 个性化券楼层先不展示,前端异步查询到的时候,再展示
|
|
|
}
|
...
|
...
|
|