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

120 lines
3.3 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
  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. });
  42. });
  43. }
  44. /**
  45. * Make a show builder.
  46. *
  47. * @param mixed $id
  48. *
  49. * @return Show
  50. */
  51. protected function detail($id)
  52. {
  53. return Show::make($id, new User(), function (Show $show) {
  54. $show->disableDeleteButton();
  55. //不允许查看非自己的数据
  56. if ($show->model()->agent_id != Admin::user()->id) {
  57. Admin::exit('数据不存在');
  58. }
  59. $show->field('id');
  60. $show->field('avatar')->image('', 80, 80);
  61. $show->field('mobile');
  62. $show->field('nickname');
  63. $show->field('status')->bool();
  64. $show->field('created_at');
  65. });
  66. }
  67. /**
  68. * Make a form builder.
  69. *
  70. * @return Form
  71. */
  72. protected function form()
  73. {
  74. return Form::make(new User(), function (Form $form) {
  75. $form->disableDeleteButton();
  76. //不允许查看非自己的数据
  77. if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
  78. return $form->response()->error('数据不存在');
  79. }
  80. $form->display('id');
  81. $form->display('nickname');
  82. $form->text('mobile');
  83. $form->switch('status');
  84. $form->switch('is_verify');
  85. })->saving(function (Form $form) {
  86. //不允许修改非自己的数据
  87. if ($form->isEditing() && $form->model()->agent_id != Admin::user()->id) {
  88. return $form->response()->error('数据不存在');
  89. }
  90. //处理特殊字段
  91. $form->agent_id = Admin::user()->id;
  92. if (isset($form->status)) { //为防止行内编辑出错,此处需要加判断
  93. $form->status = $form->status ? 1 : 0;
  94. }
  95. if (isset($form->is_verify)) { //为防止行内编辑出错,此处需要加判断
  96. $form->is_verify = $form->is_verify ? 1 : 0;
  97. }
  98. //不允许编辑的字段
  99. $form->ignore(['id', 'agent_id', 'nickname', 'deleted_at']);
  100. })->deleting(function (Form $form) {
  101. return $form->response()->error('操作禁止');
  102. });
  103. }
  104. }