33namespace App \Http \Controllers \Api ;
44
55use App \Events \ApiExcelEvent ;
6- use App \Http \Repository \MultithreadingRepository ;
6+ use App \Http \Repository \ExcelRepository ;
77use App \Http \Requests \ApiExcel \Store ;
88use App \Http \Requests \ApiExcel \Update ;
99use App \Models \ApiExcel ;
1010use App \Http \Controllers \Controller ;
1111use Illuminate \Http \Request ;
1212use Illuminate \Support \Facades \Storage ;
13- use PhpOffice \PhpSpreadsheet \IOFactory ;
14- use PhpOffice \PhpSpreadsheet \Spreadsheet ;
1513
1614class ApiExcelController extends Controller
1715{
@@ -34,7 +32,7 @@ public function __construct(Request $request)
3432 // 这样的结果是,token 只能在有效期以内进行刷新,过期无法刷新
3533 // 如果把 refresh 也放进去,token 即使过期但仍在刷新期以内也可刷新
3634 // 不过刷新一次作废
37- $ this ->middleware (['auth:api ' , 'role ' ], ['except ' => ['upload ' ]]);
35+ $ this ->middleware (['auth:api ' , 'role ' ], ['except ' => ['login ' ]]);
3836 // 另外关于上面的中间件,官方文档写的是『auth:api』
3937 // 但是我推荐用 『jwt.auth』,效果是一样的,但是有更加丰富的报错信息返回
4038
@@ -265,4 +263,21 @@ public function forceDelete($id)
265263
266264 return $ this ->out (200 );
267265 }
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+ }
268283}
0 commit comments