Authored by yyq

Merge branch 'feature/sale' of git.yoho.cn:fe/yohobuy-node into feature/sale

@@ -2,12 +2,56 @@ @@ -2,12 +2,56 @@
2 * @Author: Targaryen 2 * @Author: Targaryen
3 * @Date: 2016-05-21 10:59:20 3 * @Date: 2016-05-21 10:59:20
4 * @Last Modified by: Targaryen 4 * @Last Modified by: Targaryen
5 - * @Last Modified time: 2016-05-21 13:22:46 5 + * @Last Modified time: 2016-06-02 15:17:03
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
  9 +const headerModel = require('../../../doraemon/models/header');
  10 +const mRoot = '../models';
  11 +
  12 +// list 页 model
  13 +const list = require(`${mRoot}/list`);
9 14
10 exports.getProductPic = (req, res) => { 15 exports.getProductPic = (req, res) => {
11 16
12 res.jsonp(); 17 res.jsonp();
13 }; 18 };
  19 +
  20 +/**
  21 + * 商品列表页
  22 + * @param {[type]} req [description]
  23 + * @param {[type]} res [description]
  24 + * @return {[type]} [description]
  25 + */
  26 +exports.index = (req, res) => {
  27 + let params = Object.assign({
  28 + saleType: 2,
  29 + order: 's_t_asc,s_s_asc'
  30 + }, req.query);
  31 +
  32 + let channel = req.query.channel || req.cookies._Channel || 'boys';
  33 +
  34 + params.uid = req.user.uid || 0;
  35 +
  36 + let responseData = {};
  37 +
  38 + headerModel.requestHeaderData().then(headerData => {
  39 + responseData = headerModel.setHeaderData(headerData.data, 'vip');
  40 + responseData.module = 'product';
  41 + responseData.page = 'sale';
  42 +
  43 + // responseData.footerTop = true;
  44 + responseData.devEnv = true;
  45 +
  46 + list.getSaleOthersData(params, channel).then((result) => {
  47 + responseData.saleList = result;
  48 + responseData.resultShow = JSON.stringify(result, null, 4);
  49 +
  50 + res.render('sale/other', responseData);
  51 + });
  52 +
  53 + }).catch(() => {
  54 + res.render('error', { devEnv: true, pageErr: true });
  55 + });
  56 +
  57 +};
  1 +/*
  2 + * @Author: Targaryen
  3 + * @Date: 2016-06-02 15:11:15
  4 + * @Last Modified by: Targaryen
  5 + * @Last Modified time: 2016-06-02 15:22:08
  6 + */
  7 +
  8 +'use strict';
  9 +const library = '../../../library';
  10 +const utils = '../../../utils';
  11 +const API = require(`${library}/api`).API;
  12 +const api = new API();
  13 +const saleApi = require('./sale-api');
  14 +const saleHandler = require('./sale-handler');
  15 +const productProcess = require(`${utils}/product-process`);
  16 +const _ = require('lodash');
  17 +
  18 +/**
  19 + * 获取 VIP 会员专享和新降价专区数据 Controller 调用
  20 + * @return {[type]} [description]
  21 + */
  22 +exports.getSaleOthersData = (params) => {
  23 +
  24 + let promiseObject = [
  25 + saleApi.getSaleGoodsList(params),
  26 + saleApi.getLeftContentList()
  27 + ];
  28 +
  29 + return api.all(promiseObject).then(result => {
  30 + let finalResult = {};
  31 +
  32 + // 获取商品数据和顶部筛选条件
  33 + if (result[0].code === 200) {
  34 + finalResult.goods = productProcess.processProductList(result[0].data.product_list);
  35 + if (!_.isEmpty(result[0].data.filter)) {
  36 + finalResult.filters = saleHandler.handleSaleFilterData(result[0].data.filter, params);
  37 + }
  38 +
  39 + // 处理排序数据
  40 + finalResult.opts = saleHandler.handleSaleOptsData(params, result[0].data.total);
  41 + finalResult.totalCount = result[0].data.total;
  42 + finalResult.pager = saleHandler.handleSalePagerData(result[0].data.total, params);
  43 + }
  44 +
  45 + // 获取左侧类目数据
  46 + if (result[1].code === 200) {
  47 + if (params.gender === '2,3') {
  48 + finalResult.leftContent = saleHandler.handleSaleSortData(result[1].data.girl, params);
  49 + } else {
  50 + finalResult.leftContent = saleHandler.handleSaleSortData(result[1].data.boy, params);
  51 + }
  52 + }
  53 +
  54 + return finalResult;
  55 + });
  56 +};
@@ -197,6 +197,13 @@ exports.handleOutletsBannersData = (origin) => { @@ -197,6 +197,13 @@ exports.handleOutletsBannersData = (origin) => {
197 dest.column = value.data; 197 dest.column = value.data;
198 } 198 }
199 199
  200 + // 处理右侧一张图片
  201 + if (value.template_name === 'single_image') {
  202 + dest.limitedBuy.extra.sourceImg = {};
  203 + dest.limitedBuy.extra.sourceImg.href = value.data.url;
  204 + dest.limitedBuy.extra.sourceImg.img = value.data.src;
  205 + }
  206 +
200 // 处理热销推荐数据 207 // 处理热销推荐数据
201 if (value.template_name === 'recommendCategory') { 208 if (value.template_name === 'recommendCategory') {
202 dest.limitedBuy.extra.hotType = {}; 209 dest.limitedBuy.extra.hotType = {};
@@ -308,6 +315,9 @@ exports.handleOutletstrendGoodData = (origin) => { @@ -308,6 +315,9 @@ exports.handleOutletstrendGoodData = (origin) => {
308 315
309 dest.title = '潮品推荐'; 316 dest.title = '潮品推荐';
310 dest.goods = productProcess.processProductList(origin.product_list); 317 dest.goods = productProcess.processProductList(origin.product_list);
  318 + _.forEach(dest.goods, (value, key) => {
  319 + dest.goods[key].discount = (value.sales_price / value.market_price).toFixed(2) * 10;
  320 + });
311 321
312 return dest; 322 return dest;
313 }; 323 };
@@ -2,7 +2,7 @@ @@ -2,7 +2,7 @@
2 * @Author: Targaryen 2 * @Author: Targaryen
3 * @Date: 2016-05-30 16:20:03 3 * @Date: 2016-05-30 16:20:03
4 * @Last Modified by: Targaryen 4 * @Last Modified by: Targaryen
5 - * @Last Modified time: 2016-06-02 13:53:24 5 + * @Last Modified time: 2016-06-02 14:26:27
6 */ 6 */
7 7
8 'use strict'; 8 'use strict';
@@ -34,7 +34,8 @@ exports.getOutletsIndexData = (params) => { @@ -34,7 +34,8 @@ exports.getOutletsIndexData = (params) => {
34 outletsApi.getChannelResouceData({ content_code: channelCode.index }), 34 outletsApi.getChannelResouceData({ content_code: channelCode.index }),
35 outletsApi.getOutletsActivityOrigin(params), // 获取限时活动列表 35 outletsApi.getOutletsActivityOrigin(params), // 获取限时活动列表
36 outletsApi.getOutletsActivityOrigin(params), // 获取即将结束列表 36 outletsApi.getOutletsActivityOrigin(params), // 获取即将结束列表
37 - outletsApi.getOutletsTrendData(params) 37 + outletsApi.getOutletsTrendData(params), // 获取潮流速递商品数据
  38 + saleApi.getSaleGoodsList(params) // 获取底部商品数据
38 ]).then(result => { 39 ]).then(result => {
39 let finalResult = {}; 40 let finalResult = {};
40 41
@@ -60,6 +61,11 @@ exports.getOutletsIndexData = (params) => { @@ -60,6 +61,11 @@ exports.getOutletsIndexData = (params) => {
60 finalResult.limitedBuy.extra.trendGood = outletsProcess.handleOutletstrendGoodData(result[3].data); 61 finalResult.limitedBuy.extra.trendGood = outletsProcess.handleOutletstrendGoodData(result[3].data);
61 } 62 }
62 63
  64 + // 处理底部商品数据
  65 + if (result[4].code === 200) {
  66 + finalResult.goodsBoard.list = productProcess.processProductList(result[4].data.product_list);
  67 + }
  68 +
63 return finalResult; 69 return finalResult;
64 }); 70 });
65 }; 71 };
@@ -18,6 +18,9 @@ const sale = require(`${cRoot}/sale`); @@ -18,6 +18,9 @@ const sale = require(`${cRoot}/sale`);
18 // 奥特莱斯controller 18 // 奥特莱斯controller
19 const outlets = require(`${cRoot}/outlets`); 19 const outlets = require(`${cRoot}/outlets`);
20 20
  21 +// 商品促销controller
  22 +const list = require(`${cRoot}/list`);
  23 +
21 // 商品促销routers 24 // 商品促销routers
22 router.get('/sale', sale.index); // sale 首页 25 router.get('/sale', sale.index); // sale 首页
23 router.get('/sale/discount/detail', sale.discount); // 折扣专场详情页 26 router.get('/sale/discount/detail', sale.discount); // 折扣专场详情页
@@ -31,4 +34,7 @@ router.get('/outlets/index', outlets.index); @@ -31,4 +34,7 @@ router.get('/outlets/index', outlets.index);
31 router.get('/outlets/special/detail', outlets.special); 34 router.get('/outlets/special/detail', outlets.special);
32 router.get('/outlets/:channel', outlets.channel); 35 router.get('/outlets/:channel', outlets.channel);
33 36
  37 +// 商品列表页
  38 +router.get('/list', list.index); // 商品列表页
  39 +
34 module.exports = router; 40 module.exports = router;
@@ -16,7 +16,7 @@ $('.slide-container').slider(); @@ -16,7 +16,7 @@ $('.slide-container').slider();
16 16
17 // 请求带导航的列表数据 17 // 请求带导航的列表数据
18 function getNaviData(items) { 18 function getNaviData(items) {
19 - var location, url, goodItems; 19 + var location, url, goodItems, navTitle;
20 20
21 navTitle = items.attr('urlLocation'); 21 navTitle = items.attr('urlLocation');
22 22