123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182 |
- <?php
- namespace app\api\controller\doctors;
- use app\api\controller\ZskkDefaultController;
- use app\api\validate\doctor\DoctorValidate;
- use app\api\servies\doctor\DoctorService;
- use app\common\library\uploadToCloud;
- use think\Exception;
- //use app\api\validate\test\LoginValidate;
- class DoctorController extends ZskkDefaultController
- {
- protected $needToken = true;
- protected $logName = "DoctorController";
- /**
- * 获取用户信息
- * @author liuguiyan LoginService $service
- */
- public function info(DoctorService $service)
- {
- try{
- $user = $service->getToken($this->getToken());
- $user['autograph_url'] = $this->makeFileUrl($user['autograph'],$user['autograph_type']);
- $user['attachment_url'] = $this->makeFileUrl($user['attachment'],$user['attachment_type']);
- return $this->success($user);
- } catch (Exception $exception){
- $this->throwError('系统异常',0001);
- }
- }
- public function changePwd(DoctorService $service)
- {
- // try{
- $params = $this->getParams();
- DoctorValidate::checkPwd($params);
- $info = $service->changePwd($params,$this->getToken());
- return $this->success($info);
- // } catch (Exception $exception){
- // $this->throwError('系统异常',0001);
- // }
- }
- public function changeinfo(DoctorService $service)
- {
- try{
- $params = $this->getParams();
- DoctorValidate::check($params);
- $info = $service->changeInfo($params,$this->getToken());
- return $this->success($info);
- } catch (Exception $exception){
- $this->throwError('系统异常',0001);
- }
- }
- public function attachmentUpload()
- {
- try{
- // 获取表单上传文件 例如上传了001.jpg
- $file = request()->file('attachment');
- // 移动到框架应用根目录/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) {
- // $url = '/' . 'uploads' . '/' . $info->getSaveName();
- // return $this->success($url);
- $key = 'attachment/' . $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();
- }
- }
- }catch(Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- public function autographUpload()
- {
- try{
- // 获取表单上传文件 例如上传了001.jpg
- $file = request()->file('autograph');
- // 移动到框架应用根目录/public/uploads/ 目录下
- if($file) {
- $fildInfo = $file->getInfo();
- $name = $fildInfo['name'];
- $search = '/.php$/';
- if(preg_match($search,$name)) {
- // php文件批量不允许通过
- return '';
- }
- // $type = explode('/',$file->getInfo()['type'])[1];
- // $name = md5(time().rand(1,10000)).'.'.$type;
- // $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads',$name);
- $info = $file->move(ROOT_PATH . 'public' . DS . 'uploads');
- if ($info) {
- // $url = '/' . 'uploads' . '/' . $info->getSaveName();
- // return $this->success($url);
- $key = 'autograph/' . $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();
- }
- }
- }catch(Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- public function getPower(DoctorService $service)
- {
- try{
- $user = $service->getToken($this->getToken());
- $id = $user['id'];
- $info = $service->getPower($id);
- return $this->success($info);
- }catch(Exception $e){
- $this->throwError($e->getMessage(),0001);
- }
- }
- public function getLoginCode(DoctorService $service)
- {
- $token = $this->getToken();
- $info = $service->getLoginCode($token);
- return $this->success($info);
- }
- public function doctorList(DoctorService $service)
- {
- $token = $this->getToken();
- $user = $this->getCache($token);
- $info = $service->doctorList($user['institution_id']);
- return $this->success($info);
- }
- public function downData()
- {
- $params = $this->getParams();
- $upload = new uploadToCloud();
- $s = $upload->makeUrl($params['path'] ?? '');
- if(empty($s))
- {
- $this->throwError('下载获取失败,请联系管理员','0303');
- }
- return $this->success($s);
- }
- }
|