me-gift.js 2.03 KB
/**
 * 个人中心---我的礼品卡
 * @author xiaoxiao <xiaoxiao.hao@yoho.cn>
 * @date: 2017/9/1
 */
'use strict';

const meGiftService = require('../models/me-gift-service');

/**
 * 礼品卡列表
 */
exports.index = (req, res, next) => {
    let uid = req.user.uid;
    let responseData = {
        module: 'home',
        page: 'me-gift'
    };

    req.ctx(meGiftService).getList(req.query, uid).then(result => {
        responseData.meGiftPage = true;
        Object.assign(responseData, result);
        res.render('home/gift/me-gift', responseData);
    }).catch(next);
};

/**
 * 消费明细
 */
exports.detail = (req, res, next) => {
    let uid = req.user.uid;
    let responseData = {
        module: 'home',
        page: 'me-gift',
        layout: false
    };

    return req.ctx(meGiftService).consumeList(req.query, uid).then(result => {
        Object.assign(responseData, result);
        return res.render('home/gift/me-detail', responseData);
    }).catch(next);
};

/**
 * 激活礼品卡
 */
exports.activateGift = (req, res, next) => {
    let uid = req.user.uid;

    req.ctx(meGiftService).activateGift(req.body, uid).then(result => {
        res.json(result);
    }).catch(next);
};

/**
 * 发送邮箱验证码
 */
exports.sendEmailCode = (req, res, next) => {
    let uid = req.user.uid;

    req.ctx(meGiftService).sendEmailCode(req.body, uid).then(result => {
        res.json(result);
    }).catch(next);
};

/**
 * 验证邮箱验证码
 */
exports.verifyEmail = (req, res, next) => {
    let uid = req.user.uid;

    req.ctx(meGiftService).verifyEmail(req.body, uid).then(result => {
        res.json(result);
    }).catch(next);
};

/**
 * 发验证码
 */
exports.smsBind = (req, res, next) => {
    req.ctx(meGiftService).smsBind(req.body).then(result => {
        res.json(result);
    }).catch(next);
};

/**
 * 修改绑定的手机号
 */
exports.changeMobile = (req, res, next) => {
    let uid = req.user.uid;

    req.ctx(meGiftService).changeMobile(req.body, uid).then(result => {
        res.json(result);
    }).catch(next);
};