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

'use strict';

const library = '../../../library';
const mRoot = '../models';
const _ = require('lodash');
const cookie = require(`${library}/cookie`);

// 商品详情 model
const detail = require(`${mRoot}/detail`);

// 商品尺码信息 model
const intro = require(`${mRoot}/intro`);

// 商品偏好 model
const preference = require(`${mRoot}/preference`);

/**
 * 商品基本信息
 * @param  {[type]} req [description]
 * @param  {[type]} res [description]
 * @return {[type]}     [description]
 */
exports.index = (req, res) => {

    var uid = !_.isEmpty(cookie.getUid(req)) ? cookie.getUid(req) : null;
    var vipLevel = 0; // 用户等级

    detail({
        id: req.params.id,
        uid: uid,
        vipLevel: vipLevel,
        ua: req.get('user-agent') || ''
    }).then((result) => {
        res.render('detail', {
            result: result,
            devEnv: true,
            module: 'product',
            page: 'detail',
            title: result.goodsName
        });
    });
};

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

/**
 * 为你优选 待处理
 * @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.send(result);

        // res.render('preference', {
        //     result: result,
        //     devEnv: true
        // });
    });
};