UserController.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Models\User;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class UserController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(User::with(['info']), function (Grid $grid) {
  18. $grid->model()->orderByDesc('id');
  19. $grid->column('id')->sortable();
  20. $grid->column('avatar')->display(function () {
  21. $str = "";
  22. $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
  23. $str .= '<img data-action="preview-img" src="' . $this->avatar . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
  24. $str .= '<div>';
  25. $str .= '<p style="margin-bottom: 5px">' . $this->nickname . '</p>';
  26. $str .= '<p style="margin-bottom: 0px">' . $this->mobile . '</p>';
  27. $str .= "</div>";
  28. $str .= "</div>";
  29. return $str;
  30. });
  31. $grid->column('info.is_vip','是否会员')->using([0 => '否', 1 => '是'])->label(['gray', 'primary']);
  32. $grid->column('info.integral','金币余额');
  33. $grid->column('info.platform','注册平台')->using([1 => '抖音', 2 => '快手'])->label(['gray', 'primary']);;
  34. $grid->column('created_at','注册时间');
  35. $grid->filter(function (Grid\Filter $filter) {
  36. $filter->panel();
  37. $filter->equal('id','ID')->width(3);
  38. $filter->like('nickname')->width(3);
  39. $filter->equal('mobile')->width(3);
  40. $filter->equal('info.is_vip','是否会员')->select(function (){
  41. return ['否','是'];
  42. })->width(3);
  43. $filter->equal('info.platform','是否会员')->select(function (){
  44. return [1 => '抖音', 2 => '快手'];
  45. })->width(3);
  46. });
  47. $grid->disableCreateButton();
  48. $grid->disableDeleteButton();
  49. $grid->disableRowSelector();
  50. });
  51. }
  52. /**
  53. * Make a show builder.
  54. *
  55. * @param mixed $id
  56. *
  57. * @return Show
  58. */
  59. protected function detail($id)
  60. {
  61. return Show::make($id, new User(), function (Show $show) {
  62. $show->field('id');
  63. $show->field('nickname');
  64. $show->field('avatar');
  65. $show->field('password');
  66. $show->field('email');
  67. $show->field('mobile');
  68. $show->field('open_id');
  69. $show->field('union_id');
  70. $show->field('status');
  71. $show->field('email_verified_at');
  72. $show->field('remember_token');
  73. $show->field('created_at');
  74. $show->field('updated_at');
  75. });
  76. }
  77. /**
  78. * Make a form builder.
  79. *
  80. * @return Form
  81. */
  82. protected function form()
  83. {
  84. return Form::make(new User(), function (Form $form) {
  85. $form->display('id');
  86. $form->text('nickname');
  87. $form->text('avatar');
  88. $form->text('password');
  89. $form->text('email');
  90. $form->text('mobile');
  91. $form->text('open_id');
  92. $form->text('union_id');
  93. $form->text('status');
  94. $form->text('email_verified_at');
  95. $form->text('remember_token');
  96. $form->display('created_at');
  97. $form->display('updated_at');
  98. });
  99. }
  100. }