Browse Source

新店铺信息接口

master
lanzu_qsy 6 years ago
parent
commit
0f20d938ff
  1. 55
      app/Controller/FileUpload.php
  2. 26
      app/Controller/IndexController.php
  3. 73
      app/Controller/StoreController.php
  4. 23
      app/Controller/TestController.php
  5. 4
      composer.json

55
app/Controller/FileUpload.php

@ -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;
}
}
}

26
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);
}
}

73
app/Controller/StoreController.php

@ -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);
}
}

23
app/Controller/TestController.php

@ -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;
}
}

4
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",

Loading…
Cancel
Save