sale.js 5.13 KB
/**
 * 商品促销controller
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/5/18
 */

'use strict';

const headerModel = require('../../../doraemon/models/header');
const mRoot = '../models';

// sale 页 model
const sale = require(`${mRoot}/sale`);

// 开发用模拟数据
const simulation = require(`${mRoot}/simulation`);

/**
 * sale 首页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res) => {

    headerModel.requestHeaderData()
        .then(response => {
            response = headerModel.setHeaderData(response.data, 'sale');

            response.module = 'product';
            response.page = 'sale';
            response.footerTop = true;
            response.devEnv = true;

            // 假数据输出
            res.render('sale/index', Object.assign(response, simulation.saleIndex()));

            // 真实数据输出
            /* return sale.getSaleDate().then(result => {

                response.result = result;
                response.resultShow = JSON.stringify(result, null, 4);

                res.render('sale/index', response);
            });*/
        })
        .catch(() => {
            res.render('error', { devEnv: true, pageErr: true });
        });
};

/**
 * 折扣专场
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.discount = (req, res) => {
    headerModel.requestHeaderData()
        .then(response => {
            response = headerModel.setHeaderData(response.data, 'sale-discount');
            response.module = 'product';
            response.page = 'sale';
            response.footerTop = true;
            response.devEnv = true;

            // 假数据输出
            // res.render('sale/discount', Object.assign(response, simulation.discount()));

            return sale.getSaleGoodsListData()
                .then(result => {
                    response.result = result;
                    response.resultShow = JSON.stringify(result, null, 4);

                    res.render('sale/discount', response);
                });

        })
        .catch(() => {
            res.render('error', { devEnv: true, pageErr: true });
        });
};

/**
 * VIP会员专享
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.vip = (req, res) => {
    headerModel.requestHeaderData()
        .then(response => {
            response = headerModel.setHeaderData(response.data, 'vip');
            response.module = 'product';
            response.page = 'sale';
            response.footerTop = true;
            response.devEnv = true;

            // 假数据输出
            res.render('sale/other', Object.assign(response, simulation.other()));

            /* return sale.getSaleGoodsListData()
                .then(result => {
                    response.result = result;
                    response.resultShow = JSON.stringify(result, null, 4);

                    res.render('sale/other', response);
                });*/

        })
        .catch(() => {
            res.render('error', { devEnv: true, pageErr: true });
        });
};

/**
 * 断码专区
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.breakingYards = (req, res) => {
    headerModel.requestHeaderData()
        .then(response => {
            response = headerModel.setHeaderData(response.data, 'breakingYards');
            response.module = 'product';
            response.page = 'sale';
            response.footerTop = true;
            response.devEnv = true;

            // 假数据输出
            res.render('sale/other', Object.assign(response, simulation.other()));

            /* return sale.getSaleGoodsListData()
                .then(result => {
                    response.result = result;
                    response.resultShow = JSON.stringify(result, null, 4);

                    res.render('sale/other', response);
                });*/

        })
        .catch(() => {
            res.render('error', { devEnv: true, pageErr: true });
        });
};

/**
 * 断码专区
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.newSale = (req, res) => {
    headerModel.requestHeaderData()
        .then(response => {
            response = headerModel.setHeaderData(response.data, 'newSale');
            response.module = 'product';
            response.page = 'sale';
            response.footerTop = true;
            response.devEnv = true;

            // 假数据输出
            res.render('sale/other', Object.assign(response, simulation.other()));

            /* return sale.getSaleNewSaleData()
                .then(result => {
                    response.result = result;
                    response.resultShow = JSON.stringify(result, null, 4);

                    res.render('sale/other', response);
                });*/

        })
        .catch(() => {
            res.render('error', { devEnv: true, pageErr: true });
        });
};