作者 邓超

Merge branch 'develop' into dc

@@ -3,10 +3,12 @@ @@ -3,10 +3,12 @@
3 namespace App\Http\Logic\Bside; 3 namespace App\Http\Logic\Bside;
4 4
5 5
  6 +use App\Enums\Common\Code;
6 use App\Enums\Common\Common; 7 use App\Enums\Common\Common;
7 use App\Exceptions\BsideGlobalException; 8 use App\Exceptions\BsideGlobalException;
8 use App\Http\Controllers\file\ImageController; 9 use App\Http\Controllers\file\ImageController;
9 use App\Http\Logic\Logic; 10 use App\Http\Logic\Logic;
  11 +use App\Models\File\Image as ImageModel;
10 use Illuminate\Support\Facades\Cache; 12 use Illuminate\Support\Facades\Cache;
11 13
12 /** 14 /**
@@ -93,14 +95,40 @@ class BaseLogic extends Logic @@ -93,14 +95,40 @@ class BaseLogic extends Logic
93 } 95 }
94 96
95 /** 97 /**
96 - * @name :上传图片 98 + * @name :上传图片返回hash
97 * @return void 99 * @return void
98 * @author :liyuhang 100 * @author :liyuhang
99 * @method 101 * @method
100 */ 102 */
101 public function upload(){ 103 public function upload(){
102 - $image = new ImageController();  
103 - $hash = $image->upload(); 104 + $files = $this->request->file('image');
  105 + $hash = hash_file('md5', $files->getPathname());
  106 + //查看文件是否存在
  107 + $imageModel = new ImageModel();
  108 + $image_hash = $imageModel->read(['hash'=>$hash]);
  109 + if($image_hash !== false){
  110 + return $hash;
  111 + }
  112 + $this->config = config('filesystems.disks.upload');
  113 + $this->uploads = config('upload.default_image');
  114 + $this->path = $this->config['root'].$this->uploads['path'].'/';
  115 + $url = $this->path;
  116 + $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension();
  117 + $res = $files->move($url,$fileName);
  118 + if ($res === false) {
  119 + return false;
  120 + }
  121 + $data = [
  122 + 'path' => $url.$fileName,
  123 + 'created_at' => date('Y-m-d H:i:s',time()),
  124 + 'size' => $res->getSize(),
  125 + 'hash' => $hash,
  126 + 'type'=>$files->getClientOriginalExtension(),
  127 + ];
  128 + $rs = $imageModel->add($data);
  129 + if ($rs === false) {
  130 + return false;
  131 + }
104 return $hash; 132 return $hash;
105 } 133 }
106 134
@@ -59,19 +59,19 @@ class NewsLogic extends BaseLogic @@ -59,19 +59,19 @@ class NewsLogic extends BaseLogic
59 $this->param['project_id'] = $this->user['project_id']; 59 $this->param['project_id'] = $this->user['project_id'];
60 $this->param['created_at'] = date('Y-m-d H:i:s',time()); 60 $this->param['created_at'] = date('Y-m-d H:i:s',time());
61 $this->param['updated_at'] = date('Y-m-d H:i:s',time()); 61 $this->param['updated_at'] = date('Y-m-d H:i:s',time());
62 - DB::beginTransaction();  
63 - try { 62 +// DB::beginTransaction();
  63 +// try {
64 if(isset($this->param['image'])){ 64 if(isset($this->param['image'])){
65 $data = $this->upload(); 65 $data = $this->upload();
66 $this->param['image'] = $data; 66 $this->param['image'] = $data;
67 } 67 }
68 $rs = $this->model->insertGetId($this->param); 68 $rs = $this->model->insertGetId($this->param);
69 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); 69 RouteMap::setRoute($this->param['url'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']);
70 - DB::commit();  
71 - }catch (\Exception $e){  
72 - DB::rollBack();  
73 - $this->fail('添加失败');  
74 - } 70 +// DB::commit();
  71 +// }catch (\Exception $e){
  72 +// DB::rollBack();
  73 +// $this->fail('添加失败');
  74 +// }
75 return $this->success(); 75 return $this->success();
76 } 76 }
77 77
@@ -30,10 +30,10 @@ class LoginAuthMiddleware @@ -30,10 +30,10 @@ class LoginAuthMiddleware
30 return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']); 30 return response(['code'=>Code::USER_ERROR,'msg'=>'当前用户未登录']);
31 } 31 }
32 // 设置数据信息 32 // 设置数据信息
33 -// $project = ProjectServer::useProject($info['project_id']);  
34 -// if($project){  
35 -// return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);  
36 -// } 33 + $project = ProjectServer::useProject($info['project_id']);
  34 + if(empty($project)){
  35 + return response(['code'=>Code::USER_ERROR,'msg'=>'数据库未配置']);
  36 + }
37 //操作权限设置 37 //操作权限设置
38 $projectRoleModel = new ProjectRoleModel(); 38 $projectRoleModel = new ProjectRoleModel();
39 $role_info = $projectRoleModel->read(['id'=>$info['role_id']]); 39 $role_info = $projectRoleModel->read(['id'=>$info['role_id']]);
@@ -8,5 +8,5 @@ class File extends Base @@ -8,5 +8,5 @@ class File extends Base
8 { 8 {
9 protected $table = 'gl_file'; 9 protected $table = 'gl_file';
10 //连接数据库 10 //连接数据库
11 - protected $connection = 'custom_mysql'; 11 +// protected $connection = 'custom_mysql';
12 } 12 }
@@ -9,5 +9,5 @@ class Image extends Base @@ -9,5 +9,5 @@ class Image extends Base
9 protected $table = 'gl_image'; 9 protected $table = 'gl_image';
10 10
11 //连接数据库 11 //连接数据库
12 - protected $connection = 'custom_mysql'; 12 +// protected $connection = 'custom_mysql';
13 } 13 }