ApplyController.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416
  1. <?php
  2. namespace app\api\controller\apply;
  3. use app\api\controller\ZskkDefaultController;
  4. use app\api\validate\application\ApplicationValidate;
  5. use app\api\servies\application\ApplicationService;
  6. use app\common\library\uploadToCloud;
  7. use think\Exception;
  8. use think\facade\Config;
  9. class ApplyController extends ZskkDefaultController
  10. {
  11. protected $needToken = true;
  12. protected $logName = "ApplicationController";
  13. /**
  14. * @author liuguiyan
  15. * 获取知情同意书
  16. */
  17. public function protocol(ApplicationService $service)
  18. {
  19. // try{
  20. $params = $this->getParams();
  21. // ApplicationValidate::check($params);
  22. $token = $this->getToken();
  23. $user = $service->getUser($token);
  24. $service->checkApplyRole($user);
  25. $info = $service->get_patient_template($params,$user['institution_id']);
  26. return $this->success($info);
  27. // } catch (\Exception $exception){
  28. // $this->throwError($exception->getMessage(),0001);
  29. // }
  30. }
  31. /*
  32. * 获取申请单id
  33. */
  34. public function getRemoteStatus(ApplicationService $service)
  35. {
  36. $params = $this->getParams();
  37. ApplicationValidate::checkId($params);
  38. $info = $service->getRemote($params['id']);
  39. return $this->success($info);
  40. }
  41. /**
  42. * 同意知情同意书
  43. */
  44. public function step1(ApplicationService $service)
  45. {
  46. try{
  47. $params = $this->getParams();
  48. ApplicationValidate::checkId($params);
  49. $info = $service->get_step1_data($params,$this->getToken());
  50. return $this->success($info);
  51. }catch(\Exception $e){
  52. $this->throwError($e->getMessage(),0001);
  53. }
  54. }
  55. /**
  56. * 暂时保存
  57. */
  58. public function stage(ApplicationService $service)
  59. {
  60. try{
  61. $params = $this->getParams();
  62. ApplicationValidate::checkId($params);
  63. $param = $service->handle_save($params);
  64. $return = $service->save_application($param,Config::get('remote_status')['step2']);
  65. return $this->success($return);
  66. }catch(\Exception $e){
  67. $this->throwError($e->getMessage(),0001);
  68. }
  69. }
  70. /**
  71. * 上传附件
  72. */
  73. public function upload(){
  74. try{
  75. // 获取表单上传文件 例如上传了001.jpg
  76. $file = request()->file('file');
  77. // 移动到框架应用根目录/public/uploads/ 目录下
  78. if($file){
  79. $fildInfo = $file->getInfo();
  80. $name = $fildInfo['name'];
  81. $search = '/.php$/';
  82. if(preg_match($search,$name)) {
  83. // php文件批量不允许通过
  84. return '';
  85. }
  86. $upload = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
  87. if($upload){
  88. return $this->success('/'.$_SERVER["SERVER_NAME"]. '/' . 'uploads'. '/' .$upload->getSaveName());
  89. }else{
  90. // 上传失败获取错误信息
  91. $this->throwError($file->getError(),0011);
  92. }
  93. }
  94. }catch(\Exception $e){
  95. $this->throwError($e->getMessage(),0001);
  96. }
  97. }
  98. /**
  99. * 保存继续
  100. */
  101. public function step2(ApplicationService $service)
  102. {
  103. // try{
  104. $params = $this->getParams();
  105. ApplicationValidate::checkId($params);
  106. $param = $service->handle_save($params);
  107. $return = $service->save_application($param,Config::get('remote_status')['step3']);
  108. return $this->success($return);
  109. // }catch(\Exception $e){
  110. // $this->throwError($e->getMessage(),0001);
  111. // }
  112. }
  113. /**
  114. * 发起申请
  115. */
  116. public function step3(ApplicationService $service)
  117. {
  118. // try{
  119. $params = $this->getParams();
  120. ApplicationValidate::checkStep3($params);
  121. $doctor = $service->getUser($this->getToken());
  122. $odd_number = $service->getNum();
  123. $update = $service->application_start($params,$doctor,$odd_number);
  124. return $this->success($update);
  125. // }catch(\Exception $e){
  126. // $this->throwError($e->getMessage(),0001);
  127. // }
  128. }
  129. /**
  130. * 同意接收申请
  131. */
  132. public function agree(ApplicationService $service)
  133. {
  134. try{
  135. $params = $this->getParams();
  136. ApplicationValidate::checkId($params);
  137. $doctor = $service->getUser($this->getToken());
  138. $service->checkRole($params['id'],$doctor,'非受邀医生无法接收申请单');
  139. $service->checkStatus($params['id'],Config::get('remote_status')['step4'],'操作失败,只允许接收发起状态的申请单');
  140. // 修改状态为同意申请
  141. $service->updateStatus($params['id'],Config::get('remote_status')['step6'],3,$doctor);
  142. $service->save_progress($params['id'],$doctor,'接收了申请',2);
  143. $field = ['local_institution_id','req_doctor_id'];
  144. $service->insertMessage($params['id'],$doctor,'接受了您的远程申请',$field);
  145. return $this->success('ok');
  146. }catch(\Exception $e){
  147. $this->throwError($e->getMessage(),0001);
  148. }
  149. }
  150. /**
  151. * 驳回申请单
  152. */
  153. public function reject(ApplicationService $service)
  154. {
  155. $params = $this->getParams();
  156. ApplicationValidate::checkReject($params);
  157. $doctor = $service->getUser($this->getToken());
  158. $service->checkRole($params['id'],$doctor,'非受邀医生无法驳回申请单');
  159. $service->checkStatus($params['id'],Config::get('remote_status')['step4'],'操作失败,只允许驳回发起状态的申请单');
  160. // 修改状态为驳回申请
  161. $service->updateStatus($params['id'],Config::get('remote_status')['step5'],5,$doctor);
  162. $service->sendSms2RejectApply($params['id'],$params['description']);
  163. $service->save_progress($params['id'],$doctor,'驳回了申请,驳回原因'.$params['description'],3);
  164. $field = ['local_institution_id','req_doctor_id'];
  165. $service->insertMessage($params['id'],$doctor,'驳回了您的远程申请,驳回原因'.$params['description'],$field);
  166. return $this->success('ok');
  167. }
  168. /**
  169. * 取消订单
  170. */
  171. public function cancelOrder(ApplicationService $service)
  172. {
  173. $params = $this->getParams();
  174. ApplicationValidate::checkCancel($params);
  175. $doctor = $service->getUser($this->getToken());
  176. $service->checkApplyRole($doctor);
  177. $info = $service->cancelOrder($params['order_id'],$doctor);
  178. return $this->success($info);
  179. }
  180. /**
  181. * 完成申请单
  182. */
  183. public function complete(ApplicationService $service)
  184. {
  185. // try{
  186. $params = $this->getParams();
  187. ApplicationValidate::checkId($params);
  188. $service->checkStatus($params['id'],Config::get('remote_status')['step8'],'操作失败,只允许完成审核状态的申请单');
  189. $doctor = $service->getUser($this->getToken());
  190. // 修改状态为完成申请
  191. $service->updateStatus($params['id'],Config::get('remote_status')['step10'],9,$doctor);
  192. $service->sendSms2CompleteReport($params['id'],$doctor);
  193. $service->save_progress($params['id'],$doctor,'完成了远程申请',5);
  194. $field = ['local_institution_id','req_doctor_id'];
  195. $service->insertMessage($params['id'],$doctor,'完成了您的远程申请',$field);
  196. return $this->success('ok');
  197. // }catch(\Exception $e){
  198. // $this->throwError($e->getMessage(),0001);
  199. // }
  200. }
  201. /**
  202. * 撤回申请单
  203. */
  204. public function recall(ApplicationService $service)
  205. {
  206. try{
  207. $params = $this->getParams();
  208. ApplicationValidate::checkId($params);
  209. $service->checkStatus($params['id'],Config::get('remote_status')['step4'],'操作失败,只允许撤回发起状态的申请单');
  210. $doctor = $service->getUser($this->getToken());
  211. // 修改状态为撤回申请
  212. $service->updateStatus($params['id'],Config::get('remote_status')['step11'],4,$doctor);
  213. $service->save_progress($params['id'],$doctor,'撤回了远程申请',4);
  214. $field = ['remote_institution_id','remote_doctor_id'];
  215. $service->insertMessage($params['id'],$doctor,'撤回了远程申请',$field);
  216. return $this->success('ok');
  217. }catch(\Exception $e){
  218. $this->throwError($e->getMessage(),0001);
  219. }
  220. }
  221. /**
  222. * 申请单详情
  223. */
  224. public function details(ApplicationService $service)
  225. {
  226. try{
  227. $params = $this->getParams();
  228. ApplicationValidate::checkId($params);
  229. $info = $service->get_detail($params['id']);
  230. return $this->success($info);
  231. }catch(\Exception $e){
  232. $this->throwError($e->getMessage(),0001);
  233. }
  234. }
  235. public function applyDetails(ApplicationService $service)
  236. {
  237. try{
  238. $params = $this->getParams();
  239. ApplicationValidate::checkId($params);
  240. $info = $service->get_applyDetail($params['id']);
  241. return $this->success($info);
  242. }catch(\Exception $e){
  243. $this->throwError($e->getMessage(),0001);
  244. }
  245. }
  246. /**
  247. * 诊断详情
  248. */
  249. public function report(ApplicationService $service)
  250. {
  251. $params = $this->getParams();
  252. ApplicationValidate::checkId($params);
  253. $info = $service->getReportInfo($params);
  254. return $this->success($info);
  255. }
  256. public function progress(ApplicationService $service)
  257. {
  258. try{
  259. $params = $this->getParams();
  260. ApplicationValidate::checkId($params);
  261. $user = $service->getuser($this->getToken());
  262. $info = $service->getDialog($params['id'],$user);
  263. return $this->success($info);
  264. }catch(\Exception $e){
  265. $this->throwError($e->getMessage(),0001);
  266. }
  267. }
  268. /**
  269. * 发起对话
  270. */
  271. public function bbs(ApplicationService $service)
  272. {
  273. $params = $this->getParams();
  274. ApplicationValidate::checkBbs($params);
  275. $doctor = $service->getUser($this->getToken());
  276. $attachment = isset($params['attachment']) ? $params['attachment'] : null;
  277. $content = isset($params['content']) ? $params['content'] : null;
  278. if($attachment == null && $content == null){
  279. $this->throwError('缺少必要参数,请填写对话内容或附件信息',0001);
  280. }
  281. // 保存bbs信息
  282. $info = $service->save_bbs($doctor['id'],$params['is_remote'],$params['id'],$content,$attachment,$params['attachment_type'] ?? 1);
  283. // 添加message消息
  284. $service->save_bbs_message($params['id'],$doctor['id'],$content,$info['reply'],$params['is_remote']);
  285. return $this->success($info);
  286. }
  287. /**
  288. * 对话上传附件
  289. */
  290. public function bbsUpload()
  291. {
  292. try{
  293. // 获取表单上传文件 例如上传了001.jpg
  294. $file = request()->file('file');
  295. // 移动到框架应用根目录/public/uploads/ 目录下
  296. if($file) {
  297. $fildInfo = $file->getInfo();
  298. $name = $fildInfo['name'];
  299. $search = '/.php$/';
  300. if(preg_match($search,$name)) {
  301. // php文件批量不允许通过
  302. return '';
  303. }
  304. $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
  305. if ($info) {
  306. $type = Config::get('upload');
  307. if($type == 1)
  308. {
  309. $url = '/' . 'uploads' . '/' . $info->getSaveName();
  310. $success = ['url'=>$url,'type'=>$type,'tokenUrl'=>$url];
  311. return $this->success($success);
  312. }
  313. $key = 'bbs/' . $info->getFilename();
  314. $source_file = './' . 'uploads' . '/' . $info->getSaveName();
  315. $upload = new uploadToCloud();;
  316. $s = $upload->upload($key,$source_file);
  317. if(($s['@metadata']['statusCode'] ?? '') == '200')
  318. {
  319. gc_collect_cycles();
  320. unset($info);
  321. unlink($source_file);
  322. $success = ['url'=>$key,'type'=>'2','tokenUrl'=>$upload->makeUrl($key)];
  323. return $this->success($success);
  324. }else{
  325. return '上传云失败';
  326. }
  327. } else {
  328. // 上传失败获取错误信息
  329. echo $file->getError();
  330. }
  331. }else{
  332. $this->throwError('没有找到上传的文件','3010');
  333. }
  334. }catch(Exception $e){
  335. $this->throwError($e->getMessage(),0001);
  336. }
  337. }
  338. /**
  339. * 申请上传附件
  340. */
  341. public function applyUpload()
  342. {
  343. try{
  344. // 获取表单上传文件 例如上传了001.jpg
  345. $file = request()->file('apply');
  346. // 移动到框架应用根目录/public/uploads/ 目录下
  347. if($file) {
  348. $fildInfo = $file->getInfo();
  349. $name = $fildInfo['name'];
  350. $search = '/.php$/';
  351. if(preg_match($search,$name)) {
  352. // php文件批量不允许通过
  353. return '';
  354. }
  355. $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
  356. if ($info) {
  357. $type = Config::get('upload');
  358. if($type == 1)
  359. {
  360. $url = '/' . 'uploads' . '/' . $info->getSaveName();
  361. $success = ['url'=>$url,'type'=>$type,'tokenUrl'=>$url];
  362. return $this->success($success);
  363. }
  364. $key = 'remote/' . $info->getFilename();
  365. $source_file = './' . 'uploads' . '/' . $info->getSaveName();
  366. $upload = new uploadToCloud();;
  367. $s = $upload->upload($key,$source_file);
  368. if(($s['@metadata']['statusCode'] ?? '') == '200')
  369. {
  370. gc_collect_cycles();
  371. unset($info);
  372. unlink($source_file);
  373. $success = ['url'=>$key,'type'=>'2','tokenUrl'=>$upload->makeUrl($key)];
  374. return $this->success($success);
  375. }else{
  376. return '上传云失败';
  377. }
  378. } else {
  379. // 上传失败获取错误信息
  380. echo $file->getError();
  381. }
  382. }else{
  383. $this->throwError('没有找到上传的文件','3010');
  384. }
  385. }catch(Exception $e){
  386. $this->throwError($e->getMessage(),0001);
  387. }
  388. }
  389. }