Merge Request #22
← To merge requests
task-132985
→
master
Commits (1)
Showing 5 changed files Inline Diff
app/Console/Commands/DeleteExpiredAutoliftOptions.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace App\Console\Commands; | 3 | namespace App\Console\Commands; |
4 | 4 | ||
5 | use App\Models\EmployerAutoliftOption; | 5 | use App\Models\EmployerAutoliftOption; |
6 | use App\Models\WorkerAutoliftOption; | 6 | use App\Models\WorkerAutoliftOption; |
7 | use Illuminate\Console\Command; | 7 | use Illuminate\Console\Command; |
8 | 8 | ||
9 | class DeleteExpiredAutoliftOptions extends Command | 9 | class DeleteExpiredAutoliftOptions extends Command |
10 | { | 10 | { |
11 | protected $signature = 'vacancy:delete_expired'; | 11 | protected $signature = 'vacancy:delete_expired'; |
12 | 12 | ||
13 | protected $description = 'Command description'; | 13 | protected $description = 'Command description'; |
14 | 14 | ||
15 | public function handle() | 15 | public function handle() |
16 | { | 16 | { |
17 | EmployerAutoliftOption::query() | 17 | EmployerAutoliftOption::query() |
18 | ->whereRaw('`updated_at` < DATE_SUB(NOW(), INTERVAL `days_repeat` DAY)') | 18 | ->whereRaw('`updated_at` < DATE_SUB(NOW(), INTERVAL `days_repeat` DAY)') |
19 | ->update([ | 19 | ->delete(); |
20 | 'is_enabled' => false | ||
21 | ]); | ||
22 | WorkerAutoliftOption::query() | 20 | WorkerAutoliftOption::query() |
23 | ->whereRaw('`updated_at` < DATE_SUB(NOW(), INTERVAL `days_repeat` DAY)') | 21 | ->whereRaw('`updated_at` < DATE_SUB(NOW(), INTERVAL `days_repeat` DAY)') |
24 | ->update([ | 22 | ->delete(); |
25 | 'is_enabled' => false | ||
26 | ]); | ||
27 | return Command::SUCCESS; | 23 | return Command::SUCCESS; |
28 | } | 24 | } |
29 | } | 25 | } |
30 | 26 |
app/Console/Commands/DispatchResumeLiftJobCommand.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace App\Console\Commands; | 3 | namespace App\Console\Commands; |
4 | 4 | ||
5 | use App\Jobs\LiftResumeJob; | 5 | use App\Jobs\LiftResumeJob; |
6 | use App\Jobs\LiftVacancyJob; | ||
7 | use App\Jobs\SendVacancyToTelegramJob; | ||
8 | use App\Models\EmployerAutoliftOption; | ||
9 | use App\Models\WorkerAutoliftOption; | 6 | use App\Models\WorkerAutoliftOption; |
10 | use Illuminate\Console\Command; | 7 | use Illuminate\Console\Command; |
11 | 8 | ||
12 | class DispatchResumeLiftJobCommand extends Command | 9 | class DispatchResumeLiftJobCommand extends Command |
13 | { | 10 | { |
14 | protected $signature ='resume:dispatch'; | 11 | protected $signature ='resume:dispatch'; |
15 | 12 | ||
16 | public function handle() | 13 | public function handle() |
17 | { | 14 | { |
18 | $now = now()->timezone('Europe/Moscow')->format('H:i'); | 15 | $now = now()->timezone('Europe/Moscow')->format('H:i'); |
19 | 16 | ||
20 | $workers = WorkerAutoliftOption::query() | 17 | $workers = WorkerAutoliftOption::query() |
21 | ->where(function ($query) use ($now) { | 18 | ->where(function ($query) use ($now) { |
22 | $query->where('times_per_day', 1) | 19 | $query->where('times_per_day', 1) |
23 | ->where('time_send_first', $now); | 20 | ->where('time_send_first', $now); |
24 | }) | 21 | }) |
25 | ->orWhere(function ($query) use ($now) { | 22 | ->orWhere(function ($query) use ($now) { |
26 | $query->where('times_per_day', 2) | 23 | $query->where('times_per_day', 2) |
27 | ->where(function ($query) use ($now) { | 24 | ->where(function ($query) use ($now) { |
28 | $query->where('time_send_first', $now) | 25 | $query->where('time_send_first', $now) |
29 | ->orWhere('time_send_second', $now); | 26 | ->orWhere('time_send_second', $now); |
30 | }); | 27 | }); |
31 | }) | 28 | }) |
32 | ->orWhere(function ($query) use ($now) { | 29 | ->orWhere(function ($query) use ($now) { |
33 | $query->where('times_per_day', 3) | 30 | $query->where('times_per_day', 3) |
34 | ->where(function ($query) use ($now) { | 31 | ->where(function ($query) use ($now) { |
35 | $query->where('time_send_first', $now) | 32 | $query->where('time_send_first', $now) |
36 | ->orWhere('time_send_second', $now) | 33 | ->orWhere('time_send_second', $now) |
37 | ->orWhere('time_send_third', $now); | 34 | ->orWhere('time_send_third', $now); |
38 | }); | 35 | }); |
39 | |||
40 | }) | 36 | }) |
41 | ->get(); | 37 | ->get(); |
42 | 38 | ||
43 | LiftResumeJob::dispatch($workers->pluck('worker_id')->toArray()); | 39 | LiftResumeJob::dispatch($workers->pluck('worker_id')->toArray()); |
44 | 40 | ||
45 | return Command::SUCCESS; | 41 | return Command::SUCCESS; |
46 | } | 42 | } |
47 | } | 43 | } |
48 | 44 |
app/Jobs/LiftResumeJob.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace App\Jobs; | 3 | namespace App\Jobs; |
4 | 4 | ||
5 | use App\Models\Ad_employer; | ||
6 | use App\Models\Worker; | 5 | use App\Models\Worker; |
7 | use Illuminate\Bus\Queueable; | 6 | use Illuminate\Bus\Queueable; |
8 | use Illuminate\Contracts\Queue\ShouldQueue; | 7 | use Illuminate\Contracts\Queue\ShouldQueue; |
9 | use Illuminate\Foundation\Bus\Dispatchable; | 8 | use Illuminate\Foundation\Bus\Dispatchable; |
10 | use Illuminate\Queue\InteractsWithQueue; | 9 | use Illuminate\Queue\InteractsWithQueue; |
11 | use Illuminate\Queue\SerializesModels; | 10 | use Illuminate\Queue\SerializesModels; |
12 | 11 | ||
13 | class LiftResumeJob implements ShouldQueue | 12 | class LiftResumeJob implements ShouldQueue |
14 | { | 13 | { |
15 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | 14 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
16 | 15 | ||
17 | private array $workerIds; | 16 | private array $workerIds; |
18 | 17 | ||
19 | public function __construct(array $workerIds) | 18 | public function __construct(array $workerIds) |
20 | { | 19 | { |
21 | $this->workerIds = $workerIds; | 20 | $this->workerIds = $workerIds; |
22 | } | 21 | } |
23 | 22 | ||
24 | public function handle() | 23 | public function handle() |
25 | { | 24 | { |
26 | Worker::query() | 25 | Worker::query() |
27 | ->whereIn('id', $this->workerIds) | 26 | ->whereIn('id', $this->workerIds) |
28 | ->update([ | 27 | ->update([ |
29 | 'updated_at' => now() | 28 | 'updated_at' => now() |
30 | ]); | 29 | ]); |
31 | } | 30 | } |
32 | } | 31 | } |
33 | 32 |
app/Jobs/LiftVacancyJob.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace App\Jobs; | 3 | namespace App\Jobs; |
4 | 4 | ||
5 | use App\Models\Ad_employer; | 5 | use App\Models\Ad_employer; |
6 | use Illuminate\Bus\Queueable; | 6 | use Illuminate\Bus\Queueable; |
7 | use Illuminate\Contracts\Queue\ShouldQueue; | 7 | use Illuminate\Contracts\Queue\ShouldQueue; |
8 | use Illuminate\Foundation\Bus\Dispatchable; | 8 | use Illuminate\Foundation\Bus\Dispatchable; |
9 | use Illuminate\Queue\InteractsWithQueue; | 9 | use Illuminate\Queue\InteractsWithQueue; |
10 | use Illuminate\Queue\SerializesModels; | 10 | use Illuminate\Queue\SerializesModels; |
11 | 11 | ||
12 | class LiftVacancyJob implements ShouldQueue | 12 | class LiftVacancyJob implements ShouldQueue |
13 | { | 13 | { |
14 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | 14 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
15 | 15 | ||
16 | private array $employerIds; | 16 | private array $employerIds; |
17 | 17 | ||
18 | public function __construct(array $employerIds) | 18 | public function __construct(array $employerIds) |
19 | { | 19 | { |
20 | $this->employerIds = $employerIds; | 20 | $this->employerIds = $employerIds; |
21 | } | 21 | } |
22 | 22 | ||
23 | public function handle() | 23 | public function handle() |
24 | { | 24 | { |
25 | Ad_employer::query() | 25 | Ad_employer::query() |
26 | ->whereIn('employer_id', $this->employerIds) | 26 | ->whereIn('employer_id', $this->employerIds) |
27 | ->where('autolift_site', 1) | ||
28 | ->where('active_is', 1) | ||
29 | ->where('is_remove', 0) | ||
27 | ->update([ | 30 | ->update([ |
28 | 'updated_at' => now() | 31 | 'updated_at' => now() |
29 | ]); | 32 | ]); |
30 | } | 33 | } |
31 | } | 34 | } |
32 | 35 |
app/Jobs/SendVacancyToTelegramJob.php
1 | <?php | 1 | <?php |
2 | 2 | ||
3 | namespace App\Jobs; | 3 | namespace App\Jobs; |
4 | 4 | ||
5 | use App\Components\Integrations\Telegram\VacancyChannel; | 5 | use App\Components\Integrations\Telegram\VacancyChannel; |
6 | use App\Models\Ad_employer; | 6 | use App\Models\Ad_employer; |
7 | use Illuminate\Bus\Queueable; | 7 | use Illuminate\Bus\Queueable; |
8 | use Illuminate\Contracts\Queue\ShouldQueue; | 8 | use Illuminate\Contracts\Queue\ShouldQueue; |
9 | use Illuminate\Foundation\Bus\Dispatchable; | 9 | use Illuminate\Foundation\Bus\Dispatchable; |
10 | use Illuminate\Queue\InteractsWithQueue; | 10 | use Illuminate\Queue\InteractsWithQueue; |
11 | use Illuminate\Queue\SerializesModels; | 11 | use Illuminate\Queue\SerializesModels; |
12 | use Telegram\Bot\Exceptions\TelegramSDKException; | 12 | use Telegram\Bot\Exceptions\TelegramSDKException; |
13 | 13 | ||
14 | class SendVacancyToTelegramJob implements ShouldQueue | 14 | class SendVacancyToTelegramJob implements ShouldQueue |
15 | { | 15 | { |
16 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; | 16 | use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; |
17 | 17 | ||
18 | private array $employerIds; | 18 | private array $employerIds; |
19 | private VacancyChannel $telegramSenderHelper; | 19 | private VacancyChannel $telegramSenderHelper; |
20 | 20 | ||
21 | public function __construct(array $employerIds) | 21 | public function __construct(array $employerIds) |
22 | { | 22 | { |
23 | $this->employerIds = $employerIds; | 23 | $this->employerIds = $employerIds; |
24 | $this->telegramSenderHelper = new VacancyChannel(); | 24 | $this->telegramSenderHelper = new VacancyChannel(); |
25 | } | 25 | } |
26 | 26 | ||
27 | /** | 27 | /** |
28 | * @throws TelegramSDKException | 28 | * @throws TelegramSDKException |
29 | */ | 29 | */ |
30 | public function handle(): void | 30 | public function handle(): void |
31 | { | 31 | { |
32 | $vacancies = Ad_employer::query() | 32 | $vacancies = Ad_employer::query() |
33 | ->whereIn('employer_id', $this->employerIds) | 33 | ->whereIn('employer_id', $this->employerIds) |
34 | ->where('autosend_tg', 1) | ||
35 | ->where('active_is', 1) | ||
36 | ->where('is_remove', 0) | ||
34 | ->get(); | 37 | ->get(); |
35 | 38 | ||
36 | foreach ($vacancies as $vacancy) { | 39 | foreach ($vacancies as $vacancy) { |
37 | $this->telegramSenderHelper->sendVacancy($vacancy); | 40 | $this->telegramSenderHelper->sendVacancy($vacancy); |
38 | } | 41 | } |
39 | } | 42 | } |
40 | } | 43 | } |
41 | 44 |