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) + + @endforeach +Вы действительно хотите удалить час с ""?
+