product-detail.js 1.42 KB
'use strict';

const css = require('../css');
const co = require('bluebird').coroutine;
const _ = require('lodash');
const mRoot = '../models';
const productDetailModel = require(`${mRoot}/product-detail`);

exports.index = (req, res, next) => {
    co(function* () {
        let params = {
            productSkn: req.params.skn,
            protocol: req.protocol
        };

        let detailData = yield req.ctx(productDetailModel).index(params);
        let mipPic = _.get(detailData, 'baseInfo.goods_list[0].images_list[0].image_url');
        let mipDes = _.get(detailData, 'baseInfo.phrase');
        let miptitle = _.get(detailData, 'baseInfo.product_name');

        if (!_.get(detailData, 'baseInfo.product_skn')) {
            return next();
        }
        return res.render('product/detail', Object.assign(detailData, {
            title: `${detailData.title}-YOHO!BUY有货`,
            css: yield css('product/detail.css'),
            localStyle: detailData.mipCss,
            mipFooter: true,
            canonical: {
                currentHref: `https://m.yohobuy.com/product/${detailData.baseInfo.product_skn}.html`
            },
            showAnaJson: {
                url: `${req.protocol}://m.yohobuy.com${req.originalUrl}`,
                title: `${miptitle}-YOHO!BUY有货`,
                pic: mipPic,
                des: mipDes,
                publishTime: ''
            }
        }));
    })().catch(next);
};