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

'use strict';

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

const channelList = ['boys', 'girls', 'kids', 'lifestyle'];

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

    // SEO url 改造
    if (req.params && req.params[0] && channelList.indexOf(req.params[0]) > -1) {
        channel = req.params[0];
    }

    // 真实数据输出
    sale.getSaleIndexData(channel).then(result => {
        res.render('sale/index', Object.assign({
            module: 'product',
            page: 'sale'
        }, {
            result: result,
            headerData: result.headerData
        }));
    }).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.yoho.channel;

    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.yoho.channel;

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

    sale.getSaleOthersData(params, channel).then((result) => {
        res.render('sale/other', Object.assign({
            module: 'product',
            page: 'sale'
        }, {
            saleList: result,
            headerData: result.headerData
        }));
    }).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.yoho.channel;

    sale.getSaleOthersData(params, channel).then((result) => {
        res.render('sale/other', Object.assign({
            module: 'product',
            page: 'sale'
        }, {
            saleList: result,
            headerData: result.headerData
        }));
    }).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.yoho.channel;

    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;

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

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

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