ApplyController.php 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\Apply;
  4. use App\Models\User;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class ApplyController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. return Grid::make(new Apply(), function (Grid $grid) {
  19. $grid->column('id')->sortable();
  20. $grid->column('share_name');
  21. $grid->column('share_phone');
  22. $grid->column('state');
  23. $grid->column('user_id');
  24. $grid->column('created_at');
  25. $grid->column('updated_at')->sortable();
  26. $grid->disableCreateButton();
  27. $grid->disableViewButton();
  28. $grid->disableDeleteButton();
  29. $grid->filter(function (Grid\Filter $filter) {
  30. $filter->equal('id');
  31. });
  32. });
  33. }
  34. /**
  35. * Make a show builder.
  36. *
  37. * @return Show
  38. */
  39. protected function detail($id)
  40. {
  41. return Show::make($id, new Apply(), function (Show $show) {
  42. $show->field('id');
  43. $show->field('share_name');
  44. $show->field('share_phone');
  45. $show->field('state');
  46. $show->field('user_id');
  47. $show->field('created_at');
  48. $show->field('updated_at');
  49. });
  50. }
  51. /**
  52. * Make a form builder.
  53. *
  54. * @return Form
  55. */
  56. protected function form()
  57. {
  58. return Form::make(new Apply(), function (Form $form) {
  59. $form->display('id');
  60. $form->display('share_name');
  61. $form->display('share_phone');
  62. $form->select('state')
  63. ->when(2, function (Form $form) {
  64. $form->textarea('not_desc', '原因');
  65. })
  66. ->options([1 => '通过申请', 2 => '不通过申请'])->saving(function ($item) use (&$form) {
  67. if (1 == $item) {
  68. User::query()->where('id', $form->model()->user_id)->update([
  69. 'is_share' => 1,
  70. 'share_name' => $form->model()->share_name,
  71. 'share_phone' => $form->model()->share_phone,
  72. ]);
  73. return $item;
  74. }
  75. });
  76. $form->hidden('user_id');
  77. $form->disableViewButton();
  78. $form->disableDeleteButton();
  79. $form->display('created_at');
  80. $form->display('updated_at');
  81. });
  82. }
  83. }