UserController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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('income');
  33. $grid->column('total_income');
  34. $grid->column('parent_id')->display(function (){
  35. return $this->parent?$this->parent->nickname:'-';
  36. })->label('primary');
  37. $grid->column('child_count');
  38. $grid->column('become_share_at');
  39. $grid->filter(function (Grid\Filter $filter) {
  40. $filter->panel();
  41. $filter->equal('info.platform','所属平台')->select(config('global.platform'))->width(3);
  42. $filter->like('nickname','昵称')->width(3);
  43. $filter->equal('mobile','手机号')->width(3);
  44. });
  45. $grid->disableCreateButton();
  46. $grid->disableDeleteButton();
  47. $grid->disableRowSelector();
  48. $grid->disableActions();
  49. });
  50. }
  51. /**
  52. * Make a show builder.
  53. *
  54. * @param mixed $id
  55. *
  56. * @return Show
  57. */
  58. protected function detail($id)
  59. {
  60. return Show::make($id, new UserShare(), function (Show $show) {
  61. $show->field('id');
  62. $show->field('user_id');
  63. $show->field('child_id');
  64. $show->field('income');
  65. $show->field('created_at');
  66. $show->field('updated_at');
  67. });
  68. }
  69. /**
  70. * Make a form builder.
  71. *
  72. * @return Form
  73. */
  74. protected function form()
  75. {
  76. return Form::make(new UserShare(), function (Form $form) {
  77. $form->display('id');
  78. $form->text('user_id');
  79. $form->text('child_id');
  80. $form->text('income');
  81. $form->display('created_at');
  82. $form->display('updated_at');
  83. });
  84. }
  85. }