Studies.php 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. <?php
  2. namespace app\admin\controller\exams;
  3. use app\common\controller\Backend;
  4. use think\Config;
  5. use think\Db;
  6. /**
  7. *
  8. *
  9. * @icon fa fa-circle-o
  10. */
  11. class Studies extends Backend
  12. {
  13. protected $noNeedLogin = ['reSync','serieslist'];
  14. protected $noNeedRight = ['serieslist','series'];
  15. /**
  16. * Studies模型对象
  17. * @var \app\admin\model\exams\Studies
  18. */
  19. protected $model = null;
  20. public function _initialize()
  21. {
  22. parent::_initialize();
  23. $this->model = new \app\admin\model\exams\Studies;
  24. }
  25. /**
  26. * 默认生成的控制器所继承的父类中有index/add/edit/del/multi五个基础方法、destroy/restore/recyclebin三个回收站方法
  27. * 因此在当前控制器中可不用编写增删改查的代码,除非需要自己控制这部分逻辑
  28. * 需要将application/admin/library/traits/Backend.php中对应的方法复制到当前控制器,然后进行修改
  29. */
  30. /**
  31. * 查看
  32. */
  33. public function index()
  34. {
  35. //设置过滤方法
  36. $this->request->filter(['strip_tags']);
  37. if ($this->request->isAjax()) {
  38. //如果发送的来源是Selectpage,则转发到Selectpage
  39. if ($this->request->request('keyField')) {
  40. return $this->selectpage();
  41. }
  42. list($where, $sort, $order, $offset, $limit) = $this->buildparams();
  43. // 过滤机构
  44. $childInsIds = $this->auth->getMyInsId();
  45. if($childInsIds == false){
  46. $more = false;
  47. } else {
  48. $more = ['s.institution_id' => ['in', $childInsIds]];
  49. }
  50. $ins = $this->request->get('institution_id','');
  51. if(empty($ins))
  52. {
  53. $ins_where = false;
  54. }else{
  55. $ins_where = 's.institution_id = '.$ins;
  56. }
  57. $sort == 'id' ? $sort = 's.id' : false ;
  58. $total = $this->model
  59. ->alias('s')
  60. ->join(['patient_infos'=>'p'],'p.id=s.patient_id','left')
  61. ->where($where)
  62. ->where($more)
  63. ->where($ins_where)
  64. ->order($sort, $order)
  65. ->count();
  66. $list = $this->model
  67. ->alias('s')
  68. ->join(['patient_infos'=>'p'],'p.id=s.patient_id','left')
  69. ->where($where)
  70. ->where($more)
  71. ->where($ins_where)
  72. ->field('s.*,p.temp_patient_id,p.name')
  73. ->order($sort, $order)
  74. ->limit($offset, $limit)
  75. ->select();
  76. $list = collection($list)->toArray();
  77. $result = array("total" => $total, "rows" => $list);
  78. return json($result);
  79. }
  80. return $this->view->fetch();
  81. }
  82. public function reSync($ids)
  83. {
  84. $parse = Config::get('parse_url');
  85. $url = $parse."/fix/study";
  86. $data = ['id'=>$ids];
  87. $info = $this->curl_post($url,$data);
  88. $return = json_decode($info,true);
  89. if($return['msg'] == 'Success')
  90. {
  91. $this->success('请求成功');
  92. // return json(['code'=>1,'msg'=>'请求成功']);
  93. // }else{
  94. // return json(['code'=>200,'msg'=>$return['Msg']]);
  95. }else{
  96. $this->error($return['Msg'] ?? '请求失败');
  97. }
  98. }
  99. public function curl_post($url, $data)
  100. {
  101. $ch = curl_init ();
  102. curl_setopt ( $ch, CURLOPT_URL, $url );
  103. curl_setopt ( $ch, CURLOPT_POST, 1 );
  104. curl_setopt ( $ch, CURLOPT_HEADER, 0 );
  105. curl_setopt ( $ch, CURLOPT_RETURNTRANSFER, 1 );
  106. curl_setopt ( $ch, CURLOPT_POSTFIELDS, $data );
  107. $return = curl_exec ( $ch );
  108. curl_close ( $ch );
  109. return $return;
  110. }
  111. public function curl_get($url)
  112. {
  113. // 初始化cURL会话
  114. $ch = curl_init();
  115. // 设置cURL选项
  116. curl_setopt($ch, CURLOPT_URL, $url); // 你要访问的URL
  117. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); // 将curl_exec()获取的信息以字符串返回,而不是直接输出
  118. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
  119. // 执行cURL会话
  120. $response = curl_exec($ch);
  121. // 检查是否有错误发生
  122. if(curl_errno($ch)){
  123. echo 'cURL error: ' . curl_error($ch);
  124. }
  125. // 关闭cURL会话
  126. curl_close($ch);
  127. // 打印响应内容
  128. return $response;
  129. }
  130. public function series($ids)
  131. {
  132. $this->view->assign("id", $ids);
  133. $ins = Db::table('studies')->where('id',$ids)->value('institution_id');
  134. $this->view->assign("ins", $ins);
  135. return $this->view->fetch();
  136. }
  137. public function seriesList()
  138. {
  139. set_time_limit(0);
  140. if ($this->request->isAjax())
  141. {
  142. $id = $this->request->param('study');
  143. $ins = $this->request->param('ins');
  144. $query = Config::get('query_url');
  145. $url = $query."/query/series?study_id=".$id;
  146. $data = $this->curl_get($url);
  147. $data = json_decode($data,true);
  148. $total = count($data);
  149. foreach ($data as $k=>$v)
  150. {
  151. $data[$k]['ins'] = $ins;
  152. }
  153. $result = array("total" => $total, "rows" => $data);
  154. return json($result);
  155. }
  156. return $this->view->fetch();
  157. }
  158. public function deleteSeries($id,$study,$ins)
  159. {
  160. $query = Config::get('query_url');
  161. $url = $query."/delete/serie?key=ZSKK_DELETE_SERIES&serie_id=$id&study_id=$study&institution_id=$ins";
  162. $data = $this->curl_get($url);
  163. $this->success('删除成功','','',1);
  164. }
  165. }