Orders.php 7.56 KB
<?php

use Action\WebAction;
use WebPlugin\Helpers;
use Home\UserModel;
use Home\OrderModel;
use LibModels\Web\Home\OrderData;
use WebPlugin\Paging;

/**
 * 订单
 */
class OrdersController extends WebAction
{

    /**
     * 我的订单
     */
    public function indexAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();

        //头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        //面包屑-左侧导航
        $path = UserModel::getCenterCrumb('订单中心');
        $leftNav = UserModel::getCenterLeftNav('我的订单');
        //分页
        $page = $this->get('page', 1);
        $type = $this->get('type', 1);
        $limit = 10;
        $paging = new Paging('yoho');
        //订单
        $orders = OrderModel::getOrders($uid, $page, $limit, $type, TRUE);
        $total = isset($orders['pager']['total']) ? $orders['pager']['total'] : 0;
        $pageTotal = isset($orders['pager']['pageTotal']) ? $orders['pager']['pageTotal'] : 0;
        $page = isset($orders['pager']['page']) ? $orders['pager']['page'] : 0;
        unset($orders['pager']);
        $paging->setTotal($total)->setSize($limit)->setQuery(array('page' => $page, 'type' => $type));

        $historyOrders = array(
            array(
                'orderNum' => '98430605',
                'orderTime' => '2011/04/29 11:10:04',
                'goods' => array('MY01-3 手表', 'MY01-2 手表'),
                'orderSum' => '258.00',
                'payMode' => '支付宝'
            ),
            array(
                'orderNum' => '98430605',
                'orderTime' => '2011/04/29 11:10:04',
                'goods' => array('MY02-3 手表'),
                'orderSum' => '626.00',
                'payMode' => '货到付款'
            )
        );
        //数据整合
        $data = array(
            'path' => $path,
            'userThumb' => UserModel::getUserHeadImg($uid),
            'homeNav' => $leftNav,
            'tabs' => OrderModel::getOrderTabs($type),
//            'orders' => $orders,
            //历史订单
//            'historyOrders' => $historyOrders,
            'pager' => array(
                'count' => $total,
                'curPage' => $page,
                'totalPages' => $pageTotal,
                'pagerHtml' => $paging->view(false)
            )
        );

        if ($type == 8) {
            $data['historyOrders'] = $historyOrders;
        }
        else {
            $data['orders'] = $orders;
        }
        $this->_view->display('orders', array('meOrdersPage' => true, 'meOrders' => $data));
    }

    /**
     * 订单详情
     */
    public function detailAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();

        //头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        //面包屑-左侧导航
        $path = UserModel::getCenterCrumb('订单详细', array('url' => Helpers::url('/home/orders'), 'name' => '订单中心'));
        $leftNav = UserModel::getCenterLeftNav('我的订单');

        $orderCode = $this->get('orderCode', '');
        $detail = OrderModel::getOrderDetail($uid, $orderCode);

        $data = array(
            'path' => $path,
            'userThumb' => UserModel::getUserHeadImg($uid),
            'homeNav' => $leftNav,
            'orderNum' => $detail['orderNum'],
            'curStatus' => $detail['statusStr'],
            'complete' => $detail['complete'],
            'virtualGoods' => $detail['virtualGoods'],
            'progress' => $detail['progress'],
            'remark' => $detail['remark'],
            'goods' => $detail['goods'],
            'sumPrice' => $detail['sumPrice'],
            'freight' => isset($detail['freight']) ? $detail['freight'] : 0,
            'yohoCoin' => $detail['yohoCoin'],
            'yohoCoinUrl' => $detail['yohoCoinUrl'],
            'coupons' => isset($detail['coupons']) ? $detail['coupons'] : 0,
            'payment' => $detail['payment'],
            'operation' => $detail['operation']
        );
        if (isset($detail['noramlPayMode'])) {
            $data['orderInfo'] = $detail['orderInfo'];
            $data['traceOrder'] = $detail['traceOrder'];
            $data['noramlPayMode'] = $detail['noramlPayMode'];
        }
        else if (isset($detail['virtualPayMode'])) {
            $data['virtualPayMode'] = $detail['virtualPayMode'];
        }
//        var_dump($data);die();
        $this->_view->display('order-detail', array('meOrderDetail' => $data));
    }

    /**
     * 取消订单-ajax
     */
    public function cancelOrderAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');

        do {

            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
            $uid = $this->auditJumpLogin();
            $orderCode = trim($this->post('orderCode', ''));
            $data = OrderData::cancelUserOrder($uid, $orderCode);
            if (!isset($data['code'])) {
                break;
            }
        }
        while (false);

        $this->echoJson($data);
    }

    /**
     * 确认订单-ajax
     */
    public function confirmOrderAction()
    {
        $data = array('code' => 400, 'message' => '', 'data' => '');

        do {
            /* 判断是不是AJAX请求 */
            if (!$this->isAjax()) {
                break;
            }
            $uid = $this->auditJumpLogin();
            $orderCode = trim($this->post('orderCode', ''));
            $data = OrderData::confirmUserOrder($uid, $orderCode);
            if (!isset($data['code'])) {
                break;
            }
        }
        while (false);

        $this->echoJson($data);
    }

    /**
     * 二维码票
     */
    public function ticketsAction()
    {
        //判断是否登录
        $uid = $this->auditJumpLogin();

        //头部导航
        $channel = Helpers::getChannelNameByCookie();
        $this->setWebNavHeader($channel);
        //面包屑-左侧导航
        $path = UserModel::getCenterCrumb('查看二维码', array('url' => Helpers::url('/home/orders'), 'name' => '订单中心'));
        $leftNav = UserModel::getCenterLeftNav('我的订单');

        $orderCode = $this->get('orderCode', '');
        $detail = OrderModel::getOrderDetail($uid, $orderCode);
        if (isset($detail) && $detail) {
            $tickets = OrderModel::getTicketImgs($uid, $detail['goods'][0]['sku']);
            $data = array(
                'path' => $path,
                'userThumb' => UserModel::getUserHeadImg($uid),
                'homeNav' => $leftNav,
                'name' => $detail['goods'][0]['name'],
                'num' => $detail['goods'][0]['num'],
                'orderNum' => $detail['orderNum'],
                'myOrdersUrl' => Helpers::url('/home/orders'),
                'tickets' => array(
                    array(
                        'img' => 'http://static.yohobuy.com/images/v2/common/2dcode_disabled.png',
                        'desc' => 'Hello world'
                    ),
                    array(
                        'img' => 'http://static.yohobuy.com/images/v2/common/2dcode_disabled.png',
                        'desc' => 'Hello world'
                    ),
                    array(
                        'img' => 'http://static.yohobuy.com/images/v2/common/2dcode_disabled.png',
                        'desc' => 'Hello world'
                    )
                )
            );
        }

        $this->_view->display('ticket', array('meOrderTicket' => $data));
    }

}