|
@@ -5,6 +5,7 @@ namespace App\Models\Manager\Personnel;
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
|
+use App\Models\Manager\Personnel\EmployeeArea as EmployeeAreaModel;
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
|
* 员工模型
|
|
* 员工模型
|
|
@@ -90,7 +91,34 @@ class Employee extends Model
|
|
|
{
|
|
{
|
|
|
DB::beginTransaction();
|
|
DB::beginTransaction();
|
|
|
try {
|
|
try {
|
|
|
- $this->addEmployee_content($data);
|
|
|
|
|
|
|
+ $EmployeeAreaModel = new EmployeeAreaModel();
|
|
|
|
|
+ $insert_data = [
|
|
|
|
|
+ 'name' => $data['name'],
|
|
|
|
|
+ 'mobile' => $data['mobile'],
|
|
|
|
|
+ 'password' => md5($data['password']),
|
|
|
|
|
+ 'role_id' => $data['role_id'],
|
|
|
|
|
+ 'province_ids' => isset($data['province_ids']) ? $data['province_ids'] : '',
|
|
|
|
|
+ 'city_ids' => isset($data['city_ids']) ? ',' . $data['city_ids'] . ',' : '',
|
|
|
|
|
+ 'department_id' => $data['department_id'],
|
|
|
|
|
+ 'open_notice' => $data['open_notice'],
|
|
|
|
|
+ 'duty_type' => isset($data['duty_type']) ? $data['duty_type'] : '',
|
|
|
|
|
+ 'insert_time' => time(),
|
|
|
|
|
+ ];
|
|
|
|
|
+ $Employee_id = $this->insertGetId($insert_data);
|
|
|
|
|
+ if ($Employee_id) {
|
|
|
|
|
+ $this->where('id', $Employee_id)->update(['employee_code' => $this->employee_idToCode($Employee_id)]);
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($data['city_ids']) {
|
|
|
|
|
+ $insert_city_data = [];
|
|
|
|
|
+ $city_ids = explode(',', $data['city_ids']);
|
|
|
|
|
+ foreach ($city_ids as $city_id) {
|
|
|
|
|
+ $insert_city_data[] = [
|
|
|
|
|
+ 'employee_id' => $Employee_id,
|
|
|
|
|
+ 'city_id' => $city_id,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ $EmployeeAreaModel->insert($insert_city_data);
|
|
|
|
|
+ }
|
|
|
DB::commit();
|
|
DB::commit();
|
|
|
return true;
|
|
return true;
|
|
|
// 成功处理...
|
|
// 成功处理...
|
|
@@ -116,17 +144,42 @@ class Employee extends Model
|
|
|
if (!$Employee) {
|
|
if (!$Employee) {
|
|
|
return false;
|
|
return false;
|
|
|
}
|
|
}
|
|
|
- $Employee->name = $data['name'];
|
|
|
|
|
- $Employee->mobile = $data['mobile'];
|
|
|
|
|
- if(isset($data['password']) && $data['password'] !='') $Employee->password = md5($data['password']);
|
|
|
|
|
- $Employee->role_id = $data['role_id'];
|
|
|
|
|
- $Employee->city_ids = isset($data['city_ids'])? ','.$data['city_ids'].',' : '';
|
|
|
|
|
- $Employee->department_id = $data['department_id'];
|
|
|
|
|
- $Employee->open_notice = $data['open_notice'];
|
|
|
|
|
- $Employee->duty_type = isset($data['duty_type'])? $data['duty_type'] : '';
|
|
|
|
|
- $Employee->update_time = time();
|
|
|
|
|
- $Employee->save();
|
|
|
|
|
- return true;
|
|
|
|
|
|
|
+ DB::beginTransaction();
|
|
|
|
|
+ try {
|
|
|
|
|
+ $EmployeeAreaModel = new EmployeeAreaModel();
|
|
|
|
|
+
|
|
|
|
|
+ $Employee->name = $data['name'];
|
|
|
|
|
+ $Employee->mobile = $data['mobile'];
|
|
|
|
|
+ if (isset($data['password']) && $data['password'] != '') $Employee->password = md5($data['password']);
|
|
|
|
|
+ $Employee->role_id = $data['role_id'];
|
|
|
|
|
+ $Employee->city_ids = isset($data['city_ids']) ? ',' . $data['city_ids'] . ',' : '';
|
|
|
|
|
+ $Employee->department_id = $data['department_id'];
|
|
|
|
|
+ $Employee->open_notice = $data['open_notice'];
|
|
|
|
|
+ $Employee->duty_type = isset($data['duty_type']) ? $data['duty_type'] : '';
|
|
|
|
|
+ $Employee->update_time = time();
|
|
|
|
|
+ $Employee->save();
|
|
|
|
|
+
|
|
|
|
|
+ $EmployeeAreaModel->where('employee_id', $Employee->id)->delete();
|
|
|
|
|
+ if ($data['city_ids']) {
|
|
|
|
|
+ $insert_city_data = [];
|
|
|
|
|
+ $city_ids = explode(',', $data['city_ids']);
|
|
|
|
|
+ foreach ($city_ids as $city_id) {
|
|
|
|
|
+ $insert_city_data[] = [
|
|
|
|
|
+ 'employee_id' => $Employee->id,
|
|
|
|
|
+ 'city_id' => $city_id,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+ $EmployeeAreaModel->insert($insert_city_data);
|
|
|
|
|
+ }
|
|
|
|
|
+ DB::commit();
|
|
|
|
|
+ return true;
|
|
|
|
|
+ // 成功处理...
|
|
|
|
|
+ } catch (\Exception $e) {
|
|
|
|
|
+ DB::rollBack();
|
|
|
|
|
+
|
|
|
|
|
+ // 错误处理...
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|