...
|
...
|
@@ -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;
|
|
|
})();
|
|
|
}
|
|
|
}; |
...
|
...
|
|