作者 邓超

Merge branch 'develop' into dc

... ... @@ -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;
}
... ...
... ... @@ -59,19 +59,19 @@ class NewsLogic extends BaseLogic
$this->param['project_id'] = $this->user['project_id'];
$this->param['created_at'] = date('Y-m-d H:i:s',time());
$this->param['updated_at'] = date('Y-m-d H:i:s',time());
DB::beginTransaction();
try {
// DB::beginTransaction();
// try {
if(isset($this->param['image'])){
$data = $this->upload();
$this->param['image'] = $data;
}
$rs = $this->model->insertGetId($this->param);
RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
DB::commit();
}catch (\Exception $e){
DB::rollBack();
$this->fail('添加失败');
}
// DB::commit();
// }catch (\Exception $e){
// DB::rollBack();
// $this->fail('添加失败');
// }
return $this->success();
}
... ...
... ... @@ -30,10 +30,10 @@ class LoginAuthMiddleware
return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
}
// 设置数据信息
// $project = ProjectServer::useProject($info['project_id']);
// if($project){
// return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);
// }
$project = ProjectServer::useProject($info['project_id']);
if(empty($project)){
return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);
}
//操作权限设置
$projectRoleModel = new ProjectRoleModel();
$role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
... ...
... ... @@ -8,5 +8,5 @@ class File extends Base
{
protected $table = 'gl_file';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
}
... ...
... ... @@ -9,5 +9,5 @@ class Image extends Base
protected $table = 'gl_image';
//连接数据库
protected $connection = 'custom_mysql';
// protected $connection = 'custom_mysql';
}
... ...