Parcourir la source

Merge branch 'v5.1.0dev' of https://gitee.com/ZhongBangKeJi/CRMEB into v5.1.0dev

liaofei il y a 2 ans
Parent
commit
bd0665f9cb

+ 28 - 0
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, $uploadToken);
+        return app('json')->success(100032);
+    }
 }

+ 28 - 0
crmeb/app/adminapi/controller/v1/file/SystemAttachment.php

@@ -135,4 +135,32 @@ 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]);
+    }
+
+    /**
+     * 获取扫码上传的图片数据
+     * @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));
+    }
 }

+ 5 - 0
crmeb/app/adminapi/route/file.php

@@ -42,6 +42,11 @@ 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' => '扫码上传页面链接']);
+    //获取扫码上传的图片数据
+    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,

+ 4 - 0
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' => '登录相关']);
 
 /**

+ 16 - 0
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();
+    }
 }

+ 3 - 1
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;

+ 1 - 0
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='附件管理表';