item.js 1.16 KB
/**
 * 商品详情页controller
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/7/4
 */
'use strict';

const _ = require('lodash');
const item = require('../models/item');

/**
 * 商品详情页
 * @function index
 */
const index = (req, res, next) => {
    req.params.channel = req.yoho.channel;
    item.getProductItemData(req.params, req.url, req.user.uid).then(result => {
        if (_.isEmpty(result)) {
            return next();
        }
        result.page = 'item';
        result.title += ` | ${res.locals.title}`;
        res.display('item', result);
    }).catch(next);
};

/**
 * 获取商品信息接口
 * @function getProductInfo
 * @param { number } productId 商品id
 * @param { number } skn 商品skn
 * @return { Object } 商品信息
 */
const getProductInfo = (req, res, next) => {
    const productId = req.query.productId;
    const skn = req.query.skn;
    let uid;

    if (req.user && req.user.uid) {
        uid = req.user.uid;
    }

    item.getProductInfo(productId, skn, uid).then(result => {
        res.json(result);
    }).catch(next);
};

module.exports = {
    index, // 商品详情页
    getProductInfo // 获取商品信息接口
};