链街Dcat后台
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

107 lines
3.6 KiB

  1. <?php
  2. namespace App\Admin\Controllers\v3;
  3. use App\Admin\Repositories\v3\Banner;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Show;
  7. use Dcat\Admin\Controllers\AdminController;
  8. use App\Models\ImsCjdcMarket as MarketModel;
  9. use App\Models\v3\Banner as BannerModel;
  10. class BannerController extends AdminController
  11. {
  12. /**
  13. * Make a grid builder.
  14. *
  15. * @return Grid
  16. */
  17. protected function grid()
  18. {
  19. return Grid::make(new Banner(), function (Grid $grid) {
  20. $grid->column('id')->sortable();
  21. $grid->column('market_id')->display(function($markerId){
  22. $market = MarketModel::getMarketInfo($markerId,'name');
  23. return empty($market) ? '' : $market['name'];
  24. });
  25. $grid->column('title');
  26. $grid->column('cover_url')->image(50);
  27. $grid->column('cover_type')->display(function($coverType){
  28. return isset(BannerModel::$_coverType[$coverType]) ? BannerModel::$_coverType[$coverType] : '';
  29. });
  30. $grid->column('path');
  31. $grid->column('path_type')->display(function($pathType){
  32. return isset(BannerModel::$_pathType[$pathType]) ? BannerModel::$_pathType[$pathType] : '';
  33. });
  34. $grid->column('type')->display(function($type){
  35. return isset(BannerModel::$_type[$type]) ? BannerModel::$_type[$type] : '';
  36. });
  37. $grid->column('sort')->sortable();
  38. $grid->column('status')->switch();
  39. // ->using(BannerModel::$_status)->label(['default' => 'primary',1 => 'primary', 0 => 'danger']);
  40. $grid->filter(function (Grid\Filter $filter) {
  41. $filter->equal('id');
  42. });
  43. });
  44. }
  45. /**
  46. * Make a show builder.
  47. *
  48. * @param mixed $id
  49. *
  50. * @return Show
  51. */
  52. protected function detail($id)
  53. {
  54. return Show::make($id, new Banner(), function (Show $show) {
  55. $show->field('id');
  56. $show->field('market_id');
  57. $show->field('title');
  58. $show->field('sub_title');
  59. $show->field('cover');
  60. $show->field('cover_type');
  61. $show->field('path');
  62. $show->field('path_type');
  63. $show->field('sort');
  64. $show->field('status');
  65. $show->field('type');
  66. $show->field('created_at');
  67. $show->field('updated_at');
  68. });
  69. }
  70. /**
  71. * Make a form builder.
  72. *
  73. * @return Form
  74. */
  75. protected function form()
  76. {
  77. return Form::make(new Banner(), function (Form $form) {
  78. $form->hidden('id');
  79. // 市场
  80. $marketList = MarketModel::getMarket();
  81. $form->select('market_id')->width(4)->options($marketList)->default(0);
  82. // 多个市场
  83. $form->multipleSelect('market_ids')->options($marketList);
  84. $form->select('type')->options(BannerModel::$_type)->required();
  85. $form->text('title')->required();
  86. $form->text('sub_title');
  87. $form->image('cover')->width(2)->required();
  88. $form->select('cover_type')->options(BannerModel::$_coverType)->required();
  89. $form->text('path')->default('');
  90. $form->select('path_type')->options(BannerModel::$_pathType)->default('');
  91. $form->number('sort')->width(2)->default(0);
  92. $form->disableResetButton();
  93. $form->disableViewCheck();
  94. $form->disableEditingCheck();
  95. $form->disableCreatingCheck();
  96. });
  97. }
  98. }