WxSlideshowController.php 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Wen\Utils\FieldUtils;
  4. use App\Wen\Utils\Utils;
  5. use App\Models\Posts\WxPost;
  6. use App\Models\Posts\WxTag;
  7. use App\Models\Circle\WxCircle;
  8. use App\Models\Shop\WxShopGoods;
  9. use App\Models\WxSlideshow;
  10. use App\Models\User\WxUser;
  11. use Dcat\Admin\Form;
  12. use Dcat\Admin\Grid;
  13. use Dcat\Admin\Show;
  14. use Dcat\Admin\Http\Controllers\AdminController;
  15. class WxSlideshowController extends AdminController
  16. {
  17. /**
  18. * Make a grid builder.
  19. *
  20. * @return Grid
  21. */
  22. protected function grid()
  23. {
  24. return Grid::make(new WxSlideshow(), function (Grid $grid) {
  25. global $__MINI_GLOBAL_TENANT_ID__;
  26. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  27. $grid->model()->where('tenant_id', '=', $__MINI_GLOBAL_TENANT_ID__);
  28. }
  29. $grid->model()->orderBy('id', 'desc');
  30. $grid->column('id')->sortable();
  31. $grid->column('poster')->image('',80);
  32. $grid->column('sort')->editable();
  33. $grid->column('slideshow_type')->using(FieldUtils::getUrlTypes())->label([
  34. 'default' => 'primary', // 设置默认颜色,不设置则默认为 default
  35. ]);
  36. $grid->column('target_id', '跳转id');
  37. $grid->column('slideshow_state')->switch();
  38. //$grid->column('is_xiangqin','相亲')->switch();
  39. // $grid->column('created_at');
  40. $grid->column('updated_at')->sortable();
  41. $grid->filter(function (Grid\Filter $filter) {
  42. $filter->equal('id');
  43. });
  44. $grid->disableViewButton();
  45. });
  46. }
  47. /**
  48. * Make a show builder.
  49. *
  50. * @param mixed $id
  51. *
  52. * @return Show
  53. */
  54. protected function detail($id)
  55. {
  56. return Show::make($id, new WxSlideshow(), function (Show $show) {
  57. $show->field('id');
  58. $show->field('poster');
  59. $show->field('target_id');
  60. $show->field('slideshow_type');
  61. $show->field('slideshow_state');
  62. //$show->field('is_xiangqin');
  63. $show->field('created_at');
  64. $show->field('updated_at');
  65. });
  66. }
  67. /**
  68. * Make a form builder.
  69. *
  70. * @return Form
  71. */
  72. protected function form()
  73. {
  74. return Form::make(new WxSlideshow(), function (Form $form) {
  75. $form->display('id');
  76. $form->image('poster')->help('首页轮播建议728*300,SHOP页建议尺寸:750*750,其他:众号首图尺寸:900*383,看着差不多的宽高比例即可')
  77. ->url('files/uploads')->autoUpload();
  78. $form->number('sort');
  79. $form->radio('slideshow_type')->options(FieldUtils::getUrlTypes())->default(0)->required();
  80. $form->text('target_id', '跳转id')->help('<a href="https://doc.minisns.cn/doc/44/" target="_blank">路径大全</a>');
  81. $form->switch('slideshow_state');
  82. // $grid->column('is_xiangqin','相亲')->switch();
  83. global $__MINI_GLOBAL_TENANT_ID__;
  84. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  85. $form->text('tenant_id', '本站分应用id')->help('忽略这个配置')->default($__MINI_GLOBAL_TENANT_ID__);
  86. }
  87. $form->saving(function (Form $form){
  88. global $__MINI_GLOBAL_TENANT_ID__;
  89. $form->tenant_id = $__MINI_GLOBAL_TENANT_ID__;
  90. });
  91. $form->deleting(function (Form $form){
  92. global $__MINI_GLOBAL_TENANT_ID__;
  93. if($__MINI_GLOBAL_TENANT_ID__ > 0){
  94. return $form->response()->error('权限不足,不可以删除其他分站对象');
  95. }
  96. });
  97. });
  98. }
  99. }