Authored by yyq

outlets controllers

... ... @@ -7,15 +7,12 @@
'use strict';
const mRoot = '../models';
// const simuOutlets = require(`${mRoot}/simu-outlets`);
const headerModel = require('../../../doraemon/models/header');
const outlets = require(`${mRoot}/outlets`);
// 开发用模拟数据
// const simuOutlets = require(`${mRoot}/simu-outlets`);
// const outletsSimulation = require('../models/simulation');
// sale 页 model
const outlets = require(`${mRoot}/outlets`);
/**
* outlets 首页
* @param {[type]} req [description]
... ... @@ -23,22 +20,21 @@ const outlets = require(`${mRoot}/outlets`);
* @return {[type]} [description]
*/
exports.index = (req, res) => {
let responseData = {};
let resData = {
module: 'product',
page: 'outlets'
};
// 首页模拟数据
// responseData.result = simuOutlets.index();
headerModel.requestHeaderData().then(headerData => {
responseData = headerModel.setHeaderData(headerData.data, 'sale');
responseData.module = 'product';
responseData.page = 'outlets';
responseData.footerTop = true;
responseData.devEnv = true;
outlets.getOutletsIndexData(req.query).then(result => {
responseData.result = result;
responseData.resultShow = JSON.stringify(result, null, 4);
res.render('outlets/index', responseData);
});
// resData.result = simuOutlets.index();
outlets.getOutletsIndexData(req.query).then(result => {
resData.result = result;
resData.headerData = result.headerData;
resData.resultShow = JSON.stringify(result, null, 4);
res.render('outlets/index', resData);
}).catch(() => {
resData.pageErr = true;
res.render('error', resData);
});
};
... ... @@ -50,54 +46,19 @@ exports.index = (req, res) => {
* @return {[type]} [description]
*/
exports.channel = (req, res) => {
let channel = {
boys: 'true',
girls: 'true',
kids: 'true',
lifestyle: ''
let resData = {
module: 'product',
page: 'outlets'
};
let response = {};
// 错误页面
if (!channel[req.params.channel]) {
response.pageErr = true;
}
// 头部数据
headerModel.requestHeaderData().then(headerData => {
Object.assign(response, headerModel.setHeaderData(headerData.data, 'outlets'));
// 频道数据
outlets.getOutletsChannelData({ channel: req.params.channel }).then(outletsData => {
response.module = 'product';
response.page = 'outlets';
response.devEnv = true;
// 输出数据
Object.assign(response, outletsData);
res.render('outlets/channel', response);
});
// 假数据
// response.module = 'product';
// response.page = 'outlets';
// response.footerTop = true;
// response.devEnv = true;
// res.render('outlets/channel', Object.assign(response, outletsSimulation.outletBanner()));
// 首页模拟数据
// resData = outletsSimulation.outletBanner();
outlets.getOutletsChannelData(req.params.channel).then(result => {
res.render('outlets/channel', Object.assign(resData, result));
}).catch(() => {
resData.pageErr = true;
res.render('error', resData);
});
// outlets.getOutletsChannelData({channel:req.params.channel}).then(outletsData => {
// response.module = 'product';
// response.page = 'sale';
// response.footerTop = true;
// response.devEnv = true;
// res.render('outlets/channel', Object.assing(response, outlets.outletBanner()));
// });
// 输出数据
// res.render('outlets/channel', Object.assign(response,
// outlets.getOutletsChannelData({'channel':req.params.channel})));
};
/**
... ... @@ -131,9 +92,9 @@ exports.special = (req, res) => {
// count: '123533',
// limit: '80000000'
// };
//
outlets.getOutletsSpecialData(params).then(data => {
res.render('outlets/special', Object.assign(resData, data));
//
outlets.getOutletsSpecialData(params).then(result => {
res.render('outlets/special', Object.assign(resData, result));
}).catch(() => {
resData.pageErr = true;
res.render('error', resData);
... ...
... ... @@ -32,39 +32,40 @@ const channelCode = {
*/
exports.getOutletsIndexData = (params) => {
return api.all([
headerModel.requestHeaderData('outlets'),
outletsApi.getChannelResouceData({ content_code: channelCode.index }),
outletsApi.getOutletsActivityOrigin(params), // 获取限时活动列表
outletsApi.getOutletsActivityOrigin(params), // 获取即将结束列表
outletsApi.getOutletsTrendData(params), // 获取潮流速递商品数据
saleApi.getSaleGoodsList(params) // 获取底部商品数据
]).then(result => {
let finalResult = {};
let finalResult = result[0];
// 处理资源位数据
if (result[0].code === 200) {
if (result[1].code === 200) {
finalResult = Object.assign(finalResult,
outletsProcess.handleOutletsBannersData(result[0].data));
outletsProcess.handleOutletsBannersData(result[1].data));
}
// 处理限时嗨购列表数据
if (result[1].code === 200) {
if (result[2].code === 200) {
finalResult.limitedBuy = Object.assign(finalResult.limitedBuy,
outletsProcess.handleOutletsActivityData(result[1].data));
outletsProcess.handleOutletsActivityData(result[2].data));
}
// 处理即将结束列表数据
if (result[2].code === 200) {
finalResult.nearOver = outletsProcess.handleOutletsActivityData(result[2].data);
if (result[3].code === 200) {
finalResult.nearOver = outletsProcess.handleOutletsActivityData(result[3].data);
}
// 处理潮品推荐数据
if (result[3].code === 200) {
finalResult.limitedBuy.extra.trendGood = outletsProcess.handleOutletstrendGoodData(result[3].data);
if (result[4].code === 200) {
finalResult.limitedBuy.extra.trendGood = outletsProcess.handleOutletstrendGoodData(result[4].data);
}
// 处理底部商品数据
if (result[4].code === 200) {
finalResult.goodsBoard.list = productProcess.processProductList(result[4].data.product_list);
if (result[5].code === 200) {
finalResult.goodsBoard.list = productProcess.processProductList(result[5].data.product_list);
}
return finalResult;
... ... @@ -79,25 +80,46 @@ exports.getOutletsIndexData = (params) => {
exports.getOutletsChannelData = (params) => {
let channelData = {};
return api.all([
outletsApi.getChannelResouceData({ content_code: channelCode[params.channel] }),
outletsApi.getOutletsActivityOrigin({ platform: 2, size: 0, type: 1 }),
saleApi.getSaleGoodsList(params)
]).then(result => {
// 资源楼层
if (result[0].code === 200) {
Object.assign(channelData, outletsProcess.processFloor(result[0].data.list));
}
// 限时嗨购
if (result[1].code === 200) {
Object.assign(channelData, { flashSale: outletsProcess.formatActivityData(result[1].data) });
let apiArr = [
headerModel.requestHeaderData('outlets'),
];
if (channelCode[params]) {
apiArr.push(outletsApi.getChannelResouceData({
content_code: channelCode[params.channel]
}));
apiArr.push(outletsApi.getOutletsActivityOrigin({
platform: 2,
size: 0,
type: 1
}));
apiArr.push(saleApi.getSaleGoodsList(params));
} else {
// 错误页面
channelData.pageErr = true;
}
return api.all(apiArr).then(result => {
Object.assign(channelData, result[0]);
if (!channelData.pageErr) {
// 资源楼层
if (result[1].code === 200) {
Object.assign(channelData, outletsProcess.processFloor(result[1].data.list));
}
// 限时嗨购
if (result[2].code === 200) {
Object.assign(channelData, { flashSale: outletsProcess.formatActivityData(result[2].data) });
}
// 商品列表
if (result[3].code === 200) {
channelData.goodsBoard = {};
channelData.goodsBoard.list = productProcess.processProductList(result[3].data.product_list);
}
}
// 商品列表
if (result[2].code === 200) {
channelData.goodsBoard.list = productProcess.processProductList(result[2].data.product_list);
}
return channelData;
});
};
... ... @@ -119,7 +141,7 @@ exports.getOutletsSpecialData = (params) => {
specialData.pageErr = true;
if (result[1].code === 200) {
delete specialData.pageErr;
specialData = Object.assign(specialData,
Object.assign(specialData,
outletsProcess.handleOutletsSpecilData(result[1].data[0]));
}
... ...