UserListController.php 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. namespace App\Admin\Controllers\UserManagement\BmUser;
  3. use App\Admin\Actions\backstage\User\archives;
  4. use App\Admin\Actions\backstage\User\BalanceLog;
  5. use App\Admin\Actions\backstage\User\BlackList;
  6. use App\Admin\Actions\backstage\User\coupons;
  7. use App\Models\Patient;
  8. use App\Models\User;
  9. use Encore\Admin\Controllers\AdminController;
  10. use Encore\Admin\Form;
  11. use Encore\Admin\Grid;
  12. use Encore\Admin\Show;
  13. class UserListController extends AdminController
  14. {
  15. /**
  16. * Title for current resource.
  17. *
  18. * @var string
  19. */
  20. protected $title = '用户列表';
  21. /**
  22. * Make a grid builder.
  23. *
  24. * @return Grid
  25. */
  26. protected function grid()
  27. {
  28. $grid = new Grid(new User());
  29. $grid->disableCreateButton();
  30. $grid->actions(function ($actions) {
  31. // 去掉删除
  32. $actions->disableDelete();
  33. // 去掉编辑
  34. $actions->disableEdit();
  35. // 去掉查看
  36. $actions->disableView();
  37. $actions->add(new archives());
  38. $actions->add(new BalanceLog());
  39. $actions->add(new BlackList());
  40. $actions->add(new coupons());
  41. });
  42. //筛选
  43. $grid->filter(function ($filter){
  44. $filter->disableIdFilter();
  45. $filter->equal('phone','手机')->mobile()->placeholder("请输入手机");
  46. $filter->like('patient.name','患者姓名')->placeholder("请输入患者姓名");
  47. $filter->like('nickname','昵称');
  48. $filter->equal('status','用户状态')->radio([
  49. '' => '不限',
  50. 0 => '黑名单',
  51. 1 => '正常',
  52. ]);
  53. $filter->equal('is_pack','用户状态')->radio([
  54. '' => '全部用户',
  55. 0 => '普通用户',
  56. 1 => '服务包用户',
  57. ]);
  58. });
  59. $grid ->model()->where('status','>=','0');
  60. $grid->column('id', __('用户id'))->sortable();
  61. $grid->column('nickname', __('用户名'));
  62. $grid->column('sex', __('性别'))->using([0=>'未知',1=>'男',2=>'女']);
  63. $grid->column('age', __('年龄'));
  64. $grid->column('status', __('状态'))->using([0=>'黑名单',1=>'正常',]);
  65. $grid->column('is_pack', __('用户身份'))->using([0=>'普通用户',1=>'付费用户']);
  66. $grid->column('balance', __('当前余额'))->display(function ($price){
  67. return $price/100;
  68. });
  69. $grid->column('created_at', __('注册时间'));
  70. $grid->column('last_login_time', __('最后登录时间'))->display(function ($time){
  71. return date("Y-m-d H:i",$time);
  72. });
  73. // $grid->column('patient', __('患者姓名'))->pluck('name')->map('ucwords')->implode(',');
  74. $grid->column('patient', __('患者姓名'))->pluck('name')->label('default');
  75. return $grid;
  76. }
  77. /**
  78. * Make a show builder.
  79. *
  80. * @param mixed $id
  81. * @return Show
  82. */
  83. protected function detail($id)
  84. {
  85. $show = new Show(User::findOrFail($id));
  86. return $show;
  87. }
  88. /**
  89. * Make a form builder.
  90. *
  91. * @return Form
  92. */
  93. protected function form()
  94. {
  95. $form = new Form(new User());
  96. return $form;
  97. }
  98. }