123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416 |
- <?php
- namespace app\api\controller\apply;
- use app\api\controller\ZskkDefaultController;
- use app\api\validate\application\ApplicationValidate;
- use app\api\servies\application\ApplicationService;
- use app\common\library\uploadToCloud;
- use think\Exception;
- use think\facade\Config;
- class ApplyController extends ZskkDefaultController
- {
- protected $needToken = true;
- protected $logName = "ApplicationController";
- /**
- * @author liuguiyan
- * 获取知情同意书
- */
- public function protocol(ApplicationService $service)
- {
- // try{
- $params = $this->getParams();
- // ApplicationValidate::check($params);
- $token = $this->getToken();
- $user = $service->getUser($token);
- $service->checkApplyRole($user);
- $info = $service->get_patient_template($params,$user['institution_id']);
- return $this->success($info);
- // } catch (\Exception $exception){
- // $this->throwError($exception->getMessage(),0001);
- // }
- }
- /*
- * 获取申请单id
- */
- public function getRemoteStatus(ApplicationService $service)
- {
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $info = $service->getRemote($params['id']);
- return $this->success($info);
- }
-
- /**
- * 同意知情同意书
- */
- public function step1(ApplicationService $service)
- {
- try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $info = $service->get_step1_data($params,$this->getToken());
- return $this->success($info);
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- /**
- * 暂时保存
- */
- public function stage(ApplicationService $service)
- {
- try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $param = $service->handle_save($params);
- $return = $service->save_application($param,Config::get('remote_status')['step2']);
- return $this->success($return);
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- /**
- * 上传附件
- */
- public function upload(){
- try{
- // 获取表单上传文件 例如上传了001.jpg
- $file = request()->file('file');
- // 移动到框架应用根目录/public/uploads/ 目录下
- if($file){
- $fildInfo = $file->getInfo();
- $name = $fildInfo['name'];
- $search = '/.php$/';
- if(preg_match($search,$name)) {
- // php文件批量不允许通过
- return '';
- }
- $upload = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
- if($upload){
- return $this->success('/'.$_SERVER["SERVER_NAME"]. '/' . 'uploads'. '/' .$upload->getSaveName());
- }else{
- // 上传失败获取错误信息
- $this->throwError($file->getError(),0011);
- }
- }
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- /**
- * 保存继续
- */
- public function step2(ApplicationService $service)
- {
- // try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $param = $service->handle_save($params);
- $return = $service->save_application($param,Config::get('remote_status')['step3']);
- return $this->success($return);
- // }catch(\Exception $e){
- // $this->throwError($e->getMessage(),0001);
- // }
- }
- /**
- * 发起申请
- */
- public function step3(ApplicationService $service)
- {
- // try{
- $params = $this->getParams();
- ApplicationValidate::checkStep3($params);
- $doctor = $service->getUser($this->getToken());
- $odd_number = $service->getNum();
- $update = $service->application_start($params,$doctor,$odd_number);
- return $this->success($update);
- // }catch(\Exception $e){
- // $this->throwError($e->getMessage(),0001);
- // }
- }
- /**
- * 同意接收申请
- */
- public function agree(ApplicationService $service)
- {
- try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $doctor = $service->getUser($this->getToken());
- $service->checkRole($params['id'],$doctor,'非受邀医生无法接收申请单');
- $service->checkStatus($params['id'],Config::get('remote_status')['step4'],'操作失败,只允许接收发起状态的申请单');
- // 修改状态为同意申请
- $service->updateStatus($params['id'],Config::get('remote_status')['step6'],3,$doctor);
- $service->save_progress($params['id'],$doctor,'接收了申请',2);
- $field = ['local_institution_id','req_doctor_id'];
- $service->insertMessage($params['id'],$doctor,'接受了您的远程申请',$field);
- return $this->success('ok');
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- /**
- * 驳回申请单
- */
- public function reject(ApplicationService $service)
- {
- $params = $this->getParams();
- ApplicationValidate::checkReject($params);
- $doctor = $service->getUser($this->getToken());
- $service->checkRole($params['id'],$doctor,'非受邀医生无法驳回申请单');
- $service->checkStatus($params['id'],Config::get('remote_status')['step4'],'操作失败,只允许驳回发起状态的申请单');
- // 修改状态为驳回申请
- $service->updateStatus($params['id'],Config::get('remote_status')['step5'],5,$doctor);
- $service->sendSms2RejectApply($params['id'],$params['description']);
- $service->save_progress($params['id'],$doctor,'驳回了申请,驳回原因'.$params['description'],3);
- $field = ['local_institution_id','req_doctor_id'];
- $service->insertMessage($params['id'],$doctor,'驳回了您的远程申请,驳回原因'.$params['description'],$field);
- return $this->success('ok');
- }
- /**
- * 取消订单
- */
- public function cancelOrder(ApplicationService $service)
- {
- $params = $this->getParams();
- ApplicationValidate::checkCancel($params);
- $doctor = $service->getUser($this->getToken());
- $service->checkApplyRole($doctor);
- $info = $service->cancelOrder($params['order_id'],$doctor);
- return $this->success($info);
- }
- /**
- * 完成申请单
- */
- public function complete(ApplicationService $service)
- {
- // try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $service->checkStatus($params['id'],Config::get('remote_status')['step8'],'操作失败,只允许完成审核状态的申请单');
- $doctor = $service->getUser($this->getToken());
- // 修改状态为完成申请
- $service->updateStatus($params['id'],Config::get('remote_status')['step10'],9,$doctor);
- $service->sendSms2CompleteReport($params['id'],$doctor);
- $service->save_progress($params['id'],$doctor,'完成了远程申请',5);
- $field = ['local_institution_id','req_doctor_id'];
- $service->insertMessage($params['id'],$doctor,'完成了您的远程申请',$field);
- return $this->success('ok');
- // }catch(\Exception $e){
- // $this->throwError($e->getMessage(),0001);
- // }
- }
- /**
- * 撤回申请单
- */
- public function recall(ApplicationService $service)
- {
- try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $service->checkStatus($params['id'],Config::get('remote_status')['step4'],'操作失败,只允许撤回发起状态的申请单');
- $doctor = $service->getUser($this->getToken());
- // 修改状态为撤回申请
- $service->updateStatus($params['id'],Config::get('remote_status')['step11'],4,$doctor);
- $service->save_progress($params['id'],$doctor,'撤回了远程申请',4);
- $field = ['remote_institution_id','remote_doctor_id'];
- $service->insertMessage($params['id'],$doctor,'撤回了远程申请',$field);
- return $this->success('ok');
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- /**
- * 申请单详情
- */
- public function details(ApplicationService $service)
- {
- try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $info = $service->get_detail($params['id']);
- return $this->success($info);
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- public function applyDetails(ApplicationService $service)
- {
- try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $info = $service->get_applyDetail($params['id']);
- return $this->success($info);
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- /**
- * 诊断详情
- */
- public function report(ApplicationService $service)
- {
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $info = $service->getReportInfo($params);
- return $this->success($info);
- }
- public function progress(ApplicationService $service)
- {
- try{
- $params = $this->getParams();
- ApplicationValidate::checkId($params);
- $user = $service->getuser($this->getToken());
- $info = $service->getDialog($params['id'],$user);
- return $this->success($info);
- }catch(\Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- /**
- * 发起对话
- */
- public function bbs(ApplicationService $service)
- {
- $params = $this->getParams();
- ApplicationValidate::checkBbs($params);
- $doctor = $service->getUser($this->getToken());
- $attachment = isset($params['attachment']) ? $params['attachment'] : null;
- $content = isset($params['content']) ? $params['content'] : null;
- if($attachment == null && $content == null){
- $this->throwError('缺少必要参数,请填写对话内容或附件信息',0001);
- }
- // 保存bbs信息
- $info = $service->save_bbs($doctor['id'],$params['is_remote'],$params['id'],$content,$attachment,$params['attachment_type'] ?? 1);
- // 添加message消息
- $service->save_bbs_message($params['id'],$doctor['id'],$content,$info['reply'],$params['is_remote']);
- return $this->success($info);
- }
- /**
- * 对话上传附件
- */
- public function bbsUpload()
- {
- try{
- // 获取表单上传文件 例如上传了001.jpg
- $file = request()->file('file');
- // 移动到框架应用根目录/public/uploads/ 目录下
- if($file) {
- $fildInfo = $file->getInfo();
- $name = $fildInfo['name'];
- $search = '/.php$/';
- if(preg_match($search,$name)) {
- // php文件批量不允许通过
- return '';
- }
- $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
- if ($info) {
- $type = Config::get('upload');
- if($type == 1)
- {
- $url = '/' . 'uploads' . '/' . $info->getSaveName();
- $success = ['url'=>$url,'type'=>$type,'tokenUrl'=>$url];
- return $this->success($success);
- }
- $key = 'bbs/' . $info->getFilename();
- $source_file = './' . 'uploads' . '/' . $info->getSaveName();
- $upload = new uploadToCloud();;
- $s = $upload->upload($key,$source_file);
- if(($s['@metadata']['statusCode'] ?? '') == '200')
- {
- gc_collect_cycles();
- unset($info);
- unlink($source_file);
- $success = ['url'=>$key,'type'=>'2','tokenUrl'=>$upload->makeUrl($key)];
- return $this->success($success);
- }else{
- return '上传云失败';
- }
- } else {
- // 上传失败获取错误信息
- echo $file->getError();
- }
- }else{
- $this->throwError('没有找到上传的文件','3010');
- }
- }catch(Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- /**
- * 申请上传附件
- */
- public function applyUpload()
- {
- try{
- // 获取表单上传文件 例如上传了001.jpg
- $file = request()->file('apply');
- // 移动到框架应用根目录/public/uploads/ 目录下
- if($file) {
- $fildInfo = $file->getInfo();
- $name = $fildInfo['name'];
- $search = '/.php$/';
- if(preg_match($search,$name)) {
- // php文件批量不允许通过
- return '';
- }
- $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
- if ($info) {
- $type = Config::get('upload');
- if($type == 1)
- {
- $url = '/' . 'uploads' . '/' . $info->getSaveName();
- $success = ['url'=>$url,'type'=>$type,'tokenUrl'=>$url];
- return $this->success($success);
- }
- $key = 'remote/' . $info->getFilename();
- $source_file = './' . 'uploads' . '/' . $info->getSaveName();
- $upload = new uploadToCloud();;
- $s = $upload->upload($key,$source_file);
- if(($s['@metadata']['statusCode'] ?? '') == '200')
- {
- gc_collect_cycles();
- unset($info);
- unlink($source_file);
- $success = ['url'=>$key,'type'=>'2','tokenUrl'=>$upload->makeUrl($key)];
- return $this->success($success);
- }else{
- return '上传云失败';
- }
- } else {
- // 上传失败获取错误信息
- echo $file->getError();
- }
- }else{
- $this->throwError('没有找到上传的文件','3010');
- }
- }catch(Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- }
|