Authored by OF1706

brand ctx

... ... @@ -19,7 +19,7 @@ const brandsService = require(`${mRoot}/brands-service`); // students 页 model
exports.index = (req, res, next) => {
let channel = req.query.channel || req.cookies._Channel || 'boys';
brandsService.getBrandViewList(channel, req).then(result => {
req.ctx(brandsService).getBrandViewList(channel, req).then(result => {
// 返回null,不cashe
if (result.noCashe) {
res.set('Cache-Control', 'no-cache');
... ... @@ -35,7 +35,7 @@ exports.index = (req, res, next) => {
exports.brandList = (req, res, next) => {
let channel = req.query.channel || req.cookies._Channel || 'boys';
brandsService.getBrandList(channel, req.body.start).then(result => {
req.ctx(brandsService).getBrandList(channel, req.body.start).then(result => {
res.render('brands/brand-list', Object.assign({layout: false}, result));
... ... @@ -52,7 +52,7 @@ exports.brandInfo = (req, res, next) => {
let brandId = req.query.brandId || 0;
brandsService.brandInfo(brandId, req.user.uid).then(result => {
req.ctx(brandsService).brandInfo(brandId, req.user.uid).then(result => {
// 返回null,不cashe
if (result.noCashe) {
res.set('Cache-Control', 'no-cache');
... ... @@ -67,7 +67,7 @@ exports.brandInfo = (req, res, next) => {
exports.plusstarList = (req, res, next) => {
let channel = req.query.channel || req.yoho.channel;
brandsService.plusstarList(channel, req).then(result => {
req.ctx(brandsService).plusstarList(channel, req).then(result => {
// 返回null,不cashe
if (result.noCashe) {
res.set('Cache-Control', 'no-cache');
... ...
... ... @@ -4,100 +4,159 @@
* @date: 2016/9/29
*/
'use strict';
const api = global.yoho.API;
const serviceAPI = global.yoho.ServiceAPI;
const config = global.yoho.config;
/**
* 分开取数,品牌一览 顶部的轮翻广告及热门品牌数据-PC
* 顶部的轮翻广告及热门品牌数据
* @param string $contentCode 获取广告资源需要的位置码
*/
const getBrandTopData = (contentCode) => {
return serviceAPI.get('operations/api/v5/resource/get', {
content_code: contentCode
}, config.apiCache);
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 分开取数,获取品牌一览 "按字母'A-Z'分组的品牌列表数据"
* @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
*/
const getBrandListData = channel => {
let params = {method: 'app.brand.allBrandList'};
/**
* 分开取数,品牌一览 顶部的轮翻广告及热门品牌数据-PC
* 顶部的轮翻广告及热门品牌数据
* @param string $contentCode 获取广告资源需要的位置码
*/
getBrandTopData(contentCode) {
return this.get({
url: 'operations/api/v5/resource/get',
data: {
content_code: contentCode
},
param: {
cache: true
},
api: global.yoho.ServiceAPI
});
}
/**
* 分开取数,获取品牌一览 "按字母'A-Z'分组的品牌列表数据"
* @param int $channel 频道标识 1:男,2:女,3:潮童,4:创意生活
*/
getBrandListData(channel) {
let data = {
method: 'app.brand.allBrandList'
};
if (!isNaN(channel)) {
params.yh_channel = channel;
if (!isNaN(channel)) {
data.yh_channel = channel;
}
return this.get({
data: data,
param: {
code: 200,
cache: true
}
});
}
return api.get('', params, config.apiCache);
};
/**
* 获取品牌简介
*
* @param integer $brandId 品牌ID
* @param int 用户ID
* @return array 品牌介绍信息
*/
const getBrandIntro = (brandId, uid) => {
let param = {};
/**
* 获取品牌简介
*
* @param integer $brandId 品牌ID
* @param int 用户ID
* @return array 品牌介绍信息
*/
getBrandIntro(brandId, uid) {
let data = {
method: 'app.brand.getBrandIntro',
brand_id: brandId,
uid: uid
};
if (!uid) {
param.cache = 3600;
if (!uid) {
data.cache = 3600;
}
return this.get({
data: data,
param: {
code: 200,
cache: true
}
});
}
return api.get('', {
method: 'app.brand.getBrandIntro',
brand_id: brandId,
uid: uid
}, param, config.apiCache);
};
/**
* 获取品牌中产品图片
* @param int 品牌ID
* @return array 品牌产品信息
*/
const getProductByBrand = (brandId, limit) => {
return api.get('', {
method: 'web.search.search',
brand: brandId,
limit: limit
}, config.apiCache);
};
/**
* 获取品牌中产品图片
* @param int 品牌ID
* @return array 品牌产品信息
*/
getProductByBrand(brandId, limit) {
/**
* 获取品牌信息
*
* @param array $ids
* @return array
*/
const getBrandInfoByIds = (ids) => {
return api.get('', {
method: 'web.brand.info',
ids: ids instanceof Array ? ids.join(',') : parseInt(ids, 10)
}, config.apiCache);
};
let data = {
method: 'web.search.search',
brand: brandId,
limit: limit
};
/**
* 获取品牌列表
*
* @param int $brandType
* @param string $gender
* @param string $type
* @return array
*/
const getPlusstarList = (brandType, gender) => {
return serviceAPI.get('guang/api/v3/plustar/getlist', {
gender: gender,
brand_type: brandType
}, config.apiCache);
};
return this.get({
data: data,
param: {
code: 200,
cache: true
}
});
}
/**
* 获取品牌信息
*
* @param array $ids
* @return array
*/
getBrandInfoByIds(ids) {
let data = {
method: 'web.brand.info',
ids: ids instanceof Array ? ids.join(',') : parseInt(ids, 10)
};
return this.get({
data: data,
param: {
code: 200,
cache: true
}
});
}
/**
* 获取品牌列表
*
* @param int $brandType
* @param string $gender
* @param string $type
* @return array
*/
getPlusstarList(brandType, gender) {
return this.get({
url: 'guang/api/v3/plustar/getlist',
data: {
gender: gender,
brand_type: brandType
},
param: {
cache: true
},
api: global.yoho.ServiceAPI
});
}
getPlusstarBrandListItem(code) {
return this.get({
url: 'operations/api/v5/resource/get',
data: {
content_code: code
},
param: {
cache: 3600
},
api: global.yoho.ServiceAPI
});
}
module.exports = {
getBrandTopData,
getBrandListData,
getBrandIntro,
getProductByBrand,
getPlusstarList,
getBrandInfoByIds
};
... ...
... ... @@ -10,8 +10,9 @@ const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');
const helpers = global.yoho.helpers;
const brandApi = require('./brands-api');
const serviceApi = global.yoho.ServiceAPI;
const BrandApi = require('./brands-api');
const path = require('path');
const imgUtils = require(path.join(global.utils, 'images'));
// 品牌一览资源位CODE码
const channelCode = {
... ... @@ -33,410 +34,431 @@ const LIFESTYLE = 'lifestyle';
const GLOBAL_BASE_URI = '/product/global/list';
/**
* 获取品牌一览资源位&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;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return req;
};
/**
* 获取品牌一览页面,品牌top
* @param string $channel 频道名称
*/
const getBrandViewTop = channel => {
return co(function*() {
let switchParams = switchBrandParams(channel);
/**
* 获取品牌一览资源位&channelType
*
* @param string $channelStr
* @return array
*/
switchBrandParams(channel) {
let res = yield brandApi.getBrandTopData(switchParams.brandCode);
let req = {};
let result = {},
brandAds = [],
brandLogos = [];
switch (channel) {
if (!res || res.code !== 200) {
return result;
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;
}
// 头部10个品牌小图块 url
if (res.data && res.data instanceof Array && res.data[1].data && res.data[1].data.list) {
/**
* 获取品牌一览页面,品牌top
* @param string $channel 频道名称
*/
getBrandViewTop(channel) {
let that = this;
let brandData = new BrandApi(that.ctx);
_.forEach(res.data[1].data.list, subValue => {
brandAds.push({
name: subValue.name,
src: helpers.image(subValue.src, 80, 50, 3),
url: subValue.url
});
});
}
return co(function*() {
let switchParams = that.switchBrandParams(channel);
// 头部品牌图块,广告位
if (res.data && res.data instanceof Array && res.data[0].data) {
_.forEach(res.data[0].data, (subValue, k) => {
let srcUrl;
// kids lifestyle 第一张图尺寸不同
if (switchParams.channelType === 1 || switchParams.channelType === 2) {
srcUrl = helpers.image(subValue.src, 222, 180, 3);
} else {
srcUrl = (k === 0) ? helpers.image(subValue.src, 570, 280, 3) :
helpers.image(subValue.src, 280, 280, 3);
}
let brandPlusstarItem = {
name: subValue.title,
src: srcUrl,
url: subValue.url
};
let res = yield brandData.getBrandTopData(switchParams.brandCode);
if (channel === BOYS || channel === GIRLS) {
if (k === 0) {
brandPlusstarItem.url = helpers.urlFormat('/brands/plusstar', {channel: channel});
} else {
brandPlusstarItem.url = helpers.urlFormat('/brands/plusstar', {id: k, channel: channel});
}
}
let result = {},
brandAds = [],
brandLogos = [];
brandLogos.push(brandPlusstarItem);
});
}
if (!res || res.code !== 200) {
return result;
}
// 整合brandTop数据结构,boys、girls
if (switchParams.channelType === 1 || switchParams.channelType === 2) {
result.isTab = true;
}
result.tabHeader = brandLogos;
result.logos = brandAds;
// 头部10个品牌小图块 url
if (res.data && res.data instanceof Array && res.data[1].data && res.data[1].data.list) {
console.log(res.data[1].data.list);
_.forEach(res.data[1].data.list, subValue => {
brandAds.push({
name: subValue.name,
src: helpers.image(imgUtils.getImageUrl(
(subValue.src.match(/(\S*)imageView2/)[1] +
'imageMogr2/thumbnail/{width}x{height}/extent/{width}x{height}/' +
'background/d2hpdGU=/position/center/quality/80'),
136, 57), 136, 57),
url: subValue.url
});
});
}
return result;
})();
};
// 头部品牌图块,广告位
if (res.data && res.data instanceof Array && res.data[0].data) {
_.forEach(res.data[0].data, (subValue, k) => {
let srcUrl;
/**
* 获取品牌一览list
* @param string $channel 频道名称
* @param int start 开始位置 1 开始
* @param int length 取数长度 0 取到最后
*/
const getBrandViewList = (channel, start, length) => {
return co(function*() {
let switchParams = switchBrandParams(channel);
// kids lifestyle 第一张图尺寸不同
if (switchParams.channelType === 1 || switchParams.channelType === 2) {
srcUrl = helpers.image(subValue.src, 222, 180, 3);
} else {
srcUrl = (k === 0) ? helpers.image(subValue.src, 570, 280, 3) :
helpers.image(subValue.src, 280, 280, 3);
}
let brandPlusstarItem = {
name: subValue.title,
src: srcUrl,
url: subValue.url
};
if (channel === BOYS || channel === GIRLS) {
if (k === 0) {
brandPlusstarItem.url = helpers.urlFormat('/brands/plusstar', {channel: channel});
} else {
brandPlusstarItem.url = helpers.urlFormat('/brands/plusstar', {id: k, channel: channel});
}
}
let res = yield brandApi.getBrandListData(switchParams.channelType);
brandLogos.push(brandPlusstarItem);
});
}
let result = [],
numResult = {};
// 整合brandTop数据结构,boys、girls
if (switchParams.channelType === 1 || switchParams.channelType === 2) {
result.isTab = true;
}
result.tabHeader = brandLogos;
result.logos = brandAds;
if (!res || res.code !== 200) {
return result;
}
})();
}
// 品牌list A-Z 0-9
if (res.data && res.data.all_list) {
/**
* 获取品牌一览list
* @param string $channel 频道名称
* @param int start 开始位置 1 开始
* @param int length 取数长度 0 取到最后
*/
getBrandViewList(channel, start, length) {
let that = this;
let brandData = new BrandApi(that.ctx);
_.forEach(res.data.all_list, (subValue, key) => {
let listTmp = [];
return co(function*() {
let switchParams = that.switchBrandParams(channel);
_.forEach(subValue, ssubValue => {
let extQs = {};
let baseUri = '';
let res = yield brandData.getBrandListData(switchParams.channelType);
// 为品牌名称
let href;
let result = [],
numResult = {};
if (switchParams.channelType === 1) {
Object.assign(extQs, {gender: '1,3'});
} else if (switchParams.channelType === 2) {
Object.assign(extQs, {gender: '2,3'});
}
let shopInfo, shopId;
switch (ssubValue.type * 1) {
case 1:
extQs = {
query: ssubValue.brand_name,
brand: ssubValue.id
};
ssubValue.brand_domain = 'search';
break;
case 2:
shopInfo = _.get(ssubValue, 'shop_info.yoho_shop_list[0]', {});
shopId = shopInfo.shop_id || ssubValue.shop_id;
ssubValue.brand_domain = shopInfo.shop_domain || ssubValue.brand_domain;
if (shopId) {
Object.assign(extQs, {shopId: shopId});
}
break;
case 3:
Object.assign(extQs, {brand: ssubValue.global_brand_id});
ssubValue.brand_domain = '';
baseUri = GLOBAL_BASE_URI;
break;
default:
break;
}
if (!res || res.code !== 200) {
return result;
}
href = helpers.urlFormat(baseUri, extQs, ssubValue.brand_domain);
// 品牌list A-Z 0-9
if (res.data && res.data.all_list) {
_.forEach(res.data.all_list, (subValue, key) => {
let listTmp = [];
_.forEach(subValue, ssubValue => {
let extQs = {};
let baseUri = '';
// 为品牌名称
let href;
if (switchParams.channelType === 1) {
Object.assign(extQs, {gender: '1,3'});
} else if (switchParams.channelType === 2) {
Object.assign(extQs, {gender: '2,3'});
}
let shopInfo, shopId;
switch (ssubValue.type * 1) {
case 1:
extQs = {
query: ssubValue.brand_name,
brand: ssubValue.id
};
ssubValue.brand_domain = 'search';
break;
case 2:
shopInfo = _.get(ssubValue, 'shop_info.yoho_shop_list[0]', {});
shopId = shopInfo.shop_id || ssubValue.shop_id;
ssubValue.brand_domain = shopInfo.shop_domain || ssubValue.brand_domain;
if (shopId) {
Object.assign(extQs, {shopId: shopId});
}
break;
case 3:
Object.assign(extQs, {brand: ssubValue.global_brand_id});
ssubValue.brand_domain = '';
baseUri = GLOBAL_BASE_URI;
break;
default:
break;
}
href = helpers.urlFormat(baseUri, extQs, ssubValue.brand_domain);
let brandItem = {
name: ssubValue.brand_name,
key: ssubValue.id,
href: href
};
if (ssubValue.is_hot === 'Y') {
brandItem.hot = 'hot';
}
listTmp.push(brandItem);
let brandItem = {
name: ssubValue.brand_name,
key: ssubValue.id,
href: href
};
});
if (ssubValue.is_hot === 'Y') {
brandItem.hot = 'hot';
if (key.match(/\d+/g)) {
numResult = {// 把0-9提出来
key: key,
val: _.sortBy(listTmp, 'name')// 对name排序
};
} else {
result.push({
key: key,
val: _.sortBy(listTmp, 'name')// 对name排序
});
}
listTmp.push(brandItem);
});
if (key.match(/\d+/g)) {
numResult = {// 把0-9提出来
key: key,
val: _.sortBy(listTmp, 'name')// 对name排序
};
} else {
result.push({
key: key,
val: _.sortBy(listTmp, 'name')// 对name排序
});
}
});
}
// 只取部分数据
let begin;
if (start) {
begin = (start - 1) ? (start - 1) : 0;
begin = (begin > 0) ? begin : 0;
result = length ? result.slice(begin, length + begin) : result.slice(begin);
}
}
result = _.sortBy(result, 'key');// A-Z排序
result.push(numResult); // 0-9放到最后
result.navigation = _.map(result, 'key');
return result;
})();
};
// 只取部分数据
let begin;
/**
* 获取单个广告浮窗内容
*
* @param int $brandId
* @param int $uid
* @return array
*/
const getBrandInfo = (brandId, uid) => {
return co(function*() {
let data = {},
imgs = [];
// 获取品牌简介
let res = yield brandApi.getBrandIntro(brandId, uid);
if (start) {
begin = (start - 1) ? (start - 1) : 0;
begin = (begin > 0) ? begin : 0;
result = length ? result.slice(begin, length + begin) : result.slice(begin);
}
if (!res || res.code !== 200) {
return data;
}
if (res.data) {
// 获取品牌下的产品信息
let proInfo = yield brandApi.getProductByBrand(brandId, 3);
result = _.sortBy(result, 'key');// A-Z排序
result.push(numResult); // 0-9放到最后
result.navigation = _.map(result, 'key');
return result;
})();
}
if (!proInfo || proInfo.code !== 200) {
/**
* 获取单个广告浮窗内容
*
* @param int $brandId
* @param int $uid
* @return array
*/
getBrandInfo(brandId, uid) {
let that = this;
let brandData = new BrandApi(that.ctx);
return co(function*() {
let data = {},
imgs = [];
// 获取品牌简介
let res = yield brandData.getBrandIntro(brandId, uid);
if (!res || res.code !== 200) {
return data;
}
let proInfoTmp = proInfo.data.product_list ? proInfo.data.product_list : [];
if (res.data) {
// 获取品牌下的产品信息
let proInfo = yield brandData.getProductByBrand(brandId, 3);
if (!_.isEmpty(proInfoTmp)) {
_.forEach(proInfoTmp, subValue => {
imgs.push({
src: helpers.image(subValue.default_images, 80, 100, 3)
if (!proInfo || proInfo.code !== 200) {
return data;
}
let proInfoTmp = proInfo.data.product_list ? proInfo.data.product_list : [];
if (!_.isEmpty(proInfoTmp)) {
_.forEach(proInfoTmp, subValue => {
imgs.push({
src: helpers.image(subValue.default_images, 80, 100, 3)
});
});
});
}
// 整合
data = {
key: res.data.brand_id,
icon: helpers.image(res.data.brand_ico, 80, 50, 3),
title: res.data.brand_name,
content: res.data.brand_intro,
subtitle: 'FEATURED ITEMS',
imgs: imgs
};
}
return data;
})();
}
// 整合
data = {
key: res.data.brand_id,
icon: helpers.image(res.data.brand_ico, 80, 50, 3),
title: res.data.brand_name,
content: res.data.brand_intro,
subtitle: 'FEATURED ITEMS',
imgs: imgs
};
}
return data;
})();
};
/**
* 多个品牌ID获取品牌信息
*
* @param array $brandIds
* @return array
*/
getBrandInfoByIds(brandIds) {
let that = this;
let brandData = new BrandApi(that.ctx);
/**
* 多个品牌ID获取品牌信息
*
* @param array $brandIds
* @return array
*/
const getBrandInfoByIds = (brandIds) => {
return co(function*() {
let res = yield brandApi.getBrandInfoByIds(brandIds);
return co(function*() {
let res = yield brandData.getBrandInfoByIds(brandIds);
let brandsInfo = {};
let brandsInfo = {};
if (!res || res.code !== 200) {
return brandsInfo;
}
if (res.data && res.code === 200) {
_.forEach(res.data, (subValue, k) => {
subValue.desc = _.trim(subValue.brand_intro.replace(/(\t)|(\n)|(\r)|( )/g, '')
if (!res || res.code !== 200) {
return brandsInfo;
}
if (res.data && res.code === 200) {
_.forEach(res.data, (subValue, k) => {
subValue.desc = _.trim(subValue.brand_intro.replace(/(\t)|(\n)|(\r)|( )/g, '')
.replace(/<.*?>/ig, ''));
subValue.url = subValue.brand_domain;
delete subValue.brand_intro;
brandsInfo[k] = subValue;
});
}
subValue.url = subValue.brand_domain;
delete subValue.brand_intro;
brandsInfo[k] = subValue;
});
}
return brandsInfo;
})();
};
return brandsInfo;
})();
}
/**
* 获取plusstar品牌列表项目
*
* @param string $channel
* @return array
*/
const getPlusstarBrandListItem = (channel) => {
return co(function*() {
let code = channel === 'girls' ? channelCode.brand_plusstar_banner_girls :
channelCode.brand_plusstar_banner_boys;
/**
* 获取plusstar品牌列表项目
*
* @param string $channel
* @return array
*/
getPlusstarBrandListItem(channel) {
let that = this;
let brandData = new BrandApi(that.ctx);
// 资源位数据
let resource = yield serviceApi.get('operations/api/v5/resource/get', {content_code: code}, {cache: 3600});
return co(function*() {
let code = channel === 'girls' ? channelCode.brand_plusstar_banner_girls :
channelCode.brand_plusstar_banner_boys;
let items = [];
// 资源位数据
let resource = yield brandData.getPlusstarBrandListItem(code);
if (!resource || resource.code !== 200) {
return items;
}
if (resource.data && resource.code === 200) {
items[0] = {name: '所有品牌', src: '', url: helpers.urlFormat('/brands', {channel: channel}), brandType: ''};
items[1] = {name: '设计新潮', src: '', url: '', brandType: 4};
items[2] = {name: '潮流经典', src: '', url: '', brandType: 1};
items[3] = {name: '明星潮牌', src: '', url: '', brandType: 2};
items[4] = {name: '原创潮牌', src: '', url: '', brandType: 3};
let resourceData = resource.data,
pos = 0;
_.forEach(items, (subValue, k) => {
if (_.isEmpty(subValue.url)) {
subValue.url = helpers.urlFormat('/brands/plusstar', {id: k, channel: channel});
}
let items = [];
if (pos in resourceData[0].data) {
subValue.src = helpers.image(resourceData[0].data[pos].src, 222, 180, 1);
subValue.name = resourceData[0].data[pos].title;
}
pos++;
});
}
return items;
})();
};
/**
* 获取Plustar列表
*
* @param string $brandType
* @param string $gender
* @return array
*/
const getPlustarList = (brandType, gender) => {
return co(function*() {
let list = yield brandApi.getPlusstarList(brandType, gender);
if (!resource || resource.code !== 200) {
return items;
}
if (resource.data && resource.code === 200) {
items[0] = {name: '所有品牌', src: '', url: helpers.urlFormat('/brands',
{channel: channel}), brandType: ''};
items[1] = {name: '设计新潮', src: '', url: '', brandType: 4};
items[2] = {name: '潮流经典', src: '', url: '', brandType: 1};
items[3] = {name: '明星潮牌', src: '', url: '', brandType: 2};
items[4] = {name: '原创潮牌', src: '', url: '', brandType: 3};
let resourceData = resource.data,
pos = 0;
_.forEach(items, (subValue, k) => {
if (_.isEmpty(subValue.url)) {
subValue.url = helpers.urlFormat('/brands/plusstar', {id: k, channel: channel});
}
let brandList = {},
data = {},
brandsIds = [],
result = {brandsIds: [], data: {}};
if (pos in resourceData[0].data) {
subValue.src = helpers.image(resourceData[0].data[pos].src, 222, 180, 1);
subValue.name = resourceData[0].data[pos].title;
}
pos++;
});
}
if (!list || list.code !== 200) {
return result;
}
if (list.data && list.data.data && list.data.data.list) {
brandList = list.data.data.list[0];
}
if (brandList.data) {
_.forEach(brandList.data, brand => {
let src = '';
return items;
})();
}
if (brand.data[0]) {
src = helpers.image(brand.data[0].src, 320, 160, 1);
}
data[brand.brand_id] = {
brand_id: brand.brand_id,
name: brand.brand_name,
sort_id: brand.sort_id,
src: src,
desc: '',
url: ''
};
brandsIds.push(brand.brand_id);
});
/**
* 获取Plustar列表
*
* @param string $brandType
* @param string $gender
* @return array
*/
getPlustarList(brandType, gender) {
let that = this;
let brandData = new BrandApi(that.ctx);
return co(function*() {
let list = yield brandData.getPlusstarList(brandType, gender);
let brandList = {},
data = {},
brandsIds = [],
result = {brandsIds: [], data: {}};
if (!list || list.code !== 200) {
return result;
}
if (list.data && list.data.data && list.data.data.list) {
brandList = list.data.data.list[0];
}
if (brandList.data) {
_.forEach(brandList.data, brand => {
let src = '';
result.brandsIds = brandsIds;
result.data = data;
}
if (brand.data[0]) {
src = helpers.image(brand.data[0].src, 320, 160, 1);
}
data[brand.brand_id] = {
brand_id: brand.brand_id,
name: brand.brand_name,
sort_id: brand.sort_id,
src: src,
desc: '',
url: ''
};
brandsIds.push(brand.brand_id);
});
return result;
})();
};
result.brandsIds = brandsIds;
result.data = data;
}
module.exports = {
getBrandViewTop,
getBrandViewList,
getBrandInfo,
getBrandInfoByIds,
getPlusstarBrandListItem,
getPlustarList
return result;
})();
}
};
... ...
... ... @@ -9,7 +9,7 @@ const Promise = require('bluebird');
const co = Promise.coroutine;
const api = global.yoho.API;
const headerModel = require('../../../doraemon/models/header');
const brandsModel = require('./brands-model');
const BrandsModel = require('./brands-model');
const _ = require('lodash');
const helpers = global.yoho.helpers;
const pager = require(`${global.utils}/pager`).setPager;
... ... @@ -20,294 +20,314 @@ const KIDS = 'kids';
const LIFESTYLE = 'lifestyle';
const queryString = require('querystring');
/**
* 获取品牌一览资源位&channelType
*
* @param string $channelStr
* @return array
*/
const getGenderByChannel = channel => {
let gender = '';
switch (channel) {
case BOYS:
gender = '1,3';
break;
case GIRLS:
gender = '2,3';
break;
default:
gender = '1,2,3';
break;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return gender;
};
const getHomeurlByChannel = channel => {
let home;
switch (channel) {
case GIRLS:
home = helpers.urlFormat('/woman', {}, 'new');
break;
case LIFESTYLE:
home = helpers.urlFormat('/lifestyle', {}, 'new');
break;
case KIDS:
home = helpers.urlFormat('/kids', {}, 'new');
break;
default:
home = helpers.urlFormat('');
break;
/**
* 获取品牌一览资源位&channelType
*
* @param string $channelStr
* @return array
*/
getGenderByChannel(channel) {
let gender = '';
switch (channel) {
case BOYS:
gender = '1,3';
break;
case GIRLS:
gender = '2,3';
break;
default:
gender = '1,2,3';
break;
}
return gender;
}
return home;
};
// 添加网站的SEO
const seoMap = {
boys: {
title: '品牌一览|男装品牌排行榜,男装品牌大全|YOHO!BUY 有货 100%正品保证',
keywords: '品牌一览,男装品牌,男装品牌排行榜,男装品牌大全,YOHO!BUY 有货',
description: 'YOHO!BUY 有货男装品牌一览汇集国内国际各大男装品牌大全,为广大爱好时尚的男士青年提供品牌男装、' +
'休闲男装、商务男装.YOHO!BUY 有货,100%正品保证'
},
girls: {
title: '品牌一览|女装品牌排行榜,女装品牌大全|YOHO!BUY 有货 100%正品保证',
keywords: '品牌一览,女装品牌,女装品牌排行榜,女装品牌大全,YOHO!BUY 有货',
description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大女装品牌,为广大爱美女生提供品牌女装、休闲女装、' +
'商务女装.买品牌女装就上YOHO!BUY 有货,100%正品保证'
},
kids: {
title: '品牌一览|童装童鞋品牌,儿童鞋包配饰排行榜,潮童品牌大全|YOHO!BUY 有货 100%正品保证',
keywords: '童装品牌,童装童鞋排行榜,儿童鞋包配饰排行榜,潮童品牌大全,品牌一览,YOHO!BUY 有货',
description: 'YOHO!BUY 有货童装品牌一览汇集国内国际各大童装品牌大全,为广大爱好潮流的儿童提供品牌童装、童鞋,' +
'儿童鞋包配饰.YOHO!BUY 有货,100%正品保证'
},
lifestyle: {
title: '品牌一览|数码3c,居家,玩具娱乐,文具,美妆品牌|YOHO!BUY 有货 100%正品保证',
keywords: '数码3c品牌,居家品牌,玩具娱乐品牌,文具品牌,美妆品牌',
description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大数码3c品牌,居家品牌,玩具娱乐品牌,文具品牌,' +
'美妆品牌.买创意生活家居就上YOHO!BUY 有货,100%正品保证'
},
'boys-plusstar': {
title: '品牌plusstar,男装潮流品牌简介|YOHO!BUY有货',
keywords: '品牌plusstar,男装潮流品牌简介',
description: 'YOHO!BUY 有货男装品牌一览汇集国内国际各大男装品牌,为广大爱美男生提供品牌男装、' +
'休闲男装、商务男装.买品牌男装就上YOHO!BUY 有货,100%正品保证'
},
'girls-plusstar': {
title: '品牌plusstar,女装潮流品牌简介|YOHO!BUY有货',
keywords: '品牌plusstar,女装潮流品牌简介',
description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大女装品牌,为广大爱美女生提供品牌女装、' +
'休闲女装、商务女装.买品牌女装就上YOHO!BUY 有货,100%正品保证'
getHomeurlByChannel(channel) {
let home;
switch (channel) {
case GIRLS:
home = helpers.urlFormat('/woman', {}, 'new');
break;
case LIFESTYLE:
home = helpers.urlFormat('/lifestyle', {}, 'new');
break;
case KIDS:
home = helpers.urlFormat('/kids', {}, 'new');
break;
default:
home = helpers.urlFormat('');
break;
}
return home;
}
};
/**
* plusstar 分页链接伪静态
* @param string uri
* @param string originUrl 动态地址
*/
const staticUrl = (uri, originUrl) => {
originUrl = queryString.parse(_.split(originUrl, '?')[1]);
return `${uri}id${originUrl.id || 0}-p${originUrl.page || 1}/`;
};
/**
* 获取品牌一览list
* @param string $channel 频道名称
* @param int start 开始位置 1 开始
* @param int length 取数长度 0 取到最后
*/
exports.getBrandViewList = (channel) => {
let apiMethod = [
headerModel.requestHeaderData(channel),
brandsModel.getBrandViewTop(channel),
brandsModel.getBrandViewList(channel) // 分屏加载
];
return api.all(apiMethod).then(result => {
let responseData = {
module: 'brands',
page: 'brands',
noCashe: false
// 添加网站的SEO
seoMap() {
return {
boys: {
title: '品牌一览|男装品牌排行榜,男装品牌大全|YOHO!BUY 有货 100%正品保证',
keywords: '品牌一览,男装品牌,男装品牌排行榜,男装品牌大全,YOHO!BUY 有货',
description: 'YOHO!BUY 有货男装品牌一览汇集国内国际各大男装品牌大全,为广大爱好时尚的男士青年提供品牌男装、' +
'休闲男装、商务男装.YOHO!BUY 有货,100%正品保证'
},
girls: {
title: '品牌一览|女装品牌排行榜,女装品牌大全|YOHO!BUY 有货 100%正品保证',
keywords: '品牌一览,女装品牌,女装品牌排行榜,女装品牌大全,YOHO!BUY 有货',
description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大女装品牌,为广大爱美女生提供品牌女装、休闲女装、' +
'商务女装.买品牌女装就上YOHO!BUY 有货,100%正品保证'
},
kids: {
title: '品牌一览|童装童鞋品牌,儿童鞋包配饰排行榜,潮童品牌大全|YOHO!BUY 有货 100%正品保证',
keywords: '童装品牌,童装童鞋排行榜,儿童鞋包配饰排行榜,潮童品牌大全,品牌一览,YOHO!BUY 有货',
description: 'YOHO!BUY 有货童装品牌一览汇集国内国际各大童装品牌大全,为广大爱好潮流的儿童提供品牌童装、童鞋,' +
'儿童鞋包配饰.YOHO!BUY 有货,100%正品保证'
},
lifestyle: {
title: '品牌一览|数码3c,居家,玩具娱乐,文具,美妆品牌|YOHO!BUY 有货 100%正品保证',
keywords: '数码3c品牌,居家品牌,玩具娱乐品牌,文具品牌,美妆品牌',
description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大数码3c品牌,居家品牌,玩具娱乐品牌,文具品牌,' +
'美妆品牌.买创意生活家居就上YOHO!BUY 有货,100%正品保证'
},
'boys-plusstar': {
title: '品牌plusstar,男装潮流品牌简介|YOHO!BUY有货',
keywords: '品牌plusstar,男装潮流品牌简介',
description: 'YOHO!BUY 有货男装品牌一览汇集国内国际各大男装品牌,为广大爱美男生提供品牌男装、' +
'休闲男装、商务男装.买品牌男装就上YOHO!BUY 有货,100%正品保证'
},
'girls-plusstar': {
title: '品牌plusstar,女装潮流品牌简介|YOHO!BUY有货',
keywords: '品牌plusstar,女装潮流品牌简介',
description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大女装品牌,为广大爱美女生提供品牌女装、' +
'休闲女装、商务女装.买品牌女装就上YOHO!BUY 有货,100%正品保证'
}
};
}
// 头部数据
Object.assign(responseData, result[0]);
// 品牌一览列表
responseData.brands = result[1];
responseData.brands.navigation = result[2].navigation;
responseData.brands.category = result[2];
/**
* plusstar 分页链接伪静态
* @param string uri
* @param string originUrl 动态地址
*/
staticUrl(uri, originUrl) {
originUrl = queryString.parse(_.split(originUrl, '?')[1]);
return `${uri}id${originUrl.id || 0}-p${originUrl.page || 1}/`;
}
// 导航pathNav
responseData.brands.pathNav = [
{
href: getHomeurlByChannel(channel),
name: `${_.toUpper(channel)}首页`,
pathTitle: 'YOHO!BUY 有货'
},
{
href: helpers.urlFormat('/brands'),
name: '品牌一览',
pathTitle: '品牌一览'
}
/**
* 获取品牌一览list
* @param string $channel 频道名称
* @param int start 开始位置 1 开始
* @param int length 取数长度 0 取到最后
*/
getBrandViewList(channel) {
let that = this;
let brandsModelCtx = new BrandsModel(that.ctx);
let apiMethod = [
headerModel.requestHeaderData(channel),
brandsModelCtx.getBrandViewTop(channel),
brandsModelCtx.getBrandViewList(channel) // 分屏加载
];
// SEO
Object.assign(responseData, seoMap[channel]);
// 数据出错不cashe
if (_.isEmpty(result[0].headerData) || _.isEmpty(result[1]) || _.isEmpty(result[2])) {
responseData.noCashe = true;
}
return responseData;
});
};
return api.all(apiMethod).then(result => {
let responseData = {
module: 'brands',
page: 'brands',
noCashe: false
};
// 头部数据
Object.assign(responseData, result[0]);
// 品牌一览列表
responseData.brands = result[1];
responseData.brands.navigation = result[2].navigation;
responseData.brands.category = result[2];
// 导航pathNav
responseData.brands.pathNav = [
{
href: that.getHomeurlByChannel(channel),
name: `${_.toUpper(channel)}首页`,
pathTitle: 'YOHO!BUY 有货'
},
{
href: helpers.urlFormat('/brands'),
name: '品牌一览',
pathTitle: '品牌一览'
}
];
/**
* brandList-Ajax调用
*/
exports.getBrandList = (channel, start) => {
let apiMethod = [
brandsModel.getBrandViewList(channel, start)
];
return api.all(apiMethod).then(result => {
let responseData = {};
// 品牌一览列表
responseData.category = result[0];
return responseData;
});
};
// SEO
Object.assign(responseData, that.seoMap[channel]);
/**
* 品牌接口数据
*
* @param string brandId 获取品牌ID
* @return json
*/
exports.brandInfo = (brandId, uid) => {
let apiMethod = [
brandsModel.getBrandInfo(brandId, uid)
];
return api.all(apiMethod).then(result => {
let responseData = {
code: _.isEmpty(result[0]) ? 400 : 200,
brand: _.isEmpty(result[0]) ? '' : result[0],
noCashe: false
};
// 数据出错不cashe
if (_.isEmpty(result[0])) {
responseData.noCashe = true;
}
return responseData;
});
};
// 数据出错不cashe
if (_.isEmpty(result[0].headerData) || _.isEmpty(result[1]) || _.isEmpty(result[2])) {
responseData.noCashe = true;
}
return responseData;
});
}
/**
* 多个品牌ID获取品牌信息
*
* @param array $brandIds
* @return array
*/
exports.plusstarList = (channel, req) => {
return co(function*() {
let headerData = yield headerModel.requestHeaderData(channel);
let responseData = {
module: 'brands',
page: 'brands',
brandsHomePage: true,
noCashe: false
};
/**
* brandList-Ajax调用
*/
getBrandList(channel, start) {
let that = this;
let brandsModelCtx = new BrandsModel(that.ctx);
let id = req.query.id || '',
gender = req.query.gender || getGenderByChannel(channel),
limit = 20,
page = parseInt(req.query.page, 10) || 1;
let apiMethod = [
brandsModelCtx.getBrandViewList(channel, start)
];
let items = yield brandsModel.getPlusstarBrandListItem(channel);
return api.all(apiMethod).then(result => {
let responseData = {};
let brandType = 1;
// 品牌一览列表
responseData.category = result[0];
return responseData;
});
}
if (+id !== 0 && items[id]) {
brandType = items[id].brandType;
}
let plustarList = yield brandsModel.getPlustarList(brandType, gender);
/**
* 品牌接口数据
*
* @param string brandId 获取品牌ID
* @return json
*/
brandInfo(brandId, uid) {
let that = this;
let brandsModelCtx = new BrandsModel(that.ctx);
let apiMethod = [
brandsModelCtx.getBrandInfo(brandId, uid)
];
let list = plustarList.data;
return api.all(apiMethod).then(result => {
let responseData = {
code: _.isEmpty(result[0]) ? 400 : 200,
brand: _.isEmpty(result[0]) ? '' : result[0],
noCashe: false
};
// 数据出错不cashe
if (_.isEmpty(headerData.headerData) || _.isEmpty(items) || _.isEmpty(list)) {
responseData.noCashe = true;
}
let brandIds = [],
brands = [],
pageList = {};
brandIds = plustarList.brandsIds.slice((page - 1) * limit, page * limit);
if (plustarList.brandsIds.length > limit) {
pageList = pager(Math.ceil(plustarList.brandsIds.length / limit), {
page: page,
id: id
});
// url 伪静态
_.forEach(pageList.pages, (val) => {
val.url = staticUrl(`/${channel}-brands/plusstar/`, val.url);
});
if (pageList.nextPage) {
pageList.nextPage.url = staticUrl(`/${channel}-brands/plusstar/`, pageList.nextPage.url);
}
if (pageList.prePage) {
pageList.prePage.url = staticUrl(`/${channel}-brands/plusstar/`, pageList.prePage.url);
// 数据出错不cashe
if (_.isEmpty(result[0])) {
responseData.noCashe = true;
}
}
return responseData;
});
}
if (brandIds.length > 0) {
// 获取品牌信息
let brandsInfo = yield brandsModel.getBrandInfoByIds(brandIds);
/**
* 多个品牌ID获取品牌信息
*
* @param array $brandIds
* @return array
*/
plusstarList(channel, req) {
let that = this;
let brandsModelCtx = new BrandsModel(that.ctx);
return co(function*() {
let headerData = yield headerModel.requestHeaderData(channel);
let responseData = {
module: 'brands',
page: 'brands',
brandsHomePage: true,
noCashe: false
};
let id = req.query.id || '',
gender = req.query.gender || that.getGenderByChannel(channel),
limit = 20,
page = parseInt(req.query.page, 10) || 1;
let items = yield brandsModelCtx.getPlusstarBrandListItem(channel);
let brandType = 1;
if (+id !== 0 && items[id]) {
brandType = items[id].brandType;
}
let plustarList = yield brandsModelCtx.getPlustarList(brandType, gender);
_.forEach(brandIds, brandId => {
if (brandsInfo[brandId]) {
list[brandId].desc = brandsInfo[brandId].desc;
list[brandId].url = helpers.urlFormat('', {gender: gender}, brandsInfo[brandId].url);
}
brands.push(list[brandId]);
});
let list = plustarList.data;
// 数据出错不cashe
if (_.isEmpty(brandsInfo)) {
if (_.isEmpty(headerData.headerData) || _.isEmpty(items) || _.isEmpty(list)) {
responseData.noCashe = true;
}
}
let data = {
brandsHomePage: true,
brands: {
items: brands,
tabs: items
let brandIds = [],
brands = [],
pageList = {};
brandIds = plustarList.brandsIds.slice((page - 1) * limit, page * limit);
if (plustarList.brandsIds.length > limit) {
pageList = pager(Math.ceil(plustarList.brandsIds.length / limit), {
page: page,
id: id
});
// url 伪静态
_.forEach(pageList.pages, (val) => {
val.url = that.staticUrl(`/${channel}-brands/plusstar/`, val.url);
});
if (pageList.nextPage) {
pageList.nextPage.url = that.staticUrl(`/${channel}-brands/plusstar/`, pageList.nextPage.url);
}
if (pageList.prePage) {
pageList.prePage.url = that.staticUrl(`/${channel}-brands/plusstar/`, pageList.prePage.url);
}
}
if (brandIds.length > 0) {
// 获取品牌信息
let brandsInfo = yield brandsModelCtx.getBrandInfoByIds(brandIds);
_.forEach(brandIds, brandId => {
if (brandsInfo[brandId]) {
list[brandId].desc = brandsInfo[brandId].desc;
list[brandId].url = helpers.urlFormat('', {gender: gender}, brandsInfo[brandId].url);
}
brands.push(list[brandId]);
});
// 数据出错不cashe
if (_.isEmpty(brandsInfo)) {
responseData.noCashe = true;
}
}
};
let data = {
brandsHomePage: true,
brands: {
items: brands,
tabs: items
}
};
// 头部数据
Object.assign(responseData, headerData);
// 头部数据
Object.assign(responseData, headerData);
// 产品信息
Object.assign(responseData, data);
// 产品信息
Object.assign(responseData, data);
// 页码
Object.assign(responseData, pageList);
// 页码
Object.assign(responseData, pageList);
// SEO
Object.assign(responseData, seoMap[`${channel}-plusstar`] || {});
return responseData;
})();
// SEO
Object.assign(responseData, that.seoMap[`${channel}-plusstar`] || {});
return responseData;
})();
}
};
... ...
... ... @@ -36,7 +36,7 @@
<div class="brands-logo clearfix">
{{#each logos}}
<a href="{{url}}" title="{{name}}" target="_blank">
<img class="lazy" data-original="{{image2 src}}">
<img class="lazy" src="{{image2 src w=136 h=57}}">
</a>
{{/each}}
</div>
... ...
... ... @@ -318,6 +318,7 @@ const _getSkuDataByProductBaseInfo = (data) => {
}
}
console.log(goods.images_list);
_.get(goods, 'images_list', []).forEach((good) => {
if (good.image_url) {
goodsDetail.thumbs.push({
... ...
... ... @@ -287,5 +287,6 @@
<div class="code-down-box">
<div class="code-img"></div>
<h5 class="code-title">下载手机客户端</h5>
<i class="iconfont icon-del"></i>
</div>
{{/ headerData}}
... ...
... ... @@ -987,21 +987,8 @@ function searchSuggestHistory() {
}
$(function() {
var windowWidth = document.documentElement.clientWidth;
if (windowWidth <= 1440) {
$('.code-down-box').bind('click', '.icon-del', function() {
$('.code-down-box').hide();
}
$(window).resize(function() {
var innerWindowWidth = window.innerWidth;
if (innerWindowWidth > 1440 && innerWindowWidth <= windowWidth) {
$('.code-down-box').show();
} else {
$('.code-down-box').hide();
}
});
});
... ...
... ... @@ -1494,7 +1494,7 @@
border: none;
background-color: transparent;
z-index: 990;
display: none;
display: block;
.code-img {
width: 117px;
... ... @@ -1511,10 +1511,17 @@
line-height: 20px;
text-align: center;
}
}
@media screen and (min-width: 1440px) {
.code-down-box {
display: block;
.icon-del {
position: absolute;
top: -13px;
right: -10px;
display: inline-block;
font-size: 30px;
cursor: pointer;
&:before {
content: "\e60d";
}
}
}
... ...