refund.js 2.49 KB
/**
 * 退换货
 * @type {Object}
 */
'use strict';
const refundModel = require('../models/refund');
const notLoginCode = 400;
const notLoginTip = '抱歉,您暂未登录!';
const testUid = 8050378;// 测试uid
const isBLK = 1;

const refund = {
    refund(req, res) {
        res.render('refund');
    },
    order(req, res, next) {
        const uid = req.user.uid || 8050882;
        const orderId = req.query.orderId;

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

        refundModel.getOrderData(uid, orderId).then(result => {
            res.json(result);
        }).catch(next);
    },
    submit(req, res, next) {
        const uid = req.user.uid || 8050882;

        refundModel.submitRefundData(uid, req.body).then(result => {
            res.json(result);
        }).catch(next);
    },
    logistics(req, res, next) {
        refundModel.getExpressCompany().then(result => {
            res.render('logistics', {
                module: 'home',
                page: 'logistics',
                company_list: result ? JSON.stringify(result.data) : ''
            });
        }).catch(next);
    },
    saveLogistics(req, res) {
        // todo 调用保存物流信息接口
        // const companyId = req.body.company_id;
        // const companyName = req.body.company_name;
        // const num = req.body.num;
        res.json({
            code: 200
        });
    },
    exchangeGoods(req, res) {
        // let orderCode = req.query.orderCode;

        res.render('exchange-status');
    },
    refundOrders(req, res) {
        res.render('refund-order', {
            module: 'home',
            page: 'refund-order'
        });
    },

    /**
     * 获取退换货订单
     * @param req
     * @param res
     * @returns {*|{read, write}}
     */
    getRefundOrders(req, res) {
        let uid = req.query.id;
        let page = req.query.page;
        let limit = req.query.limit;
        let isend = true;

        uid = testUid;
        if (!uid && req.xhr) {
            return res.json({
                code: notLoginCode,
                message: notLoginTip
            });
        }
        let param = {
            uid: uid,
            page: page,
            limit: limit,
            app_type: isBLK
        };

        refundModel.getRefundOrders(param).then(result => {
            if (result && page < result.page_total) {
                isend = false;
            }
            return res.json(Object.assign({isend: isend}, result));
        });
    }
};

module.exports = refund;