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

'use strict';

// const library = '../../../library';
// const log = require(`${library}/logger`);
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(responseData => {
            responseData = headerModel.setHeaderData(responseData.data, 'sale');

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

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

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

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

                res.render('sale/index', responseData);
            });*/
        })
        .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(responseData => {
            responseData = headerModel.setHeaderData(responseData.data, 'sale-discount');
            responseData.module = 'product';
            responseData.page = 'sale';
            responseData.footerTop = true;
            responseData.devEnv = true;

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

            return sale.getSaleGoodsListData({
                saleType: req.params.saleType
            })
                .then(result => {
                    responseData.result = result;
                    responseData.resultShow = JSON.stringify(result, null, 4);

                    // log.info(result);
                    res.render('sale/discount', responseData);
                });

        })
        .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(responseData => {
        responseData = headerModel.setHeaderData(responseData.data, 'vip');
        responseData.module = 'product';
        responseData.page = 'sale';
        responseData.footerTop = true;
        responseData.devEnv = true;

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

        sale.getSaleData().then((result) => {
            responseData.saleList = result;
            responseData.resultShow = JSON.stringify(result, null, 4);

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

    }).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(responseData => {
        responseData = headerModel.setHeaderData(responseData.data, 'breakingYards');
        responseData.module = 'product';
        responseData.page = 'sale';
        responseData.footerTop = true;
        responseData.devEnv = true;

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

        sale.getSaleData().then((result) => {
            responseData.saleList = result;
            responseData.resultShow = JSON.stringify(result, null, 4);

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

    }).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(responseData => {
            responseData = headerModel.setHeaderData(responseData.data, 'newSale');
            responseData.module = 'product';
            responseData.page = 'sale';
            responseData.footerTop = true;
            responseData.devEnv = true;

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

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

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

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