支付宝记账本
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.

101 lines
3.0 KiB

10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
10 months ago
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\OrderNotify;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Http\Controllers\AdminController;
  7. use Dcat\Admin\Show;
  8. use Illuminate\Support\Str;
  9. class OrderNotifyController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new OrderNotify(), function (Grid $grid) {
  19. $grid->model()->orderBy('id', 'desc');
  20. $grid->column('id')->sortable();
  21. $grid->column('order_id');
  22. $grid->column('state')
  23. ->using(admin_trans('order.options.state'))
  24. ->label([
  25. 0 => 'primary',
  26. 1 => 'warning',
  27. 2 => 'success',
  28. 3 => 'danger',
  29. 4 => 'gray',
  30. ]);
  31. $grid->column('push_time');
  32. $grid->column('response_time');
  33. $grid->column('response_code');
  34. $grid->column('response_body')->display(fn($v) => e(Str::limit($v, 15)))->width('15%');
  35. $grid->column('push_duration')->display(function ($v) {
  36. if ($this->response_code === null) {
  37. return '';
  38. }
  39. return ($v / 1000).'秒';
  40. });
  41. $grid->disableCreateButton();
  42. $grid->disableEditButton();
  43. $grid->disableDeleteButton();
  44. $grid->disableBatchDelete();
  45. $grid->filter(function (Grid\Filter $filter) {
  46. $filter->equal('order_id')->width(3);
  47. });
  48. });
  49. }
  50. /**
  51. * Make a show builder.
  52. *
  53. * @param mixed $id
  54. *
  55. * @return Show
  56. */
  57. protected function detail($id)
  58. {
  59. return Show::make($id, new OrderNotify(), function (Show $show) {
  60. $show->disableEditButton();
  61. $show->disableDeleteButton();
  62. $show->field('id');
  63. $show->field('order_id');
  64. $show->field('state')->using(admin_trans('order.options.state'));
  65. $show->field('push_time');
  66. $show->field('push_body')->unescape()->as(function ($v) {
  67. parse_str($v, $r);
  68. return '推送数据:<pre>'.e($v).'</pre><br/>PHP数组:<pre>'.var_export($r, true).'</pre>';
  69. });
  70. $show->field('response_time');
  71. $show->field('response_code');
  72. $show->field('response_body')->unescape()->as(fn($v) => '<pre>'.e($v).'</pre>');
  73. $show->field('push_duration')->as(function ($v) {
  74. if ($this->response_code === null) {
  75. return '';
  76. }
  77. return ($v / 1000).'秒';
  78. });
  79. });
  80. }
  81. /**
  82. * Make a form builder.
  83. *
  84. * @return Form
  85. */
  86. protected function form()
  87. {
  88. return Form::make(new OrderNotify(), function (Form $form) {
  89. $form->display('id');
  90. });
  91. }
  92. }