海南旅游SAAS
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.

111 lines
2.9 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
  1. <?php
  2. namespace App\AdminAgent\Controllers;
  3. use App\AdminAgent\Repositories\User;
  4. use Dcat\Admin\Admin;
  5. use Dcat\Admin\Form;
  6. use Dcat\Admin\Grid;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. class UserController extends AdminController
  10. {
  11. /**
  12. * Make a grid builder.
  13. *
  14. * @return Grid
  15. */
  16. protected function grid()
  17. {
  18. Admin::translation('user');
  19. return Grid::make(new User(), function (Grid $grid) {
  20. $grid->disableRowSelector();
  21. $grid->disableCreateButton();
  22. $grid->disableBatchDelete();
  23. $grid->disableDeleteButton();
  24. $grid->model()->where('agent_id', Admin::user()->id);
  25. $grid->column('id')->sortable();
  26. $grid->column('avatar')->image(60, 60);
  27. $grid->column('mobile');
  28. $grid->column('nickname');
  29. $grid->column('status')->switch();
  30. $grid->column('verifier')->switch();
  31. $grid->column('created_at');
  32. $grid->filter(function (Grid\Filter $filter) {
  33. $filter->panel();
  34. $filter->equal('id')->width(2);
  35. $filter->equal('mobile')->width(2);
  36. });
  37. });
  38. }
  39. /**
  40. * Make a show builder.
  41. *
  42. * @param mixed $id
  43. *
  44. * @return Show
  45. */
  46. protected function detail($id)
  47. {
  48. return Show::make($id, new User(), function (Show $show) {
  49. $show->disableDeleteButton();
  50. //不允许查看非自己的数据
  51. if ($show->model()->agent_id != Admin::user()->id) {
  52. Admin::exit('数据不存在');
  53. }
  54. $show->field('id');
  55. $show->field('avatar')->image(80, 80);
  56. $show->field('mobile');
  57. $show->field('nickname');
  58. $show->field('status')->bool();
  59. $show->field('verifier')->bool();
  60. $show->field('created_at');
  61. });
  62. }
  63. /**
  64. * Make a form builder.
  65. *
  66. * @return Form
  67. */
  68. protected function form()
  69. {
  70. return Form::make(new User(), function (Form $form) {
  71. $form->disableDeleteButton();
  72. //不允许查看非自己的数据
  73. if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
  74. return $form->response()->error('数据不存在');
  75. }
  76. $form->display('id');
  77. $form->display('nickname');
  78. $form->text('mobile');
  79. $form->switch('status');
  80. $form->switch('verifier');
  81. })->saving(function (Form $form) {
  82. //不允许修改非自己的数据
  83. if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
  84. return $form->response()->error('数据不存在');
  85. }
  86. //不允许编辑的字段
  87. $form->ignore(['id', 'agent_id', 'nickname', 'deleted_at']);
  88. //处理特殊字段
  89. $form->agent_id = Admin::user()->id;
  90. $form->status = $form->status ? 1 : 0;
  91. $form->verifier = $form->verifier ? 1 : 0;
  92. })->deleting(function (Form $form) {
  93. return $form->response()->error('禁止删除');
  94. });
  95. }
  96. }