index.js 1.19 KB
/**
 * girls controller
 * @author: 赵彪<bill.zhao@yoho.cn>
 * @date: 2016/05/16
 */

'use strict';

const _ = require('lodash');

const channelModel = require('../models/index');

exports.boysIndex = (req, res) => {
    const channelType = req.path.substring(1);

    channelModel.getContent(channelType).then(data => {
        res.render('boys', data);
    });
};

exports.getbrandFloorDataAjax = (req, res) => {
    const channelType = req.query.channelType || 'boys';

    channelModel.getbrandFloorDataAjax(channelType).then(data => {
        res.json(data);
    });
};

exports.getNewArrival = (req, res) => {
    let reqBody = req.body,
        pageIndex = reqBody.pageIndex,
        pageCount = reqBody.pageCount,
        channel = reqBody.type,
        goods = [],
        result = {};

    if (pageIndex < 0) {
        pageIndex = 0;
    }
    if (pageCount < 0 || pageCount > 50) {
        pageCount = 20;
    }

    channelModel.getNewArrival(channel).then(data => {
        goods = _.slice(data, pageIndex, pageIndex + pageCount);

        if (goods.length !== 0) {
            result = {
                code: 200,
                goods: goods
            };
        }
        res.send(result);
    });
};