Authored by yyq

品类大全页

1 'use strict'; 1 'use strict';
2 const headerModel = require('../../../doraemon/models/header'); 2 const headerModel = require('../../../doraemon/models/header');
  3 +const aboutModel = require('../models/about');
3 4
4 let responseData = { 5 let responseData = {
5 module: 'about', 6 module: 'about',
@@ -71,10 +72,42 @@ const link = (req, res, next) => { @@ -71,10 +72,42 @@ const link = (req, res, next) => {
71 }).catch(next); 72 }).catch(next);
72 }; 73 };
73 74
  75 +/**
  76 + * 品类大全
  77 + */
  78 +const category = (req, res, next) => {
  79 + let channel = req.yoho.channel || 'boys';
  80 + let resData = {};
  81 +
  82 + return Promise.all([
  83 + headerModel.requestHeaderData(channel),
  84 + req.ctx(aboutModel).getCategoryDataWithCache(channel)
  85 + ]).then(result => {
  86 + Object.assign(resData, responseData, result[0], result[1]);
  87 +
  88 + res.render('category', resData);
  89 + }).catch(next);
  90 +};
  91 +
  92 +/**
  93 + * 产品大全
  94 + */
  95 +const chanpin = (req, res, next) => {
  96 + let channel = req.yoho.channel || 'boys';
  97 +
  98 + headerModel.requestHeaderData(channel).then(result => {
  99 + responseData.headerData = result.headerData;
  100 +
  101 + res.render('chanpin', responseData);
  102 + }).catch(next);
  103 +};
  104 +
74 module.exports = { 105 module.exports = {
75 yohobuy, 106 yohobuy,
76 newpower, 107 newpower,
77 contact, 108 contact,
78 privacy, 109 privacy,
79 - link 110 + link,
  111 + category,
  112 + chanpin
80 }; 113 };
  1 +
  2 +const _ = require('lodash');
  3 +const cache = global.yoho.cache;
  4 +const logger = global.yoho.logger;
  5 +const helpers = global.yoho.helpers;
  6 +
  7 +const hotBrandsModel = require('../../../doraemon/models/hot-brands');
  8 +
  9 +const CACHE_TIME_S = 60 * 60;
  10 +
  11 +const indexUrl = {
  12 + boys: helpers.urlFormat('/'),
  13 + girls: helpers.urlFormat('/woman'),
  14 + kids: helpers.urlFormat('/kids'),
  15 + lifestyle: helpers.urlFormat('/lifestyle')
  16 +};
  17 +
  18 +module.exports = class extends global.yoho.BaseModel {
  19 + constructor(ctx) {
  20 + super(ctx);
  21 + }
  22 +
  23 + getCategoryFromApi(channel) {
  24 + return this.get({data: {
  25 + method: 'web.regular.groupsort.sale',
  26 + sales: 'Y', // 在销售商品分类
  27 + status: 1, // 上架商品分类
  28 + stocknumber: 1, // 过滤掉已售罄
  29 + yh_channel: channel
  30 + }, param: {cache: true}});
  31 + }
  32 + getCategoryData(channel) {
  33 + return Promise.all([
  34 + this.getCategoryFromApi(1),
  35 + this.getCategoryFromApi(2),
  36 + this.getCategoryFromApi(3),
  37 + this.getCategoryFromApi(4),
  38 + hotBrandsModel.hotBrands()
  39 + ]).then(result => {
  40 + let nameMap = ['男生', '女生', '潮童', '创意生活'];
  41 + let genderMap = ['1,3', '2,3'];
  42 + let categoryList = [];
  43 +
  44 + let hotBrands = result.pop();
  45 +
  46 + _.forEach(result, (res, index) => {
  47 + if (res.code !== 200) {
  48 + return;
  49 + }
  50 +
  51 + res = res.data;
  52 +
  53 + let list = [],
  54 + gender = genderMap[index];
  55 +
  56 + _.forEach(res, cate => {
  57 + let sub = [];
  58 +
  59 + _.forEach(cate.sub, scate => {
  60 + sub.push({
  61 + name: scate.category_name,
  62 + url: {category_id: scate.category_id, gender: gender}
  63 + });
  64 + });
  65 +
  66 + list.push({
  67 + title: cate.category_name,
  68 + sub: sub
  69 + });
  70 + });
  71 +
  72 + categoryList.push({
  73 + channelName: nameMap[index],
  74 + list: list
  75 + });
  76 + });
  77 +
  78 + let upChannel = _.toUpper(channel);
  79 +
  80 + return {
  81 + pathNav: [
  82 + {pathTitle: `${upChannel}首页`, name: `${upChannel}首页`, href: indexUrl[channel]},
  83 + {pathTitle: '全部分类', name: '全部分类'}
  84 + ],
  85 + hotBrands,
  86 + categoryList
  87 + };
  88 + });
  89 + }
  90 + getCategoryDataWithCache(channel) {
  91 + let cacheKey = 'seo_category_group_map';
  92 +
  93 + return cache.get(cacheKey).then(cdata => {
  94 + let cdataObj;
  95 +
  96 + if (cdata) {
  97 + try {
  98 + cdataObj = JSON.parse(cdata);
  99 + } catch (e) {
  100 + logger.debug('category map cache data parse fail.');
  101 + }
  102 + }
  103 +
  104 + if (cdataObj) {
  105 + return cdataObj;
  106 + }
  107 +
  108 + return this.getCategoryData(channel).then(list => {
  109 + if (list && list.length) {
  110 + cache.set(cacheKey, list, CACHE_TIME_S);
  111 + }
  112 + return list;
  113 + });
  114 + }).catch(err => {
  115 + logger.debug(`get category map cache data fail:${err.toString()}`);
  116 +
  117 + return this.getCategoryData(channel);
  118 + });
  119 + }
  120 +
  121 + getChanpinData() {
  122 +
  123 + }
  124 +};
@@ -13,5 +13,8 @@ router.get('/newpower.html', aboutCtrl.newpower); @@ -13,5 +13,8 @@ router.get('/newpower.html', aboutCtrl.newpower);
13 router.get('/contact.html', aboutCtrl.contact); 13 router.get('/contact.html', aboutCtrl.contact);
14 router.get('/privacy.html', aboutCtrl.privacy); 14 router.get('/privacy.html', aboutCtrl.privacy);
15 router.get('/link.html', aboutCtrl.link); 15 router.get('/link.html', aboutCtrl.link);
  16 +router.get('/categorymap.html', aboutCtrl.category);
  17 +router.get('/chanpinmap.html', aboutCtrl.link);
  18 +
16 19
17 module.exports = router; 20 module.exports = router;
  1 +<div class="category-map-page center-content yoho-page">
  2 + {{> common/path-nav}}
  3 +
  4 + <div class="list-block">
  5 + <h1 class="main-title">全部分类</h1>
  6 + {{# categoryList}}
  7 + <p class="channel-name">{{channelName}}</p>
  8 + {{# list}}
  9 + <p><label class="left-title">{{title}}:</label>
  10 + {{# sub}}<a href="#">{{name}}</a>{{/ sub}}
  11 + </p>
  12 + {{/ list}}
  13 + {{/ categoryList}}
  14 + </div>
  15 +
  16 + {{#if hotBrands}}
  17 + <div class="hot-brands clearfix">
  18 + {{# hotBrands}}
  19 + <a href="{{url}}" alt="{{title}}">
  20 + <img src="{{image image}}" title="{{title}}">
  21 + </a>
  22 + {{/ hotBrands}}
  23 + </div>
  24 + {{/if}}
  25 +</div>
  1 +.category-map-page {
  2 + .path-nav {
  3 + padding: 22px 0;
  4 + }
  5 +
  6 + .list-block {
  7 + font-size: 12px;
  8 + border: 1px solid #dfdfdf;
  9 + margin-bottom: 30px;
  10 +
  11 + .main-title {
  12 + line-height: 50px;
  13 + background-color: #eaeceb;
  14 + padding-left: 20px;
  15 + font-weight: bold;
  16 + }
  17 +
  18 + > p {
  19 + display: block;
  20 + padding: 10px 0 10px 100px;
  21 + line-height: 30px;
  22 + border-top: 1px solid #dfdfdf;
  23 + position: relative;
  24 + box-sizing: border-box;
  25 +
  26 + a {
  27 + margin-right: 20px;
  28 + }
  29 + }
  30 +
  31 + .left-title {
  32 + position: absolute;
  33 + left: 20px;
  34 + font-weight: bold;
  35 + }
  36 +
  37 + .channel-name {
  38 + padding-left: 0;
  39 + font-weight: bold;
  40 + text-align: center;
  41 + font-size: 14px;
  42 + }
  43 + }
  44 +
  45 + .hot-brands {
  46 + width: 101%;
  47 + margin-bottom: 70px;
  48 +
  49 + > a {
  50 + width: 116px;
  51 + height: 70px;
  52 + display: block;
  53 + padding: 10px 8px;
  54 + float: left;
  55 + box-sizing: border-box;
  56 + border: 1px solid #dfdfdf;
  57 + margin-left: -1px;
  58 + margin-top: -1px;
  59 + }
  60 +
  61 + img {
  62 + width: 100%;
  63 + height: 100%;
  64 + display: block;
  65 + }
  66 + }
  67 +}
@@ -4,3 +4,4 @@ @@ -4,3 +4,4 @@
4 @import "contact"; 4 @import "contact";
5 @import "link"; 5 @import "link";
6 @import "privacy"; 6 @import "privacy";
  7 +@import "category";