chanpin.js 1.51 KB
'use strict';

const css = require('../css');
const mRoot = '../models';
const listModel = require(`${mRoot}/chanpin`);
const co = require('bluebird').coroutine;

exports.index = (req, res, next) => {
    co(function* () {
        let params = {
            page: 1,
            limit: 100,
            sales: 'Y',
            outlets: 2,
            stocknumber: 1,
            need_filter: 'no',
            type: 'default',
            order: 's_t_desc',
            id: req.params.id
        };

        let list = yield req.ctx(listModel).index(params);
        let goodsList = {
            name: list.name || '',
            list: list.list,
            fuzzyWord: list.fuzzyWord
        };

        let chanpinCss = yield css('chanpin.css');
        let commonCss = yield css('common.css');

        if (!list || !list.fuzzyWord.length) {
            return next();
        }

        return res.render('chanpin', Object.assign({
            css: chanpinCss + commonCss,
            title: `${goodsList.name}价格_图片_品牌_怎么样-YOHO!BUY有货`,
            mipUrl: `https://m.yohobuy.com${req.originalUrl}`,
            mipFooter: true,
            canonical: {
                currentHref: `https://www.yohobuy.com/chanpin/${req.params.id}.html`
            },
            pageTitle: goodsList.name
        }, goodsList));
    })().catch(next);
};

// 301到新路由
exports.redirect = (req, res) => {
    let redirectUrl = '/mip/chanpin/';

    redirectUrl += `${req.params.id}.html`;
    res.redirect(301, redirectUrl);
};