From 28b0f413f5763b68e2f3bb991bbcbd584963f70e Mon Sep 17 00:00:00 2001 From: lanzu_qsy <334039090@qq.com> Date: Wed, 22 Jul 2020 16:34:07 +0800 Subject: [PATCH] =?UTF-8?q?=E9=87=8D=E5=86=99=E5=B0=8F=E7=A8=8B=E5=BA=8F?= =?UTF-8?q?=E8=8E=B7=E5=8F=96=E9=97=A8=E5=BA=97=E4=BF=A1=E6=81=AF=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/FileUpload.php | 12 ++-- app/Controller/IndexController.php | 1 - app/Controller/StoreController.php | 105 ++++++++++++++++------------- 3 files changed, 63 insertions(+), 55 deletions(-) diff --git a/app/Controller/FileUpload.php b/app/Controller/FileUpload.php index 0f9f63a..385a02f 100644 --- a/app/Controller/FileUpload.php +++ b/app/Controller/FileUpload.php @@ -15,21 +15,17 @@ class FileUpload extends AbstractController public function __construct() { - - } - - - public function ossUpload($fileContent,$fileName) - { - if (is_file(__DIR__ . '/../autoload.php')) { require_once __DIR__ . '/../autoload.php'; } if (is_file(__DIR__ . '/../vendor/autoload.php')) { require_once __DIR__ . '/../vendor/autoload.php'; } + } + - //$base64 = input('upload'); + public function ossUpload($fileContent,$fileName) + { $img = base64_decode($fileContent); $accessKeyId = "LTAI4G8QMM97Fg1Gx8TXeast"; $accessKeySecret = "f1KIbMCiO4CXmTzC0FDl6hTRXgFobm"; diff --git a/app/Controller/IndexController.php b/app/Controller/IndexController.php index bceb474..417e4d4 100644 --- a/app/Controller/IndexController.php +++ b/app/Controller/IndexController.php @@ -33,7 +33,6 @@ class IndexController extends AbstractController public function example(Filesystem $filesystem) { - $file = $this->request->file('upload'); var_dump($file);die; diff --git a/app/Controller/StoreController.php b/app/Controller/StoreController.php index ee8b657..30ffa47 100644 --- a/app/Controller/StoreController.php +++ b/app/Controller/StoreController.php @@ -17,55 +17,68 @@ class StoreController extends BaseController { public function infoEdit() { - $id = $this->request->input('id'); - if (empty($id)){ - return $this->result(1,[],'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,[]); + if ($this->request->isMethod('post')) { + $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.保存数据到数据库存 + $fileNameLogo = $object = 'public/upload/' . date('Y') . '/' . date('m-d') . '/' . rand(0, 9999999999999999) . '.jpg'; + $fileUpload = new FileUpload(); + $resLogo = $fileUpload->ossUpload($logo, $fileNameLogo); + if (isset($resLogo['info']['http_code']) && $resLogo['info']['http_code'] == 200) { + $logo_url = $fileNameLogo; + } else { + return $this->result(1, []); + } + $environments = explode(',', $environment); + $envPaths = []; + foreach ($environments as $env) { + $fileNameEnv = $object = 'public/upload/' . date('Y') . '/' . date('m-d') . '/' . rand(0, 9999999999999999) . '.jpg'; + $resEnv = $fileUpload->ossUpload($env, $fileNameEnv); + if (isset($resEnv['info']['http_code']) && $resLogo['info']['http_code'] == 200) { + $envPaths[] = $fileNameEnv; + } + } + if (count($envPaths)) { + $envPath = implode(',', $envPaths); + } + + $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' => $envPath ?? "", + ]); + return $this->success($res); } - $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); - - - - - - - - - - - +//'id','name','logo','tel','address','coordinates','capita','start_at','announcement','environment' + //获取店铺信息 + $data = Db::table('ims_cjdc_store') + ->select(['id','name','logo','tel','address','coordinates','capita','start_at','announcement','environment']) + ->where('id',$id) + ->first(); + if ($data){ + $data->site = env('SITE_HOST'); + } + return $this->success($data);