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

121 lines
3.4 KiB

4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
4 years ago
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. use Illuminate\Support\Facades\Route;
  10. class UserController extends AdminController
  11. {
  12. /**
  13. * Make a grid builder.
  14. *
  15. * @return Grid
  16. */
  17. protected function grid()
  18. {
  19. Admin::translation('user');
  20. return Grid::make(new User(), function (Grid $grid) {
  21. $grid->disableRowSelector();
  22. $grid->disableCreateButton();
  23. $grid->disableBatchDelete();
  24. $grid->disableDeleteButton();
  25. //如果是核销人员页面,多加where条件判断
  26. if (strpos(Route::current()->uri, 'verifier')) {
  27. $grid->model()->where('is_verify', 1);
  28. }
  29. $grid->model()->where('agent_id', Admin::user()->id);
  30. $grid->column('id')->sortable();
  31. $grid->column('avatar')->image('', 60, 60);
  32. $grid->column('mobile');
  33. $grid->column('nickname');
  34. $grid->column('status')->switch()->help('禁用后用户将无法登录');
  35. // $grid->column('is_verify')->switch();
  36. $grid->column('created_at');
  37. $grid->filter(function (Grid\Filter $filter) {
  38. $filter->panel();
  39. $filter->equal('id')->width(2);
  40. $filter->equal('mobile')->width(2);
  41. // $filter->equal('is_verify')->select(['否', '是'])->width(2);
  42. });
  43. });
  44. }
  45. /**
  46. * Make a show builder.
  47. *
  48. * @param mixed $id
  49. *
  50. * @return Show
  51. */
  52. protected function detail($id)
  53. {
  54. return Show::make($id, new User(), function (Show $show) {
  55. $show->disableDeleteButton();
  56. //不允许查看非自己的数据
  57. if ($show->model()->agent_id != Admin::user()->id) {
  58. Admin::exit('数据不存在');
  59. }
  60. $show->field('id');
  61. $show->field('avatar')->image('', 80, 80);
  62. $show->field('mobile');
  63. $show->field('nickname');
  64. $show->field('status')->bool();
  65. $show->field('created_at');
  66. });
  67. }
  68. /**
  69. * Make a form builder.
  70. *
  71. * @return Form
  72. */
  73. protected function form()
  74. {
  75. return Form::make(new User(), function (Form $form) {
  76. $form->disableDeleteButton();
  77. //不允许查看非自己的数据
  78. if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
  79. return $form->response()->error('数据不存在');
  80. }
  81. $form->display('id');
  82. $form->display('nickname');
  83. $form->text('mobile');
  84. $form->switch('status');
  85. // $form->switch('is_verify');
  86. })->saving(function (Form $form) {
  87. //不允许修改非自己的数据
  88. if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
  89. return $form->response()->error('数据不存在');
  90. }
  91. //处理特殊字段
  92. $form->agent_id = Admin::user()->id;
  93. if (!is_null($form->status)) { //为防止行内编辑出错,此处需要加判断
  94. $form->status = $form->status ? 1 : 0;
  95. }
  96. /*if (!is_null($form->is_verify)) { //为防止行内编辑出错,此处需要加判断
  97. $form->is_verify = $form->is_verify ? 1 : 0;
  98. }*/
  99. //不允许编辑的字段
  100. $form->ignore(['id', 'agent_id', 'nickname', 'deleted_at']);
  101. })->deleting(function (Form $form) {
  102. return $form->response()->error('操作禁止');
  103. });
  104. }
  105. }