sale.js 3.46 KB
/**
 * sale controller
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/5/17
 */

'use strict';
const library = '../../../library';
const mRoot = '../models';

// const cookie = require(`${library}/cookie`);
const headerModel = require('../../../doraemon/models/header');
const log = require(`${library}/logger`);
const saleModel = require(`${mRoot}/sale`);

const saleLogger = (err, res) => {
    log.error('sale页面渲染错误:' + JSON.stringify(err));
    res.send('error');
};

/**
 * sale 首页
 */
exports.index = (req, res) => {
    let headerData = headerModel.setNavHeader('SALE');
    let renderData = {
        module: 'product',
        page: 'sale',
        title: 'SALE',
        pageHeader: headerData,
        pageFooter: true
    };

    saleModel.getSaleData().then((result) => {
        res.render('sale', Object.assign(renderData, {
            content: result,
            floorHeader: {
                title: {
                    title: '最新降价'
                }
            }
        }));
    }).catch((err) => {
        saleLogger(err, res);
    });
};

/**
 * 断码区
 */
exports.breakCode = (req, res) => {
    let headerData = headerModel.setNavHeader('断码区');
    let renderData = {
        module: 'product',
        page: 'break-code',
        pageHeader: headerData,
        pageFooter: true
    };

    saleModel.getBreakCodeData().then((result) => {
        res.render('break-code', Object.assign(renderData, result));
    }).catch((err) => {
        saleLogger(err, res);
    });
};

/**
 * 折扣专场列表
 */
exports.special = (req, res) => {
    let headerData = headerModel.setNavHeader('折扣专场');
    let renderData = {
        module: 'product',
        page: 'special',
        pageHeader: headerData,
        pageFooter: true
    };

    saleModel.getSpecialData().then((result) => {
        res.render('special', Object.assign(renderData, result));
    }).catch((err) => {
        saleLogger(err, res);
    });
};


/**
 * 折扣专场专题详情
 */
exports.specialDetail = (req, res) => {
    let headerData = headerModel.setNavHeader();
    let id = req.query.id;
    let renderData = {
        module: 'product',
        page: 'special-detail',
        pageFooter: true
    };

    saleModel.getSpecialDetailData(id).then((result) => {
        headerData.navTitle = result.title;
        renderData.pageHeader = headerData;
        res.render('special-detail', Object.assign(renderData, result));
    }).catch((err) => {
        saleLogger(err, res);
    });
};

/**
 * vip
 */
exports.vip = (req, res) => {
    let headerData = headerModel.setNavHeader('会员专享');
    let renderData = {
        module: 'product',
        page: 'vip',
        pageHeader: headerData,
        pageFooter: true
    };

    saleModel.getVipData().then((result) => {
        res.render('vip', Object.assign(renderData, {
            content: result
        }));
    }).catch((err) => {
        saleLogger(err, res);
    });
};

exports.filter = (req, res) => {
    let params = Object.assign({}, req.query);

    saleModel.getFilterData(params).then((result) => {
        res.render('filter', {
            layout: false,
            params: params,
            filter: result
        });
    });
};

exports.search = (req, res) => {
    let params = Object.assign({}, req.query);

    saleModel.getSearchData(params).then((result) => {
        res.render('product', {
            layout: false,
            params: params,
            goods: result
        });
    });
};