Commit e883d64b7f50372182417c55ff6358e14ec4c261

Authored by Fedor K
Exists in master

Merge branch 'task-132985' into 'master'

task-132985 minor fixes

Showing 12 changed files Side-by-side Diff

app/Console/Commands/DispatchResumeLiftJobCommand.php
... ... @@ -16,25 +16,30 @@ class DispatchResumeLiftJobCommand extends Command
16 16 {
17 17 $now = now()->timezone('Europe/Moscow')->format('H:i');
18 18  
19   - $employers = WorkerAutoliftOption::query()
  19 + $workers = WorkerAutoliftOption::query()
20 20 ->where(function ($query) use ($now) {
21 21 $query->where('times_per_day', 1)
22 22 ->where('time_send_first', $now);
23 23 })
24 24 ->orWhere(function ($query) use ($now) {
25 25 $query->where('times_per_day', 2)
26   - ->where('time_send_first', $now)
27   - ->where('time_send_second', $now);
  26 + ->where(function ($query) use ($now) {
  27 + $query->where('time_send_first', $now)
  28 + ->orWhere('time_send_second', $now);
  29 + });
28 30 })
29 31 ->orWhere(function ($query) use ($now) {
30 32 $query->where('times_per_day', 3)
31   - ->where('time_send_first', $now)
32   - ->where('time_send_second', $now)
33   - ->where('time_send_third', $now);
  33 + ->where(function ($query) use ($now) {
  34 + $query->where('time_send_first', $now)
  35 + ->orWhere('time_send_second', $now)
  36 + ->orWhere('time_send_third', $now);
  37 + });
  38 +
34 39 })
35 40 ->get();
36 41  
37   - LiftVacancyJob::dispatch($employers->pluck('employer_id')->toArray());
  42 + LiftVacancyJob::dispatch($workers->pluck('worker_id')->toArray());
38 43  
39 44 return Command::SUCCESS;
40 45 }
app/Console/Commands/DispatchVacancyLiftJobCommand.php
... ... @@ -5,6 +5,7 @@ namespace App\Console\Commands;
5 5 use App\Jobs\LiftVacancyJob;
6 6 use App\Jobs\SendVacancyToTelegramJob;
7 7 use App\Models\EmployerAutoliftOption;
  8 +use App\Models\WorkerAutoliftOption;
8 9 use Illuminate\Console\Command;
9 10  
10 11 class DispatchVacancyLiftJobCommand extends Command
... ... @@ -22,14 +23,19 @@ class DispatchVacancyLiftJobCommand extends Command
22 23 })
23 24 ->orWhere(function ($query) use ($now) {
24 25 $query->where('times_per_day', 2)
25   - ->where('time_send_first', $now)
26   - ->where('time_send_second', $now);
  26 + ->where(function ($query) use ($now) {
  27 + $query->where('time_send_first', $now)
  28 + ->orWhere('time_send_second', $now);
  29 + });
27 30 })
28 31 ->orWhere(function ($query) use ($now) {
29 32 $query->where('times_per_day', 3)
30   - ->where('time_send_first', $now)
31   - ->where('time_send_second', $now)
32   - ->where('time_send_third', $now);
  33 + ->where(function ($query) use ($now) {
  34 + $query->where('time_send_first', $now)
  35 + ->orWhere('time_send_second', $now)
  36 + ->orWhere('time_send_third', $now);
  37 + });
  38 +
33 39 })
34 40 ->orWhere('time_send_tg', $now)
35 41 ->get();
app/Events/MessageSended.php
... ... @@ -0,0 +1,20 @@
  1 +<?php
  2 +
  3 +namespace App\Events;
  4 +
  5 +use App\Models\Message;
  6 +use Illuminate\Broadcasting\InteractsWithSockets;
  7 +use Illuminate\Foundation\Events\Dispatchable;
  8 +use Illuminate\Queue\SerializesModels;
  9 +
  10 +class MessageSended
  11 +{
  12 + use Dispatchable, InteractsWithSockets, SerializesModels;
  13 +
  14 + public Message $message;
  15 +
  16 + public function __construct(Message $message)
  17 + {
  18 + $this->message = $message;
  19 + }
  20 +}
app/Http/Controllers/EmployerController.php
... ... @@ -811,7 +811,7 @@ class EmployerController extends Controller
811 811 'employer_id' => $employer->id,
812 812 ],
813 813 [
814   - 'is_enabled' => $request->get('is_enabled'),
  814 + 'is_enabled' => $request->get('is_enabled') === 'on',
815 815 'times_per_day' => $request->get('times_per_day'),
816 816 'days_repeat' => $request->get('days_repeat'),
817 817 'time_send_first' => $request->get('time_send_first'),
app/Http/Controllers/WorkerController.php
... ... @@ -1023,8 +1023,7 @@ class WorkerController extends Controller
1023 1023 $chat = Chat::where('user_id', $user1)
1024 1024 ->where('to_user_id', $user2)
1025 1025 ->where('is_removed', 0)
1026   - ->first()
1027   - ;
  1026 + ->first();
1028 1027  
1029 1028 if ($chat->id){
1030 1029 return redirect()->route('worker.dialog', ['chat' => $chat->id])->withErrors($validator);
... ... @@ -1034,8 +1033,8 @@ class WorkerController extends Controller
1034 1033 } else {
1035 1034 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
1036 1035  
  1036 + //dd('new message', $new_message);
1037 1037 return redirect()->route('worker.dialog', ['chat' => $new_message->chat_id_from]);
1038   -
1039 1038 }
1040 1039 }
1041 1040  
app/Listeners/MessageAutoresponder.php
... ... @@ -0,0 +1,70 @@
  1 +<?php
  2 +
  3 +namespace App\Listeners;
  4 +
  5 +use App\Events\MessageSended;
  6 +use App\Models\Message;
  7 +use App\Models\User;
  8 +use Illuminate\Contracts\Queue\ShouldQueue;
  9 +use Illuminate\Database\Query\Builder;
  10 +use Illuminate\Http\Request;
  11 +use Illuminate\Queue\InteractsWithQueue;
  12 +
  13 +class MessageAutoresponder
  14 +{
  15 + /**
  16 + * Create the event listener.
  17 + *
  18 + * @return void
  19 + */
  20 + public function __construct()
  21 + {
  22 + //
  23 + }
  24 +
  25 + /**
  26 + * Handle the event.
  27 + *
  28 + * @param \App\Events\MessageSended $event
  29 + * @return void
  30 + */
  31 + public function handle(MessageSended $event)
  32 + {
  33 + $message = $event->message;
  34 +
  35 + /** @var User $user */
  36 + $user = User::find($message->to_user_id);
  37 +
  38 + if ($user === null || !$user->autoresponder) {
  39 + return;
  40 + }
  41 +
  42 + $recentAutoresponderMessage = Message::query()
  43 + ->where('user_id', $message->to_user_id)
  44 + ->where('to_user_id', $message->user_id)
  45 + ->where('text', $user->autoresponder_message)
  46 + ->where('created_at', '>', now()->subDays(4))
  47 + ->orWhereExists(function (Builder $query) use ($message) {
  48 + $query->from('messages', 'm2')
  49 + ->where('m2.created_at', '>', now()->subMinutes(5))
  50 + ->where('m2.chat_id_from', $message->chat_id_to);
  51 + })
  52 + ->orderBy('id', 'desc')
  53 + ->first();
  54 +
  55 + if ($recentAutoresponderMessage !== null) {
  56 + return;
  57 + }
  58 +
  59 + Message::add_message(
  60 + request: new Request(),
  61 + user_id: $message->to_user_id,
  62 + to_user_id: $message->user_id,
  63 + message_params: [
  64 + 'text' => $user->autoresponder_message,
  65 + 'flag_new' => 1
  66 + ]
  67 + );
  68 + //dump('after listener');
  69 + }
  70 +}
app/Models/Message.php
... ... @@ -2,6 +2,7 @@
2 2  
3 3 namespace App\Models;
4 4  
  5 +use App\Events\MessageSended;
5 6 use Illuminate\Database\Eloquent\Factories\HasFactory;
6 7 use Illuminate\Database\Eloquent\Model;
7 8 use Illuminate\Http\Request;
... ... @@ -81,15 +82,18 @@ class Message extends Model
81 82 $message_params['chat_id_to'] = $chat_to->id;
82 83 }
83 84  
  85 + //dump('before creation '.$message_params['text']);
84 86 $new_message = Message::create($message_params);
  87 + //dump('after creation '.$new_message->id, [$new_message->id , $chat_form->last_message_id, $chat_to->last_message_id]);
85 88  
86   - if (!empty($new_message->id)) {
  89 + if ($new_message->id > $chat_form->last_message_id) {
87 90 $chat_form->update(['last_message_date' => date("Y-m-d H:i:s"), 'last_message_id' => $new_message->id]);
88 91  
89 92 if (!$is_admin_chat) {
90 93 $chat_to->update(['last_message_date' => date("Y-m-d H:i:s"), 'last_message_id' => $new_message->id]);
91 94 }
92 95 }
  96 + MessageSended::dispatch($new_message);
93 97  
94 98 return $new_message ?? false;
95 99 }
app/Observers/MessageObserver.php
... ... @@ -1,88 +0,0 @@
1   -<?php
2   -
3   -namespace App\Observers;
4   -
5   -use App\Models\Chat;
6   -use App\Models\Employer;
7   -use App\Models\Message;
8   -use App\Models\User;
9   -use Illuminate\Http\Request;
10   -
11   -class MessageObserver
12   -{
13   - public function created(Message $message): void
14   - {
15   - /** @var User $user */
16   - $user = User::find($message->to_user_id);
17   -
18   - if ($user === null || !$user->autoresponder) {
19   - return;
20   - }
21   -
22   - $recentAutoresponderMessage = Message::query()
23   - ->where('user_id', $message->to_user_id)
24   - ->where('to_user_id', $message->user_id)
25   - ->where('text', $user->autoresponder_message)
26   - ->where('created_at', '>', now()->subDays(4))
27   - ->orderBy('id', 'desc')
28   - ->first();
29   -
30   - if ($recentAutoresponderMessage !== null) {
31   - return;
32   - }
33   -
34   - Message::add_message(
35   - request: new Request(),
36   - user_id: $message->to_user_id,
37   - to_user_id: $message->user_id,
38   - message_params: [
39   - 'text' => $user->autoresponder_message,
40   - 'flag_new' => 1
41   - ]
42   - );
43   - }
44   -
45   - /**
46   - * Handle the Message "updated" event.
47   - *
48   - * @param \App\Models\Message $message
49   - * @return void
50   - */
51   - public function updated(Message $message)
52   - {
53   - //
54   - }
55   -
56   - /**
57   - * Handle the Message "deleted" event.
58   - *
59   - * @param \App\Models\Message $message
60   - * @return void
61   - */
62   - public function deleted(Message $message)
63   - {
64   - //
65   - }
66   -
67   - /**
68   - * Handle the Message "restored" event.
69   - *
70   - * @param \App\Models\Message $message
71   - * @return void
72   - */
73   - public function restored(Message $message)
74   - {
75   - //
76   - }
77   -
78   - /**
79   - * Handle the Message "force deleted" event.
80   - *
81   - * @param \App\Models\Message $message
82   - * @return void
83   - */
84   - public function forceDeleted(Message $message)
85   - {
86   - //
87   - }
88   -}
app/Providers/EventServiceProvider.php
... ... @@ -2,6 +2,8 @@
2 2  
3 3 namespace App\Providers;
4 4  
  5 +use App\Events\MessageSended;
  6 +use App\Listeners\MessageAutoresponder;
5 7 use App\Models\Message;
6 8 use App\Observers\MessageObserver;
7 9 use Illuminate\Auth\Events\Registered;
... ... @@ -29,7 +31,7 @@ class EventServiceProvider extends ServiceProvider
29 31 */
30 32 public function boot()
31 33 {
32   - Message::observe(MessageObserver::class);
  34 + Event::listen(MessageSended::class, MessageAutoresponder::class);
33 35 }
34 36  
35 37 /**
public/css/style_may2024.css
... ... @@ -9766,3 +9766,5 @@ nav .drop-down.closed {
9766 9766 .cabinet__inputs-item:has(.input-picker:disabled) {
9767 9767 display: none;
9768 9768 }
  9769 +
  9770 +.select select {display: none;}
resources/views/employers/vacancy_autolift.blade.php
... ... @@ -3,7 +3,7 @@
3 3 <script>
4 4 $(document).on('click', '#submit', function () {
5 5 let data = {};
6   - data.is_enabled = $('[name="is_enabled"]').checked;
  6 + data.is_enabled = $('[name="is_enabled"]').val();
7 7 data.times_per_day = $('[name="times_per_day"]').chosen().val();
8 8 data.days_repeat = $('[name="days_repeat"]').chosen().val();
9 9 data.time_send_first = $('[name="time_send_first"]').val();
resources/views/workers/resume_autolift.blade.php
... ... @@ -3,7 +3,6 @@
3 3 <script>
4 4 $(document).on('click', '#submit', function () {
5 5 let data = {};
6   - console.log($('[name="is_enabled"]').val());
7 6 data.is_enabled = $('[name="is_enabled"]').val();
8 7 data.times_per_day = $('[name="times_per_day"]').chosen().val();
9 8 data.days_repeat = $('[name="days_repeat"]').chosen().val();