WxPlateController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\WxPlate;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class WxPlateController extends AdminController
  9. {
  10. /**
  11. * Make a grid builder.
  12. *
  13. * @return Grid
  14. */
  15. protected function grid()
  16. {
  17. return Grid::make(new WxPlate(), function (Grid $grid) {
  18. global $__MINI_GLOBAL_TENANT_ID__;
  19. $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
  20. $grid->quickSearch(['id', 'plate_name','plate_introduce'])->placeholder('搜索id,名称,描述...')->width(50);
  21. // $grid->column('id')->sortable();
  22. $grid->column('plate_name')->editable();
  23. $grid->column('sort')->editable();
  24. $grid->column('plate_introduce');
  25. $grid->column('plate_state')->switch();
  26. // $grid->column('created_at');
  27. // $grid->column('updated_at')->sortable();
  28. $grid->model()->orderBy('id', 'desc');
  29. $grid->filter(function (Grid\Filter $filter) {
  30. $filter->like('plate_name');
  31. });
  32. });
  33. }
  34. /**
  35. * Make a show builder.
  36. *
  37. * @param mixed $id
  38. *
  39. * @return Show
  40. */
  41. protected function detail($id)
  42. {
  43. return Show::make($id, new WxPlate(), function (Show $show) {
  44. $show->field('id');
  45. $show->field('plate_name');
  46. $show->field('plate_introduce');
  47. $show->field('plate_state');
  48. $show->field('tenant_id');
  49. $show->field('created_at');
  50. $show->field('updated_at');
  51. });
  52. }
  53. /**
  54. * Make a form builder.
  55. *
  56. * @return Form
  57. */
  58. protected function form()
  59. {
  60. return Form::make(new WxPlate(), function (Form $form) {
  61. $form->display('id');
  62. $form->text('plate_name');
  63. $form->number('sort');
  64. $form->text('plate_introduce');
  65. $form->switch('plate_state');
  66. global $__MINI_GLOBAL_TENANT_ID__;
  67. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  68. $form->text('tenant_id', '本站分应用id')->help('忽略这个配置')->default($__MINI_GLOBAL_TENANT_ID__);
  69. }
  70. $form->saving(function (Form $form){
  71. global $__MINI_GLOBAL_TENANT_ID__;
  72. $form->tenant_id = $__MINI_GLOBAL_TENANT_ID__;
  73. });
  74. $form->deleting(function (Form $form){
  75. global $__MINI_GLOBAL_TENANT_ID__;
  76. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  77. if(\App\Models\WxPlate::where('id', $form->getKey())->value('tenant_id') != $__MINI_GLOBAL_TENANT_ID__){
  78. return $form->response()->error('权限不足,不可以删除其他分站对象');
  79. }
  80. }
  81. });
  82. });
  83. }
  84. }