Authored by htoooth

outlets

... ... @@ -21,7 +21,7 @@ const _ = require('lodash');
exports.index = (req, res, next) => {
let channel = req.query.channel || req.cookies._Channel || 'otltIdxDflt';
outlets.getOutletsIndexData(req.query, channel).then((result) => {
req.ctx(outlets).getOutletsIndexData(req.query, channel).then((result) => {
res.render('outlets/index', Object.assign({
module: 'product',
page: 'outlets'
... ... @@ -38,7 +38,7 @@ exports.index = (req, res, next) => {
exports.channel = (req, res, next) => {
let channel = req.params.channel || req.query.channel || req.cookies._Channel || 'boys';
outlets.getOutletsChannelData(req.query, channel).then((result) => {
req.ctx(outlets).getOutletsChannelData(req.query, channel).then((result) => {
res.render('outlets/channel', Object.assign({
module: 'product',
page: 'outlets'
... ... @@ -61,7 +61,7 @@ exports.special = (req, res, next) => {
return next();
}
outlets.getOutletsSpecialData(params, channel).then(result => {
req.ctx(outlets).getOutletsSpecialData(params, channel).then(result => {
res.render('outlets/special', Object.assign({
module: 'product',
page: 'outlets'
... ... @@ -81,7 +81,7 @@ exports.list = (req, res, next) => {
params.uid = req.user.uid || 0;
outlets.getOutletsCategoryData(params, channel).then((result) => {
req.ctx(outlets).getOutletsCategoryData(params, channel).then((result) => {
res.render('sale/other', Object.assign({
module: 'product',
page: 'outlets'
... ...
/*
* @Author: Targaryen
* @Date: 2016-05-25 18:03:34
* @Last Modified by: Targaryen
* @Last Modified time: 2016-06-07 13:58:53
*/
'use strict';
const _ = require('lodash');
const config = global.yoho.config;
const yhChannel = {
boys: {
channel: '1'
},
girls: {
channel: '2'
},
kids: {
channel: '3'
},
lifestyle: {
channel: '4'
}
};
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
/**
* 获取商品列表 promise 对象
* @return {[type]} [description]
*/
getSaleGoodsList(params) {
let finalParams = {
method: 'app.search.sales',
limit: 60,
order: 's_t_desc',
productSize: '384x511'
};
if (params && params.channel) {
finalParams.yh_channel = yhChannel[params.channel].channel;
}
return this.get({data: Object.assign(finalParams, params), params: {cache: config.apiCache}});
};
/**
* 断码区分类信息数据 promise 对象
* @return {[type]} [description]
*/
getSalebreakingYardsSortList(params) {
let tempChannel = _.isEmpty(params.channel) ? 'boys' : params.channel;
return this.get({
data: {
method: 'app.sale.getBreakingSort',
yh_channel: yhChannel[tempChannel].channel
}, params: {cache: config.apiCache}
});
};
/**
* 获取折扣专区活动列表 promise 对象
* @return {[type]} [description]
*/
getSaleActivityList(params, channel) {
let tempChannel = yhChannel[channel] || yhChannel.boys;
return this.get({
data: {
id: params.id || null,
method: 'app.activity.get',
sort: '2',
plateform: '1',
yh_channel: tempChannel.channel
}, params: {cache: config.apiCache}
});
};
/**
* 获取Sale首页顶部 banner promise 对象
* @return {[type]} [description]
*/
getSaleBannerList(cCode) {
return this.get({
url: 'operations/api/v5/resource/get',
data: {
content_code: cCode
},
params: {cache: config.apiCache},
api: global.yoho.ServiceAPI
});
};
/**
* 获取左侧类目列表
* @return {[type]} [description]
*/
getLeftContentList() {
return this.get({
data: {
method: 'app.sort.get'
}, params: {cache: config.apiCache}
});
};
/**
* 获取用户数据信息
* @param {[string]} uid
* @return {[array]}
*/
getUserProfile(uid) {
if (!uid) {
return Promise.resolve({
code: 200,
data: {}
});
}
return this.get({
data: {
method: 'app.passport.profile',
uid: uid
}, params: {cache: true}
});
};
/**
* 获取用户数据信息
* @param {[string]} uid
* @return {[array]}
*/
getSaleSpecialAsync(specialId) {
return this.get({
data: {
method: 'app.resources.getOneSpecial',
special_id: specialId
},
params: {
code: 200,
cache: true
}
});
};
};
... ...
... ... @@ -7,8 +7,6 @@
'use strict';
const serviceApi = global.yoho.ServiceAPI;
const api = global.yoho.API;
const _ = require('lodash');
const config = global.yoho.config;
... ... @@ -30,86 +28,101 @@ const yhChannel = {
}
};
/**
* 获取奥莱活动列表接口
* @param {[int]} id 活动id 为空表示查询全部活动
* @param {[int ]} platform 活动平台 1--WEB,2--APP,3--WAP,4--IPAD
* @param {[int]} size 查询数量,默认查询全部
* @param {[int]} channel 频道: 1 || 2 || 3 || 4
* @param {[int]} type
* @return {[type]} 0 活动列表,1 限时嗨购 2 即将结束 3.即将上线
*/
exports.getOutletsActivityOrigin = (params) => {
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
}
let tempChannel = params.channel || 'boys';
/**
* 获取奥莱活动列表接口
* @param {[int]} id 活动id 为空表示查询全部活动
* @param {[int ]} platform 活动平台 1--WEB,2--APP,3--WAP,4--IPAD
* @param {[int]} size 查询数量,默认查询全部
* @param {[int]} channel 频道: 1 || 2 || 3 || 4
* @param {[int]} type
* @return {[type]} 0 活动列表,1 限时嗨购 2 即将结束 3.即将上线
*/
getOutletsActivityOrigin(params) {
return api.get('', {
method: 'app.outlets.activityGet',
id: params.id || null,
platform: params.platform || 1,
size: params.size || 0,
yh_channel: yhChannel[tempChannel].channel,
type: params.type || 0
}, config.apiCache);
};
let tempChannel = params.channel || 'boys';
/**
* 获取奥莱频道资源位数据
* @param {[object]} params
* @return {[type]}
*/
exports.getChannelResouceData = (params) => {
return serviceApi.get('operations/api/v5/resource/home', params, config.apiCache);
};
return this.get({
data: {
method: 'app.outlets.activityGet',
id: params.id || null,
platform: params.platform || 1,
size: params.size || 0,
yh_channel: yhChannel[tempChannel].channel,
type: params.type || 0
}, params: {cache: config.apiCache}
});
}
/**
* 获取奥莱潮品速递商品数据
* @param {[type]} params [description]
* @return {[type]} [description]
*/
exports.getOutletsTrendData = (params) => {
let tempChannel = params.channel || 'boys';
/**
* 获取奥莱频道资源位数据
* @param {[object]} params
* @return {[type]}
*/
getChannelResouceData(params) {
return this.get({
url: 'operations/api/v5/resource/home',
data: params,
params: {cache: config.apiCache},
api: global.yoho.ServiceAPI
});
}
return api.get('', {
method: 'app.search.trend',
yh_channel: yhChannel[tempChannel].channel,
order: params.order || 's_s_desc,s_n_desc',
gender: params.gender || '1,3',
stocknumber: 1, // 过滤出库存 > 1的商品
limit: params.limit || 5,
outlets: params.outlets || 1 // 默认取奥莱商品
}, config.apiCache);
};
/**
* 获取奥莱潮品速递商品数据
* @param {[type]} params [description]
* @return {[type]} [description]
*/
getOutletsTrendData(params) {
let tempChannel = params.channel || 'boys';
return this.get({
data: {
method: 'app.search.trend',
yh_channel: yhChannel[tempChannel].channel,
order: params.order || 's_s_desc,s_n_desc',
gender: params.gender || '1,3',
stocknumber: 1, // 过滤出库存 > 1的商品
limit: params.limit || 5,
outlets: params.outlets || 1 // 默认取奥莱商品
}, params: {cache: config.apiCache}
});
}
/**
* 获取奥莱商品列表 promise 对象
* @return {[type]} [description]
*/
exports.getOutletsGoodsList = (params) => {
// 频道
let tempChannel = params.channel || 'boys';
/**
* 获取奥莱商品列表 promise 对象
* @return {[type]} [description]
*/
getOutletsGoodsList(params) {
// 频道
let tempChannel = params.channel || 'boys';
// 接口可接收的参数
let apiParams = ['outlets', 'page', 'limit', 'order', 'productSize', 'yh_channel', 'query',
'p_d', 'gender', 'msort', 'misort', 'sort', 'brand', 'color', 'size', 'saleType',
'breakSize', 'breakSort', 'productPool', 'price', 'method'];
// 接口可接收的参数
let apiParams = ['outlets', 'page', 'limit', 'order', 'productSize', 'yh_channel', 'query',
'p_d', 'gender', 'msort', 'misort', 'sort', 'brand', 'color', 'size', 'saleType',
'breakSize', 'breakSort', 'productPool', 'price', 'method'];
// 初始化必填的接口参数
let tempParams = {
method: 'app.search.li',
outlets: 1,
page: params.page || 1,
limit: params.limit || 60,
order: params.order || 's_t_desc',
productSize: '384x511',
yh_channel: yhChannel[tempChannel].channel
};
// 初始化必填的接口参数
let tempParams = {
method: 'app.search.li',
outlets: 1,
page: params.page || 1,
limit: params.limit || 60,
order: params.order || 's_t_desc',
productSize: '384x511',
yh_channel: yhChannel[tempChannel].channel
};
_.forEach(apiParams, (paramsName) => {
if (params[paramsName]) {
tempParams[paramsName] = params[paramsName];
}
});
return api.get('', tempParams, config.apiCache);
_.forEach(apiParams, (paramsName) => {
if (params[paramsName]) {
tempParams[paramsName] = params[paramsName];
}
});
return this.get({data: tempParams, params: {cache: config.apiCache}});
}
};
... ...
... ... @@ -5,13 +5,14 @@
* @Last Modified time: 2016-06-08 19:56:39
*/
// TODO: ctx
'use strict';
const Promise = require('bluebird');
const utils = '../../../utils';
const api = global.yoho.API;
const list = require('./list');
const outletsProcess = require('./outlets-handler');
const outletsApi = require('./outlets-api');
const OutletsApiModel = require('./outlets-api');
const productProcess = require(`${utils}/product-process`);
const headerModel = require('../../../doraemon/models/header');
const _ = require('lodash');
... ... @@ -33,15 +34,15 @@ const channelCode = {
* @param {[type]} origin [description]
* @return {[type]} [description]
*/
exports.getOutletsIndexData = (params, channel) => {
function getOutletsIndexData(params, channel) {
return api.all([
return Promise.all([
headerModel.requestHeaderData('outlets'),
outletsApi.getChannelResouceData({content_code: channelCode.index}),
outletsApi.getOutletsActivityOrigin({type: '1', channel: channel}), // 获取限时活动列表
outletsApi.getOutletsActivityOrigin({type: '2', channel: channel}), // 获取即将结束列表
outletsApi.getOutletsTrendData({limit: '30', channel: channel}), // 获取潮流速递商品数据
outletsApi.getOutletsActivityOrigin({type: '3', channel: channel}) // tar add 16171552 即将上线数据
this.outletsApi.getChannelResouceData({content_code: channelCode.index}),
this.outletsApi.getOutletsActivityOrigin({type: '1', channel: channel}), // 获取限时活动列表
this.outletsApi.getOutletsActivityOrigin({type: '2', channel: channel}), // 获取即将结束列表
this.outletsApi.getOutletsTrendData({limit: '30', channel: channel}), // 获取潮流速递商品数据
this.outletsApi.getOutletsActivityOrigin({type: '3', channel: channel}) // tar add 16171552 即将上线数据
]).then(result => {
let finalResult = {
... ... @@ -92,8 +93,8 @@ exports.getOutletsIndexData = (params, channel) => {
{msort: _.uniq(finalResult.goodsBoard.goodsMenu.msort).join()}
);
}
return api.all([
outletsApi.getOutletsGoodsList(Object.assign(
return Promise.all([
this.outletsApi.getOutletsGoodsList(Object.assign(
params,
{limit: params.limit || '100', channel: channel, method: 'app.search.category'}
))
... ... @@ -123,14 +124,14 @@ exports.getOutletsIndexData = (params, channel) => {
return finalResult;
});
});
};
}
/**
* 获取奥莱频道页面数据
* @param {[object]} gender
* @return {[type]}
*/
exports.getOutletsChannelData = (params, channel) => {
function getOutletsChannelData(params, channel) {
// 频道资源位不存在
if (!channelCode[channel]) {
return Promise.reject(`outlets channel-(${channel}) resource not found`);
... ... @@ -143,10 +144,10 @@ exports.getOutletsChannelData = (params, channel) => {
headerModel.requestHeaderData('outlets'),
// 获取频道资源位
outletsApi.getChannelResouceData({content_code: channelCode[channel]}),
this.outletsApi.getChannelResouceData({content_code: channelCode[channel]}),
// 获取奥莱活动
outletsApi.getOutletsActivityOrigin({
this.outletsApi.getOutletsActivityOrigin({
platform: 1,
size: 0,
channel: channel,
... ... @@ -154,7 +155,7 @@ exports.getOutletsChannelData = (params, channel) => {
})
];
return api.all(apiArr).then(result => {
return Promise.all(apiArr).then(result => {
// 返回页面的数据
let finalResult = {
headerData: Object.assign(result[0].headerData, {
... ... @@ -189,8 +190,8 @@ exports.getOutletsChannelData = (params, channel) => {
{msort: _.uniq(channelData.goodsBoard.goodsMenu.msort).join()}
);
}
return api.all([
outletsApi.getOutletsGoodsList(Object.assign(
return Promise.all([
this.outletsApi.getOutletsGoodsList(Object.assign(
params,
{limit: params.limit || '100', channel: channel, method: 'app.search.category'}
))
... ... @@ -220,17 +221,17 @@ exports.getOutletsChannelData = (params, channel) => {
return channelData;
});
});
};
}
/**
* 获取奥莱活动页面数据
* @param {[object]}
* @return {[type]}
*/
exports.getOutletsSpecialData = (params, channel) => {
return api.all([
function getOutletsSpecialData(params, channel) {
return Promise.all([
headerModel.requestHeaderData('outlets'),
outletsApi.getOutletsActivityOrigin({ // 获取活动信息
this.outletsApi.getOutletsActivityOrigin({ // 获取活动信息
id: params.id
})
]).then(result => {
... ... @@ -247,7 +248,7 @@ exports.getOutletsSpecialData = (params, channel) => {
Object.assign(specialData,
outletsProcess.handleOutletsSpecilData(result[1].data[0]));
return api.all([
return Promise.all([
list.getListData(Object.assign({
productPool: result[1].data[0].productPoolId,
saleType: 4
... ... @@ -258,7 +259,7 @@ exports.getOutletsSpecialData = (params, channel) => {
return specialData;
});
});
};
}
/**
* 获取奥莱分类页面数据
... ... @@ -266,8 +267,8 @@ exports.getOutletsSpecialData = (params, channel) => {
* @param {[type]} channel [description]
* @return {[type]} [description]
*/
exports.getOutletsCategoryData = (params, channel) => {
return api.all([
function getOutletsCategoryData(params, channel) {
return Promise.all([
headerModel.requestHeaderData('outlets')
]).then(result => {
let finalResult = {
... ... @@ -277,7 +278,7 @@ exports.getOutletsCategoryData = (params, channel) => {
})
};
return api.all([
return Promise.all([
list.getListData(params, channel)
]).then(listResult => {
finalResult.saleList = listResult[0];
... ... @@ -294,4 +295,17 @@ exports.getOutletsCategoryData = (params, channel) => {
return finalResult;
});
});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.outletsApi = new OutletsApiModel(ctx);
this.getOutletsIndexData = getOutletsIndexData.bind(this);
this.getOutletsChannelData = getOutletsChannelData.bind(this);
this.getOutletsSpecialData = getOutletsSpecialData.bind(this);
this.getOutletsCategoryData = getOutletsCategoryData.bind(this);
}
};
... ...
... ... @@ -7,9 +7,10 @@
'use strict';
const utils = '../../../utils';
const api = global.yoho.API;
const saleApi = require('./sale-api');
const outletsApi = require('./outlets-api');
const Promise = require('bluebird');
const SaleApiModel = require('./ctx-sale-api');
const OutletsApiModel = require('./outlets-api');
const productProcess = require(`${utils}/product-process`);
const publicHandler = require('./public-handler');
... ... @@ -19,23 +20,23 @@ const publicHandler = require('./public-handler');
* @param {[type]} extra [左侧列表额外要拼接的参数]
* @return {[type]} [description]
*/
exports.getListData = (params, channel) => {
function getListData(params, channel) {
let apiArr = [];
if (params.productPool) {
// 奥莱活动页调用app.search.sales
apiArr = [
saleApi.getSaleGoodsList({limit: '1', channel: channel }),
saleApi.getSaleGoodsList(Object.assign(params, { channel: channel }))
this.saleApi.getSaleGoodsList({limit: '1', channel: channel}),
this.saleApi.getSaleGoodsList(Object.assign(params, {channel: channel}))
];
} else {
// 奥莱品类页调用app.search.li
apiArr = [
outletsApi.getOutletsGoodsList({limit: '1', channel: channel }),
outletsApi.getOutletsGoodsList(Object.assign(params, { channel: channel }))
this.outletsApi.getOutletsGoodsList({limit: '1', channel: channel}),
this.outletsApi.getOutletsGoodsList(Object.assign(params, {channel: channel}))
];
}
return api.all(apiArr).then(result => {
return Promise.all(apiArr).then(result => {
let finalResult = {};
// 获取商品数据和顶部筛选条件
... ... @@ -58,4 +59,15 @@ exports.getListData = (params, channel) => {
return finalResult;
});
}
module.exports = class extends global.yoho.BaseModel {
constructor(ctx) {
super(ctx);
this.outletsApi = new OutletsApiModel(ctx);
this.saleApi = new SaleApiModel(ctx);
this.getListData = getListData.bind(this);
}
};
... ...