Blame view
app/Http/Controllers/Admin/MsgAnswersController.php
6.54 KB
82a9544dc Связи моделей, гр... |
1 2 3 4 5 6 |
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; use App\Models\Message; |
633ea705f Массовая рассылка... |
7 |
use App\Models\MessagesRequests; |
e688e0d8a Статистика работн... |
8 |
use App\Models\User; |
a89ff088a Поисковая система... |
9 |
use Illuminate\Database\Eloquent\Builder; |
82a9544dc Связи моделей, гр... |
10 |
use Illuminate\Http\Request; |
e688e0d8a Статистика работн... |
11 |
use Illuminate\Support\Facades\Auth; |
93a3f79f0 Поисковый движок ... |
12 |
use Illuminate\Support\Facades\DB; |
e688e0d8a Статистика работн... |
13 |
use Illuminate\Support\Facades\Validator; |
82a9544dc Связи моделей, гр... |
14 15 16 |
class MsgAnswersController extends Controller { |
a89ff088a Поисковая система... |
17 18 19 |
public function messages(Request $request) { $find_key = ""; $find_cat = ""; |
1a8d1192e Коммит в админке ... |
20 |
$Msgs = Message::with('user_from')->with('user_to'); //->with('response'); |
a89ff088a Поисковая система... |
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
$Msgs = $this->filter($Msgs, $request, $find_key, $find_cat); $Msgs = $Msgs->orderByDesc('created_at')->paginate(25); return view('admin.messages', compact('Msgs', 'find_key', 'find_cat')); } public function read_message(Message $message) { return view('admin.message-read', compact('message')); } public function filter($Msgs, Request $request, &$find_key, &$find_cat) { if (isset($request->find)) { $find_key = $request->find; $Msgs = $Msgs->where(function($q) use ($find_key) { $q->whereHas('user_from', function (Builder $query) use ($find_key) { $query->where('name', 'LIKE', "%$find_key%"); } )-> orWhereHas('user_to', function (Builder $query) use ($find_key) { $query->where('name', 'LIKE', "%$find_key%"); } ); }); } if (isset($request->category)) { $find_cat = $request->category; switch ($find_cat) { case 'Работодатели': $Msgs = $Msgs->where(function($q) { $q->whereHas('user_to', function (Builder $query) { $query->where('is_worker', '0'); } )->orwhereHas('user_from', function (Builder $query) { $query->where('is_worker', '0'); } ); }); break; case 'Соискатели': $Msgs = $Msgs->where(function($q) { $q->whereHas('user_to', function (Builder $query) { $query->where('is_worker', '1'); } )->orwhereHas('user_from', function (Builder $query) { $query->where('is_worker', '1'); } ); }); break; case 'Администраторы': $Msgs = $Msgs->where(function($q) { $q->whereHas('user_to', function (Builder $query) { $query->where('admin', '1'); } )->orwhereHas('user_from', function (Builder $query) { $query->where('admin', '1'); } ); }); break; default:break; } } return $Msgs; |
82a9544dc Связи моделей, гр... |
98 |
|
82a9544dc Связи моделей, гр... |
99 |
} |
e688e0d8a Статистика работн... |
100 |
|
d2571da21 Правки по массово... |
101 102 103 104 105 106 107 108 109 110 111 112 113 114 |
public function reject_message(Request $request) { $message_request_id = $request->get('id'); $message_request = MessagesRequests::find($message_request_id); $message_request->update(['is_rejected' => now()]); return response()->json(['success' => true]); } public function send_message(Request $request) { $message_request_id = $request->get('id'); MessagesRequests::send_message($message_request_id); return response()->json(['success' => true]); } |
e688e0d8a Статистика работн... |
115 |
public function admin_messages(Request $request) { |
f060aa75b Счетчик сообщений... |
116 117 118 119 120 |
if ($request->ajax()) { $msg = Message::find($request->id); $msg->flag_new = !($request->flag_new); $msg->save(); } |
e688e0d8a Статистика работн... |
121 |
$id_admin = Auth::user()->id; |
673a7768d Правки в админке,... |
122 |
$users = User::query()->OrderBy('name')->where('is_bd', '=', '0')->get(); |
e688e0d8a Статистика работн... |
123 |
|
633ea705f Массовая рассылка... |
124 125 126 127 128 |
$Msgs = MessagesRequests::query() ->with('user') ->orderByDesc('created_at') ->paginate(10) ; |
e688e0d8a Статистика работн... |
129 |
|
f060aa75b Счетчик сообщений... |
130 131 132 |
if ($request->ajax()) return view('admin.message.index_ajax', compact('Msgs', 'id_admin', 'users')); else |
633ea705f Массовая рассылка... |
133 |
return view('admin.message.index', compact('Msgs', 'id_admin', 'users')); |
e688e0d8a Статистика работн... |
134 |
} |
93a3f79f0 Поисковый движок ... |
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
public function messages_sql(Request $request) { $id = Auth::user()->id; DB::enableQueryLog(); //$query = DB::select('select * from users where id = :id', ['id' => 1]); $query = DB::select(DB::raw('SELECT u1.name as "To-user", u2.name as "From-user", m1.`text`, m1.created_at FROM messages m1 JOIN (SELECT MAX(id) id FROM messages GROUP BY LEAST(user_id, to_user_id), GREATEST(user_id, to_user_id) ) m2 USING (id) JOIN users u1 ON u1.id = m1.user_id JOIN users u2 ON u2.id = m1.to_user_id Where ((m1.user_id = :uid) or (m1.to_user_id = :uid2)) '), ['uid' => $id, 'uid2' => $id]); //dump(DB::getQueryLog()); dd($query); return; } |
e688e0d8a Статистика работн... |
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 |
public function admin_messages_post(Request $request) { $rules = [ 'title' => 'required|min:3|max:255', 'text' => 'required|min:1' ]; $messages = [ 'required' => 'Поле не может быть пустым!', ]; $validator = Validator::make($request->all(), $rules, $messages); if ($validator->fails()) { return redirect()->route('admin.admin-messages')->withErrors($validator); } else { $params = $request->all(); $id_admin = Auth::user()->id; if ($request->has('file')) { $params['file'] = $request->file('file')->store("upload/".$id_admin, 'public'); } Message::create($params); return redirect()->route('admin.admin-messages'); } } |
82a9544dc Связи моделей, гр... |
177 |
} |