Authored by 郭成尧

商品处理采用公共方法

... ... @@ -15,7 +15,7 @@ const mRoot = '../models';
const sale = require(`${mRoot}/sale`);
// 开发用模拟数据
const simulation = require(`${mRoot}/simulation`);
// const simulation = require(`${mRoot}/simulation`);
/**
* sale 首页
... ... @@ -114,14 +114,14 @@ exports.vip = (req, res) => {
responseData.devEnv = true;
// 假数据输出
res.render('sale/other', Object.assign(responseData, simulation.other()));
// res.render('sale/other', Object.assign(responseData, simulation.other()));
// sale.getSaleOthersData(params).then((result) => {
// responseData.saleList = result;
// responseData.resultShow = JSON.stringify(result, null, 4);
//
// res.render('sale/other', responseData);
// });
sale.getSaleOthersData(params).then((result) => {
responseData.saleList = result;
responseData.resultShow = JSON.stringify(result, null, 4);
res.render('sale/other', responseData);
});
// }).catch(() => {
// res.render('error', { devEnv: true, pageErr: true });
... ...
... ... @@ -2,15 +2,17 @@
* @Author: Targaryen
* @Date: 2016-05-19 10:20:08
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-26 16:07:54
* @Last Modified time: 2016-05-27 18:17:05
*/
'use strict';
const library = '../../../library';
const utils = '../../../utils';
const API = require(`${library}/api`).API;
const api = new API();
const saleApi = require('./sale-api');
const saleHandler = require('./sale-handler');
const productProcess = require(`${utils}/product-process`);
/**
* 获取Sale首页商品列表数据 仅 Ajax 调用 Controller 调用
... ... @@ -22,7 +24,7 @@ exports.getSaleGoodsData = (params) => {
let finalResult = {};
if (result.code === 200) {
finalResult.goods = saleHandler.handleSaleGoodsListData(result.data.product_list);
finalResult.goods = productProcess.processProductList(result.data.product_list);
}
return finalResult;
});
... ... @@ -60,7 +62,7 @@ exports.getSaleOthersData = (params) => {
let finalResult = {};
if (result[0].code === 200) {
finalResult.goods = saleHandler.handleSaleGoodsListData(result[0].data.product_list);
finalResult.goods = productProcess.processProductList(result[0].data.product_list);
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
... ... @@ -101,7 +103,7 @@ exports.getSalebreakingYardsData = (params) => {
let finalResult = {};
if (result[0].code === 200) {
finalResult.goods = saleHandler.handleSaleGoodsListData(result[0].data.product_list);
finalResult.goods = productProcess.processProductList(result[0].data.product_list);
finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
finalResult.leftContent = saleHandler.handleSaleSortData(result[0].data.filter.group_sort, params);
}
... ...
... ... @@ -30,14 +30,14 @@ exports.image = (url, width, height, mode) => {
* @param {[string]} module 模块
* @return {[string]}
*/
exports.url = (uri, qs, module) => {
exports.urlFormat = (uri, qs, module) => {
const subDomain = '.m.yohobuy.com';
const subName = {
default: config.siteUrl,
guang: '//guang' + subDomain,
list: '//list' + subDomain,
search: '//search' + subDomain,
huodong: '//huodong' + subDomain,
guang: `//guang${subDomain}`,
list: `//list${subDomain}`,
search: `//search${subDomain}`,
huodong: `//huodong${subDomain}`,
activity: '//activity.yohobuy.com',
index: config.siteUrl
};
... ... @@ -47,12 +47,12 @@ exports.url = (uri, qs, module) => {
if (subName[module]) {
url = subName[module];
} else {
url = '//' + module + subDomain; // 规则没匹配到就把模块当作子域名
url = `//${module}${subDomain}`; // 规则没匹配到就把模块当作子域名
}
url += uri;
if (qs) {
url += '?' + querystring.stringify(qs);
url += `?${querystring.stringify(qs)}`;
}
return url;
... ...
'use strict';
const _ = require('lodash');
const camelCase = require('../library/camel-case');
const helpers = require('../library/helpers');
/**
* 根据性别来决定 默认图片获取字段 如果是 2、3
*
* 则优先从cover2 --》 cover1 -- 》 images_url
* 否则优先从cover1 --》 cover2 -- 》 images_url
*
*/
const procProductImg = (product, gender) => {
if (gender === '2,3') {
return product.cover2 || product.cover1 || product.imagesUrl || '';
}
return product.cover1 || product.cover2 || product.imagesUrl || '';
};
/**
* 商品搜索商品数据处理
*/
exports.processProductList = (list, options) => {
const pruductList = [];
options = Object.assign({
showTags: true,
showNew: true,
showSale: true,
width: 290,
height: 388,
isApp: false,
showPoint: true,
gender: '2,3'
}, options);
list = camelCase(list);
_.forEach(list, (product) => {
// 商品信息有问题,则不显示
if (!product.productId || !product.goodsList.length) {
return;
}
// 市场价和售价一样,则不显示市场价
if (product.marketPrice === product.salesPrice) {
product.marketPrice = false;
}
// 判别默认的商品是否将默认的图片URL赋值到skn
let flag = false;
// 如果设置了默认图片,就取默认的图片
_.forEach(product.goodsList, (goods) => {
if (flag) {
return;
}
if (goods.isDefault === 'Y') {
product.defaultImages = procProductImg(goods);
flag = true;
}
});
// 如果还未赋值,则取第一个skc产品的默认图片
if (!flag) {
product.defaultImages = procProductImg(product.goodsList[0]);
}
product = Object.assign(product, {
id: product.productSkn,
thumb: product.defaultImages
});
if (options.showPoint) {
product.marketPrice += '.00';
product.salesPrice += '.00';
if (product.vip1Price) {
product.vip1Price = parseInt(product.vip1Price, 10) + '.00';
}
if (product.vip2Price) {
product.vip2Price = parseInt(product.vip2Price, 10) + '.00';
}
if (product.vip3Price) {
product.vip3Price = parseInt(product.vip3Price, 10) + '.00';
}
}
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
product.url = helpers.urlFormat(`/product/pro_${product.productId}_${product.goodsList[0].goodsId}/${product.cnAlphabet}.html`); // eslint-disable-line
// APP访问需要加附加的参数
// 备注:如果以后APP的接口太多,可以把这边参数提取出来,变成一个公共的方法来生成,便于以后管理维护
if (options.isApp) {
product.url += `?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":'${product.productId}'}}`; // eslint-disable-line
}
if (options.showTags) {
product.tags = {};
product.tags.isNew = options.showNew && product.isNew === 'Y'; // 新品
product.tags.isDiscount = options.showSale && product.isDiscount === 'Y'; // 在售
product.tags.isLimited = product.isLimited === 'Y'; // 限量
product.tags.isYohood = product.isYohood === 'Y'; // YOHOOD
product.tags.midYear = product.midYear === 'Y'; // 年中
product.tags.yearEnd = product.yearEnd === 'Y'; // 年末
product.tags.isAdvance = product.isAdvance === 'Y'; // 再到着
// 打折与即将售完组合显示打折
if (product.isSoonSoldOut && product.tags.isDiscount) {
product.tags.isNew = false;
} else if (product.tags.isDiscount &&
(product.tags.isNew || product.tags.isLimited || product.tags.isYohood || product.tags.isAdvance)) {
// 打折与其它组合则隐藏打折
product.tags.isDiscount = false;
} else if (product.tags.isYohood && product.tags.isNew) {
// YOHOOD和新品组合显示YOHOOD
product.tags.isNew = false;
}
}
pruductList.push(product);
});
return pruductList;
};
/**
* 处理筛选数据
* @param list
* @param string | options
* @return array 处理之后的筛选数据
*/
exports.processFilter = (list, options) => {
const filters = {
classify: []
};
const filtersType = {
brand: {
name: '所有品牌',
title: '品牌',
dataId: 'id',
subsName: 'brandName',
firstSub: 0,
dataType: 'brand'
},
color: {
name: '所有颜色',
title: '颜色',
dataId: 'colorId',
subsName: 'colorName',
firstSub: 0,
dataType: 'color'
},
discount: {
name: '所有商品',
title: '折扣',
dataId: 'key',
subsName: 'name',
firstSub: '0.1,0.9',
dataType: 'p_d'
},
gender: {
name: '所有性别',
title: '性别',
dataId: 'key',
subsName: 'flag',
firstSub: '1,2,3',
dataType: 'gender'
},
groupSort: {
name: '所有品类',
title: '品类',
dataId: 'relationParameter',
subsName: 'categoryName',
firstSub: 0,
dataType: 'sort'
},
priceRange: {
name: '所有价格',
title: '价格',
dataId: 'key',
subsName: 'flag',
firstSub: 0,
dataType: 'price'
},
size: {
name: '所有尺码',
title: '尺码',
dataId: 'sizeId',
subsName: 'sizeName',
firstSub: 0,
dataType: 'size'
}
};
options = Object.assign({
gender: '1,2,3', // 默认选择的性别,默认1,2,3表示所有
exclude: null // 需要排除的字段
}, options);
list = camelCase(list);
_.forEach(list, (item, key) => {
let classify = {
subs: []
};
if (key === 'group_sort') {
return;
}
if ((options.hideSize && key === 'size') || (options.hideSort && key === 'groupSort')) {
return;
}
classify.dataType = filtersType[key].dataType;
classify.name = filtersType[key].name;
classify.title = filtersType[key].title;
classify.subs.push({
chosed: true,
dataId: filtersType[key].firstSub,
name: filtersType[key].name
});
_.forEach(item, (sub, index) => {
let subs = {};
if (filtersType[key].dataId === 'key') {
subs.dataId = index;
} else if (filtersType[key].dataId === 'relationParameter') {
subs.dataId = sub.relationParameter['sort']; // eslint-disable-line
} else {
subs.dataId = sub[filtersType[key].dataId];
}
if (filtersType[key].subsName === 'flag') {
subs.name = sub;
} else {
subs.name = sub[filtersType[key].subsName];
if (key === 'discount') {
subs.name = subs.name + '折商品';
}
}
classify.subs.push(subs);
});
filters.classify.push(classify);
});
return filters;
};
... ...
const _ = require('lodash');
const camelCase = require('../library/camel-case');
/**
* 处理楼层数据
* @param {[array]} list
* @return {[array]}
*/
module.exports = (list) => {
const formatData = [];
list = list || [];
list = camelCase(list);
_.forEach(list, (floor) => {
floor[_.camelCase(floor.templateName)] = true;
// 特殊资源位处理
// PLUS
if (floor.singleNameImage && floor.data) {
floor.data.title = {
title: floor.data.title
};
}
// 潮流时装/经典裤裙/时尚靴履/潮人配饰/潮流上装
if (floor.recommendContentOne && floor.data) {
if (floor.data.bigImage && floor.data.bigImage.length > 1) {
floor.data.bigImage = {
bigList: floor.data.bigImage
};
}
}
formatData.push(floor);
});
return formatData;
};
... ...