SettingController.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. <?php
  2. namespace App\Admin\Controllers\Setting;
  3. use App\Models\Setting;
  4. use Dcat\Admin\Form;
  5. use Dcat\Admin\Grid;
  6. use Dcat\Admin\Layout\Content;
  7. use Dcat\Admin\Show;
  8. use Dcat\Admin\Http\Controllers\AdminController;
  9. use Dingo\Api\Http\Request;
  10. class SettingController extends AdminController
  11. {
  12. const TYPE_BASIC = 'basic'; // 基础设置
  13. const TYPE_TIPS = 'tips'; // 消息设置
  14. const TYPE_GOLD = 'gold'; // 金币设置
  15. const TYPE_ROLE = 'role'; // 会员权限
  16. protected $type = '';
  17. public function __construct()
  18. {
  19. $route = \request()->route();
  20. $arr = explode("/",$route->uri);
  21. $this->type = $arr[3];
  22. }
  23. /**
  24. * Make a grid builder.
  25. *
  26. * @return Grid
  27. */
  28. protected function grid()
  29. {
  30. return Grid::make(new Setting(), function (Grid $grid) {
  31. $grid->column('id')->sortable();
  32. if($this->type == self::TYPE_BASIC){
  33. $grid->column('name');
  34. $grid->column('logo')->image('',150);
  35. $grid->column('contact')->editable();
  36. }elseif($this->type == self::TYPE_TIPS){
  37. $grid->column('tips')->editable();
  38. }elseif($this->type == self::TYPE_GOLD){
  39. $grid->column('recharge_bg_img')->image('',150);;
  40. $grid->column('recharge_button_txt');
  41. $grid->column('recharge_desc');
  42. }elseif($this->type == self::TYPE_ROLE){
  43. $grid->column('vip_role')->radio(config('global.vip_role'));
  44. }
  45. if($this->type == self::TYPE_ROLE){
  46. $grid->disableEditButton();
  47. $grid->disableActions();
  48. }
  49. $grid->disableDeleteButton();
  50. $grid->disableCreateButton();
  51. $grid->disableViewButton();
  52. $grid->disableRowSelector();
  53. });
  54. }
  55. /**
  56. * Make a show builder.
  57. *
  58. * @param mixed $id
  59. *
  60. * @return Show
  61. */
  62. protected function detail($id)
  63. {
  64. return Show::make($id, new Setting(), function (Show $show) {
  65. $show->field('id');
  66. $show->field('name');
  67. $show->field('logo');
  68. $show->field('contact');
  69. $show->field('tips');
  70. $show->field('is_watch_auto_pay');
  71. $show->field('recharge_bg_img');
  72. $show->field('recharge_button_txt');
  73. $show->field('recharge_desc');
  74. $show->field('created_at');
  75. $show->field('updated_at');
  76. });
  77. }
  78. /**
  79. * Make a form builder.
  80. *
  81. * @param $type
  82. * @return Form
  83. */
  84. protected function form()
  85. {
  86. return Form::make(new Setting(), function (Form $form) {
  87. $form->display('id');
  88. if($this->type == self::TYPE_BASIC){
  89. $form->text('name');
  90. $form->image('logo')->saveFullUrl()
  91. ->uniqueName()->autoUpload()
  92. ->autoSave(false)
  93. ->removable(false)
  94. ->width(4);
  95. $form->text('contact')->minLength(11)->maxLength(11);
  96. }elseif($this->type == self::TYPE_TIPS){
  97. $form->text('tips');
  98. }elseif($this->type == self::TYPE_GOLD){
  99. $form->image('recharge_bg_img')->saveFullUrl()
  100. ->uniqueName()->autoUpload()
  101. ->autoSave(false)
  102. ->removable(false)
  103. ->width(4);
  104. $form->text('recharge_button_txt')->maxLength(10);
  105. $form->textarea('recharge_desc');
  106. } elseif($this->type == self::TYPE_ROLE){
  107. $form->radio('vip_role',config('global.vip_role'));;
  108. }
  109. $form->disableViewButton();
  110. $form->disableDeleteButton();
  111. $form->disableListButton();
  112. $form->disableEditingCheck();
  113. $form->disableViewCheck();
  114. });
  115. }
  116. }