diff --git a/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php b/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php index 7ff5ef86b..8dd44ce3a 100644 --- a/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php +++ b/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php @@ -163,4 +163,21 @@ class SystemAttachment extends AuthController { return app('json')->success($this->service->scanUploadImage($scan_token)); } + + /** + * 网络图片上传 + * @return \think\Response + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/06/13 + */ + public function onlineUpload() + { + $data = $this->request->postMore([ + ['pid', 0], + ['images', []] + ]); + $this->service->onlineUpload($data); + return app('json')->success(100032); + } } diff --git a/crmeb/app/adminapi/route/file.php b/crmeb/app/adminapi/route/file.php index f68a1b120..c6ad032d9 100644 --- a/crmeb/app/adminapi/route/file.php +++ b/crmeb/app/adminapi/route/file.php @@ -47,6 +47,8 @@ Route::group('file', function () { Route::get('scan_upload/qrcode', 'v1.file.SystemAttachment/scanUploadQrcode')->option(['real_name' => '扫码上传页面链接']); //获取扫码上传的图片数据 Route::get('scan_upload/image/:scan_token', 'v1.file.SystemAttachment/scanUploadImage')->option(['real_name' => '获取扫码上传的图片数据']); + //网络图片上传 + Route::post('online_upload', 'v1.file.SystemAttachment/onlineUpload')->option(['real_name' => '网络图片上传']); })->middleware([ \app\http\middleware\AllowOriginMiddleware::class, \app\adminapi\middleware\AdminAuthTokenMiddleware::class, diff --git a/crmeb/app/dao/system/attachment/SystemAttachmentDao.php b/crmeb/app/dao/system/attachment/SystemAttachmentDao.php index cfed3adfc..561fec633 100644 --- a/crmeb/app/dao/system/attachment/SystemAttachmentDao.php +++ b/crmeb/app/dao/system/attachment/SystemAttachmentDao.php @@ -106,6 +106,6 @@ class SystemAttachmentDao extends BaseDao */ public function scanUploadImage($scan_token) { - return $this->getModel()->where('scan_token', $scan_token)->select()->toArray(); + return $this->getModel()->where('scan_token', $scan_token)->field('att_dir,att_id')->select()->toArray(); } } diff --git a/crmeb/app/services/system/attachment/SystemAttachmentServices.php b/crmeb/app/services/system/attachment/SystemAttachmentServices.php index affeae8c2..7ee49f2ec 100644 --- a/crmeb/app/services/system/attachment/SystemAttachmentServices.php +++ b/crmeb/app/services/system/attachment/SystemAttachmentServices.php @@ -14,6 +14,7 @@ namespace app\services\system\attachment; use app\services\BaseServices; use app\dao\system\attachment\SystemAttachmentDao; +use app\services\product\product\CopyTaobaoServices; use crmeb\exceptions\AdminException; use crmeb\exceptions\ApiException; use crmeb\exceptions\UploadException; @@ -284,4 +285,54 @@ class SystemAttachmentServices extends BaseServices } return $res; } + + /** + * 网络图片上传 + * @param $data + * @return bool + * @throws \Exception + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/06/13 + */ + public function onlineUpload($data) + { + //生成附件目录 + if (make_path('attach', 3, true) === '') { + throw new AdminException(400555); + } + + //上传图片 + /** @var SystemAttachmentServices $systemAttachmentService */ + $systemAttachmentService = app()->make(SystemAttachmentServices::class); + $siteUrl = sys_config('site_url'); + + foreach ($data['images'] as $image) { + $uploadValue = app()->make(CopyTaobaoServices::class)->downloadImage($image); + if (is_array($uploadValue)) { + //TODO 拼接图片地址 + if ($uploadValue['image_type'] == 1) { + $imagePath = $siteUrl . $uploadValue['path']; + } else { + $imagePath = $uploadValue['path']; + } + //写入数据库 + if (!$uploadValue['is_exists']) { + $systemAttachmentService->save([ + 'name' => $uploadValue['name'], + 'real_name' => $uploadValue['name'], + 'att_dir' => $imagePath, + 'satt_dir' => $imagePath, + 'att_size' => $uploadValue['size'], + 'att_type' => $uploadValue['mime'], + 'image_type' => $uploadValue['image_type'], + 'module_type' => 1, + 'time' => time(), + 'pid' => $data['pid'] + ]); + } + } + } + return true; + } }