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({
            title: detailData.title,
            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: ''
            }
        }, detailData));
    })().catch(next);
};