Authored by 郭成尧

折扣专场

@@ -12,26 +12,65 @@ const mRoot = '../models'; @@ -12,26 +12,65 @@ const mRoot = '../models';
12 // sale 页 model 12 // sale 页 model
13 const sale = require(`${mRoot}/sale`); 13 const sale = require(`${mRoot}/sale`);
14 14
  15 +const saleDiscount = require(`${mRoot}/sale-discount`);
  16 +
  17 +/**
  18 + * sale 首页
  19 + * @param {[type]} req [description]
  20 + * @param {[type]} res [description]
  21 + * @return {[type]} [description]
  22 + */
15 exports.index = (req, res) => { 23 exports.index = (req, res) => {
16 24
17 headerModel.requestHeaderData() 25 headerModel.requestHeaderData()
18 .then(response => { 26 .then(response => {
19 - response = headerModel.setHeaderData(response.data, 'boys'); 27 + response = headerModel.setHeaderData(response.data, 'sale');
20 28
21 response.module = 'product'; 29 response.module = 'product';
22 response.page = 'sale'; 30 response.page = 'sale';
23 response.footerTop = true; 31 response.footerTop = true;
24 response.devEnv = true; 32 response.devEnv = true;
25 33
26 - res.render('sale/index', Object.assign(response, sale.outputDevData())); 34 + // 假数据输出
  35 + // res.render('sale/index', Object.assign(response, sale.outputDevData()));
27 36
28 - /* return sale.getSaleDate().then(result => { 37 + // 真实数据输出
  38 + return sale.getSaleDate().then(result => {
29 39
30 response.result = result; 40 response.result = result;
31 response.resultShow = JSON.stringify(result, null, 4); 41 response.resultShow = JSON.stringify(result, null, 4);
32 42
33 res.render('sale/index', response); 43 res.render('sale/index', response);
34 - });*/ 44 + });
  45 + })
  46 + .catch(() => {
  47 + res.render('error', { devEnv: true, pageErr: true });
  48 + });
  49 +};
  50 +
  51 +/**
  52 + * 折扣专场
  53 + * @param {[type]} req [description]
  54 + * @param {[type]} res [description]
  55 + * @return {[type]} [description]
  56 + */
  57 +exports.discount = (req, res) => {
  58 + headerModel.requestHeaderData()
  59 + .then(response => {
  60 + response = headerModel.setHeaderData(response.data, 'sale-discount');
  61 + response.module = 'product';
  62 + response.page = 'sale';
  63 + response.footerTop = true;
  64 + response.devEnv = true;
  65 +
  66 + return saleDiscount.getSaleDiscountData()
  67 + .then(result => {
  68 + response.result = result;
  69 + response.resultShow = JSON.stringify(result, null, 4);
  70 +
  71 + res.render('sale/discount', response);
  72 + });
  73 +
35 }) 74 })
36 .catch(() => { 75 .catch(() => {
37 res.render('error', { devEnv: true, pageErr: true }); 76 res.render('error', { devEnv: true, pageErr: true });
  1 +/*
  2 + * @Author: Targaryen
  3 + * @Date: 2016-05-19 16:10:11
  4 + * @Last Modified by: Targaryen
  5 + * @Last Modified time: 2016-05-19 16:16:55
  6 + */
  7 +
  8 +'use strict';
  9 +const library = '../../../library';
  10 +const API = require(`${library}/api`).API;
  11 +const sign = require(`${library}/sign`);
  12 +const api = new API();
  13 +
  14 +/**
  15 + * 处理商品列表数据
  16 + * @param {[type]} origin [description]
  17 + * @return {[type]} [description]
  18 + */
  19 +const handleSaleDiscountData = (origin) => {
  20 + var dest = {};
  21 +
  22 + dest = origin;
  23 +
  24 + return dest;
  25 +};
  26 +
  27 +/**
  28 + * 获取商品列表数据
  29 + * @return {[type]} [description]
  30 + */
  31 +exports.getSaleDiscountData = () => {
  32 +
  33 + return api.get('', sign.apiSign({
  34 + method: 'app.search.sales',
  35 + limit: 20,
  36 + order: 's_t_desc',
  37 + page: 1,
  38 + productSize: '384x511',
  39 + yh_channel: 1
  40 + })).then(result => {
  41 + return handleSaleDiscountData(result);
  42 + });
  43 +};
@@ -17,6 +17,7 @@ const sale = require(`${cRoot}/sale`); @@ -17,6 +17,7 @@ const sale = require(`${cRoot}/sale`);
17 17
18 // routers 18 // routers
19 // router.get('/detail/:id/:gid', detail.index); 19 // router.get('/detail/:id/:gid', detail.index);
20 -router.get('/sale', sale.index); 20 +router.get('/sale/index', sale.index);
  21 +router.get('/sale/discount', sale.discount);
21 22
22 module.exports = router; 23 module.exports = router;
  1 +<div>keep coding...</div>