Commit 9c1ddc75ac039ee82d4130c801d636cb148cdff3

Authored by Андрей Ларионов
Exists in master

Коммит по проекту - должности

Showing 2 changed files Inline Diff

app/Http/Controllers/Admin/UsersController.php
1 <?php 1 <?php
2 2
3 namespace App\Http\Controllers\Admin; 3 namespace App\Http\Controllers\Admin;
4 4
5 use App\Http\Controllers\Controller; 5 use App\Http\Controllers\Controller;
6 use App\Http\Requests\BaseUserRequest; 6 use App\Http\Requests\BaseUserRequest;
7 use App\Models\ContentRoles; 7 use App\Models\ContentRoles;
8 use App\Models\Job_title; 8 use App\Models\Job_title;
9 use App\Models\User; 9 use App\Models\User;
10 use App\Models\Worker; 10 use App\Models\Worker;
11 use Illuminate\Http\Request; 11 use Illuminate\Http\Request;
12 use Illuminate\Support\Facades\Auth; 12 use Illuminate\Support\Facades\Auth;
13 use Illuminate\Support\Facades\Storage; 13 use Illuminate\Support\Facades\Storage;
14 use PhpOffice\PhpSpreadsheet\Spreadsheet; 14 use PhpOffice\PhpSpreadsheet\Spreadsheet;
15 use PhpOffice\PhpSpreadsheet\Style\Alignment; 15 use PhpOffice\PhpSpreadsheet\Style\Alignment;
16 use PhpOffice\PhpSpreadsheet\Style\Border; 16 use PhpOffice\PhpSpreadsheet\Style\Border;
17 use PhpOffice\PhpSpreadsheet\Style\Font; 17 use PhpOffice\PhpSpreadsheet\Style\Font;
18 use PhpOffice\PhpSpreadsheet\Writer\Xlsx; 18 use PhpOffice\PhpSpreadsheet\Writer\Xlsx;
19 19
20 class UsersController extends Controller 20 class UsersController extends Controller
21 { 21 {
22 public function index(Request $request) { 22 public function index(Request $request) {
23 $title = 'Админка - Пользователи системы'; 23 $title = 'Админка - Пользователи системы';
24 $id_admin = Auth::user()->id; 24 $id_admin = Auth::user()->id;
25 if ($request->ajax()) { 25 if ($request->ajax()) {
26 $user = User::find($request->id); 26 $user = User::find($request->id);
27 $request->offsetUnset('id'); 27 $request->offsetUnset('id');
28 $user->update($request->all()); 28 $user->update($request->all());
29 } 29 }
30 30
31 $find_key = ""; 31 $find_key = "";
32 $users = User::query(); 32 $users = User::query();
33 if (isset($request->find)) { 33 if (isset($request->find)) {
34 $find_key = $request->find; 34 $find_key = $request->find;
35 $users = $users->where('name', 'LIKE', "%$find_key%") 35 $users = $users->where('name', 'LIKE', "%$find_key%")
36 ->orWhere('email', 'LIKE', "%$find_key%"); 36 ->orWhere('email', 'LIKE', "%$find_key%");
37 } 37 }
38 38
39 $users = $users->paginate(15); 39 $users = $users->paginate(15);
40 40
41 if ($request->ajax()) { 41 if ($request->ajax()) {
42 return view('admin.users.index_ajax', compact('users', 'id_admin')); 42 return view('admin.users.index_ajax', compact('users', 'id_admin'));
43 } else { 43 } else {
44 return view('admin.users.index', compact('users', 'title', 'id_admin', 'find_key')); 44 return view('admin.users.index', compact('users', 'title', 'id_admin', 'find_key'));
45 } 45 }
46 } 46 }
47 47
48 public function index_bd(Request $request) { 48 public function index_bd(Request $request) {
49 $title = 'Админка - Пользователи базы данных'; 49 $title = 'Админка - Пользователи базы данных';
50 50
51 $find_key = ""; 51 $find_key = "";
52 $users = User::query(); 52 $users = User::query();
53 if (isset($request->find)) { 53 if (isset($request->find)) {
54 $find_key = $request->find; 54 $find_key = $request->find;
55 $users = $users->where('name', 'LIKE', "%$find_key%") 55 $users = $users->where('name', 'LIKE', "%$find_key%")
56 ->orWhere('email', 'LIKE', "%$find_key%") 56 ->orWhere('email', 'LIKE', "%$find_key%")
57 ->orWhere('telephone', 'LIKE', "%$find_key%"); 57 ->orWhere('telephone', 'LIKE', "%$find_key%");
58 } 58 }
59 59
60 $users = $users->Baseuser()->paginate(15); 60 $users = $users->Baseuser()->paginate(15);
61 61
62 if ($request->ajax()) { 62 if ($request->ajax()) {
63 return view('admin.users.index_bd_ajax', compact('users')); 63 return view('admin.users.index_bd_ajax', compact('users'));
64 } else { 64 } else {
65 return view('admin.users.index_bd', compact('users', 'title', 'find_key')); 65 return view('admin.users.index_bd', compact('users', 'title', 'find_key'));
66 } 66 }
67 } 67 }
68 68
69 public function add_bd() { 69 public function add_bd() {
70 $list_job_titles = Job_title::query()->active()->where('is_bd', '=' , '2')->orderBy('name', 'asc')->get(); 70 $list_job_titles = Job_title::query()->active()->where('is_bd', '=' , '2')->orderBy('name', 'asc')->get();
71 return view('admin.users.add', compact('list_job_titles')); 71 return view('admin.users.add', compact('list_job_titles'));
72 } 72 }
73 73
74 public function add_store_bd(BaseUserRequest $request) { 74 public function add_store_bd(BaseUserRequest $request) {
75 $params = $request->all(); 75 $params = $request->all();
76 $position_work = $request->position_work; 76 $position_work = $request->position_work;
77 77
78 if ($request->has('file')) { 78 if ($request->has('file')) {
79 $params['file'] = $request->file('file')->store('basedata', 'public'); 79 $params['file'] = $request->file('file')->store('basedata', 'public');
80 } 80 }
81 81
82 if (isset($request->name)) { 82 if (isset($request->name)) {
83 $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2; 83 $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2;
84 } 84 }
85 85
86 $user = User::create($params); 86 $user = User::create($params);
87 $user_id = $user->id; 87 $user_id = $user->id;
88 $worker = new Worker(); 88 $worker = new Worker();
89 $worker->position_work = $position_work; 89 $worker->position_work = $position_work;
90 $worker->user_id = $user_id; 90 $worker->user_id = $user_id;
91 $worker->save(); 91 $worker->save();
92 92
93 return redirect()->route('admin.basedata'); 93 return redirect()->route('admin.basedata');
94 } 94 }
95 95
96 public function edit_bd(User $user) { 96 public function edit_bd(User $user) {
97 $list_job_titles = Job_title::query()->active()->where('is_bd', '=' , '2')->orderBy('name', 'asc')->get(); 97 $list_job_titles = Job_title::query()->active()->where('is_bd', '=' , '2')->orderBy('name', 'asc')->get();
98 return view('admin.users.edit', compact('user', 'list_job_titles')); 98 return view('admin.users.edit', compact('user', 'list_job_titles'));
99 } 99 }
100 100
101 public function update_bd(BaseUserRequest $request, User $user) { 101 public function update_bd(BaseUserRequest $request, User $user) {
102 $params = $request->all(); 102 $params = $request->all();
103 $position_work = $request->position_work; 103 $position_work = $request->position_work;
104 104
105 if ($request->has('file')) { 105 if ($request->has('file')) {
106 if (!empty($user->file)) Storage::delete($user->file); 106 if (!empty($user->file)) Storage::delete($user->file);
107 $params['file'] = $request->file('file')->store('basedata', 'public'); 107 $params['file'] = $request->file('file')->store('basedata', 'public');
108 } else { 108 } else {
109 if (!empty($user->image)) $params['file'] = $user->file; 109 if (!empty($user->image)) $params['file'] = $user->file;
110 } 110 }
111 111
112 if (isset($request->name)) { 112 if (isset($request->name)) {
113 $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2; 113 $params['name'] = $request->surname." ".$request->name_man." ".$request->surname2;
114 } 114 }
115 115
116 $user->update($params); 116 $user->update($params);
117 if (isset($user->workers[0]->id)) { 117 if (isset($user->workers[0]->id)) {
118 $worker = Worker::find($user->workers[0]->id); 118 $worker = Worker::find($user->workers[0]->id);
119 $worker->position_work = $position_work; 119 $worker->position_work = $position_work;
120 $worker->save(); 120 $worker->save();
121 } else { 121 } else {
122 $worker = new Worker(); 122 $worker = new Worker();
123 $worker->user_id = $user->id; 123 $worker->user_id = $user->id;
124 $worker->position_work = $position_work; 124 $worker->position_work = $position_work;
125 $worker->save(); 125 $worker->save();
126 } 126 }
127 127
128 return redirect()->route('admin.basedata'); 128 return redirect()->route('admin.basedata');
129 } 129 }
130 130
131 public function destroy_bd(User $user) { 131 public function destroy_bd(User $user) {
132 $user->delete(); 132 $user->delete();
133 return redirect()->route('admin.basedata'); 133 return redirect()->route('admin.basedata');
134 } 134 }
135 135
136 public function roles(Request $request) { 136 public function roles(Request $request) {
137 if ($request->ajax()) { 137 if ($request->ajax()) {
138 $user = User::find($request->id); 138 $user = User::find($request->id);
139 $request->offsetUnset('id'); 139 $request->offsetUnset('id');
140 $user->update($request->all()); 140 $user->update($request->all());
141 } 141 }
142 142
143 $users = User::query()->Realuser()->paginate(15); 143 $users = User::query()->Realuser()->paginate(15);
144 144
145 if ($request->ajax()) { 145 if ($request->ajax()) {
146 return view('admin.users.roles.index_ajax', compact('users')); 146 return view('admin.users.roles.index_ajax', compact('users'));
147 } else { 147 } else {
148 return view('admin.users.roles.index', compact('users')); 148 return view('admin.users.roles.index', compact('users'));
149 } 149 }
150 } 150 }
151 151
152 public function admin_roles(Request $request) { 152 public function admin_roles(Request $request) {
153 153
154 if ($request->ajax()) { 154 if ($request->ajax()) {
155 $id = $request->id; 155 $id = $request->id;
156 $request->offsetUnset('id'); 156 $request->offsetUnset('id');
157 ContentRoles::where('id', '=', $id)->update($request->all()); 157 ContentRoles::where('id', '=', $id)->update($request->all());
158 } 158 }
159 $roles = ContentRoles::query()->OrderBy('id')->paginate(25); 159 $roles = ContentRoles::query()->OrderBy('id')->paginate(25);
160 160
161 161
162 if ($request->ajax()) { 162 if ($request->ajax()) {
163 return view('admin.content.roles_index_ajax', compact('roles')); 163 return view('admin.content.roles_index_ajax', compact('roles'));
164 } else { 164 } else {
165 return view('admin.content.roles_index', compact('roles')); 165 return view('admin.content.roles_index', compact('roles'));
166 } 166 }
167 } 167 }
168 168
169 public function doc_bd(User $user) { 169 public function doc_bd(User $user) {
170 $id = $user->id; 170 $id = $user->id;
171 $spreadsheet = new Spreadsheet(); 171 $spreadsheet = new Spreadsheet();
172 $activeWorksheet = $spreadsheet->getActiveSheet(); 172 $activeWorksheet = $spreadsheet->getActiveSheet();
173 $activeWorksheet->setCellValue('A1', 'Отчет по соискателю'); 173 $activeWorksheet->setCellValue('A1', 'Отчет по соискателю');
174 $activeWorksheet->getStyle('A1')->applyFromArray([ 174 $activeWorksheet->getStyle('A1')->applyFromArray([
175 'font' => [ 175 'font' => [
176 'name' => 'Arial', 176 'name' => 'Arial',
177 'bold' => true, 177 'bold' => true,
178 'italic' => false, 178 'italic' => false,
179 'underline' => Font::UNDERLINE_DOUBLE, 179 'underline' => Font::UNDERLINE_DOUBLE,
180 'strikethrough' => false, 180 'strikethrough' => false,
181 'color' => [ 181 'color' => [
182 'rgb' => '808080' 182 'rgb' => '808080'
183 ] 183 ]
184 ], 184 ],
185 'borders' => [ 185 'borders' => [
186 'allBorders' => [ 186 'allBorders' => [
187 'borderStyle' => Border::BORDER_THIN, 187 'borderStyle' => Border::BORDER_THIN,
188 'color' => [ 188 'color' => [
189 'rgb' => '808080' 189 'rgb' => '808080'
190 ] 190 ]
191 ], 191 ],
192 'outline' => array( 192 'outline' => array(
193 'style' => Border::BORDER_THIN, 193 'style' => Border::BORDER_THIN,
194 'color' => array('rgb' => '000000') 194 'color' => array('rgb' => '000000')
195 ), 195 ),
196 ], 196 ],
197 197
198 'alignment' => [ 198 'alignment' => [
199 'horizontal' => Alignment::HORIZONTAL_CENTER, 199 'horizontal' => Alignment::HORIZONTAL_CENTER,
200 'vertical' => Alignment::VERTICAL_CENTER, 200 'vertical' => Alignment::VERTICAL_CENTER,
201 'wrapText' => true, 201 'wrapText' => true,
202 ] 202 ]
203 ]); 203 ]);
204 204
205 $activeWorksheet->setCellValue('A2', "Псевдоним/имя: ".$user->name); 205 $activeWorksheet->setCellValue('A2', "Псевдоним/имя: ".$user->name);
206 $activeWorksheet->setCellValue('A3', "Фамилия: ".$user->surname); 206 $activeWorksheet->setCellValue('A3', "Фамилия: ".$user->surname);
207 $activeWorksheet->setCellValue('A4', "Имя: ".$user->name_man); 207 $activeWorksheet->setCellValue('A4', "Имя: ".$user->name_man);
208 $activeWorksheet->setCellValue('A5', "Отчество: ".$user->surname2); 208 $activeWorksheet->setCellValue('A5', "Отчество: ".$user->surname2);
209 $activeWorksheet->setCellValue('A6', "Телефон: ".$user->telephone); 209 $activeWorksheet->setCellValue('A6', "Телефон: ".$user->telephone);
210 $activeWorksheet->setCellValue('A7', "Емайл: ".$user->email); 210 $activeWorksheet->setCellValue('A7', "Емайл: ".$user->email);
211 211
212 if (isset($user->workers[0]->id)) { 212 if (isset($user->workers[0]->id)) {
213 $activeWorksheet->setCellValue('A9', "Анкета: "); 213 $activeWorksheet->setCellValue('A9', "Анкета: ");
214 $activeWorksheet->setCellValue('A10', "Телефон: " . $user->workers[0]->telephone); 214 $activeWorksheet->setCellValue('A10', "Телефон: " . $user->workers[0]->telephone);
215 $activeWorksheet->setCellValue('A11', "Емайл: " . $user->workers[0]->email); 215 $activeWorksheet->setCellValue('A11', "Емайл: " . $user->workers[0]->email);
216 } 216 }
217 217
218 if (isset($user->jobtitles[0]->id)) { 218 if (isset($user->jobtitles[0]->id)) {
219 $activeWorksheet->setCellValue('A12', "Должность: " . $user->jobtitles[0]->name); 219 $activeWorksheet->setCellValue('A12', "Должность: " . $user->jobtitles[0]->name);
220 } 220 }
221 $activeWorksheet->getColumnDimension("A")->setWidth(100); 221 $activeWorksheet->getColumnDimension("A")->setWidth(100);
222 $writer = new Xlsx($spreadsheet); 222 $writer = new Xlsx($spreadsheet);
223 223
224 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); 224 header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
225 header('Content-Disposition: attachment; filename="user'.$id.'.xlsx"'); 225 header('Content-Disposition: attachment; filename="user'.$id.'.xlsx"');
226 header('Cache-Control: no-cache'); 226 header('Cache-Control: no-cache');
227 227
228 $writer->save('php://output'); 228 $writer->save('php://output');
229 $writer->save(storage_path("app/public/export/user$id.xlsx")); 229 $writer->save(storage_path("app/public/export/user$id.xlsx"));
230 230
231 //$spreadsheet->disconnectWorksheets(); 231 //$spreadsheet->disconnectWorksheets();
232 return redirect()->route('admin.basedata'); 232 return redirect()->route('admin.basedata');
233 233
234 } 234 }
235 } 235 }
236 236
app/Providers/MyServiceProvider.php
1 <?php 1 <?php
2 2
3 namespace App\Providers; 3 namespace App\Providers;
4 4
5 use App\Models\Company; 5 use App\Models\Company;
6 use App\Models\ContentRoles; 6 use App\Models\ContentRoles;
7 use App\Models\Employer; 7 use App\Models\Employer;
8 use App\Models\Job_title; 8 use App\Models\Job_title;
9 use App\Models\Worker; 9 use App\Models\Worker;
10 use Illuminate\Support\Facades\Auth; 10 use Illuminate\Support\Facades\Auth;
11 use Illuminate\Support\Facades\DB; 11 use Illuminate\Support\Facades\DB;
12 use Illuminate\Support\Facades\View; 12 use Illuminate\Support\Facades\View;
13 use Illuminate\Support\ServiceProvider; 13 use Illuminate\Support\ServiceProvider;
14 14
15 class MyServiceProvider extends ServiceProvider 15 class MyServiceProvider extends ServiceProvider
16 { 16 {
17 /** 17 /**
18 * Register services. 18 * Register services.
19 * 19 *
20 * @return void 20 * @return void
21 */ 21 */
22 public function register() 22 public function register()
23 { 23 {
24 // 24 //
25 } 25 }
26 26
27 /** 27 /**
28 * Bootstrap services. 28 * Bootstrap services.
29 * 29 *
30 * @return void 30 * @return void
31 */ 31 */
32 public function boot() 32 public function boot()
33 { 33 {
34 $views = ['admin.job_titles.parent_id']; 34 $views = ['admin.job_titles.parent_id'];
35 View::composer($views, 35 View::composer($views,
36 function($view) 36 function($view)
37 { 37 {
38 static $items = null; 38 static $items = null;
39 39
40 if (is_null($items)) { 40 if (is_null($items)) {
41 $items = Job_title::query()-> 41 $items = Job_title::query()->
42 orderByDesc('sort')-> 42 orderByDesc('sort')->
43 orderBy('name')-> 43 orderBy('name')->
44 active()-> 44 active()->
45 get(); 45 get();
46 $parent = 0; 46 $parent = 0;
47 $view->with(['items' => $items, 'parent' => $parent]); 47 $view->with(['items' => $items, 'parent' => $parent]);
48 } else { 48 } else {
49 $view->with(['items' => $items]); 49 $view->with(['items' => $items]);
50 } 50 }
51 51
52 } 52 }
53 ); 53 );
54 54
55 $views2 = ['layout.admin', 'admin.index']; 55 $views2 = ['layout.admin', 'admin.index'];
56 56
57 View::composer($views2, 57 View::composer($views2,
58 function($view){ 58 function($view){
59 $id = Auth::user()->id; 59 $id = Auth::user()->id;
60 $is_manager = Auth::user()->is_manager; 60 $is_manager = Auth::user()->is_manager;
61 $admin = Auth::user()->admin; 61 $admin = Auth::user()->admin;
62 62
63 $contents = ContentRoles::query()->get(); 63 $contents = ContentRoles::query()->get();
64 64
65 $query = DB::select(DB::raw('SELECT count(*) as MsgCount 65 $query = DB::select(DB::raw('SELECT count(*) as MsgCount
66 FROM messages m1 66 FROM messages m1
67 Where ((m1.flag_new = 1) and (m1.to_user_id = :uid)) 67 Where ((m1.flag_new = 1) and (m1.to_user_id = :uid))
68 '), ['uid' => $id] 68 '), ['uid' => $id]
69 ); 69 );
70 70
71 $view->with(['MsgCount' => $query[0]->MsgCount, 71 $view->with(['MsgCount' => $query[0]->MsgCount,
72 'UserId' => $id, 72 'UserId' => $id,
73 'is_manager' => $is_manager, 73 'is_manager' => $is_manager,
74 'admin' => $admin, 74 'admin' => $admin,
75 'contents' => $contents]); 75 'contents' => $contents]);
76 } 76 }
77 ); 77 );
78 78
79 $views3 = ['layout.frontend', 'index']; 79 $views3 = ['layout.frontend', 'index'];
80 80
81 View::composer($views3, 81 View::composer($views3,
82 function($view){ 82 function($view){
83 $id = Auth::user(); 83 $id = Auth::user();
84 $companies = Company::query()->limit(1)->get(); 84 $companies = Company::query()->limit(1)->get();
85 $jobs = Job_title::query()->where('is_remove', '=', '0')->get(); 85 $jobs = Job_title::query()->where('is_remove', '=', '0')->get();
86 $view->with(['UserId' => $id, 'companies' => $companies, 'jobs' => $jobs]); 86 $view->with(['UserId' => $id, 'companies' => $companies, 'jobs' => $jobs]);
87 } 87 }
88 ); 88 );
89 89
90 $view1 = ['employers.menu', 'employers.emblema', 'employers.send_all']; 90 $view1 = ['employers.menu', 'employers.emblema', 'employers.send_all'];
91 View::composer($view1, 91 View::composer($view1,
92 function($view){ 92 function($view){
93 $user = Auth::user(); 93 $user = Auth::user();
94 $id = $user->id; 94 $id = $user->id;
95 $employer = Employer::query()->where('user_id', $id)->get(); 95 $employer = Employer::query()->where('user_id', $id)->get();
96 $id_employer = $employer[0]->id; 96 $id_employer = $employer[0]->id;
97 $view->with(['id_employer' => $id_employer, 'Employer' => $employer]); 97 $view->with(['id_employer' => $id_employer, 'Employer' => $employer]);
98 } 98 }
99 ); 99 );
100 100
101 $view_worker = ['workers.emblema']; 101 $view_worker = ['workers.emblema'];
102 View::composer($view_worker, 102 View::composer($view_worker,
103 function($view_worker) { 103 function($view_worker) {
104 $user = Auth::user(); 104 $user = Auth::user();
105 $id = $user->id; 105 $id = $user->id;
106 $Worker = Worker::query()->where('user_id', $id)->get(); 106 $Worker = Worker::query()->where('user_id', $id)->get();
107 if (isset($Worker[0]->id)) { 107 if (isset($Worker[0]->id)) {
108 $id_worker = $Worker[0]->id; 108 $id_worker = $Worker[0]->id;
109 } else { 109 } else {
110 $id_worker = 0; 110 $id_worker = 0;
111 } 111 }
112 $view_worker->with(['id_worker' => $id_worker, 'Worker' => $Worker, 'User' => $user]); 112 $view_worker->with(['id_worker' => $id_worker, 'Worker' => $Worker, 'User' => $user]);
113 } 113 }
114 ); 114 );
115 115
116 $view_job_title = ['modals.register']; 116 $view_job_title = ['modals.register'];
117 View::composer($view_job_title, 117 View::composer($view_job_title,
118 function($view_job_title) { 118 function($view_job_title) {
119 $Job_titles = Job_title::query()->where('is_remove', '=', '0')->where('is_bd', '=' , '0')->get(); 119 $Job_titles = Job_title::query()->where('is_remove', '=', '1')->where('is_bd', '=' , '0')->get();
120 $view_job_title->with(['Job_titles' => $Job_titles]); 120 $view_job_title->with(['Job_titles' => $Job_titles]);
121 } 121 }
122 ); 122 );
123 123
124 } 124 }
125 } 125 }
126 126