GreenChannelController.php 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. namespace app\admin\controller\sys_manage;
  3. use app\model\SysConfig;
  4. use support\Request;
  5. class GreenChannelController{
  6. public function select(){
  7. $config = SysConfig::where('config_key','app-system-hospital')->first();
  8. if(!$config){
  9. return json_fail("数据异常");
  10. }
  11. $list = json_decode($config->config_value_json,true);
  12. $data = [];
  13. foreach($list as $key => $item){
  14. $item['hospital'] = $key;
  15. $data[] = $item;
  16. }
  17. return json_success('',$data);
  18. }
  19. public function insert(Request $request){
  20. $config = SysConfig::where('config_key','app-system-hospital')->first();
  21. if(!$config){
  22. return json_fail("数据异常");
  23. }
  24. $params = $request->post();
  25. $list = json_decode($config->config_value_json,true);
  26. if(isset($list[$params['hospital']])){
  27. return json_fail('医院已存在');
  28. }
  29. $data[$params['hospital']] = [
  30. 'city' => $params['city'] ?? '',
  31. 'agent'=>'',
  32. 'dates'=>''
  33. ];
  34. $list = $data + $list;//array_merge($data,$list);
  35. try{
  36. SysConfig::where('config_key','app-system-hospital')->update(['config_value_json'=>json_encode($list)]);
  37. return json_success('添加医院成功');
  38. }catch(\Exception $e){
  39. return json_fail("添加医院失败");
  40. }
  41. }
  42. public function update(Request $request){
  43. $config = SysConfig::where('config_key','app-system-hospital')->first();
  44. if(!$config){
  45. return json_fail("数据异常");
  46. }
  47. $params = $request->post();
  48. $list = json_decode($config->config_value_json,true);
  49. if(isset($list[$params['hospital']])){
  50. return json_fail('医院已存在');
  51. }
  52. $data[$params['hospital']] = [
  53. 'city' => $params['city'] ?? '',
  54. 'agent'=>'',
  55. 'dates'=>''
  56. ];
  57. array_unshift($list,$data);
  58. dump($list);
  59. }
  60. public function delete(Request $request){
  61. $hospital = $request->post('hospital','');
  62. if(!$hospital){
  63. return json_fail("参数异常");
  64. }
  65. $config = SysConfig::where('config_key','app-system-hospital')->first();
  66. if(!$config){
  67. return json_fail("数据异常");
  68. }
  69. $params = $request->post();
  70. $list = json_decode($config->config_value_json,true);
  71. if (!isset($list[$hospital])){
  72. return json_fail('医院不存在');
  73. }
  74. unset($list[$hospital]);
  75. try{
  76. SysConfig::where('config_key','app-system-hospital')->update(['config_value_json'=>json_encode($list)]);
  77. return json_success('删除医院成功');
  78. }catch(\Exception $e){
  79. return json_fail("删除医院失败");
  80. }
  81. }
  82. }