returns.js 4.5 KB
/**
 *  个人中心 退换货
 *  @author 陈轩 <xuan.chen@yoho.cn>
 */
'use strict';
const helpers = global.yoho.helpers;
const returnsModel = require('../models/returns');

/*
    我的退换货-列表页
 */
const index = (req, res, next) => {
    const page = req.query.page;

    returnsModel.getReturnsList(req.user.uid, page, 10)
        .then(data => {
            const viewData = Object.assign({
                module: 'home',
                page: 'returns',
                meReturnsPage: true
            }, data);

            res.render('returns/returns', viewData);
        })
        .catch(next);
};

/*
    我的订单-退货申请页
 */
const refundApply = (req, res, next) => {
    const orderCode = req.query.orderCode;
    const uid = req.user.uid;

    returnsModel.getOrderRefund(orderCode, uid).then(result => {
        res.render('returns/returns-apply', result);
    }).catch(next);
};

/*
 我的订单-退货提交
 */
const saveRefund = (req, res, next) => {
    const uid = req.user.uid;

    returnsModel.saveRefund(req, uid).then(result => {
        res.send(result);
    }).catch(next);
};

/*
 退货成功
 */
const refundSuccess = (req, res) => {
    let resData = {
        save: {
            type: '退货',
            ordersHref: helpers.urlFormat('/home/orders'),
            returnsHref: helpers.urlFormat('/home/returns'),
            refund: {// 退货时传退货收件地址
                address: '南京市江宁区江宁经济技术开发区苏源大道87号YOHO!有货物流中心东一楼',
                name: 'YOHO!有货',
                phone: '400-889-9646',
                postcode: '211106'
            }
        }
    }

    res.render('returns/returns-save', {returns: resData});
};

/*
 换货成功
 */
const exchangeSuccess = (req, res) => {
    let resData = {
        save: {
            type: '换货',
            ordersHref: helpers.urlFormat('/home/orders'),
            returnsHref: helpers.urlFormat('/home/returns')
        }
    }

    res.render('returns/returns-save', {returns: resData});
};

/*
 我的退换货-退货详情页
 */
const refundDetail = (req, res, next) => {
    const code = req.query.id;
    const uid = req.user.uid;
    let resData = {
        module: 'home',
        page: 'returns'
    };

    returnsModel.getRefundDetail(code, uid).then(result => {
        Object.assign(resData, result);
        res.render('returns/returns-detail', resData);
    }).catch(next);
};

/*
 * 我的退换货-换货详情页
 */
const exchangeDetail = (req, res, next) => {
    const code = req.query.id;
    const uid = req.user.uid;
    let resData = {
        module: 'home',
        page: 'returns'
    };

    returnsModel.getChangeDetail(code, uid).then(result => {
        Object.assign(resData, result);
        res.render('returns/returns-detail', resData);
    }).catch(next);
};

/*
    我的订单-换货申请页
 */
const exchangeApply = (req, res, next) => {
    const orderCode = req.query.orderCode;
    const uid = req.user.uid;

    returnsModel.getOrderExchange(orderCode, uid).then(result => {
        res.render('returns/returns-apply', result);
    }).catch(next);
};

/**
 * 取消退货申请
 */
const cancelRefund = (req, res, next) => {
    let id = req.body.id;
    let uid = req.user.uid;

    returnsModel.getCancelRefund(id, uid).then(result => {
        res.send(result);
    }).catch(next);
};

/**
 * 取消换货申请
 */
const cancelChange = (req, res, next) => {
    let id = req.body.id;
    let uid = req.user.uid;

    returnsModel.getCancelChange(id, uid).then(result => {
        res.send(result);
    }).catch(next);
};

/**
 * 我的退换货-设置快递单号
 */
const setExpressNumber = (req, res, next) => {

    let uid = req.user.uid;
    let id = req.body.id;
    let isChange = req.body.isChange === 'false' ? false : true;
    let expressId = req.body.expressId;
    let expressNumber = req.body.expressNumber;
    let expressCompany = req.body.expressCompany;

    returnsModel.setExpressNumber(id, expressId, expressNumber, uid, expressCompany, isChange).then(result => {

        if (res.code && res.code == 201) {
            res.json({message: '请求失败'});
        }

        if (id || expressId || expressNumber || uid || expressCompany || isChange) {
            res.send(result);
        }

    }).catch(next);

};

module.exports = {
    index,
    refundApply,
    saveRefund,
    refundSuccess,
    refundDetail,
    exchangeApply,
    exchangeSuccess,
    exchangeDetail,
    cancelRefund,
    cancelChange,
    setExpressNumber
};