UserController.php 3.3 KB

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