From fbe9a80577e3bc7e30c56505680ababffa2365e2 Mon Sep 17 00:00:00 2001 From: evoxwht <442384644@qq.com> Date: Tue, 13 Jun 2023 16:52:39 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../adminapi/controller/PublicController.php | 28 +++++++++++++++++++ .../controller/v1/file/SystemAttachment.php | 15 ++++++++++ crmeb/app/adminapi/route/file.php | 3 ++ crmeb/app/adminapi/route/route.php | 4 +++ 4 files changed, 50 insertions(+) diff --git a/crmeb/app/adminapi/controller/PublicController.php b/crmeb/app/adminapi/controller/PublicController.php index 312ee8c1b..854fec012 100644 --- a/crmeb/app/adminapi/controller/PublicController.php +++ b/crmeb/app/adminapi/controller/PublicController.php @@ -12,6 +12,8 @@ namespace app\adminapi\controller; +use app\Request; +use app\services\system\attachment\SystemAttachmentServices; use crmeb\services\CacheService; use think\Response; @@ -44,4 +46,30 @@ class PublicController { return app('json')->success(getWorkerManUrl()); } + + /** + * 扫码上传 + * @param Request $request + * @param int $upload_type + * @param int $type + * @return Response + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/06/13 + */ + public function scanUpload(Request $request, $upload_type = 0, $type = 0) + { + [$pid, $file, $menuName, $uploadToken] = $request->postMore([ + ['pid', 0], + ['file', 'file'], + ['menu_name', ''], + ['uploadToken', ''] + ], true); + $service = app()->make(SystemAttachmentServices::class); + if ($service->cacheDriver()->get('scan_upload') != $uploadToken) { + return app('json')->fail(410086); + } + $service->upload((int)$pid, $file, $upload_type, $type, $menuName); + return app('json')->success(100032); + } } diff --git a/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php b/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php index 93742d5e1..ff95bf1b2 100644 --- a/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php +++ b/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php @@ -135,4 +135,19 @@ class SystemAttachment extends AuthController $res = $this->service->videoUpload($data, $_FILES['file']); return app('json')->success($res); } + + /** + * 获取扫码上传页面链接以及参数 + * @return \think\Response + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/06/13 + */ + public function scanUploadQrcode() + { + $uploadToken = md5(time()); + $this->service->cacheDriver()->set('scan_upload', $uploadToken, 600); + $url = sys_config('site_url') . '/app/upload?token=' . $uploadToken; + return app('json')->success(['url' => $url]); + } } diff --git a/crmeb/app/adminapi/route/file.php b/crmeb/app/adminapi/route/file.php index 78d4a4dff..71779227b 100644 --- a/crmeb/app/adminapi/route/file.php +++ b/crmeb/app/adminapi/route/file.php @@ -42,6 +42,9 @@ Route::group('file', function () { Route::get('upload_type', 'v1.file.SystemAttachment/uploadType')->option(['real_name' => '上传类型']); //分片上传本地视频 Route::post('video_upload', 'v1.file.SystemAttachment/videoUpload')->option(['real_name' => '分片上传本地视频']); + + //获取扫码上传页面链接以及参数 + Route::get('scan_upload/qrcode', 'v1.file.SystemAttachment/scanUploadQrcode')->option(['real_name' => '扫码上传页面链接']); })->middleware([ \app\http\middleware\AllowOriginMiddleware::class, \app\adminapi\middleware\AdminAuthTokenMiddleware::class, diff --git a/crmeb/app/adminapi/route/route.php b/crmeb/app/adminapi/route/route.php index bcb82d491..809f8b052 100644 --- a/crmeb/app/adminapi/route/route.php +++ b/crmeb/app/adminapi/route/route.php @@ -36,6 +36,10 @@ Route::group(function () { Route::get('get_workerman_url', 'PublicController/getWorkerManUrl')->option(['real_name' => '获取客服数据']); //测试 Route::get('index', 'Test/index')->option(['real_name' => '测试地址']); + + //扫码上传图片 + Route::post('image/scan_upload', 'PublicController/scanUpload')->name('ajcheck')->option(['real_name' => '一次验证']); + })->middleware(AllowOriginMiddleware::class)->option(['mark' => 'login', 'mark_name' => '登录相关']); /** From 34b7ad1b926d16d3a9d1462fc86cb3d5cb1b5ecd Mon Sep 17 00:00:00 2001 From: evoxwht <442384644@qq.com> Date: Tue, 13 Jun 2023 17:27:02 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E8=8E=B7=E5=8F=96=E6=89=AB=E7=A0=81?= =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E7=9A=84=E5=9B=BE=E7=89=87=E6=95=B0=E6=8D=AE?= =?UTF-8?q?=20=E8=8E=B7=E5=8F=96=E6=89=AB=E7=A0=81=E4=B8=8A=E4=BC=A0?= =?UTF-8?q?=E9=A1=B5=E9=9D=A2=E9=93=BE=E6=8E=A5=E4=BB=A5=E5=8F=8A=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../app/adminapi/controller/PublicController.php | 2 +- .../controller/v1/file/SystemAttachment.php | 13 +++++++++++++ crmeb/app/adminapi/route/file.php | 2 ++ .../system/attachment/SystemAttachmentDao.php | 16 ++++++++++++++++ .../attachment/SystemAttachmentServices.php | 4 +++- crmeb/public/install/crmeb.sql | 1 + 6 files changed, 36 insertions(+), 2 deletions(-) diff --git a/crmeb/app/adminapi/controller/PublicController.php b/crmeb/app/adminapi/controller/PublicController.php index 854fec012..bfeacc487 100644 --- a/crmeb/app/adminapi/controller/PublicController.php +++ b/crmeb/app/adminapi/controller/PublicController.php @@ -69,7 +69,7 @@ class PublicController if ($service->cacheDriver()->get('scan_upload') != $uploadToken) { return app('json')->fail(410086); } - $service->upload((int)$pid, $file, $upload_type, $type, $menuName); + $service->upload((int)$pid, $file, $upload_type, $type, $menuName, $uploadToken); return app('json')->success(100032); } } diff --git a/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php b/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php index ff95bf1b2..7ff5ef86b 100644 --- a/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php +++ b/crmeb/app/adminapi/controller/v1/file/SystemAttachment.php @@ -150,4 +150,17 @@ class SystemAttachment extends AuthController $url = sys_config('site_url') . '/app/upload?token=' . $uploadToken; return app('json')->success(['url' => $url]); } + + /** + * 获取扫码上传的图片数据 + * @param $scan_token + * @return \think\Response + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/06/13 + */ + public function scanUploadImage($scan_token) + { + return app('json')->success($this->service->scanUploadImage($scan_token)); + } } diff --git a/crmeb/app/adminapi/route/file.php b/crmeb/app/adminapi/route/file.php index 71779227b..f68a1b120 100644 --- a/crmeb/app/adminapi/route/file.php +++ b/crmeb/app/adminapi/route/file.php @@ -45,6 +45,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' => '获取扫码上传的图片数据']); })->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 b648d0bba..cfed3adfc 100644 --- a/crmeb/app/dao/system/attachment/SystemAttachmentDao.php +++ b/crmeb/app/dao/system/attachment/SystemAttachmentDao.php @@ -92,4 +92,20 @@ class SystemAttachmentDao extends BaseDao { $this->getModel()->whereTime('time', 'yesterday')->where('module_type', 2)->delete(); } + + /** + * 获取扫码上传的图片数据 + * @param $scan_token + * @return array + * @throws \think\db\exception\DataNotFoundException + * @throws \think\db\exception\DbException + * @throws \think\db\exception\ModelNotFoundException + * @author 吴汐 + * @email 442384644@qq.com + * @date 2023/06/13 + */ + public function scanUploadImage($scan_token) + { + return $this->getModel()->where('scan_token', $scan_token)->select()->toArray(); + } } diff --git a/crmeb/app/services/system/attachment/SystemAttachmentServices.php b/crmeb/app/services/system/attachment/SystemAttachmentServices.php index 2b1cb6ef7..affeae8c2 100644 --- a/crmeb/app/services/system/attachment/SystemAttachmentServices.php +++ b/crmeb/app/services/system/attachment/SystemAttachmentServices.php @@ -25,6 +25,7 @@ use app\services\other\UploadService; * @package app\services\attachment * @method getYesterday() 获取昨日生成数据 * @method delYesterday() 删除昨日生成数据 + * @method scanUploadImage($scan_token) 获取扫码上传的图片数据 */ class SystemAttachmentServices extends BaseServices { @@ -109,7 +110,7 @@ class SystemAttachmentServices extends BaseServices * @param int $type * @return mixed */ - public function upload(int $pid, string $file, int $upload_type, int $type, $menuName) + public function upload(int $pid, string $file, int $upload_type, int $type, $menuName, $uploadToken = '') { $realName = false; if ($upload_type == 0) { @@ -139,6 +140,7 @@ class SystemAttachmentServices extends BaseServices $data['module_type'] = 1; $data['time'] = $fileInfo['time'] ?? time(); $data['pid'] = $pid; + $data['scan_token'] = $uploadToken; $this->dao->save($data); } return $res->filePath; diff --git a/crmeb/public/install/crmeb.sql b/crmeb/public/install/crmeb.sql index 9428e5060..13fb23d75 100755 --- a/crmeb/public/install/crmeb.sql +++ b/crmeb/public/install/crmeb.sql @@ -29451,6 +29451,7 @@ CREATE TABLE IF NOT EXISTS `eb_system_attachment` ( `image_type` tinyint(1) UNSIGNED NOT NULL DEFAULT '1' COMMENT '图片上传类型 1本地 2七牛云 3OSS 4COS ', `module_type` tinyint(1) UNSIGNED NOT NULL DEFAULT '1' COMMENT '图片上传模块类型 1 后台上传 2 用户生成', `real_name` varchar(255) NOT NULL DEFAULT '' COMMENT '原始文件名', + `scan_token` varchar(32) NOT NULL DEFAULT '' COMMENT '扫码上传的token', PRIMARY KEY (`att_id`) USING BTREE ) ENGINE=InnoDB AUTO_INCREMENT=92 DEFAULT CHARSET=utf8 COMMENT='附件管理表';