Blame view
app/Http/Controllers/Admin/WorkersController.php
7.64 KB
8de035475 Создание: Структу... |
1 2 3 4 5 |
<?php namespace App\Http\Controllers\Admin; use App\Http\Controllers\Controller; |
32cbe7736 Обновление блейдо... |
6 7 |
use App\Models\Company; use App\Models\Job_title; |
e688e0d8a Статистика работн... |
8 |
use App\Models\Static_worker; |
8de035475 Создание: Структу... |
9 |
use App\Models\User; |
c84db5243 Форма редактирова... |
10 |
use App\Models\Worker; |
be3039cb9 Правки по работод... |
11 |
use Illuminate\Database\Eloquent\Builder; |
8de035475 Создание: Структу... |
12 |
use Illuminate\Http\Request; |
be3039cb9 Правки по работод... |
13 |
use Illuminate\Support\Facades\DB; |
32cbe7736 Обновление блейдо... |
14 15 |
use Illuminate\Support\Facades\Storage; use Illuminate\Support\Facades\Validator; |
8de035475 Создание: Структу... |
16 17 18 19 20 21 22 23 24 |
class WorkersController extends Controller { public function index(Request $request) { if ($request->ajax()) { $user = User::find($request->id); $request->offsetUnset('id'); $user->update($request->all()); } |
be3039cb9 Правки по работод... |
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 |
$status_work = Job_title::query()->active()->orderBy('name')->get(); $users = User::with('jobtitles')->where('is_worker', '1'); $find_status_work = ""; if (isset($request->status_work)) { $find_status_work = $request->status_work; //$users = $users->where('position_work', '=', $find_status_work); /*if ($request->status_work > 0) $users = $users->with(['workers' => function($query) use ($find_status_work){ $query->where('position_work', $find_status_work); }]); else $users = $users->with('workers');*/ /*$users = $users->where(function($query) use($find_status_work) { $query->with(['workers' => function($query1) use ($find_status_work){ $query1->where('position_work', $find_status_work); }]); });*/ if ($request->status_work > 0) { $users = $users->with('workers')-> whereHas('workers', function (Builder $query) use ($find_status_work) { $query->where('position_work', $find_status_work); } ); } else { $users = $users->with('workers'); } } else { $users = $users->with('workers'); } |
93a3f79f0 Поисковый движок ... |
59 60 61 62 63 64 |
$find_key = ""; if (isset($request->find)) { $find_key = $request->find; $users = $users->where(function($query) use($find_key) { $query->Where('name_man', 'LIKE', "%$find_key%") ->orWhere('email', 'LIKE', "%$find_key%") |
3e44ec515 Настройки форм со... |
65 66 67 |
->orWhere('telephone', 'LIKE', "%$find_key%") ->orWhere('surname', 'LIKE', "%$find_key%") ->orWhere('surname2', 'LIKE', "%$find_key%"); |
93a3f79f0 Поисковый движок ... |
68 69 70 71 |
}); } $users = $users->paginate(15); |
8de035475 Создание: Структу... |
72 |
|
be3039cb9 Правки по работод... |
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 98 99 100 101 102 103 104 105 106 107 |
/* $Arr = array(); $where = ''; $find_status_work = ""; if (isset($request->status_work)) { $find_status_work = $request->status_work; //$users = $users->where('position_work', '=', $find_status_work); $where.= ' and (w.position_work = :uid1)'; $Arr['uid1'] = $find_status_work; } $find_key = ""; if (isset($request->find)) { $find_key = $request->find; /*$users = $users->where(function($query) use($find_key) { $query->Where('name_man', 'LIKE', "%$find_key%") ->orWhere('email', 'LIKE', "%$find_key%") ->orWhere('telephone', 'LIKE', "%$find_key%"); });*/ /*$where.= " and ((u.name_man LIKE %:uid2%) or (w.email LIKE %:uid2%) or (w.telephone LIKE %:uid2%))"; $Arr['uid2'] = $find_key; } //$users = $users->paginate(15); //DB::enableQueryLog(); $users = DB::select('SELECT u.*, w.*, j.* FROM workers w JOIN users u ON u.id = w.user_id JOIN job_titles j ON j.id = w.position_work Where (u.is_worker = 1) '.$where, $Arr); //dump(DB::getQueryLog()); dd($users); */ |
8de035475 Создание: Структу... |
108 109 110 |
if ($request->ajax()) { return view('admin.worker.index_ajax', compact('users')); } else { |
be3039cb9 Правки по работод... |
111 |
return view('admin.worker.index', compact('users', 'find_key', 'find_status_work', 'status_work')); |
8de035475 Создание: Структу... |
112 113 |
} } |
c84db5243 Форма редактирова... |
114 |
|
32cbe7736 Обновление блейдо... |
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
public function form_edit_worker(Worker $worker) { $job_titles = Job_title::query()->active()->orderBy('name')->get(); $time_end_anketa = 'Бессрочно'; if (!empty($worker->updated_at)) { $long_days = Company::find(1)->time_resume; $time_end_anketa = date("d.m.Y H:i:s", strtotime($worker->updated_at . "+$long_days days")); } return view('admin.worker.edit', compact('worker', 'job_titles', 'time_end_anketa')); } public function form_update_worker(Request $request, Worker $worker) { $params = $request->all(); $rules = [ 'email' => 'email|string|max:255', //'photo' => 'mimes:jpeg,jpg,png|max:15000', ]; $messages = [ 'required' => 'Укажите обязательное поле «:attribute»', 'confirmed' => 'Пароли не совпадают', 'email' => 'Введите корректный email', 'min' => [ 'string' => 'Поле «:attribute» должно быть не меньше :min символов', 'file' => 'Файл «:attribute» должен быть не меньше :min Кбайт' ], 'max' => [ 'string' => 'Поле «:attribute» должно быть не больше :max символов', 'file' => 'Файл «:attribute» должен быть не больше :max Кбайт' ], ]; $validator = Validator::make($params, $rules, $messages); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); } else { $user_id = $worker->user_id; if ($request->has('photo')) { if (!empty($worker->photo)) { Storage::delete($worker->photo); } if (!empty($request->photo)) $params['photo'] = $request->file('photo')->store("workers/$user_id", 'public'); } $worker->update($params); return redirect()->route('admin.workers'); } |
c84db5243 Форма редактирова... |
166 |
} |
bb2fb443d Архитектурное доп... |
167 168 |
// кабинет - статистика работников |
e688e0d8a Статистика работн... |
169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
public function static_workers(Request $request) { $stat = Static_worker::with('users'); //->join('users', 'users.id', '=', 'static_workers.user_id'); $users = User::query()->active()->OrderBy('id')->get(); $periods = Static_worker::query()->distinct('year_month')->select('year_month')->get(); if ($request->ajax()) { if (isset($request->user_id)) if (!$request->user_id == "0") $stat = $stat->Where('user_id', '=', $request->user_id); if (isset($request->year_month)) { if (!$request->year_month == "0") $stat = $stat->Where('year_month', '=', $request->year_month); } } $stat = $stat->OrderByDesc('year_month'); //->OrderBy('users.name'); //OrderBy('users.name')-> /*$stat->implode() loadMissing(['users' => function (Builder $query) { $query->orderBy('name', 'asc'); }]);*/ $stat = $stat->paginate(15); if ($request->ajax()) return view('admin.static.index_workers_ajax', compact('stat')); else return view('admin.static.index_workers', compact('stat', 'users', 'periods')); |
bb2fb443d Архитектурное доп... |
197 |
} |
8de035475 Создание: Структу... |
198 |
} |