<div class="content-wrapper">
    <section class="content-header">
        <?php echo $this->partial('layout/breadcrumb'); ?>

        <h1 class="pull-right" id="dbshop-menu-top">
            <a href="<?php echo $this->url('sales', [], ['query' => $this->queryData]);?>" class="btn btn-default btn-sm"><i class="fa fa-arrow-left"></i> <?php echo $this->translate('返回订单列表'); ?></a>
            <?php if(
                $this->orderInfo->getOrderStatus() > $this->salesHelper()->getOrderStatusCode('CANCEL_ORDER')
                && (
                    ($this->orderInfo->getPaymentType() == 'OnlinePay' && $this->orderInfo->getOrderStatus() < $this->salesHelper()->getOrderStatusCode('WAIT_GOODS_ARRIVE'))
                    || ($this->orderInfo->getPaymentType() == 'CashOnDelivery' && $this->orderInfo->getOrderStatus() <= $this->salesHelper()->getOrderStatusCode('FINISH_DISTRIBUTION_GOODS'))
                )
            ) { ?>
                <a href="<?php echo $this->url('sales', ['action'=>'cancelOrder', 'id'=>$this->orderInfo->getOrderId()], ['query' => array_merge(['return' => 'detail'], $this->queryData)]); ?>" class="btn btn-danger btn-sm"><i class="fa fa-trash"></i> <?php echo $this->translate('取消订单'); ?></a>
            <?php } ?>
            <?php if($this->orderInfo->getOrderStatus() == $this->salesHelper()->getOrderStatusCode('CANCEL_ORDER')) { ?>
                <a href="javascript:;" onclick="deleteConfirm('<?php echo $this->translate('您确实要删除该订单吗?'); ?>', '<?php echo $this->url('sales', ['action'=>'delete', 'id'=>$this->orderInfo->getOrderId()], ['query' => ['qToken' => $this->adminHelper()->getCsrfValue()]]); ?>');" class="btn btn-danger btn-sm"><i class="fa fa-times"></i> <?php echo $this->translate('删除订单'); ?></a>
            <?php } ?>
            <?php if($this->orderInfo->getOrderStatus() == $this->salesHelper()->getOrderStatusCode('wait_payment') && $this->orderInfo->getPaymentType() != 'CashOnDelivery') { ?>
                <a href="<?php echo $this->url('sales', ['action'=>'payOrder', 'id'=>$this->orderInfo->getOrderId()], ['query' => array_merge(['return' => 'detail'], $this->queryData)]); ?>" class="btn btn-success btn-sm"><i class="fa fa-money"></i> <?php echo $this->translate('订单付款'); ?></a>
            <?php } ?>
            <?php if(
                $this->orderInfo->getDeliveryType() != 'selfFetch'
                && (
                        ($this->orderInfo->getOrderStatus() >= $this->salesHelper()->getOrderStatusCode('wait_payment') && $this->orderInfo->getOrderStatus() <= $this->salesHelper()->getOrderStatusCode('finish_distribution_goods') && $this->orderInfo->getPaymentType() == 'CashOnDelivery')
                        || ($this->orderInfo->getOrderStatus() > $this->salesHelper()->getOrderStatusCode('wait_payment') && $this->orderInfo->getOrderStatus() <= $this->salesHelper()->getOrderStatusCode('finish_distribution_goods') && $this->orderInfo->getPaymentType() != 'CashOnDelivery')
                    )
                ) { ?>
                <a href="<?php echo $this->url('sales', ['action'=>'shipOrder', 'id'=>$this->orderInfo->getOrderId()], ['query' => array_merge(['return' => 'detail'], $this->queryData)]); ?>" class="btn btn-success btn-sm"><i class="fa fa-truck"></i> <?php echo $this->translate('订单发货'); ?></a>
            <?php } ?>
            <?php if(
                    ($this->orderInfo->getOrderStatus() >= $this->salesHelper()->getOrderStatusCode('GOODS_SHIPPED') || ($this->orderInfo->getOrderStatus() > $this->salesHelper()->getOrderStatusCode('wait_payment') && $this->orderInfo->getDeliveryType() == 'selfFetch'))
                    && $this->orderInfo->getOrderStatus() < $this->salesHelper()->getOrderStatusCode('GOODS_RECEIVED')
                    ) { ?>
                <a href="<?php echo $this->url('sales', ['action'=>'receiptOrder', 'id'=>$this->orderInfo->getOrderId()], ['query' => array_merge(['return' => 'detail'], $this->queryData)]); ?>" class="btn btn-success btn-sm"><i class="fa fa-check"></i> <?php echo $this->translate('订单收货'); ?></a>
            <?php } ?>
            <?php
            if(
                $this->orderInfo->getOrderStatus() >= $this->salesHelper()->getOrderStatusCode('GOODS_RECEIVED')
                && $this->orderInfo->getDeliveryType() == 'delivery'
                && $this->shopHelper()->getDeliveryTrackState() == 1
                && (
                    ($this->orderInfo->getDeliveryId() > 0 &&  !empty($this->deliveryIdArray) && isset($this->deliveryIdArray[$this->orderInfo->getDeliveryId()]))
                    || $this->orderInfo->getDeliveryId() <= 0
                )
            ) { ?>
                <a href="<?php echo $this->url('sales', ['action'=>'showOrderExpressTrack', 'id'=>$this->orderInfo->getOrderId()], ['query' => $this->queryData]); ?>" target="_blank" class="btn btn-primary btn-sm"><i class="fa fa-truck"></i> <?php echo $this->translate('物流轨迹'); ?></a>
            <?php } ?>
            <a href="<?php echo $this->url('sales', ['action'=>'printOrder', 'id'=>$this->orderInfo->getOrderId()]); ?>" class="btn btn-primary btn-sm"><i class="fa fa-print"></i> <?php echo $this->translate('订单打印'); ?></a>
            <?php echo $this->HelpUrl('orderDetail'); ?>
        </h1>
    </section>

    <section class="content">
        <?php echo $this->partial('layout/messages'); ?>
        <div class="row">
            <div class="col-md-12">
                <div class="box">
                    <div class="box-body">
                        <h2 class="page-header">
                            <?php echo $this->translate('订单号').'&nbsp;'.$this->orderInfo->getOrderSn(); ?>
                            <small class="pull-right"><strong><?php echo $this->translate('订单状态').'：'.$this->salesHelper()->getOrderStatus($this->orderInfo->getOrderStatus()); ?></strong></small>
                        </h2>

                        <div class="row">
                            <div class="col-xs-4">
                                <p class="lead"><?php echo $this->translate('订单时间'); ?></p>
                                <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
                                        <tr>
                                            <th style="width:30%"><?php echo $this->translate('下单时间'); ?>:</th>
                                            <td><?php echo $this->shopDateFormat()->orderTime($this->orderInfo->getOrderAddTime()); ?></td>
                                        </tr>
                                        <tr>
                                            <th><?php echo $this->translate('付款时间'); ?>:</th>
                                            <td><?php echo $this->shopDateFormat()->orderTime($this->orderInfo->getPaymentFinishTime()); ?></td>
                                        </tr>
                                        <?php if($this->orderInfo->getDeliveryType() != 'selfFetch') { ?>
                                            <tr>
                                                <th><?php echo $this->translate('发货时间'); ?>:</th>
                                                <td><?php echo $this->shopDateFormat()->orderTime($this->orderInfo->getExpressTime()); ?></td>
                                            </tr>
                                        <?php } ?>
                                        <tr>
                                            <th><?php echo $this->translate('收货时间'); ?>:</th>
                                            <td><?php echo $this->shopDateFormat()->orderTime($this->orderInfo->getOrderFinishTime()); ?></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <?php if($this->orderInfo->getDeliveryType() == 'delivery' && $this->deliveryAddress) { ?>
                                <div class="col-xs-4">
                                    <p class="lead"><?php echo $this->translate('收货信息'); ?></p>
                                    <div class="table-responsive">
                                        <table class="table">
                                            <tbody>
                                            <tr>
                                                <th style="width:20%"><?php echo $this->translate('收货人'); ?>:</th>
                                                <td><?php echo $this->escapeHtml($this->deliveryAddress->getTrueName()); ?></td>
                                            </tr>
                                            <tr>
                                                <th><?php echo $this->translate('电话号码'); ?>:</th>
                                                <td><?php echo $this->adminHelper()->getAreaPhoneCode($this->deliveryAddress->getAreaCode()) .'&nbsp;'. $this->escapeHtml($this->deliveryAddress->getPhone()); ?></td>
                                            </tr>
                                            <tr>
                                                <th><?php echo $this->translate('收货地址'); ?>:</th>
                                                <td><?php echo $this->escapeHtml($this->deliveryAddress->getRegionValue().$this->deliveryAddress->getAddressInfo()); ?></td>
                                            </tr>
                                            <?php if(!empty($this->deliveryAddress->getPostCode())) { ?>
                                                <tr>
                                                    <th><?php echo $this->translate('邮政编码'); ?>:</th>
                                                    <td><?php echo $this->escapeHtml($this->deliveryAddress->getPostCode()); ?></td>
                                                </tr>
                                            <?php } ?>
                                            <?php if(!empty($this->deliveryAddress->getDeliveryTimeInfo())) { ?>
                                                <tr>
                                                    <th><?php echo $this->translate('送货时间'); ?>:</th>
                                                    <td><?php echo $this->escapeHtml($this->deliveryAddress->getDeliveryTimeInfo()); ?></td>
                                                </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                                <div class="col-xs-4">
                                    <p class="lead"><?php echo $this->translate('配送信息'); ?>
                                        <?php if($this->orderInfo->getDeliveryMode() > 0 && $this->orderInfo->getOrderStatus() >= $this->salesHelper()->getOrderStatusCode('GOODS_SHIPPED') && $this->orderInfo->getOrderStatus() < $this->salesHelper()->getOrderStatusCode('GOODS_RECEIVED')) { ?><a href="<?php echo $this->url('sales', ['action' => 'editOrderExpressNumber', 'id' => $this->orderInfo->getOrderId()]); ?>" class="btn btn-success btn-sm pull-right"><i class="fa fa-pencil"></i> <?php echo $this->translate('修改快递单号'); ?></a><?php } ?>
                                    </p>
                                    <div class="table-responsive">
                                        <table class="table">
                                            <tbody>
                                            <tr>
                                                <th style="width:30%"><?php echo $this->translate('配送配型'); ?>:</th>
                                                <td><?php echo $this->salesHelper()->getDeliveryTypeName($this->orderInfo->getDeliveryType());  ?></td>
                                            </tr>
                                            <?php if($this->orderInfo->getDeliveryMode() == 2) { ?>
                                                <tr>
                                                    <th><?php echo $this->translate('快递信息'); ?>:</th>
                                                    <td><?php echo $this->translate('各商品拆分配送'); ?></td>
                                                </tr>
                                            <?php } else { ?>
                                                <tr>
                                                    <th><?php echo $this->translate('快递信息'); ?>:</th>
                                                    <td><?php echo $this->escapeHtml($this->orderInfo->getDeliveryName()); ?></td>
                                                </tr>
                                                <tr>
                                                    <th><?php echo $this->translate('配送费用'); ?>:</th>
                                                    <td><?php echo $this->orderInfo->getCurrencySymbol() . $this->orderInfo->getShippingFee(); ?></td>
                                                </tr>
                                                <tr>
                                                    <th><?php echo $this->translate('快递单号'); ?>:</th>
                                                    <td><?php echo $this->escapeHtml($this->orderInfo->getExpressNumber()); ?></td>
                                                </tr>
                                            <?php } ?>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            <?php } ?>
                            <?php if($this->orderInfo->getDeliveryType() == 'selfFetch') { ?>
                                <div class="col-xs-8">
                                    <p class="lead"><?php echo $this->translate('自提点信息'); ?></p>
                                    <div class="table-responsive">
                                        <table class="table">
                                            <tbody>
                                            <tr>
                                                <th style="width:15%"><?php echo $this->translate('自提点名称'); ?>:</th>
                                                <td style="width:50%"><?php echo $this->escapeHtml($this->orderSelfLocation->getLocationName()); ?></td>
                                                <th style="width:15%"><?php echo $this->translate('提货码'); ?>:</th>
                                                <td><?php echo !empty($this->orderSelfLocation->getTakeCode()) ? $this->orderSelfLocation->getTakeCode() : $this->translate('暂无'); ?></td>
                                            </tr>
                                            <tr>
                                                <th><?php echo $this->translate('自提点地址'); ?>:</th>
                                                <td colspan="3"><?php echo $this->escapeHtml($this->orderSelfLocation->getRegionInfo() . $this->orderSelfLocation->getLocationAddress()); ?></td>
                                            </tr>
                                            <tr>
                                                <th><?php echo $this->translate('联系人'); ?>:</th>
                                                <td colspan="3"><?php echo $this->escapeHtml($this->orderSelfLocation->getLocationUser()); ?></td>
                                            </tr>
                                            <tr>
                                                <th><?php echo $this->translate('联系电话'); ?>:</th>
                                                <td colspan="3"><?php echo $this->escapeHtml($this->orderSelfLocation->getLocationPhone()); ?></td>
                                            </tr>
                                            <tr>
                                                <th><?php echo $this->translate('营业时间'); ?>:</th>
                                                <td colspan="3"><?php echo $this->escapeHtml($this->orderSelfLocation->getLocationBusinessHours()); ?></td>
                                            </tr>
                                            </tbody>
                                        </table>
                                    </div>
                                </div>
                            <?php } ?>
                        </div>
                        <div class="table-responsive">
                            <table class="table shop-table table-bordered">
                                <thead>
                                <tr class="shop-bg-thead">
                                    <th><?php echo $this->translate('图片'); ?></th>
                                    <th width="35%"><?php echo $this->translate('商品名称'); ?></th>
                                    <th width="15%"><?php echo $this->translate('商品货号'); ?></th>
                                    <th width="15%"><?php echo $this->translate('商品规格'); ?></th>
                                    <th width="10%"><?php echo $this->translate('购买数量'); ?></th>
                                    <th width="10%"><?php echo $this->translate('单价'); ?></th>
                                    <th width="10%"><?php echo $this->translate('小计'); ?></th>
                                </tr>
                                </thead>
                                <tbody>
                                <?php foreach($this->orderInfo->getOrderGoods() as $goodsValue) { ?>
                                    <tr>
                                        <td><img src="<?php echo $this->goodsHelper()->goodsImage($goodsValue->getGoodsImage()); ?>" class="img-thumbnail"></td>
                                        <td>
                                            <?php if($goodsValue->getDeliveryId() > 0) { ?><small class="bg-primary" style="padding: 3px;border-radius:3px;"><?php echo $this->translate('快递信息').'：'.$this->escapeHtml($goodsValue->getDeliveryName()).'&nbsp;&nbsp;'.$this->translate('快递单号').'：'.$this->escapeHtml($goodsValue->getExpressNumber()); ?></small><?php } ?>
                                            <p style="margin-top: 5px;"><?php echo $this->escapeHtml($goodsValue->getGoodsName()); ?></p>
                                        </td>
                                        <td><?php echo $this->escapeHtml($goodsValue->getGoodsItem()); ?></td>
                                        <td>
                                            <?php if(!empty($goodsValue->getInSpecGoodsStr())) { echo $this->escapeHtml($goodsValue->getInSpecGoodsStr()); } else echo $this->translate('无'); ?>
                                        </td>
                                        <td><?php echo $goodsValue->getBuyNum(); ?></td>
                                        <td><?php echo $this->orderInfo->getCurrencySymbol() . $goodsValue->getGoodsPrice(); ?></td>
                                        <td><?php echo $this->orderInfo->getCurrencySymbol() . $goodsValue->getGoodsAmount(); ?></td>
                                    </tr>
                                <?php } ?>

                                <?php if(!empty($this->integral) || !empty($this->orderInfo->getOrderMessage())) { ?>
                                <tr>
                                    <td colspan="7" class="small">
                                        <?php if(!empty($this->integral)) { ?>
                                        <div>
                                            <strong><?php echo $this->translate('确认收货后，可获得'); ?>：</strong>
                                            <?php if($this->integral->getIntegralType1Num() > 0) echo $this->integral->getIntegralType1Num().'&nbsp;'.$this->translate('消费积分').'&nbsp;&nbsp;'; ?>
                                            <?php if($this->integral->getIntegralType2Num() > 0) echo $this->integral->getIntegralType2Num().'&nbsp;'.$this->translate('等级积分').'&nbsp;&nbsp;'; ?>
                                        </div>
                                        <?php } ?>

                                        <?php if(!empty($this->orderInfo->getOrderMessage())) { ?>
                                            <div>
                                                <strong><?php echo $this->translate('订单留言'); ?>：</strong>
                                                <?php echo nl2br($this->escapeHtml($this->orderInfo->getOrderMessage())); ?>
                                            </div>
                                        <?php } ?>
                                    </td>
                                </tr>
                                <?php } ?>
                                </tbody>
                            </table>
                        </div>

                        <div class="row">
                            <div class="col-xs-6">
                                <p class="lead"><?php echo $this->translate('订单支付信息'); ?></p>
                                <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
                                        <tr>
                                            <th style="width:20%"><?php echo $this->translate('支付类型'); ?>:</th>
                                            <td><?php echo $this->salesHelper()->getPaymentTypeName($this->orderInfo->getPaymentType()); ?></td>
                                        </tr>
                                        <tr>
                                            <th><?php echo $this->translate('支付方式'); ?>:</th>
                                            <td><?php echo $this->escapeHtml($this->orderInfo->getPaymentName()); ?></td>
                                        </tr>
                                        </tbody>
                                    </table>
                                </div>
                            </div>
                            <div class="col-xs-6">
                                <p class="lead"><?php echo $this->translate('订单应付金额'); ?><?php if(!$this->orderInfo->getPaymentFinishTime() && $this->orderInfo->getOrderStatus() < $this->salesHelper()->getOrderStatusCode('GOODS_SHIPPED')) { ?><a href="<?php echo $this->url('sales', ['action' => 'changeOrderAmount', 'id' => $this->orderInfo->getOrderId()]); ?>" class="btn btn-success btn-sm pull-right"><i class="fa fa-pencil"></i> <?php echo $this->translate('修改金额'); ?></a><?php } ?></p>
                                <div class="table-responsive">
                                    <table class="table">
                                        <tbody>
                                        <tr>
                                            <th style="width:30%"><?php echo $this->translate('商品总价'); ?>:</th>
                                            <td><?php echo $this->orderInfo->getCurrencySymbol() . '&nbsp;' . $this->orderInfo->getGoodsAmount(); ?></td>
                                        </tr>
                                        <tr>
                                            <th><?php echo $this->translate('配送费用'); ?>:</th>
                                            <td><?php echo $this->orderInfo->getCurrencySymbol() . '&nbsp;' . $this->orderInfo->getShippingFee(); ?></td>
                                        </tr>
                                        <?php if ($this->orderDiscountRecord) foreach ($this->orderDiscountRecord as $recordValue) { ?>
                                        <tr>
                                            <th><?php echo $recordValue->getDiscountInfo(); ?>:</th>
                                            <td>-<?php echo $this->orderInfo->getCurrencySymbol() . '&nbsp;' . $recordValue->getDiscountCost(); ?></td>
                                        </tr>
                                        <?php } ?>
                                        <?php if($this->orderChangeAmountLog) foreach ($this->orderChangeAmountLog as $changeLog) { ?>
                                        <tr>
                                            <th><?php echo $this->translate('金额修改'); ?>:</th>
                                            <td>
                                                <?php echo $this->orderInfo->getCurrencySymbol() . '&nbsp;' . $changeLog->getOrderChangeType() . $changeLog->getOrderChangeNum(); ?>
                                                [<b><?php echo $this->translate('时间'); ?>：</b><?php echo date("y-m-d H:i:s", $changeLog->getOrderChangeTime()); ?><b><?php echo $this->translate('备注'); ?>：</b><?php echo $this->escapeHtml($changeLog->getOrderChangeInfo()); ?>]
                                            </td>
                                        </tr>
                                        <?php } ?>
                                        <tr>
                                            <th><?php echo $this->translate('应付金额'); ?>:</th>
                                            <td class="text-bold text-primary"><?php echo $this->orderInfo->getCurrencySymbol() . '&nbsp;' . $this->orderInfo->getOrderAmount(); ?></td>
                                        </tr>
                                        </tbody></table>
                                </div>
                            </div>

                            <div class="col-xs-6">
                                <p class="lead"><?php echo $this->translate('订单历史记录'); ?></p>
                                <div class="table-responsive">
                                    <table class="table table-striped">
                                        <thead>
                                        <tr class="shop-bg-thead">
                                            <th width="35%"><?php echo $this->translate('描述'); ?></th>
                                            <th width="20%"><?php echo $this->translate('状态'); ?></th>
                                            <th width="15%"><?php echo $this->translate('操作者'); ?></th>
                                            <th width="30%"><?php echo $this->translate('操作时间'); ?></th>
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php foreach ($this->orderStatusLog as $logValue) { ?>
                                            <tr>
                                                <td><?php echo $this->escapeHtml($logValue->getStatusInfo()); ?></td>
                                                <td><?php echo $this->salesHelper()->getOrderStatus($logValue->getOrderStatus()); ?></td>
                                                <td><?php echo $this->escapeHtml($logValue->getOperateUser()); ?></td>
                                                <td><?php echo $this->shopDateFormat()->orderTime($logValue->getStatusTime()); ?></td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                </div>
                            </div>

                        </div>

                    </div>
                </div>
            </div>
        </div>
    </section>

</div>
