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

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