Authored by 郭成尧

为你优选初步

... ... @@ -17,6 +17,12 @@ const intro = require(`${mRoot}/intro`);
// 商品偏好 model
const preference = require(`${mRoot}/preference`);
/**
* 商品基本信息
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.index = (req, res) => {
var uid = null, // 需要修改为正式取 UID 的方式
vipLevel = 0; // 用户等级
... ... @@ -37,6 +43,12 @@ exports.index = (req, res) => {
});
};
/**
* 商品尺码信息详情
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.intro = (req, res) => {
intro({
productskn: req.params.productskn
... ... @@ -48,15 +60,23 @@ exports.intro = (req, res) => {
});
};
/**
* 为你优选 待处理
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.preference = (req, res) => {
preference({
productskn: req.params.productskn,
yhchannel: req.params.yhchannel,
brandId: req.params.brandId
}).then((result) => {
res.render('preference', {
result: result,
devEnv: true
});
res.send(result);
// res.render('preference', {
// result: result,
// devEnv: true
// });
});
};
... ...
... ... @@ -2,7 +2,7 @@
* @Author: Targaryen
* @Date: 2016-05-18 11:42:11
* @Last Modified by: Targaryen
* @Last Modified time: 2016-05-18 13:28:51
* @Last Modified time: 2016-05-18 16:04:09
*/
'use strict';
... ... @@ -10,6 +10,8 @@
const library = '../../../library';
const API = require(`${library}/api`).API;
const sign = require(`${library}/sign`);
const _ = require('lodash');
const helpers = require(`${library}/helpers`);
// const _ = require('lodash');
... ... @@ -23,8 +25,17 @@ var api = new API();
* @return {Object} [description]
*/
const getPreference = (origin) => {
var dest = origin;
var dest = {};
_.forEach(origin, function(value) {
let valueTemp = helpers.formatProduct(value, false, true,
true, false, false);
if (valueTemp !== false) {
dest.recommendList = [];
dest.recommendList.push(valueTemp);
}
});
return dest;
};
... ...
... ... @@ -75,3 +75,156 @@ exports.upperCase = (str) => {
str = str || '';
return str.toUpperCase();
};
/**
* 格式化商品信息 待处理 没有测试过
* @param {array} productData 需要格式化的商品数据
* @param {Boolean} showTags 控制是否显示标签
* @param {Boolean} showNew 控制是否显示NEW图标
* @param {Boolean} showSale 控制是否显示SALE图标
* @param {Boolean} isApp 判断是不是APP访问
* @param {[type]} showPoint 商品价格是否显示小数位,默认显示
* @return {array} [description]
*/
exports.formatProduct = (productData, showTags, showNew, showSale, isApp, showPoint) => {
if (_.isEmpty(productData)) {
return;
}
if (_.isEmpty(showTags)) {
showTags = true;
}
if (_.isEmpty(showNew)) {
showNew = true;
}
if (_.isEmpty(showSale)) {
showSale = true;
}
if (_.isEmpty(isApp)) {
isApp = false;
}
if (_.isEmpty(showPoint)) {
showPoint = true;
}
// 商品信息有问题,则不显示
if (_.isEmpty(productData.product_skn) ||
_.isEmpty(productData.goods_list[0])) {
return false;
}
// 市场价和售价一样,则不显示市场价
if (parseInt(productData.market_price, 10) ===
parseInt(productData.sales_price, 10)) {
productData.market_price = false;
}
// 判别默认的商品是否将默认的图片URL赋值到skn
let flag = false;
// 如果设置了默认图片,就取默认的图片
_.forEach(productData.goods_list, function(oneGoods) {
// 此skc是默认的,则将图片赋值给skn
if (oneGoods.is_default === 'Y') {
// productData.default_images = procProductImg(oneGoods);
flag = true;
return;
}
});
// 如果还未赋值,则取第一个skc产品的默认图片
if (!flag) {
// productData.default_images = procProductImg(productData.goods_list[0]);
}
let result = {};
result.id = productData.product_skn;
result.product_id = productData.product_id;
result.thumb = productData.default_images;
result.name = productData.product_name;
result.price = _.isEmpty(productData.market_price) ? false : productData.market_price;
result.salePrice = productData.sales_price;
if (showPoint) {
result.price = result.price + '.00';
result.salePrice = result.salePrice + '.00';
}
result.is_soon_sold_out = (productData.is_soon_sold_out === 'Y');
// result.url = url('/product/pro_' + productData.product_id +
// '_' + productData.goods_list[0].goods_id +
// '/' + productData.cn_alphabet + '.html');
// APP访问需要加附加的参数
if (isApp) {
result.url = result.url +
'?openby:yohobuy={"action":"go.productDetail","params":{"product_skn":' +
productData.product_skn + '}}';
}
if (showTags) {
result.tags = {};
result.tags.is_new = showNew && !_.isEmpty(productData.is_new) &&
productData.is_new === 'Y'; // 新品
result.tags.is_discount = showSale && !_.isEmpty(productData.is_discount) &&
productData.is_discount === 'Y'; // 限量
result.tags.is_limited = !_.isEmpty(productData.is_limited) &&
productData.is_limited === 'Y'; // YOHOOD
result.tags.is_yohood = !_.isEmpty(productData.is_yohood) &&
productData.is_yohood === 'Y';
result.tags.midYear = !_.isEmpty(productData.midYear) &&
productData.midYear === 'Y'; // 年中
result.tags.yearEnd = !_.isEmpty(productData.yearEnd) &&
productData.yearEnd === 'Y'; // 年末
result.tags.is_advance = !_.isEmpty(productData.is_advance) &&
productData.is_advance === 'Y'; // 再到着
// 打折与即将售完组合显示打折
// 打折与其它组合则隐藏打折
// YOHOOD和新品组合显示YOHOOD
if (!_.isEmpty(result.is_soon_sold_out) && !_.isEmpty(result.tags.is_discount)) {
result.tags.is_new = false;
} else if (result.tags.is_discount && (result.tags.is_new) || result.tags.is_advance) {
result.tags.is_discount = false;
} else if (!_.isEmpty(result.tags.is_yohood) && !_.isEmpty(result.tags.is_new)) {
result.tags.is_new = false;
}
}
return result;
};
/**
* 根据性别来决定 默认图片获取字段 如果是 2、3
* @param {[type]} images [description]
* @return {[type]} [description]
*/
/*exports.procProductImg = (images) => {
let imgUrl = (!_.isEmpty(images.images_url)) ? images.images_url : '';
let cover1 = (!_.isEmpty(images.cover_1)) ? images.cover_1 : '';
let cover2 = (!_.isEmpty(images.cover_2)) ? images.cover_2 : '';
// let gender = getGenderByCookie();
if (gender === '2,3') {
let temp = !_.isEmpty(cover1) ? cover1 : imgUrl;
return !_.isEmpty(cover2) ? cover2 : temp;
} else {
let temp = !_.isEmpty(cover2) ? cover2 : imgUrl;
return !_.isEmpty(cover1) ? cover1 : temp;
}
};*/
/**
* 根据用户访问的COOKIE判断出性别 待处理
* @return {[type]} [description]
*/
exports.getGenderByCookie = () => {
return '2,3';
};
... ...