favorite.js 1.47 KB
/**
 * 收藏商品、品牌
 * @type {Object}
 */
'use strict';
const favModel = require('../models/favorite');
const helpers = global.yoho.helpers;

const fav = {
    favorite: (req, res) => {
        if (req.query.tab === 'brand') {
            res.render('favorite-brand', {
                module: 'home',
                page: 'favorite-brand',
                brandUrl: helpers.urlFormat('/product/new')
            });
        } else {
            res.render('favorite', {
                module: 'home',
                page: 'favorite',
                productUrl: helpers.urlFormat('/product/new')
            });
        }
    },
    favpaging: (req, res, next) => {
        const uid = req.user.uid || 14459668;
        const tab = req.query.tab;
        const page = req.query.page;

        if (tab === 'brand') {
            const gender = '1,2,3'; // todo 获取频道的性别

            favModel.getFavBrandData(uid, gender, page, 10).then(data => {
                return res.json(data);
            });
        } else {
            favModel.getFavProductData(uid, page, 10).then(data => {
                return res.json(data);
            }).catch(next);
        }
    },
    deletefav: (req, res, next) => {
        const uid = req.user.uid || 14459668;
        const favId = req.body.favId;
        const type = req.body.type;

        favModel.favoriteDelete(uid, favId, type).then(data => {
            return res.json(data);
        }).catch(next);
    }
};

module.exports = fav;