<?php

use yii\helpers\Html;
use yii\grid\GridView;
use yii\helpers\Url;

/* @var $this yii\web\View */
/* @var $searchModel backend\models\search\OrderSearch */
/* @var $dataProvider yii\data\ActiveDataProvider */

$this->title = Yii::t('common', 'Orders');
$this->params['breadcrumbs'][] = $this->title;
?>
<?php $this->beginBlock('content-header') ?>
<?= $this->title ?>
<?php $this->endBlock() ?>
<?php echo $this->render('_search', ['model' => $searchModel]); ?>

<div class="box box-success">
    <div class="box-body">
        <?= GridView::widget([
            'dataProvider' => $dataProvider,
            //'filterModel' => $searchModel,
            'columns' => [
                'order_no',
                'out_trade_no',
                'user_id:user',

                'total_amount',
                'pay_amount',


                [
                    'attribute' => 'pay_time',
                    'value' => function ($model) {
                        if ($model->pay_time == 0) {
                            return '未支付';
                        } else {
                            return date('Y-m-d H:i:s', $model->pay_time);
                        }
                    },
                ],
                'receiver_name',
                'receiver_tel',
                'receiver_address',
                'created_at:datetime',
                'updated_at:datetime',
                [
                    'attribute' => 'status',
                    'value' => function ($model) {
                        return \common\models\Order::getStatusList($model->status);
                    },
                ],

                [
                    'class' => 'common\helpers\DiyActionColumn',
                    'template' => '{view} {delete}',
                    'buttons' => [
                        'view' => function ($url, $model, $key) {
                            return Html::a('查看', Url::to(['/order/view', 'id' => $model->id]), [
                                'class' => 'btn btn-success btn-xs',
                                'title' => $model->out_trade_no . '订单详情',
                                'target' => '_blank'
                            ]);
                        },
                    ]
                ],
            ],
        ]); ?>
    </div>
</div>
