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

100 lines
2.9 KiB

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