From 0e7598f30a3fc442181ed5c441ff68cac7aa121d Mon Sep 17 00:00:00 2001 From: liutong <836164388@qq.com> Date: Thu, 29 May 2025 14:24:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(upload):=20=E5=A2=9E=E5=8A=A0=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=9B=BE=E7=89=87=E6=97=B6=E6=90=BA=E5=B8=A6=E9=A2=9D?= =?UTF-8?q?=E5=A4=96=E5=8F=82=E6=95=B0=E7=9A=84=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 在 Upload 控制器中添加了 Request 参数,以便获取所有请求数据 - 在 UploadService 服务中,增加了处理额外数据的参数- 更新了 ChatService 中的消息列表查询,加入了关联查询 -修正了 ChatFriends 模型中的关联关系命名 --- niucloud/app/api/controller/upload/Upload.php | 8 ++++++-- niucloud/app/api/route/route.php | 2 +- niucloud/app/model/chat_friends/ChatFriends.php | 4 ++-- niucloud/app/service/api/apiService/ChatService.php | 7 ++++++- niucloud/app/service/api/upload/UploadService.php | 4 ++-- 5 files changed, 17 insertions(+), 8 deletions(-) diff --git a/niucloud/app/api/controller/upload/Upload.php b/niucloud/app/api/controller/upload/Upload.php index c5e422ff..1463faaf 100644 --- a/niucloud/app/api/controller/upload/Upload.php +++ b/niucloud/app/api/controller/upload/Upload.php @@ -15,6 +15,7 @@ use app\service\api\upload\Base64Service; use app\service\api\upload\FetchService; use app\service\api\upload\UploadService; use core\base\BaseApiController; +use think\Request; use think\Response; class Upload extends BaseApiController @@ -24,12 +25,15 @@ class Upload extends BaseApiController * 图片上传 * @return Response */ - public function image(){ + public function image(Request $request){ + + $extraData = $request->all(); + $data = $this->request->params([ ['file', 'file'], ]); $upload_service = new UploadService(); - return success($upload_service->image($data['file'])); + return success($upload_service->image($data['file'],$extraData)); } /** diff --git a/niucloud/app/api/route/route.php b/niucloud/app/api/route/route.php index 28a6e959..c639879e 100644 --- a/niucloud/app/api/route/route.php +++ b/niucloud/app/api/route/route.php @@ -201,7 +201,7 @@ Route::group(function () { //需要token验证的 Route::group(function () { - //上传图片 + //员工端-上传图片 Route::post('uploadImage', 'upload.Upload/image'); //员工端详情 Route::get('personnel/info', 'apiController.Personnel/info'); diff --git a/niucloud/app/model/chat_friends/ChatFriends.php b/niucloud/app/model/chat_friends/ChatFriends.php index 33d14738..37c74acc 100644 --- a/niucloud/app/model/chat_friends/ChatFriends.php +++ b/niucloud/app/model/chat_friends/ChatFriends.php @@ -80,8 +80,8 @@ class ChatFriends extends BaseModel } - public function campus(){ - return $this->hasOne(CustomerResources::class, 'id', 'customer_resources_id')->joinType('left')->withField('name,id')->bind(['customer_resources_id'=>'name']); + public function customer(){ + return $this->hasOne(CustomerResources::class, 'id', 'customer_resources_id')->joinType('left')->withField('name,id')->bind(['customer_resources_id_name'=>'name']); } public function personnel(){ diff --git a/niucloud/app/service/api/apiService/ChatService.php b/niucloud/app/service/api/apiService/ChatService.php index fb568558..c8ffa763 100644 --- a/niucloud/app/service/api/apiService/ChatService.php +++ b/niucloud/app/service/api/apiService/ChatService.php @@ -48,7 +48,12 @@ class ChatService extends BaseApiService $model = $model->where('customer_resources_id', $where['customer_resources_id']); } - $data = $model->paginate([ + $data = $model + ->with([ + 'personnel', + 'customer', + ]) + ->paginate([ 'list_rows' => $limit, 'page' => $page, ])->toArray(); diff --git a/niucloud/app/service/api/upload/UploadService.php b/niucloud/app/service/api/upload/UploadService.php index 30856447..b666bf47 100644 --- a/niucloud/app/service/api/upload/UploadService.php +++ b/niucloud/app/service/api/upload/UploadService.php @@ -34,9 +34,9 @@ class UploadService extends BaseApiService * @return array * @throws Exception */ - public function image($file) + public function image($file,array $extraData = []) { - $dir = $this->root_path . '/' . 'image' . '/' . date('Ym') . '/' . date('d'); + $dir = $this->root_path . '/' . 'image' . '/' . date('Ym') . '/' . date('d');//打印结果 例如=file/image/202505/29 $core_upload_service = new CoreUploadService(); return $core_upload_service->image($file, $dir, $this->cate_id); }