cqp 11 сар өмнө
parent
commit
54651ef29a

+ 11 - 3
app/Http/Controllers/Api/FileUploadController.php

@@ -1,11 +1,8 @@
 <?php
 namespace App\Http\Controllers\Api;
 
-use App\Exports\MyExport;
 use App\Service\FileUploadService;
-use App\Service\OssService;
 use Illuminate\Http\Request;
-use PhpOffice\PhpSpreadsheet\Calculation\Statistical\Distributions\F;
 
 //文件上传
 class FileUploadController extends BaseController
@@ -21,6 +18,17 @@ class FileUploadController extends BaseController
         }
     }
 
+    public function uploadFileForKq(Request $request){
+        $service = new FileUploadService();
+        list($status,$data) = $service->uploadFileForKq($request->file('file'));
+
+        if($status){
+            return $this->json_return(200,'上传成功',['url' => $data]);
+        }else{
+            return $this->json_return(201,$data);
+        }
+    }
+
     //获取文件的位置预览(临时文件)
     public function getFile($file_name){
         $file_name = str_replace(FileUploadService::string2,'',$file_name);

+ 2 - 1
app/Service/EmployeeService.php

@@ -88,6 +88,7 @@ class EmployeeService extends Service
             $model->state = empty($data['leave_time']) ? Employee::USE : Employee::NOT_USE;
             $model->is_admin = $data['is_admin'];
             $model->account = $data['number'];
+            $model->pic = $data['pic'] ?? "";
             if($model->is_admin == 1){
                 if($data['password'] !== '******'){
                     $model->password   = Hash::make($data['password']);
@@ -157,7 +158,7 @@ class EmployeeService extends Service
             $model->account = $data['number'];
             $model->sex = $data['sex']??'男';
             $model->birth_date = $data['birth_date']??'';
-            $model->pic = $data['pic']??'';
+            $model->pic = $data['pic'] ?? '';
             if($model->is_admin == 1){
                 if($data['password'] !== '********'){
                     $model->password = Hash::make($data['password']);

+ 29 - 4
app/Service/FileUploadService.php

@@ -19,10 +19,35 @@ class FileUploadService extends Service
         'xlsx',
         'xls'
     ];
-    const tmp_dir = 'upload_occ';
-    const string = '/api/uploadFiles/';
-    const string2 = 't9|';
-    const string3 = 't9/';
+    const tmp_dir = 'kq';
+    const string = '/image/';
+    const string2 = 'qy|';
+    const string3 = 'qy/';
+
+    public function uploadFileForKq($file){
+        if(empty($file)) return [false, '请上传文件'];
+        // 获取文件相关信息
+        $ext = $file->getClientOriginalExtension();     // 扩展名
+        $realPath = $file->getRealPath();   //临时文件的绝对路径
+
+        $ext = strtolower($ext);
+        if (! in_array($ext, self::FILE_TYPE)){
+            $str = '文件格式为:';
+            foreach (self::FILE_TYPE as $value){
+                $str.= $value . ' ' ;
+            }
+            return [false,$str];
+        }
+
+        //文件名
+        $file_name = date("Ymd").time().rand(1000,9999);
+        $filename =  $file_name . '.' . $ext;
+
+        $dir = self::tmp_dir . '/' . $filename;
+        Storage::disk('public')->put($dir, file_get_contents($realPath));
+
+        return [true, self::string . $filename];
+    }
 
     public function uploadFile($file){
         if(empty($file)) return [false, '请上传文件'];

+ 8 - 0
routes/api.php

@@ -27,6 +27,9 @@ Route::any('uploadFiles/{file_name}', 'Api\FileUploadController@getFile');
 Route::any('getExport/{file_name}','Api\SysMenuController@getExport');
 
 Route::group(['middleware'=> ['checkLogin']],function ($route){
+    //文件上传统一方法
+    $route->any('uploadFile', 'Api\FileUploadController@uploadFile');
+    $route->any('uploadFileForKq', 'Api\FileUploadController@uploadFileForKq');
 
     $route->any('menuAdd', 'Api\SysMenuController@add');
     $route->any('menuEdit', 'Api\SysMenuController@edit');
@@ -46,6 +49,11 @@ Route::group(['middleware'=> ['checkLogin']],function ($route){
     $route->any('departDel', 'Api\EmployeeController@departDel');
     $route->any('departList', 'Api\EmployeeController@departList');
 
+    $route->any('employeeAdd', 'Api\EmployeeController@employeeAdd');
+    $route->any('employeeEdit', 'Api\EmployeeController@employeeEdit');
+    $route->any('employeeEditOther', 'Api\EmployeeController@employeeEditOther');
+    $route->any('employeeDel', 'Api\EmployeeController@employeeDel');
+    $route->any('employeeList', 'Api\EmployeeController@employeeList');
 
     $route->any('kqList', 'Api\KqController@kqCollect');
     $route->any('kqCollect', 'Api\KqController@kqCollect');

+ 1 - 1
routes/device.php

@@ -18,7 +18,7 @@ Route::any('/request/addperson', 'Api\DeviceController@addperson');
 //获取人脸图片地址
 Route::any('/capture', 'Api\DeviceController@capture');
 Route::get('/image/{filename}', function ($filename) {
-    $path = storage_path('app/public/' . $filename);
+    $path = storage_path('app/public/kq/' . $filename);
     $path = $path.'.jpg';
     if (!File::exists($path)) {
         abort(404);