From 2f592b01f80b545ae7a6b7e2cbc4f42efd6ed128 Mon Sep 17 00:00:00 2001 From: Sergey Panarin Date: Tue, 23 Jul 2024 11:55:40 +0200 Subject: [PATCH] =?UTF-8?q?=D1=81=D0=BE=D0=BE=D0=B1=D1=89=D0=B5=D0=BD=D0=B8=D1?= =?UTF-8?q?=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Http/Controllers/EmployerController.php | 72 ++++-------- app/Http/Controllers/WorkerController.php | 53 ++------- app/Models/Chat.php | 34 ++++++ .../2024_07_19_063615_create_chat_table.php | 1 + public/css/style_may2024.css | 56 +++++---- public/js/func.js | 12 ++ resources/views/chats/chats_list.blade.php | 100 ++++++++++++++++ resources/views/employers/dialog.blade.php | 9 -- resources/views/employers/messages.blade.php | 111 +----------------- resources/views/layout/frontend.blade.php | 1 + resources/views/modals/chats/remove_chat.blade.php | 36 ++++++ resources/views/workers/messages.blade.php | 122 +------------------- routes/web.php | 3 + 13 files changed, 263 insertions(+), 347 deletions(-) create mode 100644 public/js/func.js create mode 100644 resources/views/chats/chats_list.blade.php create mode 100644 resources/views/modals/chats/remove_chat.blade.php diff --git a/app/Http/Controllers/EmployerController.php b/app/Http/Controllers/EmployerController.php index 4f3dd51..9f427d2 100644 --- a/app/Http/Controllers/EmployerController.php +++ b/app/Http/Controllers/EmployerController.php @@ -338,43 +338,10 @@ class EmployerController extends Controller public function messages($type_message) { $user_id = Auth()->user()->id; - $chats = Chat::query() - ->with('user') - ->with('worker') - ->with('employer') - ->with('last_message') - ->withCount(['unread_messages' => function ($query) use($user_id) { - $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1); - }]) - ->where('user_id', '=', $user_id) - ->orderByDesc('is_fixed') - ->orderByDesc('last_message_date') - ->paginate(5) - ; - //dd($chats); - - /*$messages_input = Message::query()->with('vacancies')->with('user_from')-> - Where('to_user_id', $user_id)->OrderByDesc('created_at'); - - $messages_output = Message::query()->with('vacancies')-> - with('user_to')->where('user_id', $user_id)-> - OrderByDesc('created_at'); - - $count_input = $messages_input->count(); - $count_output = $messages_output->count(); - - if ($type_message == 'input') { - $messages = $messages_input->paginate(5); - } - - if ($type_message == 'output') { - $messages = $messages_output->paginate(5); - }*/ - - //dd($user_id, $messages[2]->vacancies); - //jobs); + $chats = Chat::get_user_chats($user_id); + $user_type = 'employer'; - return view('employers.messages', compact('chats','user_id')); + return view('employers.messages', compact('chats','user_id', 'user_type')); } // Диалог между пользователями @@ -392,18 +359,17 @@ class EmployerController extends Controller where('id', $user2->id)->first(); } - $Messages = Message::query()-> - where('ad_employer_id', '=', $ad_employer)-> - where(function($query) use ($user1, $user2) { - $query->where('user_id', $user1->id)->where('to_user_id', $user2->id); - })->orWhere(function($query) use ($user1, $user2) { - $query->where('user_id', $user2->id)->where('to_user_id', $user1->id); - })->where('ad_employer_id', '=', $ad_employer)->OrderBy('created_at')->get(); - - $id_vac = $Messages[$Messages->count() - 1]->ad_employer_id; + $Messages = Message::query() + ->where(function($query) use ($user1, $user2) { + $query->where('user_id', $user1->id)->where('to_user_id', $user2->id); + }) + ->orWhere(function($query) use ($user1, $user2) { + $query->where('user_id', $user2->id)->where('to_user_id', $user1->id); + }) + ->orderBy('created_at') + ->get() + ; - //$ad_employer = null; - //if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first(); $sender = $user1; Message::where('user_id', '=', $user2->id) @@ -414,6 +380,18 @@ class EmployerController extends Controller return view('employers.dialog', compact('companion', 'sender', 'ad_employer', 'Messages')); } + public function pin_chat(Request $request){ + $chat_id = $request->get('id'); + $is_fixed = $request->get('is_fixed'); + + Chat::pin_chat($chat_id, $is_fixed); + } + + public function remove_chat(Request $request){ + $chat_id = $request->get('id'); + Chat::remove_chat($chat_id); + } + // Регистрация работодателя public function register_employer(Request $request) { $params = $request->all(); diff --git a/app/Http/Controllers/WorkerController.php b/app/Http/Controllers/WorkerController.php index b7227b3..d992b9a 100644 --- a/app/Http/Controllers/WorkerController.php +++ b/app/Http/Controllers/WorkerController.php @@ -8,6 +8,7 @@ use App\Http\Requests\PrevCompanyRequest; use App\Http\Requests\SertificationRequest; use App\Models\Ad_employer; use App\Models\ad_response; +use App\Models\Chat; use App\Models\Dop_info; use App\Models\infobloks; use App\Models\Job_title; @@ -494,27 +495,10 @@ class WorkerController extends Controller { $user_id = Auth()->user()->id; - $messages_input = Message::query()->with('vacancies')->with('user_from')-> - Where('to_user_id', $user_id)->OrderByDesc('created_at'); + $chats = Chat::get_user_chats($user_id); + $user_type = 'worker'; - $messages_output = Message::query()->with('vacancies')-> - with('user_to')->where('user_id', $user_id)-> - OrderByDesc('created_at'); - - $count_input = $messages_input->count(); - $count_output = $messages_output->count(); - - if ($type_message == 'input') { - $messages = $messages_input->paginate(5); - } - - if ($type_message == 'output') { - $messages = $messages_output->paginate(5); - } - - //dd($messages); - // Вернуть все 100% - return view('workers.messages', compact('messages', 'count_input', 'count_output', 'type_message', 'user_id')); + return view('workers.messages', compact('chats','user_id', 'user_type')); } // Избранный @@ -840,28 +824,13 @@ class WorkerController extends Controller } $Messages = Message::query()-> - //with('response')-> - where(function($query) use ($user1, $user2) { - $query->where('user_id', $user1->id)->where('to_user_id', $user2->id); - })->orWhere(function($query) use ($user1, $user2) { - $query->where('user_id', $user2->id)->where('to_user_id', $user1->id); - })->OrderBy('created_at')->get(); - - $id_vac = null; - /*foreach ($Messages as $it) { - if (isset($it->response)) { - foreach ($it->response as $r) { - if (isset($r->ad_employer_id)) { - $id_vac = $r->ad_employer_id; - break; - } - } - } - if (!is_null($id_vac)) break; - }*/ - - //$ad_employer = null; - //if (!is_null($id_vac)) $ad_employer = Ad_employer::query()->where('id', $id_vac)->first(); + where(function($query) use ($user1, $user2) { + $query->where('user_id', $user1->id)->where('to_user_id', $user2->id); + })->orWhere(function($query) use ($user1, $user2) { + $query->where('user_id', $user2->id)->where('to_user_id', $user1->id); + })->OrderBy('created_at') + ->get() + ; return view('workers.dialog', compact('companion', 'sender', 'Messages', 'ad_employer')); } diff --git a/app/Models/Chat.php b/app/Models/Chat.php index 5a229b6..eb930ba 100644 --- a/app/Models/Chat.php +++ b/app/Models/Chat.php @@ -4,6 +4,7 @@ namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; +use Carbon\Carbon; class Chat extends Model { @@ -40,4 +41,37 @@ class Chat extends Model return $this->hasMany(Message::class, 'user_id', 'to_user_id'); } + public static function pin_chat(int $chat_id, $fixed) + { + return self::where('id', '=', $chat_id) + ->update([ + 'is_fixed' => !empty($fixed) ? 1 : 0, + 'fixation_date' => !empty($fixed) ? Carbon::now() : null + ]); + } + + public static function remove_chat(int $chat_id) + { + return self::where('id', '=', $chat_id) + ->update(['is_removed' => 1]); + } + + public static function get_user_chats(int $user_id){ + return Chat::query() + ->with('user') + ->with('worker') + ->with('employer') + ->with('last_message') + ->withCount(['unread_messages' => function ($query) use($user_id) { + $query->where('to_user_id', '=', $user_id)->where('flag_new', '=', 1); + }]) + ->where('user_id', '=', $user_id) + ->where('is_removed', '=', 0) + ->orderByDesc('is_fixed') + ->orderByDesc('fixation_date') + ->orderByDesc('last_message_date') + ->paginate(5) + ; + } + } diff --git a/database/migrations/2024_07_19_063615_create_chat_table.php b/database/migrations/2024_07_19_063615_create_chat_table.php index be747c0..d8c6652 100644 --- a/database/migrations/2024_07_19_063615_create_chat_table.php +++ b/database/migrations/2024_07_19_063615_create_chat_table.php @@ -19,6 +19,7 @@ return new class extends Migration $table->integer('to_user_id'); $table->boolean('is_removed')->default(false); $table->boolean('is_fixed')->default(false); + $table->dateTime('fixation_date')->nullable(true); $table->dateTime('last_message_date')->nullable(false); $table->integer('last_message_id')->nullable(false); $table->dateTime('fixed_time')->nullable(true); diff --git a/public/css/style_may2024.css b/public/css/style_may2024.css index 6a5921a..477a64c 100644 --- a/public/css/style_may2024.css +++ b/public/css/style_may2024.css @@ -6748,23 +6748,12 @@ main + .news { gap: 20px; } .messages__body { - display: -webkit-box; - display: -ms-flexbox; - display: flex; - -webkit-box-orient: vertical; - -webkit-box-direction: normal; - -ms-flex-direction: column; - flex-direction: column; - gap: 10px; - width: 100%; -} -@media (min-width: 768px) { - .messages__body { - gap: 20px; - } + width: 100%; + max-height: 800px; + overflow: auto; + padding: 5px; } .messages__item { - display: none; -webkit-box-align: center; -ms-flex-align: center; align-items: center; @@ -6773,6 +6762,9 @@ main + .news { background: linear-gradient(95deg, #f2f5fc 59.82%, #ebf2fc 99.99%); padding: 10px; font-size: 12px; + display: flex; + justify-content: space-between; + margin-bottom: 20px; } @media (min-width: 768px) { .messages__item { @@ -6780,12 +6772,6 @@ main + .news { font-size: 18px; } } -.messages__item:nth-of-type(1), .messages__item:nth-of-type(2), .messages__item:nth-of-type(3), .messages__item:nth-of-type(4), .messages__item:nth-of-type(5), .messages__item:nth-of-type(6) { - display: -webkit-box; - display: -ms-flexbox; - display: flex; - justify-content: space-between; -} .messages__item-info { display: -webkit-box; display: -ms-flexbox; @@ -6888,9 +6874,12 @@ main + .news { .messages__item-buttons button:hover svg path{ stroke: black; } -.messages__item-buttons button:hover svg#pin_on path{ +.messages__item-buttons button.pin-on:hover svg#pin_off path{ fill: black; } +.messages__item-buttons button.pin-on svg{ + fill: gray; +} .messages__item-date { color: #00000070; width: 90px; @@ -9305,3 +9294,26 @@ body .cke_notifications_area{ padding: 5px 10px; border-radius: 45px; } + +/* Диалог модал */ +.modal-dialog{ + border-radius: 10px; +} +.modal-dialog .modal-dialog-footer{ + display: flex; + justify-content: space-between; +} + +.button-loader { + border: 2px solid #f3f3f3; + -webkit-animation: spin 1s linear infinite; + animation: spin 1s linear infinite; + border-top: 2px solid #555; + border-radius: 50%; + width: 20px; + height: 20px; +} +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} diff --git a/public/js/func.js b/public/js/func.js new file mode 100644 index 0000000..8ac238f --- /dev/null +++ b/public/js/func.js @@ -0,0 +1,12 @@ + +var spinStart = function(button) { + button.prop('disabled', true); + if (!button.find('.button-loader').length){ + button.html('
' + button.html()); + } +}; + +var spinStop= function(button) { + button.prop('disabled', false); + button.find('.button-loader').remove(); +}; diff --git a/resources/views/chats/chats_list.blade.php b/resources/views/chats/chats_list.blade.php new file mode 100644 index 0000000..27b7807 --- /dev/null +++ b/resources/views/chats/chats_list.blade.php @@ -0,0 +1,100 @@ +@if ($chats->count()) + @csrf + @foreach($chats as $chat) +
+ + +
+
{{ date(' H:i, d.m.Y', strtotime($chat->created_at)) }}
+
+ @if($chat->unread_messages_count > 0) +
{{ $chat->unread_messages_count }}
+ @endif + + + +
+
+
+
+ @endforeach +
+ {{ $chats->onEachSide(0)->appends($_GET)->links('paginate') }} +
+@else +
+ + + + Сообщений не найдено +
+@endif + + diff --git a/resources/views/employers/dialog.blade.php b/resources/views/employers/dialog.blade.php index 5cd48eb..edd42a9 100644 --- a/resources/views/employers/dialog.blade.php +++ b/resources/views/employers/dialog.blade.php @@ -92,15 +92,6 @@
{{ $companion->surname." ".$companion->name_man." ".$companion->surname2." (".$companion->id.")" }}
-
Вакансия: - @if ($ad_employer == 0) - @if (isset($_GET['ad_name'])){{ $_GET['ad_name'] }}@else Не указано @endif - @else - - @if (isset($_GET['ad_name'])){{ $_GET['ad_name'] }} ({{ $ad_employer }}) @else Не указано @endif - - @endif -
@if (isset($companion->workers[0]->id)) diff --git a/resources/views/employers/messages.blade.php b/resources/views/employers/messages.blade.php index 5fd3867..b164a33 100644 --- a/resources/views/employers/messages.blade.php +++ b/resources/views/employers/messages.blade.php @@ -1,50 +1,6 @@ @extends('layout.frontend', ['title' => 'Сообщения от пользователей - РекаМоре']) @section('scripts') - @endsection @section('content') @@ -71,70 +27,7 @@
@@ -142,5 +35,5 @@ - + @include('modals.chats.remove_chat') @endsection diff --git a/resources/views/layout/frontend.blade.php b/resources/views/layout/frontend.blade.php index dbaa94f..a7a88aa 100644 --- a/resources/views/layout/frontend.blade.php +++ b/resources/views/layout/frontend.blade.php @@ -8,6 +8,7 @@ + diff --git a/resources/views/modals/chats/remove_chat.blade.php b/resources/views/modals/chats/remove_chat.blade.php new file mode 100644 index 0000000..3c6fe1f --- /dev/null +++ b/resources/views/modals/chats/remove_chat.blade.php @@ -0,0 +1,36 @@ + + + diff --git a/resources/views/workers/messages.blade.php b/resources/views/workers/messages.blade.php index f0ef18e..16c92df 100644 --- a/resources/views/workers/messages.blade.php +++ b/resources/views/workers/messages.blade.php @@ -25,129 +25,15 @@

Сообщения

-
-
- +
+
+ @include('chats.chats_list')
-
- @if ($messages->count()) - @foreach($messages as $it) -
-
- -
- - - - - @if ($type_message == 'input') - @if (isset($it->user_from->is_worker)) - @if ($it->user_from->is_worker) - @if (isset($it->user_from->workers[0]->photo)) - - @else - - @endif - @else - @if (isset($it->user_from->employers[0]->logo)) - - @else - - @endif - @endif - @else - - @endif - @endif - - - - @if ($type_message == 'output') - @if (isset($it->user_from->is_worker)) - @if ($it->user_from->is_worker) - @if (isset($it->user_from->workers[0]->photo)) - - @else - - @endif - @else - @if (isset($it->user_from->employers->logo)) - - @else - - @endif - @endif - @else - - @endif - @endif -
-
-
@if (isset($it->vacancies)) @php $ad_name = $it->vacancies->name; @endphp @else @php $ad_name = 'Вакансия удалена'; @endphp @endif - От: @if (isset($it->user_from)) - @if ($it->user_from->id !== $user_id) - - {{ $it->user_from->surname." ".$it->user_from->name_man." ".$it->user_from->surname2." (".$it->user_from->id.")" }} - - @else - {{ $it->user_from->surname." ".$it->user_from->name_man." ".$it->user_from->surname2." (".$it->user_from->id.")" }} - @endif - @else - Удаленный пользователь - @endif -
- К: @if (isset($it->user_to)) - @if ($it->user_to->id !== $user_id) - - - {{ $it->user_to->surname." ".$it->user_to->name_man." ".$it->user_to->surname2." (".$it->user_to->id.")" }} - - @else - {{ $it->user_to->surname." ".$it->user_to->name_man." ".$it->user_to->surname2." (".$it->user_to->id.")" }} - @endif - @else - Удаленный пользователь - @endif -
-
Вакансия:@if (isset($it->vacancies)) {{ $it->vacancies->name." (".($it->vacancies->id).")" }} @else Удалена @endif
-
Текст:{{ $it->text }}
-
-
-
{{ $it->created_at }}
-
- @endforeach - -
- {{ $messages->onEachSide(0)->appends($_GET)->links('paginate') }} -
- - @else -
- - - - Сообщений не найдено -
- @endif
- -
+ @include('modals.chats.remove_chat') @endsection diff --git a/routes/web.php b/routes/web.php index c6b21eb..c39f84b 100644 --- a/routes/web.php +++ b/routes/web.php @@ -649,6 +649,9 @@ Route::group([ // Отправил сообщение Route::post('сообщение/', [EmployerController::class, 'new_message'])->name('new_message'); + + Route::post('pin_chat/', [EmployerController::class, 'pin_chat'])->name('pin_chat'); + Route::post('remove_chat/', [EmployerController::class, 'remove_chat'])->name('remove_chat'); }); Route::get('TestWorker', [WorkerController::class, 'TestWorker'])->name('TestWorker'); -- 1.7.10.4