Authored by hongweigao

品牌一览

  1 +/**
  2 + * 品牌一览 controller
  3 + * @author: ghw<hongwei.gao@yoho.cn>
  4 + * @date: 2016/9/29
  5 + */
  6 +
  7 +'use strict';
  8 +const mRoot = '../models';
  9 +const helpers = global.yoho.helpers;
  10 +
  11 +const brandsModel = require(`${mRoot}/brands-service`); // students model
  12 +
  13 +/**
  14 + * brands 首页
  15 + * @param {[type]} req [description]
  16 + * @param {[type]} res [description]
  17 + * @return {[type]} [description]
  18 + */
  19 +
  20 +exports.index = (req, res, next) => {
  21 + let channel = req.query.channel || req.cookies._Channel || 'boys';
  22 +
  23 + brandsModel.getBrandViewList(channel, req).then(result => {
  24 +
  25 + res.render('brands', result);
  26 +
  27 + }).catch(next);
  28 +};
  1 +/**
  2 + * router of sub app brands
  3 + * @author: ghw<hongwei.gao@yoho.cn>
  4 + * @date: 2016/09/29
  5 + */
  6 +
  7 +var express = require('express'),
  8 + path = require('path'),
  9 + hbs = require('express-handlebars');
  10 +
  11 +var app = express();
  12 +
  13 +// set view engin
  14 +var doraemon = path.join(__dirname, '../../doraemon/views'); // parent view root
  15 +
  16 +app.on('mount', function(parent) {
  17 + delete parent.locals.settings; // 不继承父 App 的设置
  18 + Object.assign(app.locals, parent.locals);
  19 +});
  20 +
  21 +app.set('views', path.join(__dirname, 'views/action'));
  22 +app.engine('.hbs', hbs({
  23 + extname: '.hbs',
  24 + defaultLayout: 'layout',
  25 + layoutsDir: doraemon,
  26 + partialsDir: [path.join(__dirname, 'views/partial'), `${doraemon}/partial`],
  27 + helpers: global.yoho.helpers
  28 +}));
  29 +
  30 +// router
  31 +app.use(require('./router'));
  32 +
  33 +module.exports = app;
  1 +/**
  2 + * 品牌一览 api
  3 + * @author: ghw<hongwei.gao@yoho.cn>
  4 + * @date: 2016/9/29
  5 + */
  6 +'use strict';
  7 +const api = global.yoho.API;
  8 +const serviceAPI = global.yoho.ServiceAPI;
  9 +
  10 +/**
  11 + * 分开取数,品牌一览 顶部的轮翻广告及热门品牌数据-PC
  12 + * 顶部的轮翻广告及热门品牌数据
  13 + * @param string $contentCode 获取广告资源需要的位置码
  14 + */
  15 +const getBrandTopData = (contentCode) => {
  16 + return serviceAPI.get('operations/api/v5/resource/get', {
  17 + content_code: contentCode
  18 + });
  19 +};
  20 +/**
  21 + * 分开取数,获取品牌一览 "按字母'A-Z'分组的品牌列表数据"
  22 + * @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
  23 + */
  24 +const getBrandListData = channel => {
  25 + let params = {method: 'app.brand.brandlist'};
  26 + if(!isNaN(channel)) {
  27 + params.yh_channel= channel;
  28 + }
  29 + return api.get('', params);
  30 +};
  31 +
  32 +module.exports = {
  33 + getBrandTopData,
  34 + getBrandListData
  35 +};
  1 +
  2 +/**
  3 + * 品牌一览 model
  4 + * @author: ghw<hongwei.gao@yoho.cn>
  5 + * @date: 2016/9/29
  6 + */
  7 +'use strict';
  8 +
  9 +const Promise = require('bluebird');
  10 +const co = Promise.coroutine;
  11 +const _ = require('lodash');
  12 +const helpers = global.yoho.helpers;
  13 +const brandApi = require('./brands-api');
  14 +//品牌一览资源位CODE码
  15 +const channelCode = {
  16 + boys_brand: '8b16b7baf9a66fbe553a6caa97d2ce2a',
  17 + girls_brand: 'c95ae9e40f0add10549b819f821ad626',
  18 + kids_brand: 'c575c6bfdfa4125fae7d24bbec7119c8',
  19 + lifestyle_brand: '84b7926282fdef92f1039bdcf77c18ba',
  20 + brand_list: 'f0f72b1e8f30e6ad086dfc4401f3a856', //品牌列表资源位CODE码
  21 + brand_plusstar_banner_boys: 'd0149783b8dd2adaf083fd10556c39a9',
  22 + brand_plusstar_banner_girls: 'd0149783b8dd2adaf083fd10556c39a9',
  23 + brand_plusstarindex_boys: 'a833aed63d28457156310e97faa7fa37',//plusstarindex男首资源位
  24 + brand_plusstarindex_girls: '6e4f162be3b3ba44f3bfcf1c38bdb745',//plusstarindex女首资源位
  25 +};
  26 +const BOYS = 'boys';
  27 +const GIRLS = 'girls';
  28 +const KIDS = 'kids';
  29 +const LIFESTYLE = 'lifestyle';
  30 +/**
  31 + * 获取品牌一览资源位&channelType
  32 + *
  33 + * @param string $channelStr
  34 + * @return array
  35 + */
  36 +const switchBrandParams = channel => {
  37 + let req = {};
  38 +
  39 + switch (channel) {
  40 +
  41 + case BOYS:
  42 + req = {
  43 + channelType: 1,
  44 + brandCode: channelCode.brand_plusstar_banner_boys
  45 + }
  46 + break;
  47 + case GIRLS:
  48 + req = {
  49 + channelType: 2,
  50 + brandCode: channelCode.brand_plusstar_banner_girls
  51 + }
  52 + break;
  53 + case KIDS:
  54 + req = {
  55 + channelType: 3,
  56 + brandCode: channelCode.kids_brand
  57 + }
  58 + break;
  59 + case LIFESTYLE:
  60 + req = {
  61 + channelType: 4,
  62 + brandCode: channelCode.lifestyle_brand
  63 + }
  64 + break;
  65 + default:
  66 + req = {
  67 + channelType: 1,
  68 + brandCode: channelCode.boys_brand
  69 + }
  70 + break;
  71 + }
  72 + return req;
  73 +}
  74 +
  75 +/**
  76 + * 获取品牌一览页面,品牌top
  77 + * @param string $channel 频道名称
  78 + */
  79 +const getBrandViewTop = channel => {
  80 + return co(function*() {
  81 + let switchParams = switchBrandParams(channel);
  82 +
  83 + let res = yield brandApi.getBrandTopData(switchParams.brandCode);
  84 +
  85 + let result = {},
  86 + brandAds = [],
  87 + brandLogos = [];
  88 +
  89 + //头部10个品牌小图块 url
  90 + if (res.data[1].data && res.data[1].data.list) {
  91 + _.forEach(res.data[1].data.list, subValue => {
  92 + brandAds.push({
  93 + name: subValue.name,
  94 + src: helpers.image(subValue.src, 80, 50, 3),
  95 + url: helpers.urlFormat(subValue.url)
  96 + })
  97 + });
  98 + }
  99 + //头部品牌图块,广告位
  100 + if (res.data[0].data) {
  101 + _.forEach(res.data[0].data, subValue => {
  102 + let srcUrl;
  103 + //kids lifestyle 第一张图尺寸不同
  104 + if (switchParams.channelType === 1 || switchParams.channelType === 2) {
  105 + srcUrl = helpers.image(subValue.src, 222, 180, 3);
  106 + }else {
  107 + srcUrl = (subValue === 0) ? helpers.image(subValue.src, 570, 280, 3) :
  108 + helpers.image(subValue.src, 280, 280, 3);
  109 + }
  110 + brandLogos.push({
  111 + name: subValue.title,
  112 + src: srcUrl,
  113 + url: helpers.urlFormat(subValue.url)
  114 + })
  115 + });
  116 + }
  117 +
  118 + //整合brandTop数据结构,boys、girls
  119 + if (switchParams.channelType === 1 || switchParams.channelType === 2) {
  120 + result.isTab = true;
  121 + }
  122 + result.tabHeader = brandLogos;
  123 + result.logos = brandAds;
  124 +
  125 + return result;
  126 + })();
  127 +};
  128 +/*
  129 + * 获取品牌一览list
  130 + * @param string $channel 频道名称
  131 + * @param int start 开始位置 1 开始
  132 + * @param int length 取数长度 0 取到最后
  133 + */
  134 +const getBrandViewList = (channel, start, length) =>{
  135 + return co(function*() {
  136 + let switchParams = switchBrandParams(channel);
  137 +
  138 + let res = yield brandApi.getBrandListData(switchParams.brandCode);
  139 +
  140 + let result = {},
  141 + navigation = [];
  142 +
  143 + //品牌list A-Z 0-9
  144 + if (res.data.brands) {
  145 + let listTmp = {};
  146 +
  147 + _.forEach(res.data.brands, subValue => {
  148 + // if(_.isEmpty(subValue)){
  149 + // continue;
  150 + // }
  151 + _.forEach(subValue, ssubValue => {
  152 + //为品牌名称
  153 + let brandName = ssubValue.brand_name,
  154 + href;
  155 +
  156 + if (switchParams.channelType === 1) {
  157 + href = helpers.urlFormat(ssubValue.brand_domain) + '?gender=1,3';
  158 + }else if (switchParams.channelType === 2) {
  159 + href = helpers.urlFormat(ssubValue.brand_domain) + '?gender=2,3';
  160 + }else {
  161 + href = helpers.urlFormat(ssubValue.brand_domain);
  162 + }
  163 +
  164 + listTmp[brandName] = {
  165 + name: ssubValue.brand_name,
  166 + key: ssubValue.id,
  167 + href: href
  168 + }
  169 + if (ssubValue.is_hot === 'Y') {
  170 + listTmp[brandName].hot = 'hot';
  171 + }
  172 +
  173 + })
  174 + //按键值排序
  175 + })
  176 +
  177 + }
  178 + //只取部分数据
  179 + // begin = ($start - 1) ? ($start - 1) : 0;
  180 + // begin = ($begin > 0) ? $begin : 0;
  181 + // result = $length ? array_slice($result, $begin, $length) : array_slice($result, $begin);
  182 + // $result['navigation'] = $navigation;
  183 +
  184 + return result;
  185 + })();
  186 +};
  187 +module.exports = {
  188 + getBrandViewTop,
  189 + getBrandViewList
  190 +};
  1 +/**
  2 + * 品牌一览 controller
  3 + * @author: ghw<hongwei.gao@yoho.cn>
  4 + * @date: 2016/9/29
  5 + */
  6 +'use strict';
  7 +const api = global.yoho.API;
  8 +const headerModel = require('../../../doraemon/models/header');
  9 +const brandsModel = require('./brands-model');
  10 + /*
  11 + * 获取品牌一览list
  12 + * @param string $channel 频道名称
  13 + * @param int start 开始位置 1 开始
  14 + * @param int length 取数长度 0 取到最后
  15 + */
  16 +exports.getBrandViewList = (channel, req) => {
  17 + let apiMethod = [
  18 + headerModel.requestHeaderData(channel),
  19 + brandsModel.getBrandViewTop(channel),
  20 + brandsModel.getBrandViewList(channel)
  21 + ];
  22 +
  23 + return api.all(apiMethod).then(result => {
  24 + let responseData = {
  25 + module: 'brands',
  26 + page: 'brands'
  27 + };
  28 +
  29 + // 头部数据
  30 + Object.assign(responseData, result[0]);
  31 + // 品牌一览列表
  32 + responseData.brands = result[1];
  33 +
  34 + return responseData;
  35 + });
  36 +};
  1 +/**
  2 + * router of sub app brands
  3 + * @author: ghw<hongwei.gao@yoho.cn>
  4 + * @date: 2016/09/29
  5 + */
  6 +
  7 +'use strict';
  8 +
  9 +const express = require('express');
  10 +const cRoot = './controllers';
  11 +
  12 +const router = express.Router(); // eslint-disable-line
  13 +const brandsController = require(`${cRoot}/brands`);
  14 +
  15 +//品牌一览
  16 +router.get('', brandsController.index);
  17 +
  18 +
  19 +module.exports = router;
  1 +{{> brand/brand-list}}
  1 +<div class="home-page yoho-page brands" data-page="brands">
  2 + {{# brands}}
  3 +
  4 + {{> common/path-nav}}
  5 +
  6 + {{#if isTab}}
  7 + <div class="brands-tabs">
  8 + <ul class="clearfix">
  9 + {{#each tabHeader}}
  10 + <li>
  11 + <a href="{{url}}">
  12 + <div class="g-mask"></div>
  13 + <p class="tips">{{name}}</p>
  14 + <img class="lazy" data-original="{{src}}"/>
  15 + </a>
  16 + </li>
  17 + {{/each}}
  18 + </ul>
  19 + <div class="hover-contain">
  20 + <div class="hoverarr">
  21 + <i></i>
  22 + </div>
  23 + </div>
  24 + </div>
  25 + {{^}}
  26 + <ul class="brands-ad clearfix">
  27 + {{#each tabHeader}}
  28 + <li>
  29 + <a href="{{url}}" target="_blank">
  30 + <img class="lazy" data-original="{{src}}">
  31 + </a>
  32 + </li>
  33 + {{/each}}
  34 + </ul>
  35 + {{/if}}
  36 + <div class="brands-logo clearfix">
  37 + {{#each logos}}
  38 + <a href="{{url}}" title="{{name}}" target="_blank">
  39 + <img class="lazy" data-original="{{src}}">
  40 + </a>
  41 + {{/each}}
  42 + </div>
  43 + <div class="brands-category">
  44 + <div class="category-nav">
  45 + <span>BRANDS A-Z:</span>
  46 + {{#each navigation}}
  47 + <a href="#{{this}}">{{this}}</a>
  48 + {{/each}}
  49 + </div>
  50 + </div>
  51 + <div class="brands-list" >
  52 + </div>
  53 + {{/ brands}}
  54 +</div>
  1 +{{> layout/header}}
  2 +<div class="home-page yoho-page brands" data-page="brands">
  3 +{{# brands}}
  4 +
  5 +
  6 + {{! 头部banner}}
  7 + {{# slide}}
  8 + {{>index/slide-banner}}
  9 + {{/ slide}}
  10 +
  11 + {{! 品牌 BRAND}}
  12 + {{# brand}}
  13 + {{> index/floor-header}}
  14 + <div class="brandfloor clearfix">
  15 + <ul class="g-list">
  16 + {{# list}}
  17 + <li>
  18 + <a href="{{url}}" target= "_blank">
  19 + <img class="lazy" data-original="{{src}}" alt="">
  20 +
  21 + </a>
  22 + </li>
  23 + {{/ list}}
  24 + </ul>
  25 + </div>
  26 + {{/ brand}}
  27 +
  28 + {{! 单品 SINGLE GOODS}}
  29 + {{# singlegoods}}
  30 + {{> index/floor-header}}
  31 + <div class="singlegoods clearfix">
  32 + <ul class="g-list">
  33 + {{# list}}
  34 + <li>
  35 + <a href="{{url}}" target= "_blank">
  36 + <img class="lazy" data-original="{{src}}" alt="">
  37 + <div class="singlegoods-title">
  38 + <div class="g-mask"></div>
  39 + <p>{{name}}</p>
  40 + </div>
  41 + </a>
  42 + </li>
  43 + {{/ list}}
  44 + </ul>
  45 + </div>
  46 + {{/ singlegoods}}
  47 +
  48 + {{!视频 VIDEO}}
  49 + {{# video}}
  50 + {{> index/floor-header}}
  51 + <div class="video clearfix">
  52 + <ul class="g-list">
  53 + {{# list}}
  54 + <li>
  55 + <a href="{{url}}" target= "_blank">
  56 + <img class="lazy" data-original="{{src}}" alt="" /><i class="video-play"></i>
  57 + <div class="video-title">
  58 + <div class="g-mask"></div>
  59 + <p>{{name}}</p>
  60 + </div>
  61 + </a>
  62 + </li>
  63 + {{/ list}}
  64 + </ul>
  65 + </div>
  66 + {{/ video}}
  67 +
  68 + {{!新闻 NEWS}}
  69 + {{# news}}
  70 + {{> index/floor-header}}
  71 + <div class="news clearfix">
  72 + <div class="news-pic">
  73 + {{# pics}}
  74 + {{>index/slide-banner}}
  75 + {{/ pics}}
  76 + </div>
  77 + <div class="news-txt">
  78 + {{# txts}}
  79 + <ul>
  80 + {{#each list}}
  81 + <li>
  82 + <i class="iconfont">&#xe619;</i><a href="{{url}}">{{name}}</a>
  83 + </li>
  84 + {{/each}}
  85 + </ul>
  86 + {{/ txts}}
  87 + </div>
  88 + </div>
  89 + {{/ news}}
  90 +
  91 + {{!推广 AD}}
  92 + {{# ads}}
  93 + <div class="ads clearfix">
  94 + <ul class="g-list">
  95 + {{# list}}
  96 + <li>
  97 + <a href="{{url}}" target= "_blank">
  98 + <img class="lazy" data-original="{{src}}" alt="">
  99 + <span class="name g-title">{{name}}</span>
  100 + <span class="des g-title">{{des}}</span>
  101 + </a>
  102 + </li>
  103 + {{/ list}}
  104 + </ul>
  105 + </div>
  106 + {{/ ads}}
  107 +{{/ brands}}
  108 +</div>
  109 +{{> layout/footer}}
  1 +{{> layout/header}}
  2 +<div class="home-page yoho-page brands" data-page="brands">
  3 +{{# brands}}
  4 + <div class="sit-nav">
  5 + <a href="#">BOYS首页</a><span class="sep">></span><a href="#">品牌一览</a>
  6 + </div>
  7 + <div class="brands-tabs height-initial">
  8 + <ul class="clearfix">
  9 + {{#each tabs}}
  10 + <li>
  11 + <a href="{{url}}" target="_blank">
  12 + <div class="g-mask"></div>
  13 + <p class="tips">{{name}}</p>
  14 + <img class="lazy" data-original="{{src}}"/>
  15 + </a>
  16 + </li>
  17 + {{/each}}
  18 + </ul>
  19 + <div class="hover-contain">
  20 + <div class="hoverarr">
  21 + <i></i>
  22 + </div>
  23 + </div>
  24 + </div>
  25 + <div class="brands-items clearfix">
  26 + {{#each items}}
  27 + <div class="brands-item clearfix">
  28 + <a class="brands-pic" title="{{name}}" href="{{url}}" target="_blank">
  29 + <img class="lazy" data-original="{{src}}"/>
  30 + </a>
  31 + <div class="brand-info">
  32 + <a title="{{name}}" href="{{url}}" target="_blank">
  33 + <h3>
  34 + {{name}}
  35 + </h3>
  36 + </a>
  37 + <div class="brand-desc">{{desc}}</div>
  38 + </div>
  39 + </div>
  40 + {{/each}}
  41 + </div>
  42 + <div class="pagination">
  43 + <a href="#" class="page_pre" title="上一页"><i class="iconfont">&#xe60f;</i>上一页</a>
  44 + <a href="#"><span>1</span></a>
  45 + <a href="#" class="cur"><span>2</span></a>
  46 + <a href="#"><span>3</span></a>
  47 + <a href="#"><span>4</span></a>
  48 + <a href="#"><span>5</span></a>
  49 + <a><span>...</span></a>
  50 + <a href="#"><span>215</span></a>
  51 + <a href="#" title="下一页">下一页<i class="iconfont">&#xe60e;</i></a>
  52 + </div>
  53 +{{/ brands}}
  54 +</div>
  55 +{{> layout/footer}}
  1 +{{> layout/header}}
  2 +<div class="home-page yoho-page brands" data-page="brands">
  3 +{{# brands}}
  4 +
  5 + {{> layout/path-nav}}
  6 +
  7 + <div class="brands-tabs height-initial">
  8 + <ul class="clearfix">
  9 + {{#each tabs}}
  10 + <li>
  11 + <a href="{{url}}">
  12 + <div class="g-mask"></div>
  13 + <p class="tips">{{name}}</p>
  14 + <img class="lazy" data-original="{{src}}"/>
  15 + </a>
  16 + </li>
  17 + {{/each}}
  18 + </ul>
  19 + <div class="hover-contain">
  20 + <div class="hoverarr">
  21 + <i></i>
  22 + </div>
  23 + </div>
  24 + </div>
  25 + <div class="brands-items clearfix">
  26 + {{#each items}}
  27 + <div class="brands-item clearfix">
  28 + <a class="brands-pic" title="{{name}}" href="{{url}}" target="_blank">
  29 + <img class="lazy" data-original="{{src}}"/>
  30 + </a>
  31 + <div class="brand-info">
  32 + <a title="{{name}}" href="{{url}}" target="_blank">
  33 + <h3>
  34 + {{name}}
  35 + </h3>
  36 + </a>
  37 + <div class="brand-desc">{{desc}}</div>
  38 + </div>
  39 + </div>
  40 + {{/each}}
  41 + </div>
  42 + <div class="pagination clearfix">
  43 + {{{page}}}
  44 + </div>
  45 +{{/ brands}}
  46 +</div>
  47 +{{> layout/footer}}
  1 +{{> layout/header}}
  2 +<div class="home-page yoho-page brands" data-page="brands">
  3 +{{# brands}}
  4 +
  5 +
  6 + {{! 头部banner}}
  7 + {{# slide}}
  8 + {{>index/slide-banner}}
  9 + {{/ slide}}
  10 +
  11 + {{! 品牌 BRAND}}
  12 + {{# brand}}
  13 + {{> index/floor-header}}
  14 + <div class="brandfloor list-floor clearfix">
  15 + <ul class="g-list">
  16 + {{# list}}
  17 + <li>
  18 + <a href="{{href}}" target= "_blank">
  19 + <img class="lazy" data-original="{{img}}" alt="">
  20 +
  21 + </a>
  22 + </li>
  23 + {{/ list}}
  24 + </ul>
  25 + </div>
  26 + {{/ brand}}
  27 +
  28 + {{! 单品 SINGLE GOODS}}
  29 + {{# singlegoods}}
  30 + {{> index/floor-header}}
  31 + <div class="singlegoods list-floor clearfix">
  32 + <ul class="g-list">
  33 + {{# list}}
  34 + <li>
  35 + <a href="{{href}}" target= "_blank">
  36 + <img class="lazy" data-original="{{img}}" alt="">
  37 + <div class="singlegoods-title">
  38 + <div class="g-mask"></div>
  39 + <p>{{name}}</p>
  40 + </div>
  41 + </a>
  42 + </li>
  43 + {{/ list}}
  44 + </ul>
  45 + </div>
  46 + {{/ singlegoods}}
  47 +
  48 + {{!视频 VIDEO}}
  49 + {{# video}}
  50 + {{> index/floor-header}}
  51 + <div class="video list-floor clearfix">
  52 + <ul class="g-list">
  53 + {{# list}}
  54 + <li>
  55 + <a href="{{href}}" target= "_blank">
  56 + <img class="lazy" data-original="{{img}}" alt="" /><i class="video-play"></i>
  57 + <div class="video-title">
  58 + <div class="g-mask"></div>
  59 + <p>{{name}}</p>
  60 + </div>
  61 + </a>
  62 + </li>
  63 + {{/ list}}
  64 + </ul>
  65 + </div>
  66 + {{/ video}}
  67 +
  68 + {{!新闻 NEWS}}
  69 + {{# news}}
  70 + {{> index/floor-header}}
  71 + <div class="news clearfix">
  72 + <div class="news-pic">
  73 + {{# pics}}
  74 + {{>index/slide-banner}}
  75 + {{/ pics}}
  76 + </div>
  77 + <div class="news-txt">
  78 + {{# txts}}
  79 + <ul>
  80 + {{#each list}}
  81 + <li>
  82 + <i class="iconfont">&#xe619;</i><a href="{{href}}" target= "_blank">{{name}}</a>
  83 + </li>
  84 + {{/each}}
  85 + </ul>
  86 + {{/ txts}}
  87 + </div>
  88 + </div>
  89 + {{/ news}}
  90 +
  91 + {{!推广 AD}}
  92 + {{# ads}}
  93 + <div class="ads list-floor clearfix">
  94 + <ul class="g-list">
  95 + {{# list}}
  96 + <li>
  97 + <a href="{{href}}" target= "_blank">
  98 + <img class="lazy" data-original="{{img}}" alt="">
  99 + <span class="name g-title">{{name}}</span>
  100 + <span class="des g-title">{{des}}</span>
  101 + </a>
  102 + </li>
  103 + {{/ list}}
  104 + </ul>
  105 + </div>
  106 + {{/ ads}}
  107 +{{/ brands}}
  108 +</div>
  109 +{{> layout/footer}}