Blame view

app/Console/Commands/DispatchVacancyLiftJobCommand.php 1.82 KB
ab181e741   Fedor   task-132985 autol...
1
2
3
4
5
6
7
  <?php
  
  namespace App\Console\Commands;
  
  use App\Jobs\LiftVacancyJob;
  use App\Jobs\SendVacancyToTelegramJob;
  use App\Models\EmployerAutoliftOption;
7d97dde35   Fedor   task-132985 minor...
8
  use App\Models\WorkerAutoliftOption;
ab181e741   Fedor   task-132985 autol...
9
10
11
12
13
14
15
16
  use Illuminate\Console\Command;
  
  class DispatchVacancyLiftJobCommand extends Command
  {
      protected $signature ='vacancy:dispatch';
  
      public function handle()
      {
8ec6b4403   Fedor   task-132985 autor...
17
          $now = now()->timezone('Europe/Moscow')->format('H:i');
ab181e741   Fedor   task-132985 autol...
18

9391c3aa3   Hayk Nazaryan   check send telegramm
19
          $employersAutoLift = EmployerAutoliftOption::query()
ab181e741   Fedor   task-132985 autol...
20
21
22
23
24
25
              ->where(function ($query) use ($now) {
                  $query->where('times_per_day', 1)
                      ->where('time_send_first', $now);
              })
              ->orWhere(function ($query) use ($now) {
                  $query->where('times_per_day', 2)
7d97dde35   Fedor   task-132985 minor...
26
27
28
29
                      ->where(function ($query) use ($now) {
                          $query->where('time_send_first', $now)
                              ->orWhere('time_send_second', $now);
                      });
ab181e741   Fedor   task-132985 autol...
30
31
32
              })
              ->orWhere(function ($query) use ($now) {
                  $query->where('times_per_day', 3)
7d97dde35   Fedor   task-132985 minor...
33
34
35
36
37
                      ->where(function ($query) use ($now) {
                          $query->where('time_send_first', $now)
                              ->orWhere('time_send_second', $now)
                              ->orWhere('time_send_third', $now);
                      });
ab181e741   Fedor   task-132985 autol...
38
              })
ab181e741   Fedor   task-132985 autol...
39
              ->get();
9391c3aa3   Hayk Nazaryan   check send telegramm
40

ab181e741   Fedor   task-132985 autol...
41
          LiftVacancyJob::dispatch(
9391c3aa3   Hayk Nazaryan   check send telegramm
42
              $employersAutoLift->whereNotNull('time_send_first')->pluck('employer_id')->toArray(),
ab181e741   Fedor   task-132985 autol...
43
          );
9391c3aa3   Hayk Nazaryan   check send telegramm
44
45
46
          $employersSendTelegramm = EmployerAutoliftOption::query()
              ->orWhere('time_send_tg', $now)
              ->get();
ab181e741   Fedor   task-132985 autol...
47
          SendVacancyToTelegramJob::dispatch(
9391c3aa3   Hayk Nazaryan   check send telegramm
48
              $employersSendTelegramm->whereNotNull('time_send_tg')->pluck('employer_id')->toArray()
ab181e741   Fedor   task-132985 autol...
49
50
51
52
53
          );
  
          return Command::SUCCESS;
      }
  }