|
|
@@ -5,9 +5,13 @@ namespace App\Services;
|
|
|
use App\Models\Order;
|
|
|
use Exception;
|
|
|
use Illuminate\Support\Facades\Storage;
|
|
|
+use Illuminate\Support\Str;
|
|
|
|
|
|
class GenerateDocumentsService
|
|
|
{
|
|
|
+ const INSTALL_FILENAME = 'Монт аж_';
|
|
|
+ const HANDOVER_FILENAME = 'Сдача_';
|
|
|
+
|
|
|
/**
|
|
|
* @param Order $order
|
|
|
* @param int $userId
|
|
|
@@ -16,23 +20,32 @@ class GenerateDocumentsService
|
|
|
*/
|
|
|
public function generateInstallationPack(Order $order, int $userId): string
|
|
|
{
|
|
|
+ $techDocsPath = base_path('/tech-docs/');
|
|
|
$products_sku = $order->products_sku;
|
|
|
$articles = [];
|
|
|
- Storage::disk('public')->makeDirectory('orders/' . $order->id . '/installation/Схемы сборки');
|
|
|
+ Storage::disk('public')->makeDirectory('orders/' . $order->id . '/tmp/Схемы сборки');
|
|
|
foreach ($products_sku as $sku) {
|
|
|
if(!in_array($sku->product->article, $articles)) {
|
|
|
$articles[] = $sku->product->article;
|
|
|
// find and copy scheme files to installation directory
|
|
|
- // ...
|
|
|
+ if(file_exists($techDocsPath . $sku->product->article . '/')) {
|
|
|
+ foreach(Storage::disk('base')->allFiles('tech-docs/' . $sku->product->article) as $p) {
|
|
|
+ $content = Storage::disk('base')->get($p);
|
|
|
+ Storage::disk('public')->put('orders/' . $order->id . '/tmp/Схемы сборки/' . basename($p), $content);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
// generate xlsx order file
|
|
|
// ...
|
|
|
-
|
|
|
// create zip archive
|
|
|
- $fileModel = (new FileService())->createZipArchive('orders/' . $order->id . '/installation', 'Installation-' . $order->id . '.zip', $userId);
|
|
|
+ $fileModel = (new FileService())->createZipArchive('orders/' . $order->id . '/tmp', self::INSTALL_FILENAME . $order->common_name . '.zip', $userId);
|
|
|
+
|
|
|
+ // remove temp files
|
|
|
+ Storage::disk('public')->deleteDirectory('orders/' . $order->id . '/tmp');
|
|
|
+ $order->documents()->syncWithoutDetaching($fileModel);
|
|
|
|
|
|
- // create link
|
|
|
+ // return link
|
|
|
return $fileModel->link;
|
|
|
|
|
|
|