outlets.js 2.82 KB
/**
 * 商品促销controller
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/5/19
 */

'use strict';
const mRoot = '../models';
const outlets = require(`${mRoot}/outlets`);
const log = require(`${global.library}/logger`);

/**
 * outlets 首页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res) => {
    let resData = {
        module: 'product',
        page: 'outlets'
    };

    let channel = req.query.channel || req.cookies._Channel || 'boys';

    outlets.getOutletsIndexData(req.query, channel).then(result => {
        resData.result = result;
        resData.headerData = result.headerData;
        resData.resultShow = JSON.stringify(result, null, 4);
        res.render('outlets/index', resData);
    }).catch((e) => {
        log.error(e);
        resData.pageErr = true;
        res.render('error', resData);
    });

};

/**
 * outlets 频道页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.channel = (req, res) => {
    let resData = {
        module: 'product',
        page: 'outlets'
    };

    outlets.getOutletsChannelData(req.query, req.params.channel).then(result => {
        res.render('outlets/channel', Object.assign(resData, result));
    }).catch((e) => {
        log.error(e);
        resData.pageErr = true;
        res.render('error', resData);
    });
};

/**
 * outlets 活动
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.special = (req, res) => {
    let params = req.query;
    let channel = req.query.channel || req.cookies._Channel || 'boys';
    let resData = {
        module: 'product',
        page: 'outlets'
    };

    if (!params.id) {
        resData.pageErr = true;
    }

    outlets.getOutletsSpecialData(params, channel).then(result => {
        res.render('outlets/special', Object.assign(resData, result));
    }).catch((e) => {
        log.error(e);
        resData.pageErr = true;
        res.render('error', resData);
    });
};

/**
 * 商品列表页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.list = (req, res) => {
    let params = req.query;

    let channel = req.query.channel || req.cookies._Channel || 'boys';

    params.uid = req.user.uid || 0;

    let responseData = {
        module: 'product',
        page: 'outlets'
    };

    outlets.getOutletsCategoryData(params, channel).then((result) => {
        responseData.resultShow = JSON.stringify(result, null, 4);
        res.render('sale/other', Object.assign(responseData, result));
    }).catch((e) => {
        log.error(e);
        responseData.pageErr = true;
        res.render('error', responseData);
    });

};