|
...
|
...
|
@@ -3,10 +3,12 @@ |
|
|
|
namespace App\Http\Logic\Bside;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Enums\Common\Code;
|
|
|
|
use App\Enums\Common\Common;
|
|
|
|
use App\Exceptions\BsideGlobalException;
|
|
|
|
use App\Http\Controllers\file\ImageController;
|
|
|
|
use App\Http\Logic\Logic;
|
|
|
|
use App\Models\File\Image as ImageModel;
|
|
|
|
use Illuminate\Support\Facades\Cache;
|
|
|
|
|
|
|
|
/**
|
|
...
|
...
|
@@ -93,14 +95,40 @@ class BaseLogic extends Logic |
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @name :上传图片
|
|
|
|
* @name :上传图片返回hash
|
|
|
|
* @return void
|
|
|
|
* @author :liyuhang
|
|
|
|
* @method
|
|
|
|
*/
|
|
|
|
public function upload(){
|
|
|
|
$image = new ImageController();
|
|
|
|
$hash = $image->upload();
|
|
|
|
$files = $this->request->file('image');
|
|
|
|
$hash = hash_file('md5', $files->getPathname());
|
|
|
|
//查看文件是否存在
|
|
|
|
$imageModel = new ImageModel();
|
|
|
|
$image_hash = $imageModel->read(['hash'=>$hash]);
|
|
|
|
if($image_hash !== false){
|
|
|
|
return $hash;
|
|
|
|
}
|
|
|
|
$this->config = config('filesystems.disks.upload');
|
|
|
|
$this->uploads = config('upload.default_image');
|
|
|
|
$this->path = $this->config['root'].$this->uploads['path'].'/';
|
|
|
|
$url = $this->path;
|
|
|
|
$fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
|
|
|
|
$res = $files->move($url,$fileName);
|
|
|
|
if ($res === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
$data = [
|
|
|
|
'path' => $url.$fileName,
|
|
|
|
'created_at' => date('Y-m-d H:i:s',time()),
|
|
|
|
'size' => $res->getSize(),
|
|
|
|
'hash' => $hash,
|
|
|
|
'type'=>$files->getClientOriginalExtension(),
|
|
|
|
];
|
|
|
|
$rs = $imageModel->add($data);
|
|
|
|
if ($rs === false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
return $hash;
|
|
|
|
}
|
|
|
|
|
...
|
...
|
|