ApplyController.php 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. * @param mixed $id
  38. *
  39. * @return Show
  40. */
  41. protected function detail($id)
  42. {
  43. return Show::make($id, new Apply(), function (Show $show) {
  44. $show->field('id');
  45. $show->field('share_name');
  46. $show->field('share_phone');
  47. $show->field('state');
  48. $show->field('user_id');
  49. $show->field('created_at');
  50. $show->field('updated_at');
  51. });
  52. }
  53. /**
  54. * Make a form builder.
  55. *
  56. * @return Form
  57. */
  58. protected function form()
  59. {
  60. return Form::make(new Apply(), function (Form $form) {
  61. $form->display('id');
  62. $form->display('share_name');
  63. $form->display('share_phone');
  64. $form->select('state')
  65. ->when(2, function (Form $form) {
  66. $form->textarea('not_desc','原因');
  67. })
  68. ->options([1 => '通过申请',2 => '不通过申请'])->saving(function ($item) use(&$form){
  69. if ($item == 1){
  70. User::query()->where('id',$form->model()->user_id)->update([
  71. 'is_share' => 1,
  72. 'share_name' => $form->model()->share_name,
  73. 'share_phone' => $form->model()->share_phone,
  74. ]);
  75. return $item;
  76. }
  77. });
  78. $form->hidden('user_id');
  79. $form->disableViewButton();
  80. $form->disableDeleteButton();
  81. $form->display('created_at');
  82. $form->display('updated_at');
  83. });
  84. }
  85. }