47 lines
1.1 KiB
PHP
47 lines
1.1 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use App\Contracts\WbSyncManagerInterface;
|
|
use App\Enums\WbEndpoint;
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
final class SyncOrdersCommand extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'sync:orders {--dateFrom=} {--dateTo=}';
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $description = 'Sync orders from API';
|
|
|
|
public function handle(WbSyncManagerInterface $manager): int
|
|
{
|
|
$dateFrom = $this->option('dateFrom')
|
|
?: Carbon::now()->subYears(2)->toDateString();
|
|
|
|
$dateTo = $this->option('dateTo')
|
|
?: Carbon::yesterday()->toDateString();
|
|
|
|
if ($dateFrom >= $dateTo) {
|
|
$this->info('Nothing to sync');
|
|
return self::SUCCESS;
|
|
}
|
|
|
|
$this->info("Syncing ORDERS from $dateFrom to $dateTo");
|
|
|
|
$manager->start(WbEndpoint::ORDERS, $dateFrom, $dateTo);
|
|
|
|
return self::SUCCESS;
|
|
}
|
|
}
|