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

'use strict';

const mRoot = '../models';
const sale = require(`${mRoot}/sale`); // sale  model

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

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

    // 真实数据输出
    sale.getSaleIndexData(channel).then(result => {
        responseData.result = result;
        if (result) {
            responseData.headerData = result.headerData;
        }
        res.render('sale/index', responseData);
    }).catch(next);

};

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

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

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

    sale.getSaleDiscountData(params, channel).then((result) => {
        responseData.result = result;
        if (result) {
            responseData.headerData = result.headerData;
        }
        res.render('sale/discount', responseData);
    }).catch(next);
};

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

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

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

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

    sale.getSaleOthersData(params, channel).then((result) => {
        responseData.saleList = result;
        if (result) {
            responseData.headerData = result.headerData;
        }
        res.render('sale/other', responseData);
    }).catch(next);

};

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

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

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

    sale.getSaleOthersData(params, channel).then((result) => {
        responseData.saleList = result;
        if (result) {
            responseData.headerData = result.headerData;
        }
        res.render('sale/other', responseData);
    }).catch(next);
};

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

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

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

    sale.getSalebreakingYardsData(params, channel).then((result) => {
        responseData.saleList = result;
        if (result) {
            responseData.headerData = result.headerData;
        }
        res.render('sale/other', responseData);
    }).catch(next);
};

/**
 * 活动
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.special = (req, res, next) => {
    let params = req.query;
    let specialId = params.specialsale_id || params.specialsaleId, // 专区ID
        promotion = params.promotion; // 促销ID

    if (!specialId && !promotion) {
        return next();
    }

    sale.getSaleSpecialData(specialId, params, req.yoho.channel).then(result => {
        res.render('sale/special', result);
    }).catch(next);
};

/**
 * Ajax 获取商品列表
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.getGoodsList = (req, res, next) => {
    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;

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