UserController.php 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Admin\Controllers\Share;
  3. use App\Models\User;
  4. use App\Models\UserShare;
  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. return Grid::make(User::with(['parent.info','info'])->withCount('child'), function (Grid $grid) {
  19. $grid->model()->where('is_share', 1);
  20. $grid->column('id','用户ID');
  21. $grid->column('avatar', '基本信息')->display(function () {
  22. $str = "";
  23. $str .= "<div style='margin-right:10px;display: flex;align-items: center'>";
  24. $str .= '<img data-action="preview-img" src="' . $this->avatar . '" style="height:50px;width:50px;cursor:pointer;margin-right:10px;" class="img img-thumbnail">';
  25. $str .= '<div>';
  26. $str .= '<p style="margin-bottom: 5px">' . $this->nickname . '</p>';
  27. $str .= '<p style="margin-bottom: 5px">' . $this->mobile . '</p>';
  28. $str .= "</div>";
  29. $str .= "</div>";
  30. return $str;
  31. });
  32. $grid->column('info.platform','所属平台')
  33. ->using(config('global.platform'))
  34. ->label([1=>'primary',2=>'success',3=>'info']);
  35. $grid->column('income');
  36. $grid->column('total_income');
  37. $grid->column('parent_id')->display(function (){
  38. return $this->parent?$this->parent->nickname:'-';
  39. })->label('primary');
  40. $grid->column('child_count');
  41. $grid->column('become_share_at');
  42. $grid->filter(function (Grid\Filter $filter) {
  43. $filter->panel();
  44. $filter->equal('info.platform','所属平台')->select(config('global.platform'))->width(3);
  45. $filter->like('nickname','昵称')->width(3);
  46. $filter->equal('mobile','手机号')->width(3);
  47. });
  48. $grid->disableCreateButton();
  49. $grid->disableDeleteButton();
  50. $grid->disableRowSelector();
  51. $grid->disableActions();
  52. });
  53. }
  54. /**
  55. * Make a show builder.
  56. *
  57. * @param mixed $id
  58. *
  59. * @return Show
  60. */
  61. protected function detail($id)
  62. {
  63. return Show::make($id, new UserShare(), function (Show $show) {
  64. $show->field('id');
  65. $show->field('user_id');
  66. $show->field('child_id');
  67. $show->field('income');
  68. $show->field('created_at');
  69. $show->field('updated_at');
  70. });
  71. }
  72. /**
  73. * Make a form builder.
  74. *
  75. * @return Form
  76. */
  77. protected function form()
  78. {
  79. return Form::make(new UserShare(), function (Form $form) {
  80. $form->display('id');
  81. $form->text('user_id');
  82. $form->text('child_id');
  83. $form->text('income');
  84. $form->display('created_at');
  85. $form->display('updated_at');
  86. });
  87. }
  88. }