From 0f20d938ff032982e7065faeed63b65e62465fbd Mon Sep 17 00:00:00 2001 From: lanzu_qsy <334039090@qq.com> Date: Wed, 22 Jul 2020 14:23:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=BA=97=E9=93=BA=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/FileUpload.php | 55 ++++++++++++++++++++++ app/Controller/IndexController.php | 26 ++++++++++- app/Controller/StoreController.php | 73 ++++++++++++++++++++++++++++++ app/Controller/TestController.php | 23 ++++++++++ composer.json | 4 +- 5 files changed, 179 insertions(+), 2 deletions(-) create mode 100644 app/Controller/FileUpload.php create mode 100644 app/Controller/StoreController.php create mode 100644 app/Controller/TestController.php diff --git a/app/Controller/FileUpload.php b/app/Controller/FileUpload.php new file mode 100644 index 0000000..0f9f63a --- /dev/null +++ b/app/Controller/FileUpload.php @@ -0,0 +1,55 @@ +createBucket($bucket); + $result = $ossClient->putObject($bucket, $object, $content); + return $result; + } catch (OssException $e) { + printf(__FUNCTION__ . ": FAILED\n"); + printf($e->getMessage() . "\n"); + return false; + } + } +} \ No newline at end of file diff --git a/app/Controller/IndexController.php b/app/Controller/IndexController.php index 3864423..bceb474 100644 --- a/app/Controller/IndexController.php +++ b/app/Controller/IndexController.php @@ -11,6 +11,13 @@ declare(strict_types=1); */ namespace App\Controller; +use Hyperf\HttpServer\Annotation\AutoController; +use League\Flysystem\Filesystem; + +/** + * @AutoController() + * @package App\Controller + */ class IndexController extends AbstractController { public function index() @@ -20,7 +27,24 @@ class IndexController extends AbstractController return [ 'method' => $method, - 'message' => "Hello22222 {$user}.", + 'message' => floatval(2.00), ]; } + + public function example(Filesystem $filesystem) + { + + $file = $this->request->file('upload'); + + var_dump($file);die; + $fileContent = file_get_contents($file->getRealPath()); + var_dump($fileContent);die; + + + + + $stream = fopen($file->getRealPath(),'r+'); + $filesystem->writeStream('uplaods/'.$file->getClientFilename(),$stream); + fclose($stream); + } } diff --git a/app/Controller/StoreController.php b/app/Controller/StoreController.php new file mode 100644 index 0000000..ee8b657 --- /dev/null +++ b/app/Controller/StoreController.php @@ -0,0 +1,73 @@ +request->input('id'); + if (empty($id)){ + return $this->result(1,[],'id不能为空'); + } + $logo = $this->request->input('logo'); + $name = $this->request->input('name'); + $tel = $this->request->input('tel'); + $address = $this->request->input('address'); + $coordinates = $this->request->input('coordinates'); + $capita = $this->request->input('capita'); + $start_at = $this->request->input('start_at'); + $announcement = $this->request->input('announcement'); + $environment = $this->request->input('environment'); + + //>>1上传logo到阿里云oss + //>>2.上传商家环境到阿里云oss + //>>3.保存数据到数据库存 + $fileName = $object = 'public/upload/' . date('Y') . '/' . date('m-d') . '/' . rand(0,9999999999999999).'.jpg'; + $fileUpload = new FileUpload(); + $resLogo = $fileUpload->ossUpload($logo,$fileName); + if (isset($resLogo['info']['http_code'])&&$resLogo['info']['http_code']==200){ + $logo_url = $fileName; + }else{ + return $this->result(1,[]); + } + $res = Db::table('ims_cjdc_store')->where('id',$id)->update([ + 'logo'=>$logo_url??"", + 'name'=>$name, + 'tel'=>$tel, + 'address'=>$address, + 'coordinates'=>$coordinates, + 'capita'=>$capita, + 'start_at'=>$start_at, + 'announcement'=>$announcement, + 'environment'=>$environment, + ]); + return $this->success($res); + + + + + + + + + + + + + + + } +} \ No newline at end of file diff --git a/app/Controller/TestController.php b/app/Controller/TestController.php new file mode 100644 index 0000000..4551b9b --- /dev/null +++ b/app/Controller/TestController.php @@ -0,0 +1,23 @@ +input('id',2); + return (string)$id; + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 5d55e6c..2a3907c 100644 --- a/composer.json +++ b/composer.json @@ -26,7 +26,9 @@ "hyperf/process": "~2.0.0", "hyperf/redis": "~2.0.0", "hyperf/constants": "~2.0.0", - "hyperf/model-cache": "~2.0.0" + "hyperf/model-cache": "~2.0.0", + "hyperf/filesystem": "^2.0", + "xxtime/flysystem-aliyun-oss": "^1.5" }, "require-dev": { "swoole/ide-helper": "^4.5",