5 changed files with 179 additions and 2 deletions
-
55app/Controller/FileUpload.php
-
26app/Controller/IndexController.php
-
73app/Controller/StoreController.php
-
23app/Controller/TestController.php
-
4composer.json
@ -0,0 +1,55 @@ |
|||||
|
<?php |
||||
|
|
||||
|
|
||||
|
namespace App\Controller; |
||||
|
|
||||
|
|
||||
|
use OSS\Core\OssException; |
||||
|
use OSS\OssClient; |
||||
|
|
||||
|
class FileUpload extends AbstractController |
||||
|
{ |
||||
|
private $file; |
||||
|
private $path; |
||||
|
private $type; |
||||
|
|
||||
|
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');
|
||||
|
$img = base64_decode($fileContent); |
||||
|
$accessKeyId = "LTAI4G8QMM97Fg1Gx8TXeast"; |
||||
|
$accessKeySecret = "f1KIbMCiO4CXmTzC0FDl6hTRXgFobm"; |
||||
|
// Endpoint以杭州为例,其它Region请按实际情况填写。
|
||||
|
$endpoint = "http://oss-cn-shenzhen.aliyuncs.com"; |
||||
|
// 设置存储空间名称。
|
||||
|
$bucket = "desion-test1"; |
||||
|
// 设置文件名称。
|
||||
|
$object = $fileName; |
||||
|
// 配置文件内容。
|
||||
|
$content = $img; |
||||
|
try { |
||||
|
$ossClient = new OssClient($accessKeyId, $accessKeySecret, $endpoint); |
||||
|
$ossClient->createBucket($bucket); |
||||
|
$result = $ossClient->putObject($bucket, $object, $content); |
||||
|
return $result; |
||||
|
} catch (OssException $e) { |
||||
|
printf(__FUNCTION__ . ": FAILED\n"); |
||||
|
printf($e->getMessage() . "\n"); |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,73 @@ |
|||||
|
<?php |
||||
|
declare(strict_types=1); |
||||
|
|
||||
|
namespace App\Controller; |
||||
|
|
||||
|
use Hyperf\DbConnection\Db; |
||||
|
use Hyperf\HttpServer\Annotation\AutoController; |
||||
|
use OSS\Core\OssException; |
||||
|
use OSS\OssClient; |
||||
|
|
||||
|
/** |
||||
|
* @AutoController() |
||||
|
* Class StoreController |
||||
|
* @package App\Controller |
||||
|
*/ |
||||
|
class StoreController extends BaseController |
||||
|
{ |
||||
|
public function infoEdit() |
||||
|
{ |
||||
|
|
||||
|
$id = $this->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); |
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
|
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,23 @@ |
|||||
|
<?php |
||||
|
|
||||
|
declare(strict_types=1); |
||||
|
namespace App\Controller; |
||||
|
|
||||
|
|
||||
|
use Hyperf\HttpServer\Contract\RequestInterface; |
||||
|
use Hyperf\HttpServer\Annotation\AutoController; |
||||
|
|
||||
|
/** |
||||
|
* @AutoController() |
||||
|
* Class TestController |
||||
|
* @package App\Controller |
||||
|
*/ |
||||
|
class TestController extends AbstractController |
||||
|
{ |
||||
|
|
||||
|
public function index(RequestInterface $request) |
||||
|
{ |
||||
|
$id = $request->input('id',2); |
||||
|
return (string)$id; |
||||
|
} |
||||
|
} |
||||
Write
Preview
Loading…
Cancel
Save
Reference in new issue