sale.js 5.4 KB
/**
 * 商品促销controller
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/5/18
 */

'use strict';

const mRoot = '../models';

// sale 页 model
const sale = require(`${mRoot}/sale`);

// 开发用模拟数据
// const simulation = require(`${mRoot}/simulation`);

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

    let responseData = {
        module: 'product',
        page: 'sale',
        footerTop: true
    };

    // 假数据输出
    // res.render('sale/index', Object.assign(responseData, simulation.saleIndex()));

    // 真实数据输出
    sale.getSaleIndexData(channel).then(result => {
        responseData.result = result;
        responseData.resultShow = JSON.stringify(result, null, 4);
        responseData.headerData = result.headerData;
        res.render('sale/index', responseData);
    }).catch(() => {
        responseData.pageErr = true;
        res.render('error', responseData);
    });

};

/**
 * 折扣专场
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.discount = (req, res) => {
    let params = Object.assign({
        saleType: '3'
    }, req.query);

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

    let responseData = {
        module: 'product',
        page: 'sale',
        footerTop: true
    };

    // 假数据输出
    // res.render('sale/discount', Object.assign(responseData, simulation.discount()));

    sale.getSaleDiscountData(params, channel).then((result) => {
        responseData.result = result;
        responseData.resultShow = JSON.stringify(result, null, 4);
        responseData.headerData = result.headerData;

        // log.info(result);
        res.render('sale/discount', responseData);
    }).catch(() => {
        responseData.pageErr = true;
        res.render('error', responseData);
    });
};

/**
 * VIP会员专享
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.vip = (req, res) => {
    let params = Object.assign({
        saleType: '2',
        order: 's_t_asc,s_s_asc'
    }, req.query);

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

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

    let responseData = {
        module: 'product',
        page: 'sale',
        footerTop: true
    };

    // 假数据输出
    // res.render('sale/other', Object.assign(responseData, simulation.other()));

    sale.getSaleOthersData(params, channel).then((result) => {
        responseData.saleList = result;
        responseData.resultShow = JSON.stringify(result, null, 4);
        responseData.headerData = result.headerData;
        res.render('sale/other', responseData);
    }).catch(() => {
        responseData.pageErr = true;
        res.render('error', responseData);
    });

};

/**
 * 新降价专区
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.newSale = (req, res) => {
    let params = Object.assign({
        saleType: '3',
        order: 's_t_desc'
    }, req.query);

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

    let responseData = {
        module: 'product',
        page: 'sale',
        footerTop: true
    };

    // 假数据输出
    // res.render('sale/other', Object.assign(responseData, simulation.other()));

    sale.getSaleOthersData(params, channel).then((result) => {
        responseData.saleList = result;
        responseData.resultShow = JSON.stringify(result, null, 4);
        responseData.headerData = result.headerData;
        res.render('sale/other', responseData);
    }).catch(() => {
        responseData.pageErr = true;
        res.render('error', responseData);
    });
};

/**
 * 断码专区
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.breakingYards = (req, res) => {
    let params = Object.assign({
        saleType: '1'
    }, req.query);

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

    let responseData = {
        module: 'product',
        page: 'sale',
        footerTop: true
    };

    // 假数据输出
    // res.render('sale/other', Object.assign(responseData, simulation.other()));

    sale.getSalebreakingYardsData(params, channel).then((result) => {
        responseData.saleList = result;
        responseData.resultShow = JSON.stringify(result, null, 4);
        responseData.headerData = result.headerData;
        res.render('sale/other', responseData);
    }).catch(() => {
        responseData.pageErr = true;
        res.render('error', responseData);
    });
};

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

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

    return sale.getSaleGoodsData(params).then(result => {
        let responseData = {};

        responseData.footerTop = false;
        responseData.layout = false;

        responseData.result = result;
        responseData.resultShow = JSON.stringify(result, null, 4);

        res.render('goods', responseData);
    });
};