...
|
...
|
@@ -8,11 +8,13 @@ |
|
|
const _ = require('lodash');
|
|
|
|
|
|
const ServiceAPI = require(`${global.library}/api`).ServiceAPI;
|
|
|
const SearchAPI = require(`${global.library}/api`).SearchAPI;
|
|
|
const sign = require(`${global.library}/sign`);
|
|
|
const helpers = require(`${global.library}/helpers`);
|
|
|
|
|
|
|
|
|
const serviceApi = new ServiceAPI();
|
|
|
const searchApi = new SearchAPI();
|
|
|
|
|
|
const headerModel = require('../../../doraemon/models/header');
|
|
|
|
...
|
...
|
@@ -40,6 +42,106 @@ const channelMap = { |
|
|
}
|
|
|
};
|
|
|
|
|
|
// 构建url
|
|
|
const httpBuildQuery = data => {
|
|
|
return searchApi.get('/search.json', data);
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 格式化商品信息
|
|
|
*
|
|
|
* @param array $productData 需要格式化的商品数据
|
|
|
* @param bool $showTags 控制是否显示标签
|
|
|
* @param bool $showNew 控制是否显示NEW图标
|
|
|
* @param bool $showSale 控制是否显示SALE图标
|
|
|
* @param int $width 图片的宽度
|
|
|
* @param int $height 图片的高度
|
|
|
* @param bool $isApp 判断是不是APP访问
|
|
|
* @param bool $showPoint 商品价格是否显示小数位,默认显示
|
|
|
* @return array | false
|
|
|
*/
|
|
|
const formatProduct = (productData, showTags, showNew, showSale, width, height, isApp, showPoint) => {
|
|
|
let result = {};
|
|
|
|
|
|
// 默认值
|
|
|
if (!showTags) {
|
|
|
showTags = true;
|
|
|
}
|
|
|
if (!showNew) {
|
|
|
showNew = true;
|
|
|
}
|
|
|
if (!showSale) {
|
|
|
showSale = true;
|
|
|
}
|
|
|
if (!width) {
|
|
|
width = 290;
|
|
|
}
|
|
|
if (!height) {
|
|
|
height = 388;
|
|
|
}
|
|
|
if (!isApp) {
|
|
|
isApp = false;
|
|
|
}
|
|
|
if (!showPoint) {
|
|
|
showPoint = true;
|
|
|
}
|
|
|
|
|
|
// 商品信息有问题,则不显示
|
|
|
if (!productData.product_skn || !productData.goods_list[0]) {
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
// 市场价和售价一样,则不显示市场价
|
|
|
if (parseInt(productData.market_price, 0) === parseInt(productData.sales_price, 0)) {
|
|
|
productData.market_price = false;
|
|
|
}
|
|
|
|
|
|
result.id = productData.product_skn;
|
|
|
result.product_id = productData.product_id;
|
|
|
result.thumb = 'http://img10.static.yhbimg.com/goodsimg/2016/05/23/06/0145382aaf7f6b2bcb9f73bcc26fc14228.jpg?imageView/2/w/280/h/373';
|
|
|
result.name = productData.product_name;
|
|
|
result.price = !productData.market_price ? false : productData.market_price;
|
|
|
result.salePrice = productData.sales_price;
|
|
|
if (showPoint) {
|
|
|
result.price += '.00';
|
|
|
result.salePrice += '.00';
|
|
|
}
|
|
|
|
|
|
result.is_soon_sold_out = (productData.is_soon_sold_out === 'Y');
|
|
|
result.url = 'http://item.yohobuy.com/product/pro_' +
|
|
|
productData.product_id + '_' +
|
|
|
productData.goods_list[0].goods_id + '/' +
|
|
|
productData.cn_alphabet + '.html';
|
|
|
|
|
|
// APP访问需要加附加的参数
|
|
|
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
|
|
|
if (isApp) {
|
|
|
result.url += '?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' +
|
|
|
productData.product_skn + '}}';
|
|
|
}
|
|
|
|
|
|
if (showTags) {
|
|
|
result.tags = {};
|
|
|
result.tags.is_new = showNew && productData.is_new && productData.is_new === 'Y'; // 新品
|
|
|
result.tags.is_discount = showSale && productData.is_discount && productData.is_discount === 'Y'; // 在售
|
|
|
result.tags.is_limited = productData.is_limited && productData.is_limited === 'Y'; // 限量
|
|
|
result.tags.is_yohood = productData.is_yohood && productData.is_yohood === 'Y'; // YOHOOD
|
|
|
result.tags.midYear = productData['mid-year'] && productData['mid-year'] === 'Y'; // 年中
|
|
|
result.tags.yearEnd = productData['year-end'] && productData['year-end'] === 'Y'; // 年末
|
|
|
result.tags.is_advance = productData.is_advance && productData.is_advance === 'Y'; // 再到着
|
|
|
|
|
|
if (result.is_soon_sold_out && result.tags.is_discount) {
|
|
|
result.tags.is_new = false;// 打折与即将售完组合显示打折
|
|
|
} else if (result.tags.is_discount &&
|
|
|
(result.tags.is_new || result.tags.is_limited || result.tags.is_yohood || result.tags.is_advance)) {
|
|
|
result.tags.is_discount = false;// 打折与其它组合则隐藏打折
|
|
|
} else if (result.tags.is_yohood && result.tags.is_new) {
|
|
|
result.tags.is_new = false;// YOHOOD和新品组合显示YOHOOD
|
|
|
}
|
|
|
}
|
|
|
return result;
|
|
|
};
|
|
|
|
|
|
const getBannerList = data => {
|
|
|
let list = [];
|
|
|
|
...
|
...
|
@@ -287,7 +389,103 @@ const getSingleHotFloorData = args => { |
|
|
return floorDatas;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 组装最新上架楼层数据
|
|
|
*
|
|
|
* @param string data
|
|
|
* return obj
|
|
|
*/
|
|
|
const getNewGoodsFloorData = args => {
|
|
|
const data = {
|
|
|
newArrivls: {
|
|
|
name: '最新上架',
|
|
|
navs: {
|
|
|
name: '',
|
|
|
href: ''
|
|
|
}
|
|
|
}
|
|
|
};
|
|
|
|
|
|
data.newArrivls.navs.name = args[0].data[0].name;
|
|
|
data.newArrivls.navs.href = args[0].data[0].url;
|
|
|
|
|
|
return data;
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* 获取最新上架商品数据
|
|
|
*
|
|
|
* @param string $channel
|
|
|
* @return array
|
|
|
*/
|
|
|
exports.getNewArrival = channel => {
|
|
|
const sortList = [
|
|
|
{sort: 147, viewNum: 5}, // 休闲运动鞋
|
|
|
{sort: 129, viewNum: 5}, // 休闲裤
|
|
|
{sort: 152, viewNum: 5}, // 双肩包
|
|
|
{misort: 11, viewNum: 5}, // T恤
|
|
|
{sort: 115, viewNum: 5}, // 衬衫
|
|
|
{sort: 130, viewNum: 5}, // 牛仔裤
|
|
|
{misort: 60, viewNum: 5}, // 帽子
|
|
|
{sort: 124, viewNum: 5}, // 夹克
|
|
|
{sort: 119, viewNum: 5}, // 卫衣
|
|
|
{sort: 162, viewNum: 5}, // 手表
|
|
|
{sort: 148, viewNum: 5}, // 靴子
|
|
|
{misort: 65, viewNum: 5}, // 首饰
|
|
|
{sort: 151, viewNum: 5}, // 时装鞋
|
|
|
{misort: 61, viewNum: 5}, // 太阳镜
|
|
|
{misort: 39, viewNum: 5}, // 袜子
|
|
|
{sort: 346, viewNum: 5}, // 运动裤
|
|
|
{sort: 131, viewNum: 5}, // 短裤
|
|
|
{misort: 66, viewNum: 5}, // 配饰
|
|
|
{misort: 309, viewNum: 5}, // 内裤
|
|
|
{misort: 30, viewNum: 5}, // 打底裤/紧身裤
|
|
|
{sort: 342, viewNum: 5} // 邮差包
|
|
|
];
|
|
|
|
|
|
// 一级缓存
|
|
|
let rel = [];
|
|
|
|
|
|
// 接口
|
|
|
let params = {
|
|
|
// 'shelve_time' : new Date().getTime()+','+d.getTime(),
|
|
|
order: 'shelve_time:desc',
|
|
|
status: 1,
|
|
|
sales: 'Y',
|
|
|
attribute_not: 2,
|
|
|
stocknumber: 3
|
|
|
};
|
|
|
|
|
|
// 最新上架参数(男首频道:gender=1,3 女首频道gender=2,4)
|
|
|
if (channel === 'boys') {
|
|
|
params.gender = '1,3';
|
|
|
} else {
|
|
|
params.gender = '2,4';
|
|
|
}
|
|
|
|
|
|
_.forEach(sortList, (item) => {
|
|
|
let data = Object.assign(item, params);
|
|
|
|
|
|
rel.push(httpBuildQuery(data));
|
|
|
});
|
|
|
|
|
|
return Promise.all(rel).then(res => {
|
|
|
let data = [],
|
|
|
result = [];
|
|
|
|
|
|
_.forEach(sortList, (it, index) => {
|
|
|
if (res[index].data.product_list.length === sortList[index].viewNum) {
|
|
|
data = data.concat(res[index].data.product_list);
|
|
|
}
|
|
|
});
|
|
|
|
|
|
_.forEach(data, (item) => {
|
|
|
result.push(formatProduct(item, true, true, true, 280, 373));
|
|
|
});
|
|
|
|
|
|
return result;
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const requestContent = type => {
|
|
|
|
...
|
...
|
@@ -310,6 +508,7 @@ const floorMap = { |
|
|
最新速报: getNewReportFloorData,
|
|
|
人气单品: getSingleHotFloorData,
|
|
|
优选品牌: getPreBrandTopData,
|
|
|
最新上架: getNewGoodsFloorData,
|
|
|
ad: getadbannerData
|
|
|
};
|
|
|
|
...
|
...
|
|