product-detail.js 1.75 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');
        let appParams = {product_skn: _.get(detailData, 'baseInfo.product_skn')};
        let appPath = 'openby:yohobuy={"action":"go.productDetail","params":' +
            JSON.stringify(appParams) +
            '}';

        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'),
            commonCss: yield css('common.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: ''
            },
            pageTitle: '商品详情',
            appPath: appPath
        }));
    })().catch(next);
};