...
|
...
|
@@ -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,13 +20,18 @@ const KIDS = 'kids'; |
|
|
const LIFESTYLE = 'lifestyle';
|
|
|
const queryString = require('querystring');
|
|
|
|
|
|
/**
|
|
|
module.exports = class extends global.yoho.BaseModel {
|
|
|
constructor(ctx) {
|
|
|
super(ctx);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 获取品牌一览资源位&channelType
|
|
|
*
|
|
|
* @param string $channelStr
|
|
|
* @return array
|
|
|
*/
|
|
|
const getGenderByChannel = channel => {
|
|
|
getGenderByChannel(channel) {
|
|
|
let gender = '';
|
|
|
|
|
|
switch (channel) {
|
...
|
...
|
@@ -42,9 +47,9 @@ const getGenderByChannel = channel => { |
|
|
break;
|
|
|
}
|
|
|
return gender;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
const getHomeurlByChannel = channel => {
|
|
|
getHomeurlByChannel(channel) {
|
|
|
let home;
|
|
|
|
|
|
switch (channel) {
|
...
|
...
|
@@ -62,10 +67,11 @@ const getHomeurlByChannel = channel => { |
|
|
break;
|
|
|
}
|
|
|
return home;
|
|
|
};
|
|
|
}
|
|
|
|
|
|
// 添加网站的SEO
|
|
|
const seoMap = {
|
|
|
// 添加网站的SEO
|
|
|
seoMap() {
|
|
|
return {
|
|
|
boys: {
|
|
|
title: '品牌一览|男装品牌排行榜,男装品牌大全|YOHO!BUY 有货 100%正品保证',
|
|
|
keywords: '品牌一览,男装品牌,男装品牌排行榜,男装品牌大全,YOHO!BUY 有货',
|
...
|
...
|
@@ -102,29 +108,33 @@ const seoMap = { |
|
|
description: 'YOHO!BUY 有货女装品牌一览汇集国内国际各大女装品牌,为广大爱美女生提供品牌女装、' +
|
|
|
'休闲女装、商务女装.买品牌女装就上YOHO!BUY 有货,100%正品保证'
|
|
|
}
|
|
|
};
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* plusstar 分页链接伪静态
|
|
|
* @param string uri
|
|
|
* @param string originUrl 动态地址
|
|
|
*/
|
|
|
const staticUrl = (uri, originUrl) => {
|
|
|
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) => {
|
|
|
getBrandViewList(channel) {
|
|
|
let that = this;
|
|
|
let brandsModelCtx = new BrandsModel(that.ctx);
|
|
|
|
|
|
let apiMethod = [
|
|
|
headerModel.requestHeaderData(channel),
|
|
|
brandsModel.getBrandViewTop(channel),
|
|
|
brandsModel.getBrandViewList(channel) // 分屏加载
|
|
|
brandsModelCtx.getBrandViewTop(channel),
|
|
|
brandsModelCtx.getBrandViewList(channel) // 分屏加载
|
|
|
];
|
|
|
|
|
|
return api.all(apiMethod).then(result => {
|
...
|
...
|
@@ -145,7 +155,7 @@ exports.getBrandViewList = (channel) => { |
|
|
// 导航pathNav
|
|
|
responseData.brands.pathNav = [
|
|
|
{
|
|
|
href: getHomeurlByChannel(channel),
|
|
|
href: that.getHomeurlByChannel(channel),
|
|
|
name: `${_.toUpper(channel)}首页`,
|
|
|
pathTitle: 'YOHO!BUY 有货'
|
|
|
},
|
...
|
...
|
@@ -157,7 +167,7 @@ exports.getBrandViewList = (channel) => { |
|
|
];
|
|
|
|
|
|
// SEO
|
|
|
Object.assign(responseData, seoMap[channel]);
|
|
|
Object.assign(responseData, that.seoMap[channel]);
|
|
|
|
|
|
// 数据出错不cashe
|
|
|
if (_.isEmpty(result[0].headerData) || _.isEmpty(result[1]) || _.isEmpty(result[2])) {
|
...
|
...
|
@@ -165,14 +175,17 @@ exports.getBrandViewList = (channel) => { |
|
|
}
|
|
|
return responseData;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* brandList-Ajax调用
|
|
|
*/
|
|
|
exports.getBrandList = (channel, start) => {
|
|
|
getBrandList(channel, start) {
|
|
|
let that = this;
|
|
|
let brandsModelCtx = new BrandsModel(that.ctx);
|
|
|
|
|
|
let apiMethod = [
|
|
|
brandsModel.getBrandViewList(channel, start)
|
|
|
brandsModelCtx.getBrandViewList(channel, start)
|
|
|
];
|
|
|
|
|
|
return api.all(apiMethod).then(result => {
|
...
|
...
|
@@ -182,17 +195,20 @@ exports.getBrandList = (channel, start) => { |
|
|
responseData.category = result[0];
|
|
|
return responseData;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 品牌接口数据
|
|
|
*
|
|
|
* @param string brandId 获取品牌ID
|
|
|
* @return json
|
|
|
*/
|
|
|
exports.brandInfo = (brandId, uid) => {
|
|
|
brandInfo(brandId, uid) {
|
|
|
let that = this;
|
|
|
let brandsModelCtx = new BrandsModel(that.ctx);
|
|
|
|
|
|
let apiMethod = [
|
|
|
brandsModel.getBrandInfo(brandId, uid)
|
|
|
brandsModelCtx.getBrandInfo(brandId, uid)
|
|
|
];
|
|
|
|
|
|
return api.all(apiMethod).then(result => {
|
...
|
...
|
@@ -208,15 +224,18 @@ exports.brandInfo = (brandId, uid) => { |
|
|
}
|
|
|
return responseData;
|
|
|
});
|
|
|
};
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
/**
|
|
|
* 多个品牌ID获取品牌信息
|
|
|
*
|
|
|
* @param array $brandIds
|
|
|
* @return array
|
|
|
*/
|
|
|
exports.plusstarList = (channel, req) => {
|
|
|
plusstarList(channel, req) {
|
|
|
let that = this;
|
|
|
let brandsModelCtx = new BrandsModel(that.ctx);
|
|
|
|
|
|
return co(function*() {
|
|
|
let headerData = yield headerModel.requestHeaderData(channel);
|
|
|
|
...
|
...
|
@@ -228,18 +247,18 @@ exports.plusstarList = (channel, req) => { |
|
|
};
|
|
|
|
|
|
let id = req.query.id || '',
|
|
|
gender = req.query.gender || getGenderByChannel(channel),
|
|
|
gender = req.query.gender || that.getGenderByChannel(channel),
|
|
|
limit = 20,
|
|
|
page = parseInt(req.query.page, 10) || 1;
|
|
|
|
|
|
let items = yield brandsModel.getPlusstarBrandListItem(channel);
|
|
|
let items = yield brandsModelCtx.getPlusstarBrandListItem(channel);
|
|
|
|
|
|
let brandType = 1;
|
|
|
|
|
|
if (+id !== 0 && items[id]) {
|
|
|
brandType = items[id].brandType;
|
|
|
}
|
|
|
let plustarList = yield brandsModel.getPlustarList(brandType, gender);
|
|
|
let plustarList = yield brandsModelCtx.getPlustarList(brandType, gender);
|
|
|
|
|
|
let list = plustarList.data;
|
|
|
|
...
|
...
|
@@ -260,19 +279,19 @@ exports.plusstarList = (channel, req) => { |
|
|
|
|
|
// url 伪静态
|
|
|
_.forEach(pageList.pages, (val) => {
|
|
|
val.url = staticUrl(`/${channel}-brands/plusstar/`, val.url);
|
|
|
val.url = that.staticUrl(`/${channel}-brands/plusstar/`, val.url);
|
|
|
});
|
|
|
if (pageList.nextPage) {
|
|
|
pageList.nextPage.url = staticUrl(`/${channel}-brands/plusstar/`, pageList.nextPage.url);
|
|
|
pageList.nextPage.url = that.staticUrl(`/${channel}-brands/plusstar/`, pageList.nextPage.url);
|
|
|
}
|
|
|
if (pageList.prePage) {
|
|
|
pageList.prePage.url = staticUrl(`/${channel}-brands/plusstar/`, pageList.prePage.url);
|
|
|
pageList.prePage.url = that.staticUrl(`/${channel}-brands/plusstar/`, pageList.prePage.url);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
if (brandIds.length > 0) {
|
|
|
// 获取品牌信息
|
|
|
let brandsInfo = yield brandsModel.getBrandInfoByIds(brandIds);
|
|
|
let brandsInfo = yield brandsModelCtx.getBrandInfoByIds(brandIds);
|
|
|
|
|
|
_.forEach(brandIds, brandId => {
|
|
|
if (brandsInfo[brandId]) {
|
...
|
...
|
@@ -306,8 +325,9 @@ exports.plusstarList = (channel, req) => { |
|
|
Object.assign(responseData, pageList);
|
|
|
|
|
|
// SEO
|
|
|
Object.assign(responseData, seoMap[`${channel}-plusstar`] || {});
|
|
|
Object.assign(responseData, that.seoMap[`${channel}-plusstar`] || {});
|
|
|
return responseData;
|
|
|
})();
|
|
|
|
|
|
}
|
|
|
}; |
...
|
...
|
|