Authored by yyq

品类大全页

'use strict';
const headerModel = require('../../../doraemon/models/header');
const aboutModel = require('../models/about');
let responseData = {
module: 'about',
... ... @@ -71,10 +72,42 @@ const link = (req, res, next) => {
}).catch(next);
};
/**
* 品类大全
*/
const category = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
let resData = {};
return Promise.all([
headerModel.requestHeaderData(channel),
req.ctx(aboutModel).getCategoryDataWithCache(channel)
]).then(result => {
Object.assign(resData, responseData, result[0], result[1]);
res.render('category', resData);
}).catch(next);
};
/**
* 产品大全
*/
const chanpin = (req, res, next) => {
let channel = req.yoho.channel || 'boys';
headerModel.requestHeaderData(channel).then(result => {
responseData.headerData = result.headerData;
res.render('chanpin', responseData);
}).catch(next);
};
module.exports = {
yohobuy,
newpower,
contact,
privacy,
link
link,
category,
chanpin
};
... ...
const _ = require('lodash');
const cache = global.yoho.cache;
const logger = global.yoho.logger;
const helpers = global.yoho.helpers;
const hotBrandsModel = require('../../../doraemon/models/hot-brands');
const CACHE_TIME_S = 60 * 60;
const indexUrl = {
boys: helpers.urlFormat('/'),
girls: helpers.urlFormat('/woman'),
kids: helpers.urlFormat('/kids'),
lifestyle: helpers.urlFormat('/lifestyle')
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
getCategoryFromApi(channel) {
return this.get({data: {
method: 'web.regular.groupsort.sale',
sales: 'Y', // 在销售商品分类
status: 1, // 上架商品分类
stocknumber: 1, // 过滤掉已售罄
yh_channel: channel
}, param: {cache: true}});
}
getCategoryData(channel) {
return Promise.all([
this.getCategoryFromApi(1),
this.getCategoryFromApi(2),
this.getCategoryFromApi(3),
this.getCategoryFromApi(4),
hotBrandsModel.hotBrands()
]).then(result => {
let nameMap = ['男生', '女生', '潮童', '创意生活'];
let genderMap = ['1,3', '2,3'];
let categoryList = [];
let hotBrands = result.pop();
_.forEach(result, (res, index) => {
if (res.code !== 200) {
return;
}
res = res.data;
let list = [],
gender = genderMap[index];
_.forEach(res, cate => {
let sub = [];
_.forEach(cate.sub, scate => {
sub.push({
name: scate.category_name,
url: {category_id: scate.category_id, gender: gender}
});
});
list.push({
title: cate.category_name,
sub: sub
});
});
categoryList.push({
channelName: nameMap[index],
list: list
});
});
let upChannel = _.toUpper(channel);
return {
pathNav: [
{pathTitle: `${upChannel}首页`, name: `${upChannel}首页`, href: indexUrl[channel]},
{pathTitle: '全部分类', name: '全部分类'}
],
hotBrands,
categoryList
};
});
}
getCategoryDataWithCache(channel) {
let cacheKey = 'seo_category_group_map';
return cache.get(cacheKey).then(cdata => {
let cdataObj;
if (cdata) {
try {
cdataObj = JSON.parse(cdata);
} catch (e) {
logger.debug('category map cache data parse fail.');
}
}
if (cdataObj) {
return cdataObj;
}
return this.getCategoryData(channel).then(list => {
if (list && list.length) {
cache.set(cacheKey, list, CACHE_TIME_S);
}
return list;
});
}).catch(err => {
logger.debug(`get category map cache data fail:${err.toString()}`);
return this.getCategoryData(channel);
});
}
getChanpinData() {
}
};
... ...
... ... @@ -13,5 +13,8 @@ router.get('/newpower.html', aboutCtrl.newpower);
router.get('/contact.html', aboutCtrl.contact);
router.get('/privacy.html', aboutCtrl.privacy);
router.get('/link.html', aboutCtrl.link);
router.get('/categorymap.html', aboutCtrl.category);
router.get('/chanpinmap.html', aboutCtrl.link);
module.exports = router;
... ...
<div class="category-map-page center-content yoho-page">
{{> common/path-nav}}
<div class="list-block">
<h1 class="main-title">全部分类</h1>
{{# categoryList}}
<p class="channel-name">{{channelName}}</p>
{{# list}}
<p><label class="left-title">{{title}}:</label>
{{# sub}}<a href="#">{{name}}</a>{{/ sub}}
</p>
{{/ list}}
{{/ categoryList}}
</div>
{{#if hotBrands}}
<div class="hot-brands clearfix">
{{# hotBrands}}
<a href="{{url}}" alt="{{title}}">
<img src="{{image image}}" title="{{title}}">
</a>
{{/ hotBrands}}
</div>
{{/if}}
</div>
... ...
.category-map-page {
.path-nav {
padding: 22px 0;
}
.list-block {
font-size: 12px;
border: 1px solid #dfdfdf;
margin-bottom: 30px;
.main-title {
line-height: 50px;
background-color: #eaeceb;
padding-left: 20px;
font-weight: bold;
}
> p {
display: block;
padding: 10px 0 10px 100px;
line-height: 30px;
border-top: 1px solid #dfdfdf;
position: relative;
box-sizing: border-box;
a {
margin-right: 20px;
}
}
.left-title {
position: absolute;
left: 20px;
font-weight: bold;
}
.channel-name {
padding-left: 0;
font-weight: bold;
text-align: center;
font-size: 14px;
}
}
.hot-brands {
width: 101%;
margin-bottom: 70px;
> a {
width: 116px;
height: 70px;
display: block;
padding: 10px 8px;
float: left;
box-sizing: border-box;
border: 1px solid #dfdfdf;
margin-left: -1px;
margin-top: -1px;
}
img {
width: 100%;
height: 100%;
display: block;
}
}
}
... ...
... ... @@ -4,3 +4,4 @@
@import "contact";
@import "link";
@import "privacy";
@import "category";
... ...