1
This commit is contained in:
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace app\api\controller;
|
||||
use support\Request;
|
||||
use support\Response;
|
||||
use Shopwwi\WebmanFilesystem\FilesystemFactory;
|
||||
use Shopwwi\WebmanFilesystem\Facade\Storage;
|
||||
use hg\apidoc\annotation as Apidoc;
|
||||
/**
|
||||
* 基础控制器
|
||||
* @Apidoc\NotParse()
|
||||
* @Apidoc\NotDebug()
|
||||
*/
|
||||
class BaseController
|
||||
{
|
||||
/**
|
||||
* 不需要鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedAuth = [];
|
||||
|
||||
/**
|
||||
* 无需登录及鉴权的方法
|
||||
* @var array
|
||||
*/
|
||||
public $noNeedLogin = [];
|
||||
function __construct()
|
||||
{
|
||||
$this->_init();
|
||||
}
|
||||
protected function _init(){
|
||||
}
|
||||
/**
|
||||
* 返回格式化json数据
|
||||
*
|
||||
* @param int $code
|
||||
* @param string $msg
|
||||
* @param array $data
|
||||
* @return Response
|
||||
*/
|
||||
protected function json(int $code, string $msg = 'ok', array|object|null $data = []): Response
|
||||
{
|
||||
return json(['code' => $code, 'data' => $data, 'msg' => $msg]);
|
||||
}
|
||||
|
||||
protected function success(string $msg = '成功', array|object|null $data = []): Response
|
||||
{
|
||||
return $this->json(0, $msg, $data);
|
||||
}
|
||||
|
||||
protected function fail(string $msg = '失败', array|object|null $data = []): Response
|
||||
{
|
||||
return $this->json(1,$msg, $data);
|
||||
}
|
||||
protected function error(string $msg = '失败', array|object|null $data = []): Response
|
||||
{
|
||||
return $this->json(1,$msg, $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @Apidoc\Title("上传")
|
||||
* @Apidoc\Method("POST")
|
||||
*/
|
||||
function upload(Request $request)
|
||||
{
|
||||
//多文件上传
|
||||
$files = $request->file();
|
||||
try {
|
||||
$result = Storage::adapter('public')
|
||||
->path('upload/files')
|
||||
->size(1024*1024*10)
|
||||
->extYes(['image/jpeg','image/png'])
|
||||
->uploads($files,0,1024*1024*100,false);
|
||||
return $this->success(__('successful'),$result);
|
||||
}catch (\Exception $e){
|
||||
return $this->error($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user