gift.js 1.08 KB
/**
 * 个人中心---兑换礼品卡
 * @author gaohongwei <hongwei.gao@yoho.cn>
 * @date: 2016/9/7
 */
'use strict';

const mRoot = '../models';
const giftService = require(`${mRoot}/gift-service`); // user  model
const helpers = global.yoho.helpers;

/**
 * 礼品卡页面
 */
exports.index = (req, res, next) => {
    if (!req.user.uid) {
        res.redirect(helpers.urlFormat('/signin.html'));
    }
    let uid = req.user.uid;

    let responseData = {
        module: 'home',
        page: 'gift'
    };

    // 真实数据输出
    giftService.index(req.query, uid).then(result => {
        responseData.meGiftPage = true;
        Object.assign(responseData, result);
        res.render('gift', responseData);
    }).catch(next);
};

/**
 * 个人中心-兑换礼品卡提交返回信息
 */
exports.exchange = (req, res, next) => {
    if (!req.user.uid) {
        res.redirect(helpers.urlFormat('/signin.html'));
    }
    let uid = req.user.uid;

    // 真实数据输出
    giftService.exchange(req, req.body, uid).then(result => {
        res.json(result);
    }).catch(next);
};