sale.js 2.11 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 saleDiscount = require(`${mRoot}/sale-discount`);

/**
 * 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, sale.outputDevData()));

            // 真实数据输出
            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;

            return saleDiscount.getSaleDiscountData()
                .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 });
        });
};