order.js 3.28 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 = global.yoho.uid || '13549567';

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

const getOrderList = (req, res) => {
    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
        });
    });
};

const getOrderTotal = (req, res) => {
    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
        });
    });
};

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

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

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

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

const getExpressInfo = (req, res) => {
    const uid = global.yoho.uid || '7394907';
    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 = global.yoho.uid || '7394907';
    const query = req.query;

    query.uid = uid;

    orderModel.editOrder(query).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
};