You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
134 lines
4.3 KiB
134 lines
4.3 KiB
<?php
|
|
|
|
namespace App\Admin\Controllers;
|
|
|
|
use App\Models\OrderNotify;
|
|
use Dcat\Admin\Form;
|
|
use Dcat\Admin\Grid;
|
|
use Dcat\Admin\Http\Controllers\AdminController;
|
|
use Dcat\Admin\Show;
|
|
use Dcat\Admin\Widgets\Card;
|
|
use Illuminate\Support\Str;
|
|
|
|
class OrderNotifyController extends AdminController
|
|
{
|
|
/**
|
|
* Make a grid builder.
|
|
*
|
|
* @return Grid
|
|
*/
|
|
protected function grid()
|
|
{
|
|
return Grid::make(new OrderNotify(), function (Grid $grid) {
|
|
$grid->model()->orderBy('id', 'desc');
|
|
|
|
$grid->column('id')->sortable();
|
|
$grid->column('order_id');
|
|
|
|
$grid->column('state')
|
|
->using(admin_trans('order.options.state'))
|
|
->label([
|
|
0 => 'primary',
|
|
1 => 'warning',
|
|
2 => 'success',
|
|
3 => 'danger',
|
|
4 => 'gray',
|
|
]);
|
|
|
|
$grid->column('push_time');
|
|
|
|
$grid->column('push_body')
|
|
->width('15%')
|
|
->display(fn($v) => e(Str::limit($v, 20)))
|
|
->modal(function (Grid\Displayers\Modal $modal) {
|
|
$modal->title(admin_trans('order-notify.fields.push_body'));
|
|
parse_str($this->push_body, $r);
|
|
$html = '推送数据:<pre>'.e($this->push_body).'</pre><br/>PHP数组:<pre>'.var_export($r, true).'</pre>';
|
|
$card = new Card(null, $html);
|
|
return $card->render();
|
|
});
|
|
|
|
$grid->column('response_time');
|
|
$grid->column('response_code');
|
|
|
|
$grid->column('response_body')
|
|
->width('15%')
|
|
->if(function (Grid\Column $column) {
|
|
return mb_strlen($this->response_body) > 20;
|
|
})
|
|
->then(function (Grid\Column $column) {
|
|
$column
|
|
->display(fn($v) => e(Str::limit($v, 20)))
|
|
->modal(function (Grid\Displayers\Modal $modal) {
|
|
$modal->title(admin_trans('order-notify.fields.response_body'));
|
|
$card = new Card(null, '<pre>'.e($this->response_body).'</pre>');
|
|
return $card->render();
|
|
});
|
|
})
|
|
->else(function (Grid\Column $column) {
|
|
$column->display($this->response_body);
|
|
});
|
|
|
|
$grid->column('push_duration')->display(function ($v) {
|
|
if ($this->response_code === null) {
|
|
return '';
|
|
}
|
|
return ($v / 1000).'秒';
|
|
});
|
|
|
|
$grid->disableCreateButton();
|
|
$grid->disableEditButton();
|
|
$grid->disableDeleteButton();
|
|
$grid->disableBatchDelete();
|
|
|
|
$grid->filter(function (Grid\Filter $filter) {
|
|
$filter->equal('order_id')->width(3);
|
|
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a show builder.
|
|
*
|
|
* @param mixed $id
|
|
*
|
|
* @return Show
|
|
*/
|
|
protected function detail($id)
|
|
{
|
|
return Show::make($id, new OrderNotify(), function (Show $show) {
|
|
$show->disableEditButton();
|
|
$show->disableDeleteButton();
|
|
$show->field('id');
|
|
$show->field('order_id');
|
|
$show->field('state')->using(admin_trans('order.options.state'));
|
|
$show->field('push_time');
|
|
$show->field('push_body')->unescape()->as(function ($v) {
|
|
parse_str($v, $r);
|
|
return '推送数据:<pre>'.e($v).'</pre><br/>PHP数组:<pre>'.var_export($r, true).'</pre>';
|
|
});
|
|
$show->field('response_time');
|
|
$show->field('response_code');
|
|
$show->field('response_body')->unescape()->as(fn($v) => '<pre>'.e($v).'</pre>');
|
|
$show->field('push_duration')->as(function ($v) {
|
|
if ($this->response_code === null) {
|
|
return '';
|
|
}
|
|
return ($v / 1000).'秒';
|
|
});
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Make a form builder.
|
|
*
|
|
* @return Form
|
|
*/
|
|
protected function form()
|
|
{
|
|
return Form::make(new OrderNotify(), function (Form $form) {
|
|
$form->display('id');
|
|
});
|
|
}
|
|
}
|