51 lines
1.8 KiB
PHP
51 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Services\Wb\WbSyncService;
|
|
use Illuminate\Console\Command;
|
|
|
|
class SyncWbDataCommand extends Command
|
|
{
|
|
protected $signature = 'wb:sync
|
|
{--endpoint= : Endpoint: sales, orders, incomes, stocks. Empty means all.}
|
|
{--from= : Period start date YYYY-MM-DD for sales/orders/incomes.}
|
|
{--to= : Period end date YYYY-MM-DD for sales/orders/incomes.}
|
|
{--stocks-date= : Date YYYY-MM-DD for stocks.}';
|
|
|
|
protected $description = 'Load WB API data into MySQL tables';
|
|
|
|
public function handle(WbSyncService $syncService): int
|
|
{
|
|
$from = (string) ($this->option('from') ?: '2024-01-01');
|
|
$to = (string) ($this->option('to') ?: now()->toDateString());
|
|
$stocksDate = (string) ($this->option('stocks-date') ?: now()->toDateString());
|
|
$endpoint = $this->option('endpoint') ? (string) $this->option('endpoint') : null;
|
|
|
|
$this->info('WB API sync started');
|
|
$this->line("Period: {$from} - {$to}");
|
|
$this->line("Stocks date: {$stocksDate}");
|
|
$this->newLine();
|
|
|
|
$progress = function (string $endpoint, int $page, int $items, int $total, bool $finished): void {
|
|
if ($finished) {
|
|
$this->line(sprintf('%s page=%d empty, total=%d, finished', $endpoint, $page, $total));
|
|
return;
|
|
}
|
|
|
|
$this->line(sprintf('%s page=%d items=%d total=%d', $endpoint, $page, $items, $total));
|
|
};
|
|
|
|
$result = $syncService->syncAll($from, $to, $stocksDate, $endpoint, $progress);
|
|
|
|
$this->newLine();
|
|
$this->info('WB API sync finished');
|
|
|
|
foreach ($result as $name => $count) {
|
|
$this->line("{$name}: {$count} item(s) processed");
|
|
}
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|