Browse Source

feat(upload): 增加上传图片时携带额外参数的功能

- 在 Upload 控制器中添加了 Request 参数,以便获取所有请求数据
- 在 UploadService 服务中,增加了处理额外数据的参数- 更新了 ChatService 中的消息列表查询,加入了关联查询
-修正了 ChatFriends 模型中的关联关系命名
master
liutong 10 months ago
parent
commit
0e7598f30a
  1. 8
      niucloud/app/api/controller/upload/Upload.php
  2. 2
      niucloud/app/api/route/route.php
  3. 4
      niucloud/app/model/chat_friends/ChatFriends.php
  4. 7
      niucloud/app/service/api/apiService/ChatService.php
  5. 4
      niucloud/app/service/api/upload/UploadService.php

8
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));
}
/**

2
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');

4
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(){

7
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();

4
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);
}

Loading…
Cancel
Save