Kirin 2 months ago
parent
commit
3381cc8be0

+ 15 - 1
app/controller/admin/system/attachment/SystemAttachment.php

@@ -14,6 +14,8 @@ use app\common\AdminBaseController;
 use app\Request;
 use app\services\system\attachment\SystemAttachmentServices;
 use app\services\system\admin\SystemAdminServices;
+use Exception;
+use qiniu\services\UploadService;
 use qiniu\services\CacheService;
 use think\db\exception\DataNotFoundException;
 use think\db\exception\DbException;
@@ -162,7 +164,7 @@ class SystemAttachment extends AdminBaseController
 
     /**网络图片上传
      * @return Response
-     * @throws \Exception
+     * @throws Exception
      */
     public function onlineUpload()
     {
@@ -173,4 +175,16 @@ class SystemAttachment extends AdminBaseController
         $this->service->onlineUpload($data);
         return app('json')->success('上传完成');
     }
+
+    /**
+     * 获取视频上传token
+     * @return mixed
+     * @throws Exception
+     */
+    public function getTempKeys()
+    {
+        $upload = UploadService::init();
+        $re = $upload->getTempKeys();
+        return $re ? $this->success($re) : $this->error($upload->getError());
+    }
 }

+ 1 - 1
app/controller/admin/system/attachment/SystemAttachmentCategory.php

@@ -34,7 +34,7 @@ class SystemAttachmentCategory extends AdminBaseController
         $this->service = $service;
         $this->searchable = [
             ['name', ''],
-            ['pid', 0],
+            ['pid', ''],
             ['file_type', 1],
         ];
         $this->searchDeal = function (&$data) {

+ 7 - 6
app/controller/admin/system/config/SystemConfig.php

@@ -93,17 +93,18 @@ class SystemConfig extends AdminBaseController
         if ($data['config_tab_id']) $data['config_tab_id'] = end($data['config_tab_id']);
         if (!$data['info']) return $this->error('请输入配置名称');
         if (!$data['menu_name']) return $this->error('请输入字段名称');
+        if ($this->service->be(['menu_name' => $data['menu_name']])) return $this->error('字段名已存在');
         if (!$data['desc']) return $this->error('请输入配置简介');
         if ($data['sort'] < 0) {
             $data['sort'] = 0;
         }
         $data['value'] = json_encode($data['value']);
-        $config = $this->service->getOne(['menu_name' => $data['menu_name']]);
-        if ($config) {
-            $this->service->update($config['id'], $data, 'id');
-        } else {
-            $this->service->create($data);
-        }
+//        $config = $this->service->getOne(['menu_name' => $data['menu_name']]);
+//        if ($config) {
+//            $this->service->update($config['id'], $data, 'id');
+//        } else {
+        $this->service->create($data);
+//        }
         event('config.create', [$data]);
         return $this->success('添加配置成功!');
     }

+ 1 - 5
app/services/system/attachment/SystemAttachmentCategoryServices.php

@@ -46,11 +46,7 @@ class SystemAttachmentCategoryServices extends BaseServices
     public function getAll(array $where)
     {
         $list = $this->getList($where);
-        foreach ($list as &$item) {
-            $item['title'] = $item['name'];
-            $item['children'] = [];
-            if ($where['name'] == '' && $this->getCount(['pid' => $item['id'], 'file_type' => $where['file_type']])) $item['loading'] = false;
-        }
+        $list = get_tree_children($list);
         return compact('list');
     }
 

+ 12 - 2
app/services/system/config/SystemConfigServices.php

@@ -54,8 +54,18 @@ class SystemConfigServices extends BaseServices implements ServeConfigInterface
             $service = app()->make(SystemStoreConfigServices::class);
             return $service->getConfig($configName, $store_id);
         } else {//平台
-            $value = $this->search(['menu_name' => $configName])->value('value');
-            return is_null($value) ? $default : json_decode($value, true);
+            $info = $this->search(['menu_name' => $configName])->find();
+            $value = $info['value'];
+            $type = $info['type'];
+            $detail = $info['configuration'];
+            $value = is_null($value) ? $default : json_decode($value, true);
+            if ($type == 'Upload' && !empty($value)) {
+                $value = set_file_url($value);
+                if ($detail['upload_type'] != 2) {
+                    $value = $value[0] ?? $default;
+                }
+            }
+            return $value;
         }
     }
 

+ 1 - 1
qiniu/services/upload/storage/Cos.php

@@ -14,7 +14,7 @@ use qiniu\basic\BaseUpload;
 use qiniu\exceptions\UploadException;
 use GuzzleHttp\Psr7\Utils;
 use think\exception\ValidateException;
-use QCloud\COSSTS\Sts;
+use qiniu\services\upload\extend\cos\Sts;
 use qiniu\services\upload\extend\cos\Client as CosClient;
 
 /**

+ 37 - 34
qiniu/services/upload/storage/Local.php

@@ -127,15 +127,18 @@ class Local extends BaseUpload
                 return $this->setError($e->getMessage());
             }
         }
-//		$stream = fopen($fileHandle->getPathname(), 'r');
-//		$content = (fread($stream, filesize($fileHandle->getPathname())));
-//		if (is_resource($stream)) {
-//			fclose($stream);
-//		}
-//		if (preg_match('/think|php|log|phar|Socket|Channel|Flysystem|Psr6Cache|Cached|Request|debug|Psr6Cachepool|eval/i', $content)) {
-//			return $this->setError('文件内容不合法');
-//		}
-		$fileType = pathinfo($fileHandle->getOriginalName(), PATHINFO_EXTENSION);
+        if(!$this->checkImage($fileHandle)) {
+            $stream = fopen($fileHandle->getPathname(), 'r');
+            $content = (fread($stream, filesize($fileHandle->getPathname())));
+            if (is_resource($stream)) {
+                fclose($stream);
+            }
+            if (preg_match('/think|php|log|phar|Socket|Channel|Flysystem|Psr6Cache|Cached|Request|debug|Psr6Cachepool|eval/i', $content)) {
+                return $this->setError('文件内容不合法');
+            }
+        }
+        $fileType = pathinfo($fileHandle->getOriginalName(), PATHINFO_EXTENSION);
+
         $fileName = Filesystem::putFileAs($this->path, $fileHandle, in_array($fileType, ['ico']) ? $fileHandle->getOriginalName() : strtolower($fileHandle->hashName()));
 
         if (!$fileName)
@@ -239,12 +242,12 @@ class Local extends BaseUpload
                             $savePath = $this->createSaveFilePath($filePath, $this->thumbWaterPath, [$height => $config[$height], $width => $config[$width]]);
                             //防止重复生成
                             if (!file_exists(root_path() . 'public' . $savePath)) {
-								if ($this->authThumb) {//生成
-									$Image = Image::open(app()->getRootPath() . 'public' . $filePath);
-                                	$Image->thumb($config[$width], $config[$height])->save(root_path() . 'public' . $savePath);
-								} else {
-									$savePath = $filePath;
-								}
+                                if ($this->authThumb) {//生成
+                                    $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
+                                    $Image->thumb($config[$width], $config[$height])->save(root_path() . 'public' . $savePath);
+                                } else {
+                                    $savePath = $filePath;
+                                }
                             }
                             $key = 'filePath' . ucfirst($v);
                             $data[$v] = $this->fileInfo->$key = $savePath;
@@ -327,12 +330,12 @@ class Local extends BaseUpload
         }
         try {
             if (!file_exists(root_path() . 'public' . $waterPath)) {
-				if ($this->authThumb) {//生成
-					$Image = Image::open(app()->getRootPath() . 'public' . $filePath);
-					$Image->water(app()->getRootPath() . 'public' . $watermark_image, $waterConfig['watermark_position'] ?: 1, $waterConfig['watermark_opacity'])->save(root_path() . 'public' . $waterPath);
-				} else {
-					$waterPath = $filePath;
-				}
+                if ($this->authThumb) {//生成
+                    $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
+                    $Image->water(app()->getRootPath() . 'public' . $watermark_image, $waterConfig['watermark_position'] ?: 1, $waterConfig['watermark_opacity'])->save(root_path() . 'public' . $waterPath);
+                } else {
+                    $waterPath = $filePath;
+                }
             }
         } catch (\Throwable $e) {
             throw new ValidateException($e->getMessage());
@@ -361,19 +364,19 @@ class Local extends BaseUpload
         }
         try {
             if (!file_exists(root_path() . 'public' . $waterPath)) {
-				if ($this->authThumb) {//生成
-					$Image = Image::open(app()->getRootPath() . 'public' . $filePath);
-					if (strlen($waterConfig['watermark_text_color']) < 7) {
-						$waterConfig['watermark_text_color'] = substr($waterConfig['watermark_text_color'], 1);
-						$waterConfig['watermark_text_color'] = '#' . $waterConfig['watermark_text_color'] . $waterConfig['watermark_text_color'];
-					}
-					if (strlen($waterConfig['watermark_text_color']) > 7) {
-						$waterConfig['watermark_text_color'] = substr($waterConfig['watermark_text_color'], 0, 7);
-					}
-					$Image->text($waterConfig['watermark_text'], $waterConfig['watermark_text_font'], $waterConfig['watermark_text_size'], $waterConfig['watermark_text_color'], $waterConfig['watermark_position'], [$waterConfig['watermark_x'], $waterConfig['watermark_y'], $waterConfig['watermark_text_angle']])->save(root_path() . 'public' . $waterPath);
-				} else {
-					$waterPath = $filePath;
-				}
+                if ($this->authThumb) {//生成
+                    $Image = Image::open(app()->getRootPath() . 'public' . $filePath);
+                    if (strlen($waterConfig['watermark_text_color']) < 7) {
+                        $waterConfig['watermark_text_color'] = substr($waterConfig['watermark_text_color'], 1);
+                        $waterConfig['watermark_text_color'] = '#' . $waterConfig['watermark_text_color'] . $waterConfig['watermark_text_color'];
+                    }
+                    if (strlen($waterConfig['watermark_text_color']) > 7) {
+                        $waterConfig['watermark_text_color'] = substr($waterConfig['watermark_text_color'], 0, 7);
+                    }
+                    $Image->text($waterConfig['watermark_text'], $waterConfig['watermark_text_font'], $waterConfig['watermark_text_size'], $waterConfig['watermark_text_color'], $waterConfig['watermark_position'], [$waterConfig['watermark_x'], $waterConfig['watermark_y'], $waterConfig['watermark_text_angle']])->save(root_path() . 'public' . $waterPath);
+                } else {
+                    $waterPath = $filePath;
+                }
             }
         } catch (\Throwable $e) {
             throw new ValidateException($e->getMessage() . $e->getLine());

+ 2 - 0
route/admin.php

@@ -110,6 +110,8 @@ Route::group('adminapi', function () {
                 Route::put('update/:id', 'system.attachment.SystemAttachment/update')->option(['real_name' => '修改图片名称']);
                 //上传图片
                 Route::post('upload/[:upload_type]', 'system.attachment.SystemAttachment/upload')->option(['real_name' => '上传图片']);
+                //获取上传key
+                Route::get('temp_key', 'system.attachment.SystemAttachment/getTempKeys')->option(['real_name' => '获取上传key']);
                 //分片上传本地视频
                 Route::post('video_upload', 'system.attachment.SystemAttachment/videoUpload')->option(['real_name' => '分片上传本地视频']);
                 //oss视频素材保存