returns.js 3.73 KB
/**
 *  个人中心 退换货
 *  @author 陈轩 <xuan.chen@yoho.cn>
 */
'use strict';

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 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;


    console.log('uid' + uid);
    console.log('id' + id);
    console.log('isChange' + isChange);
    console.log('expressId' + expressId);
    console.log('expressNumber' + expressNumber);
    console.log('expressCompany' + 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,
    refundDetail,
    exchangeApply,
    exchangeDetail,
    cancelRefund,
    cancelChange,
    setExpressNumber
};