exchange.js 1.83 KB
/*
 *  换货 controller
 */
'use strict';
const headerModel = require('../../../doraemon/models/header'); // 头部model
const exchangeModel = require('../models/exchange');

const exchange = {
    exchange(req, res) {
        res.render('refund/exchange', {
            module: 'home',
            page: 'refund-exchange',
            pageHeader: headerModel.setNav({
                navTitle: '换货申请',
                suggestSub: {
                    text: '提交'
                },
                navBtn: false
            }),
            title: '换货申请',
            localCss: true
        });
    },

    // 订单 可换货商品列表
    order(req, res, next) {
        const uid = req.user.uid; // const udi = 8039837  //test account
        const orderCode = req.query.orderCode;

        if (!orderCode) {
            return next();
        }

        exchangeModel.getOrderData(uid, orderCode).then(result => {
            res.json(result);
        }).catch(next);
    },

    delivery(req, res, next) {
        const uid = req.user.uid;
        const areaCode = req.query.areaCode;

        if (!areaCode) {
            return next();
        }

        exchangeModel.getDelivery(uid, areaCode).then(result => {
            res.json(result);
        }).catch(next);
    },

    // 提交 换货
    submit(req, res, next) {
        const uid = req.user.uid;

        exchangeModel.submitExchange(uid, req.body).then(result => {
            res.json(result);
        }).catch(next);
    },

    /**
     * 取消换货申请
     * @param req
     * @param res
     * @param next
     */
    cancelApply(req, res, next) {
        const id = req.body.id;
        const uid = req.user.uid;

        exchangeModel.cancelApply(uid, id).then(result => {
            return res.json(result);
        }).catch(next);
    }
};

module.exports = exchange;