SettingController.php 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  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\Show;
  7. use Dcat\Admin\Http\Controllers\AdminController;
  8. class SettingController extends AdminController
  9. {
  10. public const TYPE_BASIC = 'basic'; // 基础设置
  11. public const TYPE_TIPS = 'tips'; // 消息设置
  12. public const TYPE_GOLD = 'gold'; // 金币设置
  13. public const TYPE_ROLE = 'role'; // 会员权限
  14. public const TYPE_SIGN = 'sign'; // 签到权限
  15. protected $type = '';
  16. public function __construct()
  17. {
  18. $route = \request()->route();
  19. $arr = explode('/', $route->uri);
  20. $this->type = $arr[3];
  21. }
  22. /**
  23. * Make a grid builder.
  24. *
  25. * @return Grid
  26. */
  27. protected function grid()
  28. {
  29. return Grid::make(new Setting(), function (Grid $grid) {
  30. $grid->column('id')->sortable();
  31. if (self::TYPE_BASIC == $this->type) {
  32. $grid->column('name');
  33. $grid->column('logo')->image('', 150);
  34. $grid->column('contact')->editable();
  35. $grid->column('is_review')->switch();
  36. } elseif (self::TYPE_TIPS == $this->type) {
  37. $grid->column('tips')->editable();
  38. } elseif (self::TYPE_GOLD == $this->type) {
  39. $grid->column('recharge_bg_img')->image('', 150);
  40. $grid->column('recharge_button_txt');
  41. $grid->column('recharge_desc');
  42. } elseif (self::TYPE_ROLE == $this->type) {
  43. $grid->column('vip_role')->radio(config('global.vip_role'));
  44. } elseif (self::TYPE_SIGN == $this->type) {
  45. $grid->column('is_open_sign')->radio(config('global.open_sign'));
  46. }
  47. if (self::TYPE_ROLE == $this->type || self::TYPE_SIGN == $this->type) {
  48. $grid->disableEditButton();
  49. $grid->disableActions();
  50. }
  51. $grid->disableDeleteButton();
  52. $grid->disableCreateButton();
  53. $grid->disableViewButton();
  54. $grid->disableRowSelector();
  55. });
  56. }
  57. /**
  58. * Make a show builder.
  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. * @return Form
  82. */
  83. protected function form()
  84. {
  85. return Form::make(new Setting(), function (Form $form) {
  86. $form->display('id');
  87. if (self::TYPE_BASIC == $this->type) {
  88. $form->text('name');
  89. $form->image('logo')->saveFullUrl()
  90. ->uniqueName()->autoUpload()
  91. ->autoSave(false)
  92. ->removable(false)
  93. ->width(4);
  94. $form->text('contact')->minLength(11)->maxLength(11);
  95. $form->radio('is_review')->options(config('global.bool_status'))->default(0);
  96. $form->editor('protocol');
  97. } elseif (self::TYPE_TIPS == $this->type) {
  98. $form->text('tips');
  99. } elseif (self::TYPE_GOLD == $this->type) {
  100. $form->image('recharge_bg_img')->saveFullUrl()
  101. ->uniqueName()->autoUpload()
  102. ->autoSave(false)
  103. ->removable(false)
  104. ->width(4);
  105. $form->text('recharge_button_txt')->maxLength(10);
  106. $form->textarea('recharge_desc');
  107. } elseif (self::TYPE_ROLE == $this->type) {
  108. $form->radio('vip_role')->options(config('global.vip_role'))->default(1);
  109. }
  110. $form->disableViewButton();
  111. $form->disableDeleteButton();
  112. $form->disableListButton();
  113. $form->disableEditingCheck();
  114. $form->disableViewCheck();
  115. });
  116. }
  117. }