Authored by 郭成尧

goods-detail-done

... ... @@ -3,30 +3,10 @@ const model = require('../models/feature');
const _ = require('lodash');
const stringProcess = require('../../../utils/string-process');
const _getPname = (req) => {
let userAgent = req.get('User-Agent');
let isiOS = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(userAgent);
let isAndroid = /Android/i.test(userAgent);
let pName = '';
if (isiOS) {
pName = 'iFP_SalesPromotion';
}
if (isAndroid) {
pName = 'aFP_SalesPromotion';
}
return pName;
};
exports.index = function(req, res, next) {
req.ctx(model).index({
code: req.params.code,
type: stringProcess.paramsFilter(req.query.type),
from_page_name: _getPname(req),
from_page_param: req.url
type: stringProcess.paramsFilter(req.query.type)
}).then((result) => {
if (!result) {
return next();
... ...
... ... @@ -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; // 个性化券楼层先不展示,前端异步查询到的时候,再展示
}
... ...
const getPname = (req) => {
let userAgent = req.get('User-Agent');
let isiOS = /\(i[^;]+;( U;)? CPU.+Mac OS X/i.test(userAgent);
let isAndroid = /Android/i.test(userAgent);
let pName = '';
if (isiOS) {
pName = 'iFP_SalesPromotion';
}
if (isAndroid) {
pName = 'aFP_SalesPromotion';
}
return pName;
};
module.exports = {
getPname
};
... ...