ConfigController.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190
  1. <?php
  2. namespace app\admin\controller\sys_manage;
  3. use app\admin\service\sys_manage\ConfigService;
  4. use app\admin\validate\sys_manage\ConfigValidate;
  5. use app\model\SysConfig;
  6. use support\Request;
  7. class ConfigController
  8. {
  9. /**
  10. * @Desc 配置列表
  11. * @Author Gorden
  12. * @Date 2024/2/22 16:35
  13. *
  14. * @param Request $request
  15. * @return \support\Response
  16. */
  17. public function configList(Request $request)
  18. {
  19. return ConfigService::configList($request);
  20. }
  21. /**
  22. * @Desc 配置详情
  23. * @Author Gorden
  24. * @Date 2024/2/22 16:36
  25. *
  26. * @param $id
  27. * @return \support\Response
  28. */
  29. public function configInfo($id)
  30. {
  31. return ConfigService::configInfo($id);
  32. }
  33. /**
  34. * @Desc 添加配置
  35. * @Author Gorden
  36. * @Date 2024/2/22 15:57
  37. *
  38. * @param Request $request
  39. * @return \support\Response
  40. */
  41. public function addConfig(Request $request)
  42. {
  43. $validate = new ConfigValidate();
  44. if (!$validate->scene('add')->check($request->post())) {
  45. return json_fail($validate->getError());
  46. }
  47. return ConfigService::addConfig($request->post());
  48. }
  49. /**
  50. * @Desc 修改配置
  51. * @Author Gorden
  52. * @Date 2024/2/22 16:24
  53. *
  54. * @param $id
  55. * @param Request $request
  56. * @return \support\Response
  57. */
  58. public function updateConfig($id, Request $request)
  59. {
  60. $validate = new ConfigValidate();
  61. if (!$validate->scene('update')->check($request->post())) {
  62. return json_fail($validate->getError());
  63. }
  64. return ConfigService::updateConfig($id, $request->post());
  65. }
  66. /**
  67. * @Desc 修改配置状态
  68. * @Author Gorden
  69. * @Date 2024/2/22 16:38
  70. *
  71. * @param $id
  72. * @param Request $request
  73. * @return \support\Response
  74. */
  75. public function updateStatus($id, Request $request)
  76. {
  77. $validate = new ConfigValidate();
  78. if (!$validate->scene('update_status')->check($request->post())) {
  79. return json_fail($validate->getError());
  80. }
  81. return ConfigService::updateStatus($id, $request->post());
  82. }
  83. /**
  84. * @Desc 删除配置
  85. * @Author Gorden
  86. * @Date 2024/2/22 16:39
  87. *
  88. * @param $id
  89. * @return \support\Response
  90. */
  91. public function delConfig(Request $request)
  92. {
  93. return ConfigService::delConfig($request);
  94. }
  95. public function bottomMenuList()
  96. {
  97. $config = SysConfig::where('config_name', 'APP底部菜单')->first()->toArray();
  98. return json_success('', json_decode($config['config_value_json']));
  99. }
  100. public function bottomMenuSave(Request $request)
  101. {
  102. try {
  103. SysConfig::where('config_name', 'APP底部菜单')->update(['config_value_json' => json_encode($request->post())]);
  104. return json_success('success');
  105. } catch (\Exception $e) {
  106. return json_fail('APP底部菜单保存失败');
  107. }
  108. }
  109. public function navMenuList()
  110. {
  111. $config = SysConfig::where('config_name', 'APP导航菜单')->first()->toArray();
  112. return json_success('', json_decode($config['config_value_json']));
  113. }
  114. public function navMenuSave(Request $request)
  115. {
  116. try {
  117. SysConfig::where('config_name', 'APP导航菜单')->update(['config_value_json' => json_encode($request->post())]);
  118. return json_success('success');
  119. } catch (\Exception $e) {
  120. return json_fail('APP底部菜单保存失败');
  121. }
  122. }
  123. public function paramsList(Request $request)
  124. {
  125. $type = $request->get('type', '');
  126. return ConfigService::getParams($this->getType($type));
  127. }
  128. public function paramsSave(Request $request)
  129. {
  130. return ConfigService::paramsSave($request, $this->getType($request->post('type', '')));
  131. }
  132. private function getType($type)
  133. {
  134. switch ($type) {
  135. case 'sys':
  136. return 'sys';
  137. break;
  138. case 'pay':
  139. return 'app-pay-unionpay';
  140. break;
  141. case 'msg':
  142. return 'app-sms-aliyun';
  143. break;
  144. case 'face':
  145. return 'app-face-aliyun';
  146. break;
  147. case 'ocr':
  148. return 'app-cert-ocr-aliyun';
  149. break;
  150. case 'ws':
  151. return 'app-websocket';
  152. break;
  153. case 'shortcutMenu':
  154. return 'app-menu-shortcut';
  155. break;
  156. case 'navigationMenu':
  157. return 'app-menu-navigation';
  158. break;
  159. case 'footerMenu':
  160. return 'app-menu-footer';
  161. break;
  162. default:
  163. return '';
  164. break;
  165. }
  166. }
  167. }