Merge branch 'develop' of http://47.244.231.31:8099/zhl/globalso-v6 into develop
正在显示
6 个修改的文件
包含
163 行增加
和
58 行删除
| @@ -5,6 +5,8 @@ namespace App\Http\Controllers\File; | @@ -5,6 +5,8 @@ namespace App\Http\Controllers\File; | ||
| 5 | use App\Enums\Common\Code; | 5 | use App\Enums\Common\Code; |
| 6 | use App\Models\File\File; | 6 | use App\Models\File\File; |
| 7 | use App\Models\File\Image as ImageModel; | 7 | use App\Models\File\Image as ImageModel; |
| 8 | +use App\Models\Project\Project; | ||
| 9 | +use App\Services\CosService; | ||
| 8 | use Illuminate\Http\Exceptions\HttpResponseException; | 10 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 9 | use Illuminate\Http\JsonResponse; | 11 | use Illuminate\Http\JsonResponse; |
| 10 | use Illuminate\Support\Facades\Cache; | 12 | use Illuminate\Support\Facades\Cache; |
| @@ -34,7 +36,7 @@ class FileController | @@ -34,7 +36,7 @@ class FileController | ||
| 34 | public $token = '';//token | 36 | public $token = '';//token |
| 35 | 37 | ||
| 36 | public $cache = '';//缓存数据 | 38 | public $cache = '';//缓存数据 |
| 37 | - | 39 | + public $upload_location = 1; |
| 38 | public $image_type = [ | 40 | public $image_type = [ |
| 39 | 1 => 'file_other', | 41 | 1 => 'file_other', |
| 40 | 0 => 'file' | 42 | 0 => 'file' |
| @@ -134,7 +136,9 @@ class FileController | @@ -134,7 +136,9 @@ class FileController | ||
| 134 | ],[ | 136 | ],[ |
| 135 | 'file.required'=>'必须填写', | 137 | 'file.required'=>'必须填写', |
| 136 | ]); | 138 | ]); |
| 137 | - $files = $this->param['file']; | 139 | + $files = $this->request->file('file'); |
| 140 | + $size = $files->getSize(); | ||
| 141 | + $file_type = $files->getClientOriginalExtension(); | ||
| 138 | if (empty($files)) { | 142 | if (empty($files)) { |
| 139 | $this->response('没有上传的文件!', 400); | 143 | $this->response('没有上传的文件!', 400); |
| 140 | } | 144 | } |
| @@ -143,7 +147,7 @@ class FileController | @@ -143,7 +147,7 @@ class FileController | ||
| 143 | if ($type == 'multi') { | 147 | if ($type == 'multi') { |
| 144 | return $this->multi($files); | 148 | return $this->multi($files); |
| 145 | } else { | 149 | } else { |
| 146 | - return $this->single($files); | 150 | + return $this->single($files,$size,$file_type); |
| 147 | } | 151 | } |
| 148 | } | 152 | } |
| 149 | 153 | ||
| @@ -155,7 +159,7 @@ class FileController | @@ -155,7 +159,7 @@ class FileController | ||
| 155 | * @method :post | 159 | * @method :post |
| 156 | * @time :2023/6/17 16:32 | 160 | * @time :2023/6/17 16:32 |
| 157 | */ | 161 | */ |
| 158 | - public function single($files){ | 162 | + public function single($files,$size,$file_type){ |
| 159 | $hash = hash_file('md5', $files->getPathname()); | 163 | $hash = hash_file('md5', $files->getPathname()); |
| 160 | //查看文件是否存在 | 164 | //查看文件是否存在 |
| 161 | $fileModel = new File(); | 165 | $fileModel = new File(); |
| @@ -165,37 +169,52 @@ class FileController | @@ -165,37 +169,52 @@ class FileController | ||
| 165 | } | 169 | } |
| 166 | $url = $this->config['root'].$this->path; | 170 | $url = $this->config['root'].$this->path; |
| 167 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); | 171 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); |
| 168 | - $res = $files->move($url,$fileName); | ||
| 169 | - if ($res === false) { | ||
| 170 | - return $this->response($files->getError(), Code::USER_ERROR); | 172 | + //同步数据到cos |
| 173 | + if($this->upload_location == 1){ | ||
| 174 | + $cosService = new CosService(); | ||
| 175 | + $cosService->uploadFile($files,$this->path,$fileName); | ||
| 176 | + }else{ | ||
| 177 | + $res = $files->move($url,$fileName); | ||
| 178 | + if ($res === false) { | ||
| 179 | + return $this->response($files->getError(), Code::USER_ERROR); | ||
| 180 | + } | ||
| 171 | } | 181 | } |
| 182 | + $this->saveMysql($fileModel,$size,$file_type,$fileName,$hash); | ||
| 183 | + return $this->response('资源',Code::SUCCESS,['file'=>$hash]); | ||
| 184 | + } | ||
| 185 | + | ||
| 186 | + /** | ||
| 187 | + * @remark :保存数据库 | ||
| 188 | + * @name :saveMysql | ||
| 189 | + * @author :lyh | ||
| 190 | + * @method :post | ||
| 191 | + * @time :2023/7/19 16:38 | ||
| 192 | + */ | ||
| 193 | + public function saveMysql(&$fileModel,$size,$image_type,$fileName,$hash){ | ||
| 172 | $data = [ | 194 | $data = [ |
| 173 | 'path' => $this->path.'/'.$fileName, | 195 | 'path' => $this->path.'/'.$fileName, |
| 174 | 'created_at' => date('Y-m-d H:i:s',time()), | 196 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 175 | - 'size' => $res->getSize(), | 197 | + 'size' => $size, |
| 176 | 'hash' => $hash, | 198 | 'hash' => $hash, |
| 177 | - 'type'=>$files->getClientOriginalExtension(), | ||
| 178 | - 'refer'=>$this->param['refer'] ?? 0 | 199 | + 'type'=>$image_type, |
| 200 | + 'refer'=>$this->param['refer'] ?? 1, | ||
| 179 | ]; | 201 | ]; |
| 180 | $rs = $fileModel->add($data); | 202 | $rs = $fileModel->add($data); |
| 181 | if ($rs === false) { | 203 | if ($rs === false) { |
| 182 | return $this->response('添加失败', Code::USER_ERROR); | 204 | return $this->response('添加失败', Code::USER_ERROR); |
| 183 | } | 205 | } |
| 184 | - return $this->response('资源',Code::SUCCESS,['file'=>$hash]); | 206 | + return true; |
| 185 | } | 207 | } |
| 186 | 208 | ||
| 187 | /** | 209 | /** |
| 188 | * @param $files | 210 | * @param $files |
| 189 | - * @remark :多文件上传 | 211 | + * @remark :多文件上传(暂时未用) |
| 190 | * @name :multi | 212 | * @name :multi |
| 191 | * @author :lyh | 213 | * @author :lyh |
| 192 | * @method :post | 214 | * @method :post |
| 193 | * @time :2023/6/17 16:32 | 215 | * @time :2023/6/17 16:32 |
| 194 | */ | 216 | */ |
| 195 | private function multi($files) { | 217 | private function multi($files) { |
| 196 | - if (!is_array($files)) { | ||
| 197 | - $files = [$files]; | ||
| 198 | - } | ||
| 199 | $save_data = []; | 218 | $save_data = []; |
| 200 | $data = []; | 219 | $data = []; |
| 201 | foreach ($files as $file) { | 220 | foreach ($files as $file) { |
| @@ -322,6 +341,9 @@ class FileController | @@ -322,6 +341,9 @@ class FileController | ||
| 322 | if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){ | 341 | if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){ |
| 323 | $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); | 342 | $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); |
| 324 | }else{ | 343 | }else{ |
| 344 | + $projectModel = new Project(); | ||
| 345 | + $project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']); | ||
| 346 | + $this->upload_location = $project_info['upload_location']; | ||
| 325 | $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); | 347 | $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); |
| 326 | } | 348 | } |
| 327 | } | 349 | } |
| @@ -6,6 +6,8 @@ use App\Enums\Common\Code; | @@ -6,6 +6,8 @@ use App\Enums\Common\Code; | ||
| 6 | use App\Http\Controllers\Controller; | 6 | use App\Http\Controllers\Controller; |
| 7 | use App\Http\Controllers\type; | 7 | use App\Http\Controllers\type; |
| 8 | use App\Models\File\Image as ImageModel; | 8 | use App\Models\File\Image as ImageModel; |
| 9 | +use App\Models\Project\Project; | ||
| 10 | +use App\Services\CosService; | ||
| 9 | use App\Services\TencentCosService; | 11 | use App\Services\TencentCosService; |
| 10 | use Illuminate\Http\Exceptions\HttpResponseException; | 12 | use Illuminate\Http\Exceptions\HttpResponseException; |
| 11 | use Illuminate\Http\JsonResponse; | 13 | use Illuminate\Http\JsonResponse; |
| @@ -26,8 +28,6 @@ class ImageController extends Controller | @@ -26,8 +28,6 @@ class ImageController extends Controller | ||
| 26 | 'Content-Description' => 'File Transfer', | 28 | 'Content-Description' => 'File Transfer', |
| 27 | ], | 29 | ], |
| 28 | ]; | 30 | ]; |
| 29 | - const TYPE = 1; | ||
| 30 | - | ||
| 31 | public $path = '';//路径 | 31 | public $path = '';//路径 |
| 32 | 32 | ||
| 33 | public $config = '';//存储默认配置 | 33 | public $config = '';//存储默认配置 |
| @@ -40,11 +40,12 @@ class ImageController extends Controller | @@ -40,11 +40,12 @@ class ImageController extends Controller | ||
| 40 | 40 | ||
| 41 | public $cache = '';//缓存数据 | 41 | public $cache = '';//缓存数据 |
| 42 | 42 | ||
| 43 | + public $upload_location = 0;//是否同步到cos | ||
| 43 | public $image_type = [ | 44 | public $image_type = [ |
| 44 | 1 => 'image_product', | 45 | 1 => 'image_product', |
| 45 | 2 => 'image_news', | 46 | 2 => 'image_news', |
| 46 | 3 => 'image_blog', | 47 | 3 => 'image_blog', |
| 47 | - 4 => 'image_other', | 48 | + 0 => 'image_other', |
| 48 | ]; | 49 | ]; |
| 49 | 50 | ||
| 50 | public function __construct() | 51 | public function __construct() |
| @@ -85,7 +86,7 @@ class ImageController extends Controller | @@ -85,7 +86,7 @@ class ImageController extends Controller | ||
| 85 | $content = file_get_contents($filename); | 86 | $content = file_get_contents($filename); |
| 86 | $header['Content-Length'] = strlen($content); | 87 | $header['Content-Length'] = strlen($content); |
| 87 | }else{ | 88 | }else{ |
| 88 | - $path = $this->config['url'].'/'.$info['path']; | 89 | + $path = $this->config['root'].'/'.$info['path']; |
| 89 | if (!is_file($path)) { | 90 | if (!is_file($path)) { |
| 90 | $this->response('指定图片已被系统删除!', Code::USER_ERROR); | 91 | $this->response('指定图片已被系统删除!', Code::USER_ERROR); |
| 91 | } | 92 | } |
| @@ -119,6 +120,8 @@ class ImageController extends Controller | @@ -119,6 +120,8 @@ class ImageController extends Controller | ||
| 119 | 'image.required'=>'图片必须填写', | 120 | 'image.required'=>'图片必须填写', |
| 120 | ]); | 121 | ]); |
| 121 | $files = $this->request->file('image'); | 122 | $files = $this->request->file('image'); |
| 123 | + $size = $files->getSize(); | ||
| 124 | + $image_type = $files->getClientOriginalExtension(); | ||
| 122 | if (empty($files)) { | 125 | if (empty($files)) { |
| 123 | $this->response('没有上传的文件!', 400); | 126 | $this->response('没有上传的文件!', 400); |
| 124 | } | 127 | } |
| @@ -126,8 +129,8 @@ class ImageController extends Controller | @@ -126,8 +129,8 @@ class ImageController extends Controller | ||
| 126 | $this->setUrl(); | 129 | $this->setUrl(); |
| 127 | if ($type == 'multi') { | 130 | if ($type == 'multi') { |
| 128 | return $this->multi($files); | 131 | return $this->multi($files); |
| 129 | - } else { | ||
| 130 | - return $this->single($files); | 132 | + }else{ |
| 133 | + return $this->single($files,$size,$image_type); | ||
| 131 | } | 134 | } |
| 132 | } | 135 | } |
| 133 | 136 | ||
| @@ -139,7 +142,7 @@ class ImageController extends Controller | @@ -139,7 +142,7 @@ class ImageController extends Controller | ||
| 139 | * @method :post | 142 | * @method :post |
| 140 | * @time :2023/6/17 16:30 | 143 | * @time :2023/6/17 16:30 |
| 141 | */ | 144 | */ |
| 142 | - public function single($files){ | 145 | + public function single(&$files,$size,$image_type){ |
| 143 | $hash = hash_file('md5', $files->getPathname()); | 146 | $hash = hash_file('md5', $files->getPathname()); |
| 144 | //查看文件是否存在 | 147 | //查看文件是否存在 |
| 145 | $imageModel = new ImageModel(); | 148 | $imageModel = new ImageModel(); |
| @@ -149,25 +152,42 @@ class ImageController extends Controller | @@ -149,25 +152,42 @@ class ImageController extends Controller | ||
| 149 | } | 152 | } |
| 150 | $url = $this->config['root'].$this->path; | 153 | $url = $this->config['root'].$this->path; |
| 151 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); | 154 | $fileName = uniqid().rand(10000,99999).'.'.$files->getClientOriginalExtension(); |
| 152 | - $res = $files->move($url,$fileName); | ||
| 153 | - if ($res === false) { | ||
| 154 | - return $this->response($files->getError(), Code::USER_ERROR); | 155 | + //同步数据到cos |
| 156 | + if($this->upload_location == 1){ | ||
| 157 | + $cosService = new CosService(); | ||
| 158 | + $cosService->uploadFile($files,$this->path,$fileName); | ||
| 159 | + }else{ | ||
| 160 | + $res = $files->move($url,$fileName); | ||
| 161 | + if ($res === false) { | ||
| 162 | + return $this->response($files->getError(), Code::USER_ERROR); | ||
| 163 | + } | ||
| 155 | } | 164 | } |
| 165 | + $this->saveMysql($imageModel,$size,$image_type,$fileName,$hash); | ||
| 166 | + return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); | ||
| 167 | + } | ||
| 168 | + | ||
| 169 | + /** | ||
| 170 | + * @remark :保存数据库 | ||
| 171 | + * @name :saveMysql | ||
| 172 | + * @author :lyh | ||
| 173 | + * @method :post | ||
| 174 | + * @time :2023/7/19 16:38 | ||
| 175 | + */ | ||
| 176 | + public function saveMysql(&$imageModel,$size,$image_type,$fileName,$hash){ | ||
| 156 | $data = [ | 177 | $data = [ |
| 157 | 'path' => $this->path.'/'.$fileName, | 178 | 'path' => $this->path.'/'.$fileName, |
| 158 | 'created_at' => date('Y-m-d H:i:s',time()), | 179 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 159 | - 'size' => $res->getSize(), | 180 | + 'size' => $size, |
| 160 | 'hash' => $hash, | 181 | 'hash' => $hash, |
| 161 | - 'type'=>$files->getClientOriginalExtension(), | ||
| 162 | - 'refer'=>$this->param['refer'] ?? 0, | 182 | + 'type'=>$image_type, |
| 183 | + 'refer'=>$this->param['refer'] ?? 1, | ||
| 163 | ]; | 184 | ]; |
| 164 | $rs = $imageModel->add($data); | 185 | $rs = $imageModel->add($data); |
| 165 | if ($rs === false) { | 186 | if ($rs === false) { |
| 166 | return $this->response('添加失败', Code::USER_ERROR); | 187 | return $this->response('添加失败', Code::USER_ERROR); |
| 167 | } | 188 | } |
| 168 | - return $this->response('图片资源',Code::SUCCESS,['image'=>$hash]); | 189 | + return true; |
| 169 | } | 190 | } |
| 170 | - | ||
| 171 | /** | 191 | /** |
| 172 | * @param $info | 192 | * @param $info |
| 173 | * @param $w | 193 | * @param $w |
| @@ -193,13 +213,12 @@ class ImageController extends Controller | @@ -193,13 +213,12 @@ class ImageController extends Controller | ||
| 193 | * @method :post | 213 | * @method :post |
| 194 | * @time :2023/6/17 16:31 | 214 | * @time :2023/6/17 16:31 |
| 195 | */ | 215 | */ |
| 196 | - private function multi($files) { | ||
| 197 | - if (!is_array($files)) { | ||
| 198 | - $files = [$files]; | ||
| 199 | - } | 216 | + private function multi(&$files) { |
| 200 | $save_data = []; | 217 | $save_data = []; |
| 201 | $data = []; | 218 | $data = []; |
| 202 | foreach ($files as $file) { | 219 | foreach ($files as $file) { |
| 220 | + $size = $file->getSize(); | ||
| 221 | + $image_type = $file->getClientOriginalExtension(); | ||
| 203 | $imageModel = new ImageModel(); | 222 | $imageModel = new ImageModel(); |
| 204 | $hash = hash_file('md5', $file->getPathname()); | 223 | $hash = hash_file('md5', $file->getPathname()); |
| 205 | $image_hash = $imageModel->read(['hash'=>$hash]); | 224 | $image_hash = $imageModel->read(['hash'=>$hash]); |
| @@ -209,18 +228,24 @@ class ImageController extends Controller | @@ -209,18 +228,24 @@ class ImageController extends Controller | ||
| 209 | } | 228 | } |
| 210 | $url = $this->config['root'].$this->path; | 229 | $url = $this->config['root'].$this->path; |
| 211 | $fileName = uniqid().rand(10000,99999).'.'.$file->getClientOriginalExtension(); | 230 | $fileName = uniqid().rand(10000,99999).'.'.$file->getClientOriginalExtension(); |
| 212 | - $res = $file->move($url,$fileName); | ||
| 213 | - if ($res === false) { | ||
| 214 | - return $this->response($file->getError(), Code::USER_ERROR); | 231 | + //同步数据到cos |
| 232 | + if($this->upload_location == 1){ | ||
| 233 | + $cosService = new CosService(); | ||
| 234 | + $cosService->uploadFile($file,$this->path,$fileName); | ||
| 235 | + }else{ | ||
| 236 | + $res = $file->move($url,$fileName); | ||
| 237 | + if ($res === false) { | ||
| 238 | + return $this->response($file->getError(), Code::USER_ERROR); | ||
| 239 | + } | ||
| 215 | } | 240 | } |
| 216 | $save_data[] = [ | 241 | $save_data[] = [ |
| 217 | 'path' => $this->path.'/'.$fileName, | 242 | 'path' => $this->path.'/'.$fileName, |
| 218 | 'created_at' => date('Y-m-d H:i:s',time()), | 243 | 'created_at' => date('Y-m-d H:i:s',time()), |
| 219 | 'updated_at'=>date('Y-m-d H:i:s',time()), | 244 | 'updated_at'=>date('Y-m-d H:i:s',time()), |
| 220 | - 'size' => $res->getSize(), | 245 | + 'size' => $size, |
| 221 | 'hash' => $hash, | 246 | 'hash' => $hash, |
| 222 | - 'type'=>$file->getClientOriginalExtension(), | ||
| 223 | - 'refer'=>$this->param['refer'] ?? '', | 247 | + 'type'=>$image_type, |
| 248 | + 'refer'=>$this->param['refer'] ?? 0, | ||
| 224 | ]; | 249 | ]; |
| 225 | $data[] = ['image'=>$hash]; | 250 | $data[] = ['image'=>$hash]; |
| 226 | } | 251 | } |
| @@ -274,7 +299,8 @@ class ImageController extends Controller | @@ -274,7 +299,8 @@ class ImageController extends Controller | ||
| 274 | //获取操作人 | 299 | //获取操作人 |
| 275 | switch ((string) $k) { | 300 | switch ((string) $k) { |
| 276 | case 'image': | 301 | case 'image': |
| 277 | - $data['image_link'] = url('/b/image/' . $v); | 302 | + $cos = new CosService(); |
| 303 | + $data['image_link'] = $cos->getImageUrl('/p/1/image_other/2023-07/64b7abf16721020421.png'); | ||
| 278 | break; | 304 | break; |
| 279 | case 'hash': | 305 | case 'hash': |
| 280 | $data['image_link'] = url('/b/image/' . $v); | 306 | $data['image_link'] = url('/b/image/' . $v); |
| @@ -315,6 +341,9 @@ class ImageController extends Controller | @@ -315,6 +341,9 @@ class ImageController extends Controller | ||
| 315 | if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){ | 341 | if(isset($this->param['refer_type']) && $this->param['refer_type'] == 1){ |
| 316 | $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); | 342 | $this->path = $this->uploads['path_a'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); |
| 317 | }else{ | 343 | }else{ |
| 344 | + $projectModel = new Project(); | ||
| 345 | + $project_info = $projectModel->read(['id'=>$this->cache['project_id']],['upload_location']); | ||
| 346 | + $this->upload_location = $project_info['upload_location']; | ||
| 318 | $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); | 347 | $this->path = $this->uploads['path_b'].'/'.$this->cache['project_id'].'/'.$this->image_type[$this->param['refer']].'/'.date('Y-m'); |
| 319 | } | 348 | } |
| 320 | } | 349 | } |
| @@ -57,10 +57,6 @@ class BlogLogic extends BaseLogic | @@ -57,10 +57,6 @@ class BlogLogic extends BaseLogic | ||
| 57 | //拼接参数 | 57 | //拼接参数 |
| 58 | DB::beginTransaction(); | 58 | DB::beginTransaction(); |
| 59 | try { | 59 | try { |
| 60 | - if(isset($this->param['image'])){ | ||
| 61 | - $data = $this->upload(); | ||
| 62 | - $this->param['image'] = $data; | ||
| 63 | - } | ||
| 64 | $this->param = $this->paramProcessing($this->param); | 60 | $this->param = $this->paramProcessing($this->param); |
| 65 | $rs = $this->model->insertGetId($this->param); | 61 | $rs = $this->model->insertGetId($this->param); |
| 66 | RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']); | 62 | RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $rs, $this->user['project_id']); |
| @@ -84,10 +80,6 @@ class BlogLogic extends BaseLogic | @@ -84,10 +80,6 @@ class BlogLogic extends BaseLogic | ||
| 84 | $this->param = $this->paramProcessing($this->param); | 80 | $this->param = $this->paramProcessing($this->param); |
| 85 | DB::beginTransaction(); | 81 | DB::beginTransaction(); |
| 86 | try { | 82 | try { |
| 87 | - //是否有图片更新 | ||
| 88 | - if(isset($this->param['image']) && is_file($this->param['image'])){ | ||
| 89 | - $this->param['image'] = $this->upload(); | ||
| 90 | - } | ||
| 91 | RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']); | 83 | RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_BLOG, $this->param['id'], $this->user['project_id']); |
| 92 | $this->edit($this->param,['id'=>$this->param['id']]); | 84 | $this->edit($this->param,['id'=>$this->param['id']]); |
| 93 | DB::commit(); | 85 | DB::commit(); |
| @@ -57,10 +57,6 @@ class NewsLogic extends BaseLogic | @@ -57,10 +57,6 @@ class NewsLogic extends BaseLogic | ||
| 57 | //拼接参数 | 57 | //拼接参数 |
| 58 | DB::beginTransaction(); | 58 | DB::beginTransaction(); |
| 59 | try { | 59 | try { |
| 60 | - if(isset($this->param['image'])){ | ||
| 61 | - $data = $this->upload(); | ||
| 62 | - $this->param['image'] = $data; | ||
| 63 | - } | ||
| 64 | $this->param = $this->paramProcessing($this->param); | 60 | $this->param = $this->paramProcessing($this->param); |
| 65 | $rs = $this->model->insertGetId($this->param); | 61 | $rs = $this->model->insertGetId($this->param); |
| 66 | RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); | 62 | RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $rs, $this->user['project_id']); |
| @@ -83,10 +79,6 @@ class NewsLogic extends BaseLogic | @@ -83,10 +79,6 @@ class NewsLogic extends BaseLogic | ||
| 83 | $this->param = $this->paramProcessing($this->param); | 79 | $this->param = $this->paramProcessing($this->param); |
| 84 | DB::beginTransaction(); | 80 | DB::beginTransaction(); |
| 85 | try { | 81 | try { |
| 86 | - //上传图片 | ||
| 87 | - if(isset($this->param['image']) && is_file($this->param['image'])){ | ||
| 88 | - $this->param['image'] = $this->upload(); | ||
| 89 | - } | ||
| 90 | //设置路由 | 82 | //设置路由 |
| 91 | RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']); | 83 | RouteMap::setRoute($this->param['url'] ?: $this->param['name'], RouteMap::SOURCE_NEWS, $this->param['id'], $this->user['project_id']); |
| 92 | $this->edit($this->param,['id'=>$this->param['id']]); | 84 | $this->edit($this->param,['id'=>$this->param['id']]); |
app/Services/CosService.php
0 → 100644
| 1 | +<?php | ||
| 2 | + | ||
| 3 | +namespace App\Services; | ||
| 4 | + | ||
| 5 | +use Qcloud\Cos\Client; | ||
| 6 | +/** | ||
| 7 | + * @remark : | ||
| 8 | + * @class :CosService.php | ||
| 9 | + * @author :lyh | ||
| 10 | + * @time :2023/7/19 15:09 | ||
| 11 | + */ | ||
| 12 | +class CosService | ||
| 13 | +{ | ||
| 14 | + | ||
| 15 | + /** | ||
| 16 | + * @param $file | ||
| 17 | + * @remark :上传图片 | ||
| 18 | + * @name :uploadFile | ||
| 19 | + * @author :lyh | ||
| 20 | + * @method :post | ||
| 21 | + * @time :2023/7/19 15:28 | ||
| 22 | + */ | ||
| 23 | + public function uploadFile(&$files,$path,$filename) | ||
| 24 | + { | ||
| 25 | + $cos = config('filesystems.disks.cos'); | ||
| 26 | + $cosClient = new Client([ | ||
| 27 | + 'region' => $cos['region'], | ||
| 28 | + 'credentials' => [ | ||
| 29 | + 'secretId' => $cos['credentials']['secretId'], | ||
| 30 | + 'secretKey' => $cos['credentials']['secretKey'], | ||
| 31 | + ], | ||
| 32 | + ]); | ||
| 33 | + $key = $path.'/'.$filename; | ||
| 34 | + $cosClient->putObject([ | ||
| 35 | + 'Bucket' => $cos['bucket'], | ||
| 36 | + 'Key' => $key, | ||
| 37 | + 'Body' => fopen($files->getRealPath(), 'r'), | ||
| 38 | + ]); | ||
| 39 | + return $key; | ||
| 40 | + } | ||
| 41 | + | ||
| 42 | + /** | ||
| 43 | + * @param $image_name | ||
| 44 | + * @remark :获取图片访问链接 | ||
| 45 | + * @name :getImageUrl | ||
| 46 | + * @author :lyh | ||
| 47 | + * @method :post | ||
| 48 | + * @time :2023/7/19 16:08 | ||
| 49 | + */ | ||
| 50 | + public function getImageUrl($image_name) | ||
| 51 | + { | ||
| 52 | + $cos = config('filesystems.disks.cos'); | ||
| 53 | + $cosClient = new Client([ | ||
| 54 | + 'region' => $cos['region'], | ||
| 55 | + 'credentials' => [ | ||
| 56 | + 'secretId' => $cos['credentials']['secretId'], | ||
| 57 | + 'secretKey' => $cos['credentials']['secretKey'], | ||
| 58 | + ], | ||
| 59 | + ]); | ||
| 60 | + $imageUrl = $cosClient->getObjectUrl(config('app.cos_bucket'), basename($image_name)); | ||
| 61 | + return response()->json([ | ||
| 62 | + 'image_url' => $imageUrl, | ||
| 63 | + ]); | ||
| 64 | + } | ||
| 65 | +} |
| @@ -86,7 +86,12 @@ Route::middleware(['aloginauth'])->group(function () { | @@ -86,7 +86,12 @@ Route::middleware(['aloginauth'])->group(function () { | ||
| 86 | Route::any('/delete', [Aside\Manage\MenuController::class, 'delete'])->name('admin.menu_delete'); | 86 | Route::any('/delete', [Aside\Manage\MenuController::class, 'delete'])->name('admin.menu_delete'); |
| 87 | Route::any('/routes', [Aside\Manage\MenuController::class, 'routes'])->name('admin.menu_routes'); | 87 | Route::any('/routes', [Aside\Manage\MenuController::class, 'routes'])->name('admin.menu_routes'); |
| 88 | }); | 88 | }); |
| 89 | - | 89 | + //人事 |
| 90 | + Route::prefix('hr')->group(function () { | ||
| 91 | + Route::any('/', [Aside\Manage\HrController::class, 'list'])->name('admin.hr'); | ||
| 92 | + Route::any('/info', [Aside\Manage\HrController::class, 'info'])->name('admin.hr_info'); | ||
| 93 | + Route::any('/save', [Aside\Manage\HrController::class, 'save'])->name('admin.hr_save'); | ||
| 94 | + }); | ||
| 90 | //权限组 | 95 | //权限组 |
| 91 | Route::prefix('group')->group(function () { | 96 | Route::prefix('group')->group(function () { |
| 92 | Route::get('/', [Aside\Manage\GroupController::class, 'list'])->name('admin.group'); | 97 | Route::get('/', [Aside\Manage\GroupController::class, 'list'])->name('admin.group'); |
-
请 注册 或 登录 后发表评论