first commit
This commit is contained in:
46
laravel/app/Console/Commands/SyncOrdersCommand.php
Normal file
46
laravel/app/Console/Commands/SyncOrdersCommand.php
Normal file
@@ -0,0 +1,46 @@
|
||||
<?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;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user