first commit

This commit is contained in:
2026-02-15 01:34:17 +07:00
commit baac22e3ae
95 changed files with 13238 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
<?php
declare(strict_types=1);
namespace App\Services\WbService\SyncServices;
use App\Contracts\WbClientInterface;
use App\Contracts\WbSyncInterface;
use App\DTO\WbRequestDTO;
use App\Exceptions\WbServiceException;
use App\Models\Stock;
final readonly class StocksSyncService implements WbSyncInterface
{
public function __construct(
private WbClientInterface $client,
) {
}
/**
* @throws WbServiceException
*/
public function sync(WbRequestDTO $dto): array
{
return $this->client->fetch($dto);
}
public function save(array $data): void
{
if (empty($data)) {
return;
}
collect($data)
->chunk(500)
->each(function ($chunk) {
$rows = $chunk->map(function (array $row) {
return [
'date' => $row['date'],
'last_change_date' => $row['last_change_date'],
'supplier_article' => $row['supplier_article'],
'tech_size' => $row['tech_size'],
'barcode' => (string)$row['barcode'],
'quantity' => $row['quantity'],
'is_supply' => $row['is_supply'],
'is_realization' => $row['is_realization'],
'quantity_full' => $row['quantity_full'],
'warehouse_name' => $row['warehouse_name'],
'in_way_to_client' => $row['in_way_to_client'],
'in_way_from_client' => $row['in_way_from_client'],
'nm_id' => $row['nm_id'],
'subject' => $row['subject'],
'category' => $row['category'],
'brand' => $row['brand'],
'sc_code' => (string)$row['sc_code'],
'price' => $row['price'],
'discount' => $row['discount'],
'updated_at' => now(),
'created_at' => now(),
];
})->toArray();
Stock::insert($rows);// todo upsert
});
}
}