order.js 3.43 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) => {
    const type = req.query.type;
    const page = req.query.page;
    const uid = req.user.uid;

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

const detail = (req, res) => {
    const code = req.query.code;
    const uid = req.user.uid;

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

const getOrderList = (req, res) => {
    const type = req.query.type;
    const page = req.query.page;
    const uid = req.user.uid;

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

const getOrderTotal = (req, res) => {
    const type = req.query.type;
    const uid = req.user.uid;


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

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

const cancelOrder = (req, res) => {
    const uid = req.user.uid;
    const data = req.query;

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

const deleteOrder = (req, res) => {
    const uid = req.user.uid;
    const code = req.query.orderCode;

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

const getExpressInfo = (req, res) => {
    const uid = req.user.uid;
    const code = req.query.orderCode;

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

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

const editOrder = (req, res) => {
    const uid = req.user.uid;
    const query = req.query;

    query.uid = uid;

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

const reAdd = (req, res) => {
    const uid = req.user.uid;
    const code = req.query.orderCode;

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

const confirmReceive = (req, res) => {
    const uid = req.user.uid;
    const code = req.query.orderCode;

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

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