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

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

const _ = require('lodash');

/**
 * outlets 首页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res, next) => {
    let channel = req.query.channel || req.cookies._Channel || 'otltIdxDflt';

    outlets.getOutletsIndexData(req.query, channel).then((result) => {
        res.render('outlets/index', Object.assign({
            module: 'product',
            page: 'outlets'
        }, result));
    }).catch(next);
};

/**
 * outlets 频道页
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.channel = (req, res, next) => {
    let channel = req.params.channel || req.query.channel || req.cookies._Channel || 'boys';

    outlets.getOutletsChannelData(req.query, channel).then((result) => {
        res.render('outlets/channel', Object.assign({
            module: 'product',
            page: 'outlets'
        }, result));
    }).catch(next);
};

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

    // 判断活动id是否合法
    if (!params.id || !+params.id || !_.isNumber(+params.id)) {
        return next();
    }

    outlets.getOutletsSpecialData(params, channel).then(result => {
        res.render('outlets/special', Object.assign({
            module: 'product',
            page: 'outlets'
        }, result));
    }).catch(next);
};

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

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

    outlets.getOutletsCategoryData(params, channel).then((result) => {
        res.render('sale/other', Object.assign({
            module: 'product',
            page: 'outlets'
        }, result));
    }).catch(next);

};