Authored by yyq

sale special

... ... @@ -146,6 +146,26 @@ exports.breakingYards = (req, res, next) => {
};
/**
* 活动
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.special = (req, res, next) => {
let params = req.query;
let specialId = params.specialsale_id || params.specialsaleId, // 专区ID
promotion = params.promotion; // 促销ID
if (!specialId && !promotion) {
return next();
}
sale.getSaleSpecialData(specialId, params, req.yoho.channel).then(result => {
res.render('sale/special', result);
}).catch(next);
};
/**
* Ajax 获取商品列表
* @param {[type]} req [description]
* @param {[type]} res [description]
... ...
... ... @@ -113,3 +113,18 @@ exports.getUserProfile = (uid) => {
uid: uid
}, true);
};
/**
* 获取用户数据信息
* @param {[string]} uid
* @return {[array]}
*/
exports.getSaleSpecialAsync = (specialId) => {
return api.get('', {
method: 'app.resources.getOneSpecial',
special_id: specialId
}, {
code: 200,
cache: true
});
};
... ...
... ... @@ -6,17 +6,25 @@
*/
'use strict';
const utils = '../../../utils';
const logger = global.yoho.logger;
const camelCase = global.yoho.camelCase;
const api = global.yoho.API;
const saleApi = require('./sale-api');
const searchApi = require('./search-api');
const publicHandler = require('./public-handler');
const saleHandler = require('./sale-handler');
const productProcess = require(`${utils}/product-process`);
const searchHandler = require('./search-handler');
const productProcess = require(`${global.utils}/product-process`);
const pager = require(`${global.utils}/pager`).setPager;
const imageHandler = require(`${global.utils}/images`).getImageUrl;
const _ = require('lodash');
const headerModel = require('../../../doraemon/models/header');
const limitNum = 60; // 商品每页显示数目
// 下一页图片
const nextPageImg = '//img10.static.yhbimg.com/product/2014/01/15/11/01fa01614784f6239760f1b749663016f1.jpg?imageMogr2/thumbnail/235x314/extent/235x314/background/d2hpdGU=/position/center/quality/90'; // eslint-disable-line
/**
* 资源位code码
*/
... ... @@ -383,14 +391,16 @@ exports.getSaleDiscountData = (params, channel) => {
}
}
return api.all([
saleApi.getSaleGoodsList({channel: channel, saleType: '3', limit: '1', productPool: result[1].data[0].product_pool}),
saleApi.getSaleGoodsList({channel: channel, saleType: '3', limit: '1',
productPool: result[1].data[0].product_pool}),
saleApi.getSaleGoodsList(Object.assign(params, {productPool: result[1].data[0].product_pool}))
]).then(subResult => {
// 处理分页等筛选信息
if (subResult[0].code === 200) {
Object.assign(finalResult, {
leftContent: publicHandler.handleSaleSortData(subResult[0].data.filter.group_sort, params, 'discount'),
leftContent: publicHandler.handleSaleSortData(subResult[0].data.filter.group_sort,
params, 'discount'),
saleList: {
footPager: publicHandler.handlePagerData(subResult[0].data.total, params),
opts: publicHandler.handleSaleOptsData(params, subResult[0].data.total)
... ... @@ -515,3 +525,109 @@ exports.getSalebreakingYardsData = (params, channel) => {
}
});
};
/**
* 获取断码区数据 Controller 调用
* @param params
* @param channel
* @returns {*|Promise.<TResult>}
*/
exports.getSaleSpecialData = (id, params, channel) => {
const limit = limitNum - 1; // 最后一个商品是翻页
const page = params.page || 1;
return saleApi.getSaleSpecialAsync(id).then(special => {
let resData = {},
apiList = [
headerModel.requestHeaderData(channel),
searchApi.getSortList()
];
if (special && special.data) {
let data = special.data,
condition = {
page: page,
limit: limit
};
let banner = JSON.parse(data.banner_img) || [];
Object.assign(resData, {
mainBanner: {
src: imageHandler(_.get(banner, '[0].img', ''), 1920, 350, 1, 'couponImg')
},
specialHead: {
title: '全部商品',
count: 0
},
node: data.left_ad_code // 水牌node
});
// 传品牌ID参数
if (special.brand_id) {
condition.brand = data.brand_id;
}
// 传促销id,促销id为空时传专区id
if (data.ispromotion) {
condition.promotion = data.ispromotion;
} else {
condition.promotion = params.promotion;
}
// 搜索sale活动商品
apiList.push(searchApi.getProductList(condition));
}
return Promise.all(apiList).then(result => {
if (!_.isEmpty(result[0])) {
resData.headerData = Object.assign(result[0].headerData, {header: true});
}
if (!_.isEmpty(result[1])) {
resData.leftContent = searchHandler.handleSortData(_.get(result[1],
'data.sort', []), params);
}
if (!_.isEmpty(result[2])) {
let tip = {
start: (_.get(result[2], 'data.page', 1) - 1) * limitNum + 1,
total: _.get(result[2], 'data.total', 0)
};
tip.end = tip.start + limit - 1;
if (tip.end > tip.total) {
tip.end = tip.total;
}
resData.specialHead.count = tip.total;
Object.assign(resData, {
filters: searchHandler.handleFilterData(_.get(result[2], 'data.filter', {}), params),
opts: searchHandler.handleOptsData(params, tip.total),
goods: productProcess.processProductList(_.get(result[2], 'data.product_list', [])),
footPager: {tip: tip}
});
// 设置分页
Object.assign(resData.footPager,
pager(_.get(result[2], 'data.page_total', 0), params));
if (_.has(resData, 'footPager.nextPage')) {
resData.hasNextPage = {
href: _.get(resData, 'footPager.nextPage.url', ''),
src: nextPageImg
};
}
// 获取高级筛选条件
if (resData.list && resData.list.filters) {
Object.assign(resData.list.filters, searchHandler.handleSeniorFilterData({
style: _.get(result[2], 'data.filter.style', []),
standard: _.get(result[2], 'data.standard', [])
}, params));
}
}
return resData;
});
});
};
... ...
... ... @@ -335,9 +335,17 @@ exports.handleOptsData = (params, total, extra) => {
*/
exports.handleSortData = (origin, params) => {
let leftContent = {};
let list = [],
allCount = 0;
leftContent.allSort = {};
leftContent.allSort.list = [];
leftContent.allSort.all = [{
name: '全部品类',
num: allCount,
href: handleFilterUrl(params)
}];
//
_.forEach(origin, value => {
let category = {
... ... @@ -355,6 +363,8 @@ exports.handleSortData = (origin, params) => {
active: params.msort === value.sort_id
};
allCount += parseInt(value.count, 10);
_.forEach(value.sub, subValue => {
category.childList.push({
name: subValue.sort_name,
... ... @@ -368,9 +378,11 @@ exports.handleSortData = (origin, params) => {
});
leftContent.allSort.list.push(category);
list.push(category);
});
leftContent.allSort.list = list;
return leftContent;
};
... ...
... ... @@ -36,6 +36,7 @@ router.get('/sale/discount/detail', sale.discount); // 折扣专场详情页
router.get('/sale/vip', sale.vip); // VIP 活动专区
router.get('/sale/breakingYards', sale.breakingYards); // 断码区
router.get('/sale/newSale', sale.newSale); // 最新降价
router.get('/sale/special/detail', sale.special); // sale活动页 原PHP sale.yohobuy.com
router.get('/sale/goods', sale.getGoodsList); // ajax 获取商品列表
// 奥特莱斯routers
... ...
<div class="sale-special-page product-page yoho-page">
{{> common/main-banner}}
<div class="center-content clearfix">
{{> common/special-head}}
<div class="list-left left">
{{> product/left-content}}
</div>
<div class="list-right right">
{{> product/standard-content}}
</div>
</div>
</div>
\ No newline at end of file
... ...
... ... @@ -10,7 +10,7 @@
<span><i>{{discount}}</i>{{discountText}}</span>
</div>
<div class="special-title">
{{title}}
{{title}}<br>
<label class="all-count">
{{count}}个结果
</label>
... ...
... ... @@ -12,7 +12,7 @@
<div class="pager">
{{# prePage}}
<a href="{{url}}" title="上一页">上一页<span class="iconfont">&#xe60e;</span></a>
<a href="{{url}}" title="上一页"><span class="iconfont">&#xe60e;</span>上一页</a>
{{/ prePage}}
{{# pages}}
... ...
... ... @@ -26,7 +26,7 @@
</div>
<div class="good-detail-img">
<a class="good-thumb" href="{{url}}" target="_blank">
<img class="lazy" data-original="{{image thumb 220 300}}">
<img class="lazy" data-original="{{image thumb 235 314}}">
</a>
{{# isFew}}
<p class="few-tag">即将售罄</p>
... ...
... ... @@ -15,6 +15,11 @@
text-align: center;
margin-right: 8px;
color: #222;
> .iconfont {
position: relative;
top: 2px;
}
}
.cur {
... ...
@import "new-sale";
.center-content {
width: 1150px;
margin-left: auto;
... ... @@ -91,7 +89,7 @@
display: block;
margin-right: 10px;
background: #f5f5f5;
&.last {
margin-right: 0;
}
... ... @@ -680,3 +678,6 @@
}
}
}
@import "new-sale";
@import "special";
... ...
.sale-special-page {
.main-banner {
height: 350px;
}
.special-limit,
.special-name {
display: none;
}
.special-title {
font-size: 20px;
height: 34px;
text-align: center;
border-bottom: 1px dotted #999;
margin: 20px 0;
.all-count {
color: #999;
font-size: 12px;
line-height: 26px;
background: #fff;
display: inline-block;
padding: 0 10px;
}
}
.filter-box .brand .attr-content {
max-width: 730px;
}
.good-detail-text .discount {
display: none;
}
.block-next-page {
width: 235px;
> a {
width: 100%;
height: 315px;
}
}
}
... ...
/**
* 分页处理
* @author: yyq<yanqing.yang@yoho.cn>
* @date: 2016/8/19
*/
'use strict';
const _ = require('lodash');
/**
* 拼接url
* @function joinUrl
* @param params 要拼接的 参数
* @returns {string}
*/
const joinUrl = (params) => {
let dest = '?';
_.forEach(params, function(value, key) {
dest += `${key}=${value}&`;
});
return _.trim(dest, '&');
};
/**
* 设置分页
* @setPager setPager
* @param total 总页数
* @param params 参数
* @returns {object}
*/
exports.setPager = (total, params)=>{
let resData = {};
let cutStatus, // 切割状态 1:去头 2:去尾 3:双切
i;
let pages = [];
let currentPage = parseInt(params.page || 1, 10); // 当前页
for (i = currentPage - 2; i <= currentPage + 2; i++) {
if (i < 1) {
cutStatus = 1;
continue;
}
if (i > total) {
cutStatus = cutStatus ? 3 : 2;
continue;
}
pages.push({
url: joinUrl(Object.assign(params, {page: i})),
num: i,
cur: currentPage === i
});
}
// 分页中部补全
let len = 5 - pages.length;
let list = [];
if (cutStatus === 1) {
for (i = 1; i <= len; i++) {
let p = currentPage + i + 2;
if (i > total) {
break;
}
list.push({
url: joinUrl(Object.assign(params, {page: p})),
num: p
});
}
pages = _.concat(pages, list);
} else if (cutStatus === 2) {
for (i = 1; i <= len; i++) {
let p = currentPage - i - 2;
if (i < 1) {
break;
}
list.push({
url: joinUrl(Object.assign(params, {page: p})),
num: p
});
}
pages = _.concat(list, pages);
}
// 分页头尾补全
let fnum = _.get(_.head(pages), 'num', 1),
lnum = _.get(_.last(pages), 'num', 1);
if (fnum > 1) {
if (fnum > 2) {
pages = _.concat({
url: joinUrl(Object.assign(params, {page: 1})),
num: 1
}, {num: '...'}, pages);
} else {
pages = _.concat({
url: '?page=1',
num: 1
}, pages);
}
}
if (lnum < total) {
if (lnum < total - 1) {
pages = _.concat(pages, {num: '...'}, {
url: joinUrl(Object.assign(params, {page: total})),
num: total
});
} else {
pages = _.concat(pages, {
url: joinUrl(Object.assign(params, {page: total})),
num: total
});
}
}
resData.pages = pages;
// 上一页
if (currentPage > 1) {
resData.prePage = {url: joinUrl(Object.assign(params, {page: currentPage - 1}))};
}
// 下一页
if (currentPage < total) {
resData.nextPage = {url: joinUrl(Object.assign(params, {page: currentPage + 1}))};
}
return resData;
};
... ...