WxSearchController.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Renderable\UsersRender;
  4. use App\Admin\Repositories\WxSearch;
  5. use App\Models\User\WxUser;
  6. use Dcat\Admin\Form;
  7. use Dcat\Admin\Grid;
  8. use Dcat\Admin\Show;
  9. use Dcat\Admin\Http\Controllers\AdminController;
  10. class WxSearchController extends AdminController
  11. {
  12. /**
  13. * Make a grid builder.
  14. *
  15. * @return Grid
  16. */
  17. protected function grid()
  18. {
  19. return Grid::make(new WxSearch(['user']), function (Grid $grid) {
  20. $grid->simplePaginate();
  21. $grid->model()->orderBy('id', 'desc');
  22. $grid->quickSearch(['id','search_content', 'user.user_name'])->placeholder('搜索id,内容,用户名...')->width(35);
  23. $grid->column('id')->sortable();
  24. $grid->column('user.user_avatar','头像')->image('',30,30);
  25. $grid->column('user.user_name',)->display(function ($v) {
  26. if($v){
  27. return '<a target="_blank" href="'.admin_url('users?_search_='.$v).'">'.$v.'</a>' ?? '用户已删除';
  28. }
  29. return '用户已删除';
  30. })->width('100px');
  31. $grid->column('search_content')->label();
  32. $grid->column('is_hot')->switch()->sortable();
  33. $grid->column('created_at');
  34. $grid->column('updated_at')->sortable();
  35. $grid->filter(function (Grid\Filter $filter) {
  36. $filter->equal('id');
  37. $filter->equal('is_hot')->select([0=>'否',1=>'是']);
  38. });
  39. // $grid->disableCreateButton();
  40. $grid->disableViewButton();
  41. });
  42. }
  43. /**
  44. * Make a show builder.
  45. *
  46. * @param mixed $id
  47. *
  48. * @return Show
  49. */
  50. protected function detail($id)
  51. {
  52. return Show::make($id, new WxSearch(), function (Show $show) {
  53. $show->field('id');
  54. $show->field('user_id');
  55. $show->field('search_content');
  56. $show->field('created_at');
  57. $show->field('updated_at');
  58. });
  59. }
  60. /**
  61. * Make a form builder.
  62. *
  63. * @return Form
  64. */
  65. protected function form()
  66. {
  67. return Form::make(new WxSearch(), function (Form $form) {
  68. $form->display('id');
  69. $form->select('user_id', '用户')->options(function ($id) {
  70. $user = \App\Models\User\WxUser::find($id);
  71. if ($user) {
  72. return [$user->id => $user->user_name];
  73. }
  74. })->ajax('select/users');
  75. // $form->multipleSelectTable('user_id')
  76. // ->title('用户')
  77. // ->max(2)
  78. // ->from(UsersRender::make())
  79. // ->model(\App\Models\User\WxUser::class, 'id', 'user_name')->saving(function ($v) {
  80. // if(is_array($v) && count($v) > 0){
  81. // return $v[0];
  82. // }else if(is_numeric($v)){
  83. // return $v;
  84. // }
  85. // return 0;
  86. // })->required();
  87. $form->text('search_content');
  88. $form->switch('is_hot');
  89. $form->deleting(function (Form $form){
  90. global $__MINI_GLOBAL_TENANT_ID__;
  91. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  92. return $form->response()->error('权限不足,不可以删除其他分站对象');
  93. }
  94. });
  95. });
  96. }
  97. }