Authored by htoooth

global

... ... @@ -16,7 +16,7 @@ const globalModel = require(`${mRoot}/global`); // global model
* @return {[type]} [description]
*/
exports.list = (req, res, next) => {
globalModel.getGlobalProductListData(req.query, req.yoho).then(result => {
req.ctx(globalModel).getGlobalProductListData(req.query, req.yoho).then(result => {
res.render('list/index', Object.assign({
page: 'list',
pageClass: 'global-list-page'
... ... @@ -31,7 +31,7 @@ exports.list = (req, res, next) => {
* @return {[type]} [description]
*/
exports.detail = (req, res, next) => {
globalModel.getGlobalProductDetailData(req.params[0], req.yoho.channelNum,
req.ctx(globalModel).getGlobalProductDetailData(req.params[0], req.yoho.channelNum,
req.yoho.channel).then(result => {
res.render('global/detail', Object.assign({
page: 'detail'
... ...
... ... @@ -6,48 +6,63 @@
'use strict';
const globalApi = global.yoho.GlobalAPI;
const config = global.yoho.config;
const getGlobalProductListAsync = (params, from) => {
let finalParams = {
limit: 60
};
Object.assign(finalParams, params);
if (from) {
finalParams.fromPage = from;
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
return globalApi.get('product/api/v2/detail/getlist', finalParams, config.apiCache);
};
getGlobalProductListAsync(params, from) {
let finalParams = {
limit: 60
};
const getGlobalProductDetailAsync = (skn, channelNum) => {
return globalApi.get('product/api/v2/detail/get', {
physical_channel: channelNum,
product_skn: skn
}, config.apiCache);
};
Object.assign(finalParams, params);
const getGlobalProductHtmlAsync = (skn, channelNum) => {
return globalApi.get('product/api/v1/detail/gethtml', {
physical_channel: channelNum,
product_skn: skn,
return_type: 'html'
}, config.apiCache);
};
if (from) {
finalParams.fromPage = from;
}
const getGlobalBrandInfoAsync = brand => {
return globalApi.get('editor/api/v1/brand/get', {
brandId: brand
}, config.apiCache);
return this.get({
url: 'product/api/v2/detail/getlist',
data: finalParams,
params: {cache: config.apiCache},
api: global.yoho.GlobalAPI
});
}
};
getGlobalProductDetailAsync(skn, channelNum) {
return this.get({
url: 'product/api/v2/detail/get',
data: {
physical_channel: channelNum,
product_skn: skn
},
params: { cache: config.apiCache },
api: global.yoho.GlobalAPI
});
}
module.exports = {
getGlobalProductListAsync,
getGlobalProductDetailAsync,
getGlobalProductHtmlAsync,
getGlobalBrandInfoAsync
getGlobalProductHtmlAsync(skn, channelNum) {
return this.get({
url: 'product/api/v1/detail/gethtml',
data: {
physical_channel: channelNum,
product_skn: skn,
return_type: 'html'
},
params: {cache: config.apiCache},
api: global.yoho.GlobalAPI
});
}
getGlobalBrandInfoAsync(brand) {
return this.get({
url: 'editor/api/v1/brand/get',
data: { brandId: brand },
params: {cache: config.apiCache},
api: global.yoho.GlobalAPI
});
}
};
... ...
... ... @@ -12,12 +12,12 @@ const cheerio = require('cheerio');
const helpers = global.yoho.helpers;
const homeService = require('./home-service');
const globalApi = require('./global-api');
const headerModel = require('../../../doraemon/models/header');
const searchHandler = require('./search-handler');
const pager = require(`${global.utils}/pager`).setPager;
const productProcess = require(`${global.utils}/product-process`);
const GlobalApiModel = require('./global-api');
const GLOBAL_LIST_URI = '/product/global/list';
const _handelGlobalPathNav = (data, channel, page) => {
... ... @@ -157,7 +157,7 @@ const _getProductSeoData = (detail) => {
return resData;
};
const getGlobalProductListData = (params, yoho) => {
function getGlobalProductListData(params, yoho) {
let limitNum = params.limit ? params.limit - 1 : 59;
let dps = {};
... ... @@ -169,14 +169,14 @@ const getGlobalProductListData = (params, yoho) => {
return Promise.props({
header: headerModel.requestHeaderData(yoho.channel),
fullList: globalApi.getGlobalProductListAsync(Object.assign({
fullList: this.globalApi.getGlobalProductListAsync(Object.assign({
physical_channel: yoho.channelNum,
limit: 1
}, dps)),
list: globalApi.getGlobalProductListAsync(Object.assign({
list: this.globalApi.getGlobalProductListAsync(Object.assign({
physical_channel: yoho.channelNum
}, params, {limit: limitNum})),
brand: dps.brand ? globalApi.getGlobalBrandInfoAsync(dps.brand) : {}
brand: dps.brand ? this.globalApi.getGlobalBrandInfoAsync(dps.brand) : {}
}).then(result => {
let resData = {};
... ... @@ -253,13 +253,13 @@ const getGlobalProductListData = (params, yoho) => {
return resData;
});
};
}
const getGlobalProductDetailData = (skn, channelNum, channel) => {
function getGlobalProductDetailData(skn, channelNum, channel) {
return Promise.props({
header: headerModel.requestHeaderData(channel),
detail: globalApi.getGlobalProductDetailAsync(skn, channelNum),
html: globalApi.getGlobalProductHtmlAsync(skn, channelNum)
detail: this.globalApi.getGlobalProductDetailAsync(skn, channelNum),
html: this.globalApi.getGlobalProductHtmlAsync(skn, channelNum)
}).then(result => {
let resData = {};
let detailInfo, html = '';
... ... @@ -361,9 +361,15 @@ const getGlobalProductDetailData = (skn, channelNum, channel) => {
return resData;
});
};
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
module.exports = {
getGlobalProductListData,
getGlobalProductDetailData
this.globalApi = new GlobalApiModel(ctx);
this.getGlobalProductListData = getGlobalProductListData.bind(this);
this.getGlobalProductDetailData = getGlobalProductDetailData.bind(this);
}
};
... ...
... ... @@ -150,10 +150,10 @@ module.exports = {
port: '6379',
retry_strategy(options) {
if (options.error && options.error.code === 'ECONNREFUSED') {
console.log('redis连接不成功');
// console.log('redis连接不成功');
}
if (options.total_retry_time > 1000 * 60 * 60 * 6) {
console.log('redis连接超时');
// console.log('redis连接超时');
return;
}
if (options.attempt > 10) {
... ...