| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- <?php
- declare(strict_types=1);
- namespace App\Console\Commands;
- use App\Jobs\BackfillPaidOrderStatusesJob;
- use App\Services\OrderPaymentStatusService;
- use Illuminate\Console\Command;
- class BackfillPaidOrderStatuses extends Command
- {
- protected $signature = 'orders:backfill-paid-statuses
- {--year= : Год площадок для обработки}
- {--chunk=500 : Размер чанка}
- {--sync : Выполнить сразу без постановки в очередь}';
- protected $description = 'Запускает backfill статуса "Оплачено" для площадок с заполненными ведомостью и УПД по всем МАФ';
- public function handle(OrderPaymentStatusService $paymentStatusService): int
- {
- $year = $this->yearOption();
- $chunkSize = $this->chunkSizeOption();
- if ($chunkSize < 1) {
- $this->error('Размер чанка должен быть больше 0.');
- return self::FAILURE;
- }
- if ((bool) $this->option('sync')) {
- (new BackfillPaidOrderStatusesJob($year, $chunkSize))->handle($paymentStatusService);
- $this->info('Backfill статуса "Оплачено" выполнен.');
- return self::SUCCESS;
- }
- BackfillPaidOrderStatusesJob::dispatch($year, $chunkSize);
- $this->info('Backfill статуса "Оплачено" поставлен в очередь.');
- return self::SUCCESS;
- }
- private function yearOption(): ?int
- {
- $year = $this->option('year');
- if ($year === null || $year === '') {
- return null;
- }
- return (int) $year;
- }
- private function chunkSizeOption(): int
- {
- $chunk = $this->option('chunk');
- if (!is_numeric($chunk)) {
- return 0;
- }
- return (int) $chunk;
- }
- }
|