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,59 @@
<?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\Income;
final readonly class IncomesSyncService 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 [
'income_id' => $row['income_id'],
'number' => $row['number'],
'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'],
'total_price' => $row['total_price'],
'date_close' => $row['date_close'],
'warehouse_name' => $row['warehouse_name'],
'nm_id' => $row['nm_id'],
'created_at' => now(),
'updated_at' => now(),
];
})->toArray();
Income::insert($rows);
});
}
}

View File

@@ -0,0 +1,74 @@
<?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\Order;
final readonly class OrdersSyncService 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 [
'g_number' => $row['g_number'],
'date' => !empty($row['date']) ? $row['date'] : now(),
'last_change_date' => $row['last_change_date'],
'supplier_article' => $row['supplier_article'],
'tech_size' => $row['tech_size'],
'barcode' => (int)$row['barcode'],
'total_price' => $row['total_price'],
'discount_percent' => $row['discount_percent'],
'warehouse_name' => $row['warehouse_name'],
'oblast' => $row['oblast'],
'income_id' => $row['income_id'],
'odid' => (int)$row['odid'],
'nm_id' => $row['nm_id'],
'subject' => $row['subject'],
'category' => $row['category'],
'brand' => $row['brand'],
'is_cancel' => $row['is_cancel'],
'cancel_dt' => $row['cancel_dt'],
'created_at' => now(),
'updated_at' => now(),
];
})->toArray();
try {
Order::insert($rows);
} catch (\Throwable $e) {
\Log::error('Insert failed', [
'error' => $e->getMessage(),
'row_sample' => $rows[0] ?? null,
]);
throw $e;
}
});
}
}

View File

@@ -0,0 +1,74 @@
<?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\Sale;
final readonly class SalesSyncService 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 [
'g_number' => $row['g_number'],
'date' => $row['date'],
'last_change_date' => $row['last_change_date'],
'supplier_article' => $row['supplier_article'],
'tech_size' => $row['tech_size'],
'barcode' => (string)$row['barcode'],
'total_price' => $row['total_price'],
'discount_percent' => $row['discount_percent'],
'is_supply' => $row['is_supply'],
'is_realization' => $row['is_realization'],
'promo_code_discount' => $row['promo_code_discount'],
'warehouse_name' => $row['warehouse_name'],
'country_name' => $row['country_name'],
'oblast_okrug_name' => $row['oblast_okrug_name'],
'region_name' => $row['region_name'],
'income_id' => $row['income_id'],
'sale_id' => $row['sale_id'],
'odid' => $row['odid'],
'spp' => $row['spp'],
'for_pay' => $row['for_pay'],
'finished_price' => $row['finished_price'],
'price_with_disc' => $row['price_with_disc'],
'nm_id' => $row['nm_id'],
'subject' => $row['subject'],
'category' => $row['category'],
'brand' => $row['brand'],
'is_storno' => $row['is_storno'],
'created_at' => now(),
'updated_at' => now(),
];
})->toArray();
Sale::insert($rows);
});
}
}

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
});
}
}