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

120 lines
3.9 KiB

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. <?php
  2. namespace App\Admin\Controllers\v3;
  3. use App\Admin\Repositories\v3\SystemConfig;
  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\v3\SystemConfig as SystemConfigModel;
  9. use App\Libs\SsdbClient;
  10. use App\Constants\v3\SsdbKeys;
  11. class SystemConfigController extends AdminController
  12. {
  13. /**
  14. * Make a grid builder.
  15. *
  16. * @return Grid
  17. */
  18. protected function grid()
  19. {
  20. return Grid::make(new SystemConfig(), function (Grid $grid) {
  21. $grid->column('id')->sortable();
  22. $grid->column('menu_name');
  23. $grid->column('info');
  24. $grid->column('value');
  25. $grid->column('category_text');
  26. $grid->column('sort');
  27. $grid->column('status')->switch();
  28. $grid->model()->orderby('id','desc');
  29. $grid->filter(function (Grid\Filter $filter) {
  30. $filter->equal('id');
  31. $filter->like('menu_name');
  32. $filter->equal('category')->select(SystemConfigModel::$_CATEGORY);
  33. });
  34. });
  35. }
  36. /**
  37. * Make a show builder.
  38. *
  39. * @param mixed $id
  40. *
  41. * @return Show
  42. */
  43. protected function detail($id)
  44. {
  45. return Show::make($id, new SystemConfig(), function (Show $show) {
  46. $menuName = $show->model()->menu_name;
  47. $show->field('id');
  48. $show->field('menu_name');
  49. $show->field('category_text');
  50. $show->field('value')->width(6);
  51. if($menuName == 'initial_delivery_amount'){
  52. $delivery = SsdbClient::client()->get(SsdbKeys::INTIAL_DELIVERY_AMOUNT);
  53. $show->field('value_text','已存ssdb的值:')->width(6)->value($delivery);
  54. }
  55. $show->field('info');
  56. $show->field('desc');
  57. $show->field('sort');
  58. $show->field('status_text');
  59. $show->field('created_at');
  60. $show->field('updated_at');
  61. });
  62. }
  63. /**
  64. * Make a form builder.
  65. *
  66. * @return Form
  67. */
  68. protected function form()
  69. {
  70. return Form::make(new SystemConfig(), function (Form $form) {
  71. $menuName = $form->model()->menu_name;
  72. $form->hidden('id');
  73. $form->text('menu_name')->width(4)->required()->rules('regex:/^[0-9a-z_]{1,}$/',['regex'=>'只能输入数字、小写字母和下划线'])->help('本字段在添加成功后不能编辑!');
  74. $form->select('category')->width(4)->options(SystemConfigModel::$_CATEGORY);
  75. $deliveryForm = $form->text('value')->required()->width(6)->maxLength(100);
  76. if($menuName == 'initial_delivery_amount'){
  77. $delivery = SsdbClient::client()->get(SsdbKeys::INTIAL_DELIVERY_AMOUNT);
  78. $deliveryForm->help('已存ssdb的值:'.$delivery);
  79. }
  80. $form->text('info')->maxLength(255);
  81. $form->text('desc')->maxLength(500);
  82. $form->number('sort')->width(2)->default(0);
  83. $form->saving(function(Form $form){
  84. $id = $form->input('id');
  85. $menuName = $form->input('menu_name');
  86. if($id && $menuName ){
  87. $form->deleteInput('menu_name');
  88. }
  89. if($id && $menuName == 'initial_delivery_amount'){
  90. $delivery = $form->input('value');
  91. SsdbClient::client()->set(SsdbKeys::INTIAL_DELIVERY_AMOUNT,$delivery);
  92. }
  93. });
  94. $form->switch('status')
  95. ->customFormat(function ($v) {
  96. return $v == 1 ? 1 : 0;
  97. })
  98. ->saving(function ($v) {
  99. return $v == 1 ? 1 : 0;
  100. });
  101. $form->disableResetButton();
  102. $form->disableViewCheck();
  103. $form->disableEditingCheck();
  104. $form->disableCreatingCheck();
  105. });
  106. }
  107. }