Authored by 王水玲

sale

... ... @@ -13,14 +13,14 @@ const headerModel = require('../../../doraemon/models/header');
const log = require(`${library}/logger`);
const saleModel = require(`${mRoot}/sale`);
// const queryParam = {
// brand: '0',
// gender: '1,2,3',
// sort: '0',
// size: '0',
// price: '0',
// discount: '0.1,0.9'
// };
const queryParam = {
brand: '0',
gender: '1,2,3',
sort: '0',
size: '0',
price: '0',
pD: '0.1,0.9'
};
const saleLogger = (err, res) => {
log.error('sale页面渲染错误:' + JSON.stringify(err));
... ... @@ -28,7 +28,10 @@ const saleLogger = (err, res) => {
};
/**
* sale 首页
* sale 首页 资源位获取
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.index = (req, res) => {
let headerData = headerModel.setNavHeader('SALE');
... ... @@ -41,7 +44,7 @@ exports.index = (req, res) => {
};
saleModel.getSaleData().then((result) => {
res.render('sale', Object.assign(renderData, {
res.render('sale', Object.assign(renderData, queryParam, {
content: result,
floorHeader: {
title: {
... ... @@ -56,6 +59,9 @@ exports.index = (req, res) => {
/**
* 断码区
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.breakCode = (req, res) => {
let headerData = headerModel.setNavHeader('断码区');
... ... @@ -66,7 +72,9 @@ exports.breakCode = (req, res) => {
pageFooter: true
};
saleModel.getBreakCodeData().then((result) => {
saleModel.getBreakCodeData({
yhChannel: req.query.channel
}).then((result) => {
res.render('break-code', Object.assign(renderData, result));
}).catch((err) => {
saleLogger(err, res);
... ... @@ -75,6 +83,9 @@ exports.breakCode = (req, res) => {
/**
* 折扣专场列表
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.special = (req, res) => {
let headerData = headerModel.setNavHeader('折扣专场');
... ... @@ -95,6 +106,9 @@ exports.special = (req, res) => {
/**
* 折扣专场专题详情
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.specialDetail = (req, res) => {
let headerData = headerModel.setNavHeader();
... ... @@ -115,7 +129,10 @@ exports.specialDetail = (req, res) => {
};
/**
* vip
* vip 会员专享
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.vip = (req, res) => {
let headerData = headerModel.setNavHeader('会员专享');
... ... @@ -135,6 +152,12 @@ exports.vip = (req, res) => {
});
};
/**
* 筛选
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.filter = (req, res) => {
let params = Object.assign({}, req.query);
... ... @@ -147,18 +170,36 @@ exports.filter = (req, res) => {
});
};
/**
* 商品搜索
* @param {[object]} req
* @param {[object]} res
* @return {[type]}
*/
exports.search = (req, res) => {
let params = Object.assign({}, req.query);
let uid = req.user.uid || 0;
let uid = 9239279 || req.user.uid || 0;
saleModel.getSearchData(params, uid).then((result) => {
let vipLevel = result[1].curLevel;
res.render('product', {
let vipObj = {};
if (req.query.saleType === '2') {
vipObj = Object.assign({
saleVip: (req.query.saleType === '2' && (!uid || vipLevel === '1')),
vipLevel: vipLevel,
saleViplogin: vipLevel >= 1 ? true : false,
vipPrice1: vipLevel === '1',
vipPrice2: vipLevel === '2',
vipPrice3: vipLevel === '3'
}, vipObj);
}
res.render('product', Object.assign({
layout: false,
params: params,
goods: result[0],
saleVip: (req.query.saleType === '2' && (!uid || vipLevel === '1'))
});
goods: result[0]
}, vipObj));
});
};
... ...
... ... @@ -21,6 +21,9 @@ const aMinute = 60000;
const anHour = 3600000;
const aDay = anHour * 24;
/**
* 需要格式化的时间格式
*/
const timeFormat = {
d: '剩{d}天',
h: '剩{h}小时',
... ... @@ -32,6 +35,9 @@ const timeFormat = {
ms: '剩{m}分钟{s}秒'
};
/**
* 排序转换
*/
const typeCont = {
price: ['s_p_desc', 's_p_asc'],
discount: ['p_d_desc', 'p_d_asc'],
... ... @@ -42,6 +48,8 @@ const typeCont = {
/**
* 折扣专场专题列表过期时间处理
* @param {[string]} time
* @return {[object]}
*/
const processTime = (time) => {
let data = {};
... ... @@ -65,6 +73,8 @@ const processTime = (time) => {
/**
* 折扣专场专题详情过期时间处理
* @param {[string]} time
* @return {[boject]}
*/
const processTimes = (time) => {
let data = {};
... ... @@ -91,6 +101,8 @@ const processTimes = (time) => {
/**
* 折扣专场列表数据处理
* @param {[array]} list
* @return {[array]}
*/
const processSpecial = (list) => {
const formatData = [];
... ... @@ -119,6 +131,8 @@ const processSpecial = (list) => {
/**
* 折扣专场接口调用
* @param {[object]} params
* @return {[array]}
*/
const special = (params) => {
params = params || {};
... ... @@ -132,6 +146,8 @@ const special = (params) => {
/**
* 断码区分类数据处理
* @param {[array]} list
* @return {[array]}
*/
const processBreakingSort = (list) => {
const formatData = {};
... ... @@ -157,8 +173,18 @@ const processBreakingSort = (list) => {
/**
* 商品搜索接口请求
* @param {[object]} params
* @return {[array]}
*/
const searchSales = (params) => {
// 排除基本筛选项默认值为0的对象
for(let str in params){
if (str !== 'order' && params[str] === '0' || params[str] === null) {
delete params[str];
}
}
params = Object.assign({
limit: '50'
}, params);
... ... @@ -173,22 +199,10 @@ const searchSales = (params) => {
};
/**
* 获取筛选数据
* 获取用户数据信息
* @param {[string]} uid
* @return {[array]}
*/
exports.getFilterData = (params) => {
return searchSales(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || [], {
hideSize: params.saleType === '1',
hideSort: params.saleType === '1'
});
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
});
};
const getUserProfile = (uid) => {
return api.get('', sign.apiSign({
method: 'app.passport.profile',
... ... @@ -197,31 +211,9 @@ const getUserProfile = (uid) => {
};
/**
* 获取商品数据
*/
exports.getSearchData = (params, uid) => {
return Promise.all([
searchSales(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processProductList(result.data.product_list || []);
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
}),
getUserProfile(uid).then((result) => {
if (result && result.code === 200) {
return camelCase(result.data.vip_info);
} else {
logger.error('获取用户信息返回 code 不是 200');
return {};
}
})
]);
};
/**
* 获取资源位数据
* @param {[string]} page
* @return {[array]}
*/
const getResources = (page) => {
const contentCode = {
... ... @@ -244,6 +236,8 @@ const getResources = (page) => {
/**
* 获取断码区分类数据
* @param {[string]} yhChannel
* @return {[object]}
*/
const getBreakingSort = (yhChannel) => {
return api.get('', sign.apiSign({
... ... @@ -260,7 +254,54 @@ const getBreakingSort = (yhChannel) => {
};
/**
* 获取筛选数据
* @param {[object]} params
* @return {[array]}
*/
exports.getFilterData = (params) => {
return searchSales(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processFilter(result.data.filter || [], {
hideSize: params.saleType === '1',
hideSort: params.saleType === '1'
});
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
});
};
/**
* 获取商品数据
* @param {[object]} params
* @param {[string]} uid
* @return {[array]}
*/
exports.getSearchData = (params, uid) => {
return Promise.all([
searchSales(params).then((result) => {
if (result && result.code === 200) {
return productProcess.processProductList(result.data.product_list || []);
} else {
logger.error('SALE 商品搜索返回 code 不是 200');
return [];
}
}),
getUserProfile(uid).then((result) => {
if (result && result.code === 200) {
return camelCase(result.data.vip_info);
} else {
logger.error('获取用户信息返回 code 不是 200');
return {};
}
})
]);
};
/**
* 获取sale首页数据
* @return {[array]}
*/
exports.getSaleData = () => {
return getResources('sale');
... ... @@ -268,8 +309,7 @@ exports.getSaleData = () => {
/**
* 获取会员享数据
* @param {[object]} params
* @return {[object]}
* @return {[array]}
*/
exports.getVipData = () => {
return getResources('vip');
... ... @@ -312,7 +352,7 @@ exports.getSpecialData = (params) => {
/**
* 获取折扣专场专题详情数据
* @param {[object]} params
* @param {[string]} id
* @return {[object]}
*/
exports.getSpecialDetailData = (id) => {
... ... @@ -324,6 +364,7 @@ exports.getSpecialDetailData = (id) => {
return special(param).then((result) => {
if (result && result.code === 200) {
res = processSpecial(result.data);
console.log(res)
return {
title: res[0].title,
activity: {
... ...
{{#if this}} {{!-- 剔除值为false的项 --}}
<div class="good-info" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false">
<div class="good-info {{#if @root.saleViplogin}}sale-vip{{/if}}" data-id="{{productSkn}}" data-bp-id="guang_goodList_{{productName}}_false">
<div class="tag-container clearfix">
{{# tags}}
{{# isNew}}
... ... @@ -32,10 +32,16 @@
<a href="{{url}}">{{productName}}</a>
</div>
<div class="price">
{{#if saleViplogin}}
<i class="vip-grade-{{vipGrade}}"></i>
{{#if @root.saleViplogin}}
<i class="vip-grade vip-grade-{{@root.vipLevel}}"></i>
<span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥
{{#if @root.vipPrice1}}{{vip1Price}}{{/if}}
{{#if @root.vipPrice2}}{{vip2Price}}{{/if}}
{{#if @root.vipPrice3}}{{vip3Price}}{{/if}}
</span>
{{else}}
<span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥{{salesPrice}}</span>
{{/if}}
<span class="sale-price {{^marketPrice}}no-price{{/marketPrice}}">¥{{salesPrice}}</span>
{{#marketPrice}}
<span class="market-price">¥{{.}}</span>
{{/marketPrice}}
... ...
... ... @@ -177,6 +177,11 @@ function search(opt) {
discount: opt[i].id
};
break;
case 'p_d':
ext = {
p_d: opt[i].id
};
break;
default:
break;
}
... ...
... ... @@ -69,6 +69,25 @@ ellipsis.init();
lazyLoad($('img.lazy'));
// 获取url里面的参数的值
function getUrlParam(name) {
// 构造一个含有目标参数的正则表达式对象
var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)");
// 匹配目标参数
var r = window.location.search.substr(1).match(reg);
if (r !== null) {
return r[2];
}
return null; //返回参数值
}
// 获取频道
$.extend(defaultOpt, {
yhChannel: getUrlParam('channel')
});
// 判断导航类型
function judgeType(dom) {
var navType;
... ... @@ -153,6 +172,11 @@ function search(opt) {
discount: opt.id
};
break;
case 'p_d':
ext = {
p_d: opt.id
};
break;
default:
break;
}
... ...
... ... @@ -132,17 +132,17 @@
vertical-align: text-bottom;
}
.vip-grade-golden {
.vip-grade-3 {
background: resolve('product/golden.png') no-repeat;
background-size: contain;
}
.vip-grade-platinum {
.vip-grade-2 {
background: resolve('product/platinum.png') no-repeat;
background-size: contain;
}
.vip-grade-silver {
.vip-grade-1 {
background: resolve('product/silver.png') no-repeat;
background-size: contain;
}
... ...
... ... @@ -36,4 +36,12 @@
.good-info {
height: 570px;
}
.sale-vip {
height: 506px;
}
.good-detail-text .price {
white-space: nowrap;
}
}
... ...
... ... @@ -73,8 +73,20 @@ exports.processProductList = (list, options) => {
// });
if (options.showPoint) {
product.price += '.00';
product.salePrice += '.00';
product.marketPrice += '.00';
product.salesPrice += '.00';
if (product.vip1Price) {
product.vip1Price = parseInt(product.vip1Price) + '.00';
}
if (product.vip2Price) {
product.vip2Price = parseInt(product.vip2Price) + '.00';
}
if (product.vip3Price) {
product.vip3Price = parseInt(product.vip3Price) + '.00';
}
}
product.isSoonSoldOut = product.isSoonSoldOut === 'Y';
... ... @@ -150,7 +162,7 @@ exports.processFilter = (list, options) => {
dataId: 'key',
subsName: 'name',
firstSub: '0.1,0.9',
dataType: 'discount'
dataType: 'p_d'
},
gender: {
name: '所有性别',
... ...