new.js 1.92 KB
/**
 * 新品到着 controller
 * @author: wsl<shuiling.wang@yoho.cn>
 * @date: 2016/7/28
 */

'use strict';
const mRoot = '../models';
const utils = '../../../utils';
const headerModel = require('../../../doraemon/models/header');
const searchProcess = require(`${utils}/search-process`);
const newModel = require(`${mRoot}/new`);
const _ = require('lodash');
const helpers = global.yoho.helpers;

// 新品到着
const newGoods = (req, res, next) => {
    let channel = req.cookies._Channel;

    newModel.getNewFocus(channel).then((result) => {
        res.render('new/new', {
            module: 'product',
            page: 'new',
            title: '新品到着',
            pageHeader: headerModel.setNav({
                navTitle: '新品到着'
            }),
            headerBanner: result,
            brand: '0',
            sort: '0',
            gender: req.query.gender ? req.query.gender : searchProcess.getGenderByChannel(channel),
            channel: channel,
            price: '0',
            size: '0',
            dayLimit: 1,
            discount: '',
            cartUrl: helpers.urlFormat('/cart/index/index', null),
            pageFooter: true,
            showDownloadApp: true
        });
    }).catch(next);
};

const selectNewSale = (req, res, next) => {
    let params = _.assign({}, req.query);

    newModel.getSearchData(params).then((result) => {
        res.render('search/page', {
            layout: false,
            new: result
        });
    }).catch(next);
};

/**
 * 筛选
 * @param  {[object]} req
 * @param  {[object]} res
 * @return {[type]}
 */
let filter = (req, res, next) => {
    let params = Object.assign({}, req.query);

    newModel.getFilterData(params).then((result) => {
        res.render('search/filter', {
            layout: false,
            params: params,
            filter: result
        });
    }).catch(next);
};


module.exports = {
    newGoods,
    selectNewSale,
    filter
};