链街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.

122 lines
3.9 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->row(function (Show\Row $show) {
  56. $show->width(6)->field('id');
  57. $show->width(6)->field('market_id');
  58. $show->width(6)->field('cover_type');
  59. $show->width(6)->field('cover')->image();
  60. $show->width(6)->field('type');
  61. $show->width(6)->field('sort');
  62. $show->width(6)->field('created_at');
  63. });
  64. $show->row(function (Show\Row $show) {
  65. $show->width(6)->field('title');
  66. $show->width(6)->field('sub_title');
  67. $show->width(6)->field('path_type');
  68. $show->width(6)->field('path');
  69. $show->width(6)->field('status');
  70. $show->width(6)->field('updated_at');
  71. });
  72. });
  73. }
  74. /**
  75. * Make a form builder.
  76. *
  77. * @return Form
  78. */
  79. protected function form()
  80. {
  81. return Form::make(new Banner(), function (Form $form) {
  82. $form->hidden('id');
  83. // 市场
  84. $marketList = MarketModel::getMarket();
  85. $form->select('market_id')->width(4)->options($marketList)->default(0);
  86. // 多个市场
  87. $form->multipleSelect('market_ids')->options($marketList);
  88. $form->select('type')->options(BannerModel::$_type)->required();
  89. $form->text('title')->required();
  90. $form->text('sub_title');
  91. $form->image('cover')->width(2)->required();
  92. $form->select('cover_type')->options(BannerModel::$_coverType)->required();
  93. $form->text('path')->default('');
  94. $form->select('path_type')->options(BannerModel::$_pathType)->default('');
  95. $form->number('sort')->width(2)->default(0);
  96. $form->disableResetButton();
  97. $form->disableViewCheck();
  98. $form->disableEditingCheck();
  99. $form->disableCreatingCheck();
  100. });
  101. }
  102. }