detail.js 1.99 KB
/**
 * 商品详情controller
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2016/5/6
 */

'use strict';

const mRoot = '../models';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const detail = require(`${mRoot}/detail`); // 商品详情 model
const intro = require(`${mRoot}/intro`); // 商品尺码信息 model
const preference = require(`${mRoot}/preference`); // 商品偏好 model
const _ = require('lodash');

/**
 * 商品基本信息
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res, next) => {
    let vipLevel = 0; // 用户等级 待处理
    let uid = _.isEmpty(req.user.uid) ? null : req.user.uid;

    let headerData = headerModel.setNav({
        navTitle: '商品详情'
    });

    detail({
        id: req.params[0],
        goodsId: req.params[1],
        uid: uid,
        vipLevel: vipLevel,
        ua: req.get('user-agent') || ''
    }).then((result) => {
        res.render('detail/detail', {
            pageHeader: headerData,
            result: result,
            page: 'detail',
            title: result.goodsName,
            pageFooter: true
        });
    }).catch(next);
};

/**
 * 商品尺码信息详情
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.intro = (req, res) => {
    intro({
        productskn: req.params.productskn
    }).then((result) => {
        res.render('detail/intro', {
            result: result
        });
    });
};

/**
 * 为你优选
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.preference = (req, res) => {
    preference({
        productskn: req.params.productskn,
        yhchannel: req.params.yhchannel,
        brandId: req.params.brandId
    }).then((result) => {
        res.render('detail/preference', {
            result: result,
            devEnv: true
        });
    });
};