mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-13 11:21:07 +03:30
change export download way
This commit is contained in:
@@ -3,13 +3,36 @@
|
|||||||
namespace App\Http\Controllers;
|
namespace App\Http\Controllers;
|
||||||
|
|
||||||
use App\Models\Cycle;
|
use App\Models\Cycle;
|
||||||
|
use App\Models\FakeModel;
|
||||||
use App\Models\Item;
|
use App\Models\Item;
|
||||||
use App\Models\Package;
|
use App\Models\Package;
|
||||||
use App\Services\ExportCollection;
|
use App\Services\ExportCollection;
|
||||||
|
use App\Services\Responser;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use Illuminate\Support\Facades\Storage;
|
||||||
|
|
||||||
class ExportController extends Controller
|
class ExportController extends Controller
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private function sendToS3($export){
|
||||||
|
$fakeModel = FakeModel::firstOrCreate(['batch_id' => Str::random(6)]);
|
||||||
|
|
||||||
|
$tempFileName = 'excel_' . Str::random(10) . '.xlsx';
|
||||||
|
$tempDir = 'temp';
|
||||||
|
Storage::makeDirectory($tempDir);
|
||||||
|
$tempFilePath = $tempDir . '/' . $tempFileName;
|
||||||
|
|
||||||
|
Excel::store($export, $tempFilePath, 'local', \Maatwebsite\Excel\Excel::XLSX);
|
||||||
|
|
||||||
|
$media = $fakeModel->addMedia(storage_path('app/' . $tempFilePath))->toMediaCollection('temp_medias');
|
||||||
|
|
||||||
|
// اگه مشکلی پیش نمیاد بعد از این مرحله بالایی فیک مدل رو هم حذف کن که دیتابیس شلوغ نشه
|
||||||
|
|
||||||
|
Storage::delete($tempFilePath);
|
||||||
|
return $media;
|
||||||
|
}
|
||||||
|
|
||||||
public function items()
|
public function items()
|
||||||
{
|
{
|
||||||
$Items = Item::with( [ 'user' => function ( $query ) {
|
$Items = Item::with( [ 'user' => function ( $query ) {
|
||||||
@@ -67,8 +90,17 @@ class ExportController extends Controller
|
|||||||
'نام بیمارستان',
|
'نام بیمارستان',
|
||||||
'اخرین انتقال'
|
'اخرین انتقال'
|
||||||
] );
|
] );
|
||||||
|
|
||||||
$export = new ExportCollection( $Items );
|
$export = new ExportCollection( $Items );
|
||||||
return Excel::download( $export , 'items.xlsx' , null , [ \Maatwebsite\Excel\Excel::XLSX ] );
|
$media = $this->sendToS3($export);
|
||||||
|
|
||||||
|
return response()->json(
|
||||||
|
Responser::success(
|
||||||
|
'خروجی اکسل',
|
||||||
|
null,
|
||||||
|
['id' => $media->id, 'url' => $media->getUrl()]
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function packages()
|
public function packages()
|
||||||
@@ -122,7 +154,14 @@ class ExportController extends Controller
|
|||||||
'اخرین انتقال'
|
'اخرین انتقال'
|
||||||
] );
|
] );
|
||||||
$export = new ExportCollection( $Packages );
|
$export = new ExportCollection( $Packages );
|
||||||
return Excel::download( $export , 'packages.xlsx' , null , [ \Maatwebsite\Excel\Excel::XLSX ] );
|
$media = $this->sendToS3($export);
|
||||||
|
return response()->json(
|
||||||
|
Responser::success(
|
||||||
|
'خروجی اکسل',
|
||||||
|
null,
|
||||||
|
['id' => $media->id, 'url' => $media->getUrl()]
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function cycles()
|
public function cycles()
|
||||||
@@ -170,6 +209,16 @@ class ExportController extends Controller
|
|||||||
'نام بیمارستان',
|
'نام بیمارستان',
|
||||||
]);
|
]);
|
||||||
$export = new ExportCollection($cycles);
|
$export = new ExportCollection($cycles);
|
||||||
return Excel::download($export, 'cycles.xlsx', null, [\Maatwebsite\Excel\Excel::XLSX]);
|
|
||||||
|
$media = $this->sendToS3($export);
|
||||||
|
|
||||||
|
return response()->json(
|
||||||
|
Responser::success(
|
||||||
|
'خروجی اکسل',
|
||||||
|
null,
|
||||||
|
['id' => $media->id, 'url' => $media->getUrl()]
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user