DoctorController.php 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182
  1. <?php
  2. namespace app\api\controller\doctors;
  3. use app\api\controller\ZskkDefaultController;
  4. use app\api\validate\doctor\DoctorValidate;
  5. use app\api\servies\doctor\DoctorService;
  6. use app\common\library\uploadToCloud;
  7. use think\Exception;
  8. //use app\api\validate\test\LoginValidate;
  9. class DoctorController extends ZskkDefaultController
  10. {
  11. protected $needToken = true;
  12. protected $logName = "DoctorController";
  13. /**
  14. * 获取用户信息
  15. * @author liuguiyan LoginService $service
  16. */
  17. public function info(DoctorService $service)
  18. {
  19. try{
  20. $user = $service->getToken($this->getToken());
  21. $user['autograph_url'] = $this->makeFileUrl($user['autograph'],$user['autograph_type']);
  22. $user['attachment_url'] = $this->makeFileUrl($user['attachment'],$user['attachment_type']);
  23. return $this->success($user);
  24. } catch (Exception $exception){
  25. $this->throwError('系统异常',0001);
  26. }
  27. }
  28. public function changePwd(DoctorService $service)
  29. {
  30. // try{
  31. $params = $this->getParams();
  32. DoctorValidate::checkPwd($params);
  33. $info = $service->changePwd($params,$this->getToken());
  34. return $this->success($info);
  35. // } catch (Exception $exception){
  36. // $this->throwError('系统异常',0001);
  37. // }
  38. }
  39. public function changeinfo(DoctorService $service)
  40. {
  41. try{
  42. $params = $this->getParams();
  43. DoctorValidate::check($params);
  44. $info = $service->changeInfo($params,$this->getToken());
  45. return $this->success($info);
  46. } catch (Exception $exception){
  47. $this->throwError('系统异常',0001);
  48. }
  49. }
  50. public function attachmentUpload()
  51. {
  52. try{
  53. // 获取表单上传文件 例如上传了001.jpg
  54. $file = request()->file('attachment');
  55. // 移动到框架应用根目录/public/uploads/ 目录下
  56. if($file) {
  57. $fildInfo = $file->getInfo();
  58. $name = $fildInfo['name'];
  59. $search = '/.php$/';
  60. if(preg_match($search,$name)) {
  61. // php文件批量不允许通过
  62. return '';
  63. }
  64. $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
  65. if ($info) {
  66. // $url = '/' . 'uploads' . '/' . $info->getSaveName();
  67. // return $this->success($url);
  68. $key = 'attachment/' . $info->getFilename();
  69. $source_file = './' . 'uploads' . '/' . $info->getSaveName();
  70. $upload = new uploadToCloud();;
  71. $s = $upload->upload($key,$source_file);
  72. if(($s['@metadata']['statusCode'] ?? '') == '200')
  73. {
  74. gc_collect_cycles();
  75. unset($info);
  76. unlink($source_file);
  77. $success = ['url'=>$key,'type'=>'2','tokenUrl'=>$upload->makeUrl($key)];
  78. return $this->success($success);
  79. }else{
  80. return '上传云失败';
  81. }
  82. } else {
  83. // 上传失败获取错误信息
  84. echo $file->getError();
  85. }
  86. }
  87. }catch(Exception $e){
  88. $this->throwError($e->getMessage(),0001);
  89. }
  90. }
  91. public function autographUpload()
  92. {
  93. try{
  94. // 获取表单上传文件 例如上传了001.jpg
  95. $file = request()->file('autograph');
  96. // 移动到框架应用根目录/public/uploads/ 目录下
  97. if($file) {
  98. $fildInfo = $file->getInfo();
  99. $name = $fildInfo['name'];
  100. $search = '/.php$/';
  101. if(preg_match($search,$name)) {
  102. // php文件批量不允许通过
  103. return '';
  104. }
  105. // $type = explode('/',$file->getInfo()['type'])[1];
  106. // $name = md5(time().rand(1,10000)).'.'.$type;
  107. // $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads',$name);
  108. $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
  109. if ($info) {
  110. // $url = '/' . 'uploads' . '/' . $info->getSaveName();
  111. // return $this->success($url);
  112. $key = 'autograph/' . $info->getFilename();
  113. $source_file = './' . 'uploads' . '/' . $info->getSaveName();
  114. $upload = new uploadToCloud();;
  115. $s = $upload->upload($key,$source_file);
  116. if(($s['@metadata']['statusCode'] ?? '') == '200')
  117. {
  118. gc_collect_cycles();
  119. unset($info);
  120. unlink($source_file);
  121. $success = ['url'=>$key,'type'=>'2','tokenUrl'=>$upload->makeUrl($key)];
  122. return $this->success($success);
  123. }else{
  124. return '上传云失败';
  125. }
  126. } else {
  127. // 上传失败获取错误信息
  128. echo $file->getError();
  129. }
  130. }
  131. }catch(Exception $e){
  132. $this->throwError($e->getMessage(),0001);
  133. }
  134. }
  135. public function getPower(DoctorService $service)
  136. {
  137. try{
  138. $user = $service->getToken($this->getToken());
  139. $id = $user['id'];
  140. $info = $service->getPower($id);
  141. return $this->success($info);
  142. }catch(Exception $e){
  143. $this->throwError($e->getMessage(),0001);
  144. }
  145. }
  146. public function getLoginCode(DoctorService $service)
  147. {
  148. $token = $this->getToken();
  149. $info = $service->getLoginCode($token);
  150. return $this->success($info);
  151. }
  152. public function doctorList(DoctorService $service)
  153. {
  154. $token = $this->getToken();
  155. $user = $this->getCache($token);
  156. $info = $service->doctorList($user['institution_id']);
  157. return $this->success($info);
  158. }
  159. public function downData()
  160. {
  161. $params = $this->getParams();
  162. $upload = new uploadToCloud();
  163. $s = $upload->makeUrl($params['path'] ?? '');
  164. if(empty($s))
  165. {
  166. $this->throwError('下载获取失败,请联系管理员','0303');
  167. }
  168. return $this->success($s);
  169. }
  170. }