order.js 3.73 KB
/**
 * [个人中心]首页/我的订单
 * @author: xuqi<qi.xu@yoho.cn>
 * @date: 2016/07/04
 */

'use strict';

const mcHandler = require('../models/menu-crumb-handler');
const orderModel = require('../models/order');

/**
 * 我的订单
 */
const index = (req, res, next) => {
    const type = req.query.type;
    const page = req.query.page;
    const uid = global.yoho.uid || '7394907';

    orderModel.getOrderData(uid, type, page).then(result => {
        res.display('index', {
            page: 'order',
            isMe: true,
            content: Object.assign({
                nav: mcHandler.getMeCrumb(),
                navigation: mcHandler.getSideMenu('我的订单'),
                banner: 'http://placehold.it/{width}x{height}'
            }, result)
        });
    }).catch(next);
};

const detail = (req, res, next) => {
    const code = req.query.code;
    const uid = global.yoho.uid || '7394907';

    orderModel.getOrderDetail(uid, code).then(result => {
        res.display('index', {
            isMe: true,
            page: 'order-detail',
            content: Object.assign({
                nav: mcHandler.getMeCrumb(),
                navigation: mcHandler.getSideMenu('订单详情'),
                banner: 'http://placehold.it/{width}x{height}'
            }, result)
        });
    }).catch(next);
};

const getOrderList = (req, res, next) => {
    const type = req.query.type;
    const page = req.query.page;
    const uid = global.yoho.uid || '7394907';

    orderModel.getOrderData(uid, type, page).then(result => {
        res.display('order-table', {
            layout: false,
            page: 'order',
            isMe: true,
            orderList: result.order.orderList,
            paginationOpts: result.order.paginationOpts,
            emptyMsg: result.order.emptyMsg,
            showEmptyEn: result.order.showEmptyEn
        });
    }).catch(next);
};

const getOrderTotal = (req, res, next) => {
    const type = req.query.type;
    const uid = global.yoho.uid || '7394907';


    orderModel.getOrderData(uid, type).then(result => {

        res.json({
            total: result.order.total,
            type: result.order.type
        });
    }).catch(next);
};

const cancelOrder = (req, res, next) => {
    const uid = global.yoho.uid || '7394907';
    const data = req.query;

    orderModel.cancelOrder(uid, data).then(result => {
        res.json(result);
    }).catch(next);
};

const deleteOrder = (req, res, next) => {
    const uid = global.yoho.uid || '7394907';
    const code = req.query.orderCode;

    orderModel.deleteOrder(uid, code).then(result => {
        res.json(result);
    }).catch(next);
};

const getExpressInfo = (req, res, next) => {
    const uid = global.yoho.uid || '7394907';
    const code = req.query.orderCode;

    orderModel.getExpressInfo(uid, code).then(result => {
        res.json(result);
    }).catch(next);
};

const getCancelOrderReason = (req, res, next) => {
    orderModel.getCancelOrderReason().then(result => {
        res.json(result);
    }).catch(next);
};

const editOrder = (req, res) => {
    const uid = global.yoho.uid || '7394907';
    const query = req.query;

    query.uid = uid;

    orderModel.editOrder(query).then(result => {
        res.json(result);
    });
};

const reAddCart = (req, res) => {
    const uid = global.yoho.uid || '7394907';
    const code = req.query.orderCode;

    orderModel.reAddCart(uid, code).then(result => {
        res.json(result);
    });

};

module.exports = {
    index: index,
    detail: detail,
    getOrderList: getOrderList,
    getOrderTotal: getOrderTotal,
    cancelOrder: cancelOrder,
    deleteOrder: deleteOrder,
    editOrder: editOrder,
    getExpressInfo: getExpressInfo,
    getCancelOrderReason: getCancelOrderReason,
    reAddCart: reAddCart
};