Commit df58eaf866f733375eba98bc3a72d72644792f6d

Authored by Сергей П
1 parent 4a58df1ed3
Exists in master

правки

Showing 6 changed files with 27 additions and 14 deletions Side-by-side Diff

app/Http/Controllers/EmployerController.php
... ... @@ -534,11 +534,10 @@ class EmployerController extends Controller
534 534 return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2])
535 535 ->withErrors($validator);
536 536 } else {
537   - Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
  537 + $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
538 538  
539 539 //return redirect()->route('employer.dialog', ['user1' => $user1, 'user2' => $user2]);
540   - return redirect()->route('employer.dialog',
541   - ['user1' => $user1, 'user2' => $user2, 'ad_employer' => $id_vacancy, 'ad_name' => $ad_name]);
  540 + return redirect()->route('employer.dialog', ['chat' => $new_message->chat_id_from]);
542 541  
543 542 }
544 543 }
app/Http/Controllers/WorkerController.php
... ... @@ -817,9 +817,7 @@ class WorkerController extends Controller
817 817  
818 818 $Messages = Chat::get_chat_messages($chat);
819 819  
820   - Message::where('user_id', '=', $chat->to_user_id)
821   - ->where('to_user_id', '=', $chat->user_id)
822   - ->update(['flag_new' => 0]);
  820 + Message::where('chat_id_to', '=', $chat->id)->update(['flag_new' => 0]);
823 821  
824 822 return view('workers.dialog', compact('companion', 'sender', 'chat', 'Messages', 'ad_employer'));
825 823 }
... ... @@ -1062,8 +1060,7 @@ class WorkerController extends Controller
1062 1060 } else {
1063 1061 $new_message = Message::add_message($request, $user1, $user2, $request->all(), file_store_path: 'messages');
1064 1062  
1065   - return redirect()->route('worker.dialog',
1066   - ['user1' => $user1, 'user2' => $user2, 'chat' => $new_message->chat_id_from]);
  1063 + return redirect()->route('worker.dialog', ['chat' => $new_message->chat_id_from]);
1067 1064  
1068 1065 }
1069 1066 }
... ... @@ -42,6 +42,11 @@ class Chat extends Model
42 42 return $this->hasMany(Message::class, 'user_id', 'to_user_id');
43 43 }
44 44  
  45 + public function admin_chat_unread_messages()
  46 + {
  47 + return $this->hasMany(Message::class, 'to_user_id', 'to_user_id');
  48 + }
  49 +
45 50 public static function pin_chat(int $chat_id, $fixed)
46 51 {
47 52 return self::where('id', '=', $chat_id)
... ... @@ -79,8 +84,8 @@ class Chat extends Model
79 84 {
80 85 return Chat::query()
81 86 ->with('last_message')
82   - ->withCount(['unread_messages' => function ($query) use($user_id) {
83   - $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1);
  87 + ->withCount(['admin_chat_unread_messages' => function ($query) use($user_id) {
  88 + $query->whereNull('chat_id_from')->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1);
84 89 }])
85 90 ->where('to_user_id', '=', $user_id)
86 91 ->where('is_admin_chat', 1)
app/Models/MessagesRequests.php
... ... @@ -33,18 +33,21 @@ class MessagesRequests extends Model
33 33 $job_ids = json_decode($message_request->job_titles);
34 34  
35 35 if (!empty($job_ids)){
36   - $workers = Title_worker::select('worker_id')
  36 + $title_workers = Title_worker::select('worker_id')
  37 + ->with('worker')
37 38 ->whereIN('job_title_id', $job_ids)
38 39 ->groupBy('worker_id')
39 40 ->get()
40 41 ;
41 42  
42   - if ($workers->count()){
  43 +
  44 +
  45 + if ($title_workers->count()){
43 46 $message_params = [
44 47 'text' => $message_request->text
45 48 ];
46   - foreach ($workers as $worker){
47   - Message::add_message(null, $message_request->user_id, $worker->worker_id, $message_params, file_store_path : '/', is_admin_chat: true);
  49 + foreach ($title_workers as $title_worker){
  50 + Message::add_message(null, $message_request->user_id, $title_worker->worker->user_id, $message_params, file_store_path : '/', is_admin_chat: true);
48 51 }
49 52 }
50 53 }
app/Models/Title_worker.php
... ... @@ -8,4 +8,8 @@ use Illuminate\Database\Eloquent\Model;
8 8 class Title_worker extends Model
9 9 {
10 10 use HasFactory;
  11 +
  12 + public function worker() {
  13 + return $this->belongsTo(Worker::class, 'worker_id');
  14 + }
11 15 }
resources/views/chats/chats_list.blade.php
... ... @@ -17,6 +17,11 @@
17 17  
18 18 <div class="messages__item-actions" data-chat-id="{{ $admin_chat->id }}">
19 19 <div class="messages__item-date max-content">{{ date(' H:i, d.m.Y', strtotime($admin_chat->created_at)) }}</div>
  20 + <div class="messages__item-buttons">
  21 + @if($admin_chat->admin_chat_unread_messages_count > 0)
  22 + <div class="unread-messages-count mr-15">{{ $admin_chat->admin_chat_unread_messages_count }}</div>
  23 + @endif
  24 + </div>
20 25 </div>
21 26 </div>
22 27 @endif