UserController.php 3.2 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. ->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. * @return Show
  59. */
  60. protected function detail($id)
  61. {
  62. return Show::make($id, new UserShare(), function (Show $show) {
  63. $show->field('id');
  64. $show->field('user_id');
  65. $show->field('child_id');
  66. $show->field('income');
  67. $show->field('created_at');
  68. $show->field('updated_at');
  69. });
  70. }
  71. /**
  72. * Make a form builder.
  73. *
  74. * @return Form
  75. */
  76. protected function form()
  77. {
  78. return Form::make(new UserShare(), function (Form $form) {
  79. $form->display('id');
  80. $form->text('user_id');
  81. $form->text('child_id');
  82. $form->text('income');
  83. $form->display('created_at');
  84. $form->display('updated_at');
  85. });
  86. }
  87. }