Advertisement
Guest User

Untitled

a guest
Apr 26th, 2019
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.81 KB | None | 0 0
  1. public function store(StoreApplicationRequest $request){
  2.  
  3.         $rawData = $request->input();
  4.  
  5.         if (!$request->has(['last_name', 'first_name', 'middle_name',
  6.             'passport_id', 'snils', 'inn', 'employment_history', 'email',
  7.             'post_id', 'medical_id', 'criminal_record',
  8.             'scientific_works', '_token'])){
  9.             return back()->withErrors(['msg' => 'Ошибка сохранения (#1)'])->withInput();
  10.         }
  11.         if ($request->has('status', 'description')){
  12.             return back()->withErrors(['msg' => 'Ошибка сохранения (#2)'])->withInput();
  13.         }
  14.  
  15.         $data = [
  16.             'first_name' => $rawData['first_name'],
  17.             'middle_name' => $rawData['middle_name'],
  18.             'last_name' => $rawData['last_name'],
  19.             'passport_id' => $rawData['passport_id'],
  20.             'snils' => $rawData['snils'],
  21.             'inn' => $rawData['inn'],
  22.             'employment_history' => $rawData['employment_history'],
  23.             'email' => $rawData['email'],
  24.             'post_id' => $rawData['post_id'],
  25.             'scientific_works' => $rawData['scientific_works'],
  26.         ];
  27.         $item = new Application($data);
  28.         $item->save();
  29.         $app_id = $item->id;
  30.  
  31.         $const_files = [
  32.             ['medical_id', 'Медицинская карта'],
  33.             ['criminal_record', 'Справка о наличии (отсутствии) судимости и (или) факта уголовного преследования либо о прекращении уголовного преследования по реабилитирующим основаниям.'],
  34.             ['military_id', 'Документы воинского учета (для военнообязанных и лиц, подлежащих призыву на военную службу).'],
  35.             ['edu_id', 'Документ об образовании, о присвоении ученой степени, о присвоении ученого звания.'],
  36.         ];
  37.  
  38.         foreach ($const_files as $cf) {
  39.             if(!empty($request->file($cf[0]))) {
  40.                 $files = $request->file($cf[0]);
  41.                 $j = 0;
  42.                 foreach ($files as $file) {
  43.                     $cfile = Storage::putFile('public/docs', $file);
  44.                     $j++;
  45.                     if($cfile) {
  46.                         $addiction_data = [
  47.                             'application_id' => $app_id,
  48.                             'description' => $cf[1] . ' ('. $j . ')',
  49.                             'file' => $cfile,
  50.                         ];
  51.                         $addiction = new Addiction($addiction_data);
  52.                         $addiction->save();
  53.                         if (!$addiction) {
  54.                             return back()->withErrors(['msg' => 'Ошибка сохранения (#6)'])->withInput();
  55.                         }
  56.                     } else {
  57.                         return back()->withErrors(['msg' => 'Ошибка сохранения (#7)'])->withInput();
  58.                     }
  59.                 }
  60.  
  61.             }
  62.         }
  63.  
  64.         if ($item) {
  65.             if(!empty($request->file('files'))){
  66.                 $files = $request->file('files');
  67.                 $descriptions = $rawData['description'];
  68.                 $count = count($files);
  69.  
  70.                 for ($i = 0; $i < $count; $i++){
  71.                     $file = Storage::putFile('public/docs', $files[$i]);
  72.                     if ($file) {
  73.                         $addiction_data = [
  74.                             'application_id' => $app_id,
  75.                             'description' => $descriptions[$i],
  76.                             'file' => $file,
  77.                         ];
  78.                         $addiction = new Addiction($addiction_data);
  79.                         $addiction->save();
  80.  
  81.                         if (!$addiction){
  82.                             return back()->withErrors(['msg' => 'Ошибка сохранения (#5)'])->withInput();
  83.                         }
  84.                     } else {
  85.                         return back()->withErrors(['msg' => 'Ошибка сохранения (#4)'])->withInput();
  86.                     }
  87.                 }
  88.             }
  89.  
  90. //            Mail::to('hrd@muindor.com')->queue((new AlertHRD($item))->subject('Новая заявка #'.$app_id)->from(['address' => 'robot@muindor.com', 'name' => 'robot']));
  91. //            dd(ExportTo1C::dispatchNow($item));
  92.             ExportTo1C::dispatch($item);
  93.  
  94.             return redirect()->route('registration.index')
  95.                 ->with(['success' => 'Ваша заявка отправлнена']);
  96.  
  97.         } else {
  98.             return back()->withErrors(['msg' => 'Ошибка сохранения (#3)'])->withInput();
  99.         }
  100.  
  101.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement