From 1f854b73f7d53b414bcaa297cd3ec4c39f99e09a Mon Sep 17 00:00:00 2001 From: gaofeng <1212121@qq.com> Date: Thu, 13 Aug 2026 10:09:22 +0800 Subject: [PATCH] =?UTF-8?q?=E6=8F=90=E4=BA=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/miniapi/controller/Upload.php | 31 ++++++++++++++++++++----------- route/app.php | 2 +- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/app/miniapi/controller/Upload.php b/app/miniapi/controller/Upload.php index 1b2817b..0c22684 100644 --- a/app/miniapi/controller/Upload.php +++ b/app/miniapi/controller/Upload.php @@ -21,37 +21,37 @@ class Upload extends Base $file = request()->file('file'); if (!$file) { - return $this->fail('请上传图片'); + return $this->uploadResponse(0, '请上传图片'); } $path = $file->getPathname(); if (!is_file($path)) { - return $this->fail('上传文件读取失败'); + return $this->uploadResponse(0, '上传文件读取失败'); } $size = filesize($path); if ($size === false || $size <= 0) { - return $this->fail('上传文件为空'); + return $this->uploadResponse(0, '上传文件为空'); } if ($size > 10 * 1024 * 1024) { - return $this->fail('图片不能超过10MB'); + return $this->uploadResponse(0, '图片不能超过10MB'); } $originalName = (string)($_FILES['file']['name'] ?? 'upload.jpg'); $ext = strtolower(pathinfo($originalName, PATHINFO_EXTENSION)); $ext = $ext === 'jpeg' ? 'jpg' : $ext; if (!in_array($ext, ['jpg', 'png', 'gif', 'webp', 'bmp'], true)) { - return $this->fail('请上传图片文件'); + return $this->uploadResponse(0, '请上传图片文件'); } $mime = function_exists('mime_content_type') ? (string)mime_content_type($path) : ''; if ($mime !== '' && strpos($mime, 'image/') !== 0) { - return $this->fail('请上传图片文件'); + return $this->uploadResponse(0, '请上传图片文件'); } $content = file_get_contents($path); if ($content === false || $content === '') { - return $this->fail('上传文件读取失败'); + return $this->uploadResponse(0, '上传文件读取失败'); } $fileName = date('YmdHis') . uniqid('', true) . '.' . $ext; @@ -72,16 +72,25 @@ class Upload extends Base $client->close(); if (!$sent) { - return $this->fail('上传失败,请重试'); + return $this->uploadResponse(0, '上传失败,请重试'); } $url = OSS_URL . $objectKey; - return $this->ok([ + return $this->uploadResponse(1, '上传成功', [ 'path' => $url, 'url' => $url, - ], '上传成功'); + ]); } catch (\Throwable $e) { - return $this->fail('上传失败,请重试'); + return $this->uploadResponse(0, '上传失败,请重试'); } } + + private function uploadResponse(int $code, string $msg, array $data = []) + { + return json([ + 'code' => $code, + 'msg' => $msg, + 'data' => $data, + ], 200, [], ['json_encode_param' => 0]); + } } diff --git a/route/app.php b/route/app.php index ef66615..29bde63 100644 --- a/route/app.php +++ b/route/app.php @@ -39,7 +39,7 @@ Route::group('miniapi', function () { Route::get('customer-center/orders', 'CustomerCenter/orders'); Route::post('customer-center/applicant/save', 'CustomerCenter/saveApplicant'); Route::post('customer-center/applicant/remove', 'CustomerCenter/removeApplicant'); - Route::post('customer-center/applicant', 'CustomerCenter/applicant'); + Route::post('customer-center/applicant', 'CustomerCenter/applicant')->completeMatch(); Route::get('ocr/signature', 'Ocr/signature'); Route::post('upload/image', 'Upload/image');