芝麻web文件管理V1.00
编辑当前文件:/home/qrafawbu/qrafiqxcreativeagency.com/accounts/office/app/Jobs/ImportEmployeeJob.php
row = $row; $this->columns = $columns; $this->company = $company; } /** * Execute the job. * * @return void */ public function handle() { if (!empty(array_keys($this->columns, 'name')) && !empty(array_keys($this->columns, 'email')) && filter_var($this->row[array_keys($this->columns, 'email')[0]], FILTER_VALIDATE_EMAIL)) { if (!checkCompanyCanAddMoreEmployees($this->company?->id)) { $this->job->fail(__('superadmin.updatePlanNote')); return; } $user = User::where('email', $this->row[array_keys($this->columns, 'email')[0]])->first(); if ($user) { $this->job->fail(__('messages.duplicateEntryForEmail') . $this->row[array_keys($this->columns, 'email')[0]]); return; } $employeeDetails = EmployeeDetails::where('employee_id', $this->row[array_keys($this->columns, 'employee_id')[0]])->first(); if ($employeeDetails) { $this->job->fail(__('messages.duplicateEntryForEmployeeId') . $this->row[array_keys($this->columns, 'employee_id')[0]]); } else { DB::beginTransaction(); try { $user = new User(); $user->company_id = $this->company?->id; $user->name = $this->row[array_keys($this->columns, 'name')[0]]; $user->email = $this->row[array_keys($this->columns, 'email')[0]]; if (isWorksuite()) { $user->password = bcrypt(123456); } $user->mobile = !empty(array_keys($this->columns, 'mobile')) ? $this->row[array_keys($this->columns, 'mobile')[0]] : null; $user->gender = !empty(array_keys($this->columns, 'gender')) ? strtolower($this->row[array_keys($this->columns, 'gender')[0]]) : null; if (isWorksuiteSaas()) { $userAuth = UserAuth::createUserAuthCredentials($this->row[array_keys($this->columns, 'email')[0]], 123456); $user->user_auth_id = $userAuth->id; } $user->save(); if ($user->id) { $employee = new EmployeeDetails(); $employee->company_id = $this->company?->id; $employee->user_id = $user->id; $employee->address = !empty(array_keys($this->columns, 'address')) ? $this->row[array_keys($this->columns, 'address')[0]] : null; $employee->employee_id = !empty(array_keys($this->columns, 'employee_id')) ? $this->row[array_keys($this->columns, 'employee_id')[0]] : (EmployeeDetails::max('id') + 1); $employee->joining_date = !empty(array_keys($this->columns, 'joining_date')) ? Carbon::createFromFormat('Y-m-d', $this->row[array_keys($this->columns, 'joining_date')[0]]) : null; $employee->hourly_rate = !empty(array_keys($this->columns, 'hourly_rate')) ? preg_replace('/[^0-9.]/', '', $this->row[array_keys($this->columns, 'hourly_rate')[0]]) : null; $employee->save(); } $employeeRole = Role::where('name', 'employee')->first(); $user->attachRole($employeeRole); $user->assignUserRolePermission($employeeRole->id); $this->logSearchEntry($user->id, $user->name, 'employees.show', 'employee'); DB::commit(); } catch (\Carbon\Exceptions\InvalidFormatException $e) { DB::rollBack(); $this->job->fail(__('messages.invalidDate') . json_encode($this->row, true)); } catch (\Exception $e) { DB::rollBack(); $this->job->fail($e->getMessage()); } } } else { $this->job->fail(__('messages.invalidData') . json_encode($this->row, true)); } } }