ApplyController.php 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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->model()->orderByDesc('id');
  20. $grid->column('id')->sortable();
  21. $grid->column('share_name');
  22. $grid->column('share_phone');
  23. $grid->column('state')->display(function($item){
  24. return $item == 0 ? '待审核' : ($item == 1 ? '已通过' : '已拒绝');
  25. });
  26. $grid->column('user_id');
  27. $grid->column('created_at');
  28. $grid->column('updated_at')->sortable();
  29. $grid->disableCreateButton();
  30. $grid->disableViewButton();
  31. $grid->disableDeleteButton();
  32. $grid->filter(function (Grid\Filter $filter) {
  33. $filter->equal('id');
  34. });
  35. });
  36. }
  37. /**
  38. * Make a show builder.
  39. *
  40. * @param mixed $id
  41. *
  42. * @return Show
  43. */
  44. protected function detail($id)
  45. {
  46. return Show::make($id, new Apply(), function (Show $show) {
  47. $show->field('id');
  48. $show->field('share_name');
  49. $show->field('share_phone');
  50. $show->field('state');
  51. $show->field('user_id');
  52. $show->field('created_at');
  53. $show->field('updated_at');
  54. });
  55. }
  56. /**
  57. * Make a form builder.
  58. *
  59. * @return Form
  60. */
  61. protected function form()
  62. {
  63. return Form::make(new Apply(), function (Form $form) {
  64. $form->display('id');
  65. $form->display('share_name');
  66. $form->display('share_phone');
  67. $form->select('state')
  68. ->when(2, function (Form $form) {
  69. $form->textarea('not_desc','原因');
  70. })
  71. ->options([1 => '通过申请',2 => '不通过申请'])->saving(function ($item) use(&$form){
  72. if ($item == 1){
  73. User::query()->where('id',$form->model()->user_id)->update([
  74. 'is_share' => 1,
  75. 'share_name' => $form->model()->share_name,
  76. 'share_phone' => $form->model()->share_phone,
  77. ]);
  78. }
  79. return $item;
  80. });
  81. $form->hidden('user_id');
  82. $form->disableViewButton();
  83. $form->disableDeleteButton();
  84. $form->display('created_at');
  85. $form->display('updated_at');
  86. });
  87. }
  88. }