brands.js 1.83 KB
/**
 * 品牌一览 controller
 * @author: ghw<hongwei.gao@yoho.cn>
 * @date: 2016/9/29
 */

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

const brandsService = require(`${mRoot}/brands-service`); // students  model

/**
 * brands 首页
 * @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';

    brandsService.getBrandViewList(channel, req).then(result => {
        // 返回null,不cashe
        if (result.noCashe) {
            res.set('Cashe-Control', 'no-cashe');
        }
        res.render('brands/brands', result);

    }).catch(next);
};

/**
 * brandList-Ajax调用
 */
exports.brandList = (req, res, next) => {
    let channel = req.query.channel || req.cookies._Channel || 'boys';

    brandsService.getBrandList(channel, req.body.start).then(result => {

        res.render('brands/brand-list', Object.assign({layout: false}, result));

    }).catch(next);
};

/**
 * 品牌接口数据
 *
 * @param string brandId 获取品牌ID
 * @return json
 */
exports.brandInfo = (req, res, next) => {

    let brandId = req.query.brandId || 0;

    brandsService.brandInfo(brandId, req.user.uid).then(result => {
        // 返回null,不cashe
        if (result.noCashe) {
            res.set('Cashe-Control', 'no-cashe');
        }
        res.json(result);
    }).catch(next);
};

/**
 * 品牌plusstar列表
 */
exports.plusstarList = (req, res, next) => {
    let channel = req.query.channel || req.cookies._Channel || 'boys';

    brandsService.plusstarList(channel, req).then(result => {
        // 返回null,不cashe
        if (result.noCashe) {
            res.set('Cashe-Control', 'no-cashe');
        }
        res.render('brands/plusstar', result);
    }).catch(next);
};