3
3
namespace App \Http \Controllers \Api ;
4
4
5
5
use App \Events \ApiExcelEvent ;
6
- use App \Http \Repository \MultithreadingRepository ;
6
+ use App \Http \Repository \ExcelRepository ;
7
7
use App \Http \Requests \ApiExcel \Store ;
8
8
use App \Http \Requests \ApiExcel \Update ;
9
9
use App \Models \ApiExcel ;
10
10
use App \Http \Controllers \Controller ;
11
11
use Illuminate \Http \Request ;
12
12
use Illuminate \Support \Facades \Storage ;
13
- use PhpOffice \PhpSpreadsheet \IOFactory ;
14
- use PhpOffice \PhpSpreadsheet \Spreadsheet ;
15
13
16
14
class ApiExcelController extends Controller
17
15
{
@@ -34,7 +32,7 @@ public function __construct(Request $request)
34
32
// 这样的结果是,token 只能在有效期以内进行刷新,过期无法刷新
35
33
// 如果把 refresh 也放进去,token 即使过期但仍在刷新期以内也可刷新
36
34
// 不过刷新一次作废
37
- $ this ->middleware (['auth:api ' , 'role ' ], ['except ' => ['upload ' ]]);
35
+ $ this ->middleware (['auth:api ' , 'role ' ], ['except ' => ['login ' ]]);
38
36
// 另外关于上面的中间件,官方文档写的是『auth:api』
39
37
// 但是我推荐用 『jwt.auth』,效果是一样的,但是有更加丰富的报错信息返回
40
38
@@ -265,4 +263,21 @@ public function forceDelete($id)
265
263
266
264
return $ this ->out (200 );
267
265
}
266
+
267
+ public function downloadLog ()
268
+ {
269
+ $ api_excel_id = $ this ->request ->input ('id ' );
270
+ // 判断用户有没有下载权限
271
+ $ user_id = auth ('api ' )->user ()['id ' ];
272
+ // $user_id = 1;
273
+ $ failed_done_file = ExcelRepository::getInstent ()->exportExcelLogs ($ api_excel_id , $ user_id );
274
+ if ($ failed_done_file === false ) {
275
+ // 权限不足
276
+ return $ this ->out (4001 );
277
+ } elseif ($ failed_done_file === '' ) {
278
+ // 无可下载内容
279
+ return $ this ->out (4009 , [], '下载失败,无可下载内容 ' );
280
+ }
281
+ return $ this ->out (200 , ['failed_done_file ' => $ failed_done_file ]);
282
+ }
268
283
}
0 commit comments