Authored by hongweigao

品牌一览

/**
* 品牌一览 controller
* @author: ghw<hongwei.gao@yoho.cn>
* @date: 2016/9/29
*/
'use strict';
const mRoot = '../models';
const helpers = global.yoho.helpers;
const brandsModel = require(`${mRoot}/brands-service`); // students model
/**
* brands 首页
* @param {[type]} req [description]
* @param {[type]} res [description]
* @return {[type]} [description]
*/
exports.index = (req, res, next) => {
let channel = req.query.channel || req.cookies._Channel || 'boys';
brandsModel.getBrandViewList(channel, req).then(result => {
res.render('brands', result);
}).catch(next);
};
... ...
/**
* router of sub app brands
* @author: ghw<hongwei.gao@yoho.cn>
* @date: 2016/09/29
*/
var express = require('express'),
path = require('path'),
hbs = require('express-handlebars');
var app = express();
// set view engin
var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
app.on('mount', function(parent) {
delete parent.locals.settings; // 不继承父 App 的设置
Object.assign(app.locals, parent.locals);
});
app.set('views', path.join(__dirname, 'views/action'));
app.engine('.hbs', hbs({
extname: '.hbs',
defaultLayout: 'layout',
layoutsDir: doraemon,
partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
helpers: global.yoho.helpers
}));
// router
app.use(require('./router'));
module.exports = app;
... ...
/**
* 品牌一览 api
* @author: ghw<hongwei.gao@yoho.cn>
* @date: 2016/9/29
*/
'use strict';
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
/**
* 分开取数,品牌一览 顶部的轮翻广告及热门品牌数据-PC
* 顶部的轮翻广告及热门品牌数据
* @param string $contentCode 获取广告资源需要的位置码
*/
const getBrandTopData = (contentCode) => {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
});
};
/**
* 分开取数,获取品牌一览 "按字母'A-Z'分组的品牌列表数据"
* @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
*/
const getBrandListData = channel => {
let params = {method: 'app.brand.brandlist'};
if(!isNaN(channel)) {
params.yh_channel= channel;
}
return api.get('', params);
};
module.exports = {
getBrandTopData,
getBrandListData
};
... ...
/**
* 品牌一览 model
* @author: ghw<hongwei.gao@yoho.cn>
* @date: 2016/9/29
*/
'use strict';
const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const brandApi = require('./brands-api');
//品牌一览资源位CODE码
const channelCode = {
boys_brand: '8b16b7baf9a66fbe553a6caa97d2ce2a',
girls_brand: 'c95ae9e40f0add10549b819f821ad626',
kids_brand: 'c575c6bfdfa4125fae7d24bbec7119c8',
lifestyle_brand: '84b7926282fdef92f1039bdcf77c18ba',
brand_list: 'f0f72b1e8f30e6ad086dfc4401f3a856', //品牌列表资源位CODE码
brand_plusstar_banner_boys: 'd0149783b8dd2adaf083fd10556c39a9',
brand_plusstar_banner_girls: 'd0149783b8dd2adaf083fd10556c39a9',
brand_plusstarindex_boys: 'a833aed63d28457156310e97faa7fa37',//plusstarindex男首资源位
brand_plusstarindex_girls: '6e4f162be3b3ba44f3bfcf1c38bdb745',//plusstarindex女首资源位
};
const BOYS = 'boys';
const GIRLS = 'girls';
const KIDS = 'kids';
const LIFESTYLE = 'lifestyle';
/**
* 获取品牌一览资源位&channelType
*
* @param string $channelStr
* @return array
*/
const switchBrandParams = channel => {
let req = {};
switch (channel) {
case BOYS:
req = {
channelType: 1,
brandCode: channelCode.brand_plusstar_banner_boys
}
break;
case GIRLS:
req = {
channelType: 2,
brandCode: channelCode.brand_plusstar_banner_girls
}
break;
case KIDS:
req = {
channelType: 3,
brandCode: channelCode.kids_brand
}
break;
case LIFESTYLE:
req = {
channelType: 4,
brandCode: channelCode.lifestyle_brand
}
break;
default:
req = {
channelType: 1,
brandCode: channelCode.boys_brand
}
break;
}
return req;
}
/**
* 获取品牌一览页面,品牌top
* @param string $channel 频道名称
*/
const getBrandViewTop = channel => {
return co(function*() {
let switchParams = switchBrandParams(channel);
let res = yield brandApi.getBrandTopData(switchParams.brandCode);
let result = {},
brandAds = [],
brandLogos = [];
//头部10个品牌小图块 url
if (res.data[1].data && res.data[1].data.list) {
_.forEach(res.data[1].data.list, subValue => {
brandAds.push({
name: subValue.name,
src: helpers.image(subValue.src, 80, 50, 3),
url: helpers.urlFormat(subValue.url)
})
});
}
//头部品牌图块,广告位
if (res.data[0].data) {
_.forEach(res.data[0].data, subValue => {
let srcUrl;
//kids lifestyle 第一张图尺寸不同
if (switchParams.channelType === 1 || switchParams.channelType === 2) {
srcUrl = helpers.image(subValue.src, 222, 180, 3);
}else {
srcUrl = (subValue === 0) ? helpers.image(subValue.src, 570, 280, 3) :
helpers.image(subValue.src, 280, 280, 3);
}
brandLogos.push({
name: subValue.title,
src: srcUrl,
url: helpers.urlFormat(subValue.url)
})
});
}
//整合brandTop数据结构,boys、girls
if (switchParams.channelType === 1 || switchParams.channelType === 2) {
result.isTab = true;
}
result.tabHeader = brandLogos;
result.logos = brandAds;
return result;
})();
};
/*
* 获取品牌一览list
* @param string $channel 频道名称
* @param int start 开始位置 1 开始
* @param int length 取数长度 0 取到最后
*/
const getBrandViewList = (channel, start, length) =>{
return co(function*() {
let switchParams = switchBrandParams(channel);
let res = yield brandApi.getBrandListData(switchParams.brandCode);
let result = {},
navigation = [];
//品牌list A-Z 0-9
if (res.data.brands) {
let listTmp = {};
_.forEach(res.data.brands, subValue => {
// if(_.isEmpty(subValue)){
// continue;
// }
_.forEach(subValue, ssubValue => {
//为品牌名称
let brandName = ssubValue.brand_name,
href;
if (switchParams.channelType === 1) {
href = helpers.urlFormat(ssubValue.brand_domain) + '?gender=1,3';
}else if (switchParams.channelType === 2) {
href = helpers.urlFormat(ssubValue.brand_domain) + '?gender=2,3';
}else {
href = helpers.urlFormat(ssubValue.brand_domain);
}
listTmp[brandName] = {
name: ssubValue.brand_name,
key: ssubValue.id,
href: href
}
if (ssubValue.is_hot === 'Y') {
listTmp[brandName].hot = 'hot';
}
})
//按键值排序
})
}
//只取部分数据
// begin = ($start - 1) ? ($start - 1) : 0;
// begin = ($begin > 0) ? $begin : 0;
// result = $length ? array_slice($result, $begin, $length) : array_slice($result, $begin);
// $result['navigation'] = $navigation;
return result;
})();
};
module.exports = {
getBrandViewTop,
getBrandViewList
};
... ...
/**
* 品牌一览 controller
* @author: ghw<hongwei.gao@yoho.cn>
* @date: 2016/9/29
*/
'use strict';
const api = global.yoho.API;
const headerModel = require('../../../doraemon/models/header');
const brandsModel = require('./brands-model');
/*
* 获取品牌一览list
* @param string $channel 频道名称
* @param int start 开始位置 1 开始
* @param int length 取数长度 0 取到最后
*/
exports.getBrandViewList = (channel, req) => {
let apiMethod = [
headerModel.requestHeaderData(channel),
brandsModel.getBrandViewTop(channel),
brandsModel.getBrandViewList(channel)
];
return api.all(apiMethod).then(result => {
let responseData = {
module: 'brands',
page: 'brands'
};
// 头部数据
Object.assign(responseData, result[0]);
// 品牌一览列表
responseData.brands = result[1];
return responseData;
});
};
... ...
/**
* router of sub app brands
* @author: ghw<hongwei.gao@yoho.cn>
* @date: 2016/09/29
*/
'use strict';
const express = require('express');
const cRoot = './controllers';
const router = express.Router(); // eslint-disable-line
const brandsController = require(`${cRoot}/brands`);
//品牌一览
router.get('', brandsController.index);
module.exports = router;
... ...
{{> brand/brand-list}}
\ No newline at end of file
... ...
<div class="home-page yoho-page brands" data-page="brands">
{{# brands}}
{{> common/path-nav}}
{{#if isTab}}
<div class="brands-tabs">
<ul class="clearfix">
{{#each tabHeader}}
<li>
<a href="{{url}}">
<div class="g-mask"></div>
<p class="tips">{{name}}</p>
<img class="lazy" data-original="{{src}}"/>
</a>
</li>
{{/each}}
</ul>
<div class="hover-contain">
<div class="hoverarr">
<i></i>
</div>
</div>
</div>
{{^}}
<ul class="brands-ad clearfix">
{{#each tabHeader}}
<li>
<a href="{{url}}" target="_blank">
<img class="lazy" data-original="{{src}}">
</a>
</li>
{{/each}}
</ul>
{{/if}}
<div class="brands-logo clearfix">
{{#each logos}}
<a href="{{url}}" title="{{name}}" target="_blank">
<img class="lazy" data-original="{{src}}">
</a>
{{/each}}
</div>
<div class="brands-category">
<div class="category-nav">
<span>BRANDS A-Z:</span>
{{#each navigation}}
<a href="#{{this}}">{{this}}</a>
{{/each}}
</div>
</div>
<div class="brands-list" >
</div>
{{/ brands}}
</div>
... ...
{{> layout/header}}
<div class="home-page yoho-page brands" data-page="brands">
{{# brands}}
{{! 头部banner}}
{{# slide}}
{{>index/slide-banner}}
{{/ slide}}
{{! 品牌 BRAND}}
{{# brand}}
{{> index/floor-header}}
<div class="brandfloor clearfix">
<ul class="g-list">
{{# list}}
<li>
<a href="{{url}}" target= "_blank">
<img class="lazy" data-original="{{src}}" alt="">
</a>
</li>
{{/ list}}
</ul>
</div>
{{/ brand}}
{{! 单品 SINGLE GOODS}}
{{# singlegoods}}
{{> index/floor-header}}
<div class="singlegoods clearfix">
<ul class="g-list">
{{# list}}
<li>
<a href="{{url}}" target= "_blank">
<img class="lazy" data-original="{{src}}" alt="">
<div class="singlegoods-title">
<div class="g-mask"></div>
<p>{{name}}</p>
</div>
</a>
</li>
{{/ list}}
</ul>
</div>
{{/ singlegoods}}
{{!视频 VIDEO}}
{{# video}}
{{> index/floor-header}}
<div class="video clearfix">
<ul class="g-list">
{{# list}}
<li>
<a href="{{url}}" target= "_blank">
<img class="lazy" data-original="{{src}}" alt="" /><i class="video-play"></i>
<div class="video-title">
<div class="g-mask"></div>
<p>{{name}}</p>
</div>
</a>
</li>
{{/ list}}
</ul>
</div>
{{/ video}}
{{!新闻 NEWS}}
{{# news}}
{{> index/floor-header}}
<div class="news clearfix">
<div class="news-pic">
{{# pics}}
{{>index/slide-banner}}
{{/ pics}}
</div>
<div class="news-txt">
{{# txts}}
<ul>
{{#each list}}
<li>
<i class="iconfont">&#xe619;</i><a href="{{url}}">{{name}}</a>
</li>
{{/each}}
</ul>
{{/ txts}}
</div>
</div>
{{/ news}}
{{!推广 AD}}
{{# ads}}
<div class="ads clearfix">
<ul class="g-list">
{{# list}}
<li>
<a href="{{url}}" target= "_blank">
<img class="lazy" data-original="{{src}}" alt="">
<span class="name g-title">{{name}}</span>
<span class="des g-title">{{des}}</span>
</a>
</li>
{{/ list}}
</ul>
</div>
{{/ ads}}
{{/ brands}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
{{> layout/header}}
<div class="home-page yoho-page brands" data-page="brands">
{{# brands}}
<div class="sit-nav">
<a href="#">BOYS首页</a><span class="sep">></span><a href="#">品牌一览</a>
</div>
<div class="brands-tabs height-initial">
<ul class="clearfix">
{{#each tabs}}
<li>
<a href="{{url}}" target="_blank">
<div class="g-mask"></div>
<p class="tips">{{name}}</p>
<img class="lazy" data-original="{{src}}"/>
</a>
</li>
{{/each}}
</ul>
<div class="hover-contain">
<div class="hoverarr">
<i></i>
</div>
</div>
</div>
<div class="brands-items clearfix">
{{#each items}}
<div class="brands-item clearfix">
<a class="brands-pic" title="{{name}}" href="{{url}}" target="_blank">
<img class="lazy" data-original="{{src}}"/>
</a>
<div class="brand-info">
<a title="{{name}}" href="{{url}}" target="_blank">
<h3>
{{name}}
</h3>
</a>
<div class="brand-desc">{{desc}}</div>
</div>
</div>
{{/each}}
</div>
<div class="pagination">
<a href="#" class="page_pre" title="上一页"><i class="iconfont">&#xe60f;</i>上一页</a>
<a href="#"><span>1</span></a>
<a href="#" class="cur"><span>2</span></a>
<a href="#"><span>3</span></a>
<a href="#"><span>4</span></a>
<a href="#"><span>5</span></a>
<a><span>...</span></a>
<a href="#"><span>215</span></a>
<a href="#" title="下一页">下一页<i class="iconfont">&#xe60e;</i></a>
</div>
{{/ brands}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
{{> layout/header}}
<div class="home-page yoho-page brands" data-page="brands">
{{# brands}}
{{> layout/path-nav}}
<div class="brands-tabs height-initial">
<ul class="clearfix">
{{#each tabs}}
<li>
<a href="{{url}}">
<div class="g-mask"></div>
<p class="tips">{{name}}</p>
<img class="lazy" data-original="{{src}}"/>
</a>
</li>
{{/each}}
</ul>
<div class="hover-contain">
<div class="hoverarr">
<i></i>
</div>
</div>
</div>
<div class="brands-items clearfix">
{{#each items}}
<div class="brands-item clearfix">
<a class="brands-pic" title="{{name}}" href="{{url}}" target="_blank">
<img class="lazy" data-original="{{src}}"/>
</a>
<div class="brand-info">
<a title="{{name}}" href="{{url}}" target="_blank">
<h3>
{{name}}
</h3>
</a>
<div class="brand-desc">{{desc}}</div>
</div>
</div>
{{/each}}
</div>
<div class="pagination clearfix">
{{{page}}}
</div>
{{/ brands}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...
{{> layout/header}}
<div class="home-page yoho-page brands" data-page="brands">
{{# brands}}
{{! 头部banner}}
{{# slide}}
{{>index/slide-banner}}
{{/ slide}}
{{! 品牌 BRAND}}
{{# brand}}
{{> index/floor-header}}
<div class="brandfloor list-floor clearfix">
<ul class="g-list">
{{# list}}
<li>
<a href="{{href}}" target= "_blank">
<img class="lazy" data-original="{{img}}" alt="">
</a>
</li>
{{/ list}}
</ul>
</div>
{{/ brand}}
{{! 单品 SINGLE GOODS}}
{{# singlegoods}}
{{> index/floor-header}}
<div class="singlegoods list-floor clearfix">
<ul class="g-list">
{{# list}}
<li>
<a href="{{href}}" target= "_blank">
<img class="lazy" data-original="{{img}}" alt="">
<div class="singlegoods-title">
<div class="g-mask"></div>
<p>{{name}}</p>
</div>
</a>
</li>
{{/ list}}
</ul>
</div>
{{/ singlegoods}}
{{!视频 VIDEO}}
{{# video}}
{{> index/floor-header}}
<div class="video list-floor clearfix">
<ul class="g-list">
{{# list}}
<li>
<a href="{{href}}" target= "_blank">
<img class="lazy" data-original="{{img}}" alt="" /><i class="video-play"></i>
<div class="video-title">
<div class="g-mask"></div>
<p>{{name}}</p>
</div>
</a>
</li>
{{/ list}}
</ul>
</div>
{{/ video}}
{{!新闻 NEWS}}
{{# news}}
{{> index/floor-header}}
<div class="news clearfix">
<div class="news-pic">
{{# pics}}
{{>index/slide-banner}}
{{/ pics}}
</div>
<div class="news-txt">
{{# txts}}
<ul>
{{#each list}}
<li>
<i class="iconfont">&#xe619;</i><a href="{{href}}" target= "_blank">{{name}}</a>
</li>
{{/each}}
</ul>
{{/ txts}}
</div>
</div>
{{/ news}}
{{!推广 AD}}
{{# ads}}
<div class="ads list-floor clearfix">
<ul class="g-list">
{{# list}}
<li>
<a href="{{href}}" target= "_blank">
<img class="lazy" data-original="{{img}}" alt="">
<span class="name g-title">{{name}}</span>
<span class="des g-title">{{des}}</span>
</a>
</li>
{{/ list}}
</ul>
</div>
{{/ ads}}
{{/ brands}}
</div>
{{> layout/footer}}
\ No newline at end of file
... ...