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

104 lines
3.4 KiB

  1. <?php
  2. namespace App\Admin\Controllers;
  3. use App\Admin\Repositories\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\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')->using(BannerModel::$_status)->label(['default' => 'primary',1 => 'primary', 0 => 'danger']);
  39. $grid->filter(function (Grid\Filter $filter) {
  40. $filter->equal('id');
  41. });
  42. });
  43. }
  44. /**
  45. * Make a show builder.
  46. *
  47. * @param mixed $id
  48. *
  49. * @return Show
  50. */
  51. protected function detail($id)
  52. {
  53. return Show::make($id, new Banner(), function (Show $show) {
  54. $show->field('id');
  55. $show->field('market_id');
  56. $show->field('title');
  57. $show->field('sub_title');
  58. $show->field('cover');
  59. $show->field('cover_type');
  60. $show->field('path');
  61. $show->field('path_type');
  62. $show->field('sort');
  63. $show->field('status');
  64. $show->field('type');
  65. $show->field('created_at');
  66. $show->field('updated_at');
  67. });
  68. }
  69. /**
  70. * Make a form builder.
  71. *
  72. * @return Form
  73. */
  74. protected function form()
  75. {
  76. return Form::make(new Banner(), function (Form $form) {
  77. $form->hidden('id');
  78. // 市场
  79. $marketList = MarketModel::getMarket();
  80. $form->select('market_id')->width(4)->options($marketList);
  81. $form->select('type')->options(BannerModel::$_type)->required();
  82. $form->text('title')->required();
  83. $form->text('sub_title');
  84. $form->image('cover')->width(2)->required();
  85. $form->select('cover_type')->options(BannerModel::$_coverType)->required();
  86. $form->text('path')->default('');
  87. $form->select('path_type')->options(BannerModel::$_pathType)->default('');
  88. $form->text('sort');
  89. $form->disableResetButton();
  90. $form->disableViewCheck();
  91. $form->disableEditingCheck();
  92. $form->disableCreatingCheck();
  93. });
  94. }
  95. }