material.js 2.08 KB
'use strict';

const Model = require('../models/material');

const index = (req, res, next) => {
    let uid = req.user.uid;

    Model.canLogin(uid).then(canLogin => {
        if (canLogin === 'N') {
            return next();
        } else {
            Model.getList({
                page: 1,
                maxSortId: 0,
                middleSortId: 0,
                smallSortId: 0
            }).then(result => {
                if (result && result.code === 200) {
                    res.render('material', Object.assign({
                        module: '3party',
                        page: 'material',
                        layout: false
                    }, result.product_list));
                }
            });
        }
    }).catch(next);
};

const newBrandList = (req, res, next) => {
    Model.newBrandList(req).then(data => {
        res.send(data);
    }).catch(next);
};

const getCategory = (req, res, next) => {
    Model.getCategory().then(data => {
        res.send(data);
    }).catch(next);
};

const getList = (req, res, next) => {
    Model.getList(req.query).then(result => {
        res.send(result);
    }).catch(next);
};

const getRecommendlist = (req, res, next) => {
    Model.getRecommendlist().then(result => {
        res.send(result);
    }).catch(next);
};

// exports.getIndexGuide = (req, res, next) => {
//     channelModel.getIndexGuideData().then(data => {
//         if (data.code !== 200) {
//             const err = new Error('异常');

//             throw err;
//         }
//         return channelModel.formatIndexGuideData(data.data);
//     }).then(data => {
//         return channelModel.getResourceData(data);
//     }).then(data => {
//         let result = {list: data, layout: false};

//         res.render('guide', result);
//     }).catch(next);
// };

// exports.hasNewUserFloor = (req, res, next) => {

//     channelModel.hasNewUserFloor(req.yoho.channel, req.user.uid).then(data => {
//         res.send(data);
//     }).catch(next);
// };

module.exports = {
    index,
    newBrandList,
    getCategory,
    getList,
    getRecommendlist
};