ConfigController.php 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. public function partnerParamsInfo()
  133. {
  134. $config = SysConfig::where('config_key', 'app-identity-partner-config')->first()->toArray();
  135. $config['config_value_json'] = json_decode($config['config_value_json'], true);
  136. if (!empty($config['config_value_json']['account']['added'])) {
  137. $config['config_value_json']['account']['added'] = round($config['config_value_json']['account']['added'] * 100, 2);
  138. }
  139. if (!empty($config['config_value_json']['commission'])) {
  140. $config['config_value_json']['commission']['direct'] = round($config['config_value_json']['commission']['direct'] * 100, 2);
  141. $config['config_value_json']['commission']['indirect'] = round($config['config_value_json']['commission']['indirect'] * 100, 2);
  142. $config['config_value_json']['commission']['relate_consum'] = round($config['config_value_json']['commission']['relate-consum'] * 100, 2);
  143. $config['config_value_json']['commission']['invite_non_identity'] = round($config['config_value_json']['commission']['invite-non-identity'] * 100, 2);
  144. $config['config_value_json']['commission']['agent_senior_join'] = round($config['config_value_json']['commission']['agent-senior-join'] * 100, 2);
  145. $config['config_value_json']['commission']['agent_senior_strategy'] = round($config['config_value_json']['commission']['agent-senior-strategy'] * 100, 2);
  146. }
  147. return json_success('success', $config);
  148. }
  149. public function setPartnerParams(Request $request)
  150. {
  151. $params = $request->post();
  152. if (!empty($params['account']['added'])) {
  153. $params['account']['added'] = $params['account']['added'] / 100;
  154. }
  155. if (!empty($params['commission'])) {
  156. $params['commission']['direct'] = $params['commission']['direct'] / 100;
  157. $params['commission']['indirect'] = $params['commission']['indirect'] / 100;
  158. $params['commission']['relate-consum'] = $params['commission']['relate_consum'] / 100;
  159. $params['commission']['invite-non-identity'] = $params['commission']['invite_non_identity'] / 100;
  160. $params['commission']['agent-senior-join'] = $params['commission']['agent_senior_join'] / 100;
  161. $params['commission']['agent-senior-strategy'] = $params['commission']['agent_senior_strategy'] / 100;
  162. unset($params['commission']['relate_consum'], $params['commission']['invite_non_identity'], $params['commission']['agent_senior_join'], $params['commission']['agent_senior_strategy']);
  163. }
  164. try {
  165. SysConfig::where('config_key', 'app-identity-partner-config')->update(['config_value_json' => json_encode($params)]);
  166. return json_success('success');
  167. } catch (\Exception $e) {
  168. return json_fail("保存失败");
  169. }
  170. }
  171. private function getType($type)
  172. {
  173. switch ($type) {
  174. case 'sys':
  175. return 'sys';
  176. break;
  177. case 'pay':
  178. return 'app-pay-unionpay';
  179. break;
  180. case 'msg':
  181. return 'app-sms-aliyun';
  182. break;
  183. case 'face':
  184. return 'app-face-aliyun';
  185. break;
  186. case 'ocr':
  187. return 'app-cert-ocr-aliyun';
  188. break;
  189. case 'ws':
  190. return 'app-websocket';
  191. break;
  192. case 'shortcutMenu':
  193. return 'app-menu-shortcut';
  194. break;
  195. case 'navigationMenu':
  196. return 'app-menu-navigation';
  197. break;
  198. case 'footerMenu':
  199. return 'app-menu-footer';
  200. break;
  201. default:
  202. return '';
  203. break;
  204. }
  205. }
  206. }