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

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

const outlets = require(`${mRoot}/outlets`);

// 开发用模拟数据
// const simuOutlets = require(`${mRoot}/simu-outlets`);
// const outletsSimulation = require('../models/simulation');

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

    // 首页模拟数据
    // resData.result = simuOutlets.index();
    outlets.getOutletsIndexData(req.query).then(result => {
        resData.result = result;
        resData.headerData = result.headerData;
        resData.resultShow = JSON.stringify(result, null, 4);
        res.render('outlets/index', resData);
    }).catch(() => {
        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'
    };

    // 首页模拟数据
    // resData = outletsSimulation.outletBanner();
    outlets.getOutletsChannelData(req.params.channel).then(result => {
        res.render('outlets/channel', Object.assign(resData, result));
    }).catch(() => {
        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 resData = {
        module: 'product',
        page: 'outlets'
    };

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

    // resData.mainBanner = {
    //     url: '#',
    //     src: 'http://img10.static.yhbimg.com/brandBanner/2014/11/24/07/01ff74fb2a33764c2fd18b3c8a60f5beef.jpg'
    // };

    // resData.specialHead = {
    //     logo: 'http://img10.static.yhbimg.com/brandLogo/2012/08/02/15/0119ad6a2407f5505268688a470d6f6c13.jpg',
    //     special: '精品上装专场',
    //     discount: '8',
    //     title: '全部商品',
    //     count: '123533',
    //     limit: '80000000'
    // };
    //
    outlets.getOutletsSpecialData(params).then(result => {
        res.render('outlets/special', Object.assign(resData, result));
    }).catch(() => {
        resData.pageErr = true;
        res.render('error', resData);
    });
};