|
@@ -21,55 +21,38 @@ use Illuminate\Support\Facades\Hash;
|
|
*/
|
|
*/
|
|
class EmployeeService extends Service
|
|
class EmployeeService extends Service
|
|
{
|
|
{
|
|
-
|
|
|
|
- public function employeeEdit($data){
|
|
|
|
- list($status,$msg) = $this->employeeRule($data);
|
|
|
|
|
|
+ public function employeeEdit($data,$user){
|
|
|
|
+ list($status,$msg) = $this->employeeRule($data,false);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
- $first = SysMenu::where('emp_id',$data['emp_id'])->where('del_time',0)->first();
|
|
|
|
- if(!empty($first))return [false,'工号已存在!'];
|
|
|
|
|
|
|
|
$model = new Employee();
|
|
$model = new Employee();
|
|
$model = $model->where('id',$data['id'])->first();
|
|
$model = $model->where('id',$data['id'])->first();
|
|
-
|
|
|
|
$model->id_card = $data['id_card']??'';
|
|
$model->id_card = $data['id_card']??'';
|
|
- $model->emp_id = $data['emp_id'] ;
|
|
|
|
|
|
+ $model->number = $data['number'] ;
|
|
$model->mobile = $data['mobile'];
|
|
$model->mobile = $data['mobile'];
|
|
$model->emp_name = $data['emp_name'];
|
|
$model->emp_name = $data['emp_name'];
|
|
- $model->state = 1;
|
|
|
|
-// $model->crt_id = $user->id;
|
|
|
|
-// $model->crt_time = time();
|
|
|
|
$model->is_admin = $data['is_admin'];
|
|
$model->is_admin = $data['is_admin'];
|
|
if($model->is_admin == 1){
|
|
if($model->is_admin == 1){
|
|
$model->account = $data['account'];
|
|
$model->account = $data['account'];
|
|
if($data['password'] !== '********'){
|
|
if($data['password'] !== '********'){
|
|
$model->password = Hash::make($data['password']);
|
|
$model->password = Hash::make($data['password']);
|
|
}
|
|
}
|
|
-
|
|
|
|
}
|
|
}
|
|
$model->save();
|
|
$model->save();
|
|
return [true,'保存成功!'];
|
|
return [true,'保存成功!'];
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public function employeeAdd($data,$user){
|
|
public function employeeAdd($data,$user){
|
|
-
|
|
|
|
-
|
|
|
|
-// if($this->isEmpty($data,'title')) return [201,'名称不存在!'];
|
|
|
|
list($status,$msg) = $this->employeeRule($data);
|
|
list($status,$msg) = $this->employeeRule($data);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
-// $first = SysMenu::where('title',$data['title'])->where('del_time',0)->first();
|
|
|
|
- if(!empty($first))return [false,'名称已存在!'];
|
|
|
|
|
|
|
|
$model = new Employee();
|
|
$model = new Employee();
|
|
-
|
|
|
|
$model->id_card = $data['id_card']??'';
|
|
$model->id_card = $data['id_card']??'';
|
|
- $model->emp_id = $data['emp_id'] ;
|
|
|
|
|
|
+ $model->number = $data['number'] ;
|
|
$model->mobile = $data['mobile'];
|
|
$model->mobile = $data['mobile'];
|
|
$model->emp_name = $data['emp_name'];
|
|
$model->emp_name = $data['emp_name'];
|
|
$model->state = 1;
|
|
$model->state = 1;
|
|
-// $model->crt_id = $user->id;
|
|
|
|
- $model->crt_id = 1;
|
|
|
|
-// $model->crt_time = time();
|
|
|
|
|
|
+ $model->crt_id = $user['id'];
|
|
$model->is_admin = $data['is_admin'];
|
|
$model->is_admin = $data['is_admin'];
|
|
if($model->is_admin == 1){
|
|
if($model->is_admin == 1){
|
|
$model->account = $data['account'];
|
|
$model->account = $data['account'];
|
|
@@ -78,7 +61,6 @@ class EmployeeService extends Service
|
|
$model->save();
|
|
$model->save();
|
|
|
|
|
|
return [true,'保存成功!'];
|
|
return [true,'保存成功!'];
|
|
-
|
|
|
|
}
|
|
}
|
|
|
|
|
|
public function employeeDel($data){
|
|
public function employeeDel($data){
|
|
@@ -92,38 +74,37 @@ class EmployeeService extends Service
|
|
}
|
|
}
|
|
|
|
|
|
public function employeeList($data){
|
|
public function employeeList($data){
|
|
- $model = Employee::where('del_time',0)
|
|
|
|
- ->select('id_card','emp_name','mobile','emp_name','crt_time','account','is_admin','upd_time','id')
|
|
|
|
- ->orderBy('id','desc');
|
|
|
|
-
|
|
|
|
- if(! empty($data['depart_id'])) {
|
|
|
|
- $depart = Depart::where('del_time',0)
|
|
|
|
- ->select('id','parent_id')
|
|
|
|
- ->get()->toArray();
|
|
|
|
- $result = array_merge($this->getAllDescendants($depart,$data['depart_id']),[$data['depart_id']]);
|
|
|
|
- $employee_id = DB::table('employee_depart_permission')
|
|
|
|
- ->whereIn("depart_id", $result)
|
|
|
|
- ->select("employee_id")
|
|
|
|
- ->get()->toArray();
|
|
|
|
- $employee_id = array_column($employee_id,'employee_id');
|
|
|
|
- $model->whereIn("id", $employee_id);
|
|
|
|
- }
|
|
|
|
|
|
+ $list = Employee::where('del_time',0)->select('id_card','emp_name','mobile','crt_time','account','is_admin','upd_time','id')->orderBy('id','desc');
|
|
|
|
|
|
- $list = $this->limit($model,'',$data);
|
|
|
|
|
|
+ $list = $this->limit($list,'',$data);
|
|
|
|
|
|
return [200,$list];
|
|
return [200,$list];
|
|
}
|
|
}
|
|
|
|
|
|
- public function employeeRule($data){
|
|
|
|
- if($this->isEmpty($data,'emp_id')) return [false,'工号不存在!'];
|
|
|
|
-// if($this->isEmpty($data,'icon')) return [201,'d不存在!'];
|
|
|
|
|
|
+ public function employeeRule($data,$is_add = true){
|
|
|
|
+ if($this->isEmpty($data,'number')) return [false,'工号不存在!'];
|
|
if($this->isEmpty($data,'mobile')) return [false,'手机号不存在!'];
|
|
if($this->isEmpty($data,'mobile')) return [false,'手机号不存在!'];
|
|
if($this->isEmpty($data,'emp_name')) return [false,'姓名不存在!'];
|
|
if($this->isEmpty($data,'emp_name')) return [false,'姓名不存在!'];
|
|
|
|
+ if(! $is_add){
|
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
|
|
+ $bool = Employee::where('number',$data['number'])
|
|
|
|
+ ->where('id','<>',$data['id'])
|
|
|
|
+ ->where('del_time',0)->exists();
|
|
|
|
+ $bool_account = Employee::where('account',$data['account'])
|
|
|
|
+ ->where('id','<>',$data['id'])
|
|
|
|
+ ->where('del_time',0)->exists();
|
|
|
|
+ }else{
|
|
|
|
+ $bool = Employee::where('number',$data['number'])
|
|
|
|
+ ->where('del_time',0)->exists();
|
|
|
|
+ $bool_account = Employee::where('account',$data['account'])
|
|
|
|
+ ->where('del_time',0)->exists();
|
|
|
|
+ }
|
|
|
|
+ if($bool) return [false,'工号已存在!'];
|
|
|
|
+ if($bool_account) return [false,'账号已存在!'];
|
|
|
|
|
|
return [true,''];
|
|
return [true,''];
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
public function roleEdit($data){
|
|
public function roleEdit($data){
|
|
list($status,$msg) = $this->roleRule($data);
|
|
list($status,$msg) = $this->roleRule($data);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
@@ -182,7 +163,6 @@ class EmployeeService extends Service
|
|
return [true,''];
|
|
return [true,''];
|
|
}
|
|
}
|
|
|
|
|
|
-
|
|
|
|
public function departEdit($data){
|
|
public function departEdit($data){
|
|
list($status,$msg) = $this->departRule($data);
|
|
list($status,$msg) = $this->departRule($data);
|
|
if(!$status) return [$status,$msg];
|
|
if(!$status) return [$status,$msg];
|
|
@@ -230,17 +210,9 @@ class EmployeeService extends Service
|
|
}
|
|
}
|
|
|
|
|
|
public function departList($data){
|
|
public function departList($data){
|
|
- $model = Depart::where('del_time',0)
|
|
|
|
- ->select('title','id','code','parent_id')
|
|
|
|
- ->orderby('code', 'asc');
|
|
|
|
- if(! empty($data['title'])) $model->where('title', 'LIKE', '%'.$data['title'].'%');
|
|
|
|
- if(! empty($data['code'])) $model->where('code', 'LIKE', '%'.$data['code'].'%');
|
|
|
|
-
|
|
|
|
- $list = $model->get()->toArray();
|
|
|
|
- if(! empty($list)) {
|
|
|
|
- $list = $this->makeTree(0,$list);
|
|
|
|
- $list = $this->set_sort_circle($list);
|
|
|
|
- }
|
|
|
|
|
|
+ $list = Depart::where('del_time',0)->select('title','crt_time','id','upd_time','code')->orderBy('id','desc');
|
|
|
|
+
|
|
|
|
+ $list = $this->limit($list,'',$data);
|
|
|
|
|
|
return [200,$list];
|
|
return [200,$list];
|
|
}
|
|
}
|
|
@@ -312,18 +284,6 @@ class EmployeeService extends Service
|
|
return [true,''];
|
|
return [true,''];
|
|
}
|
|
}
|
|
|
|
|
|
- public function teamDetail($data){
|
|
|
|
- if($this->isEmpty($data,'id')) return [false,'ID不能为空!'];
|
|
|
|
-
|
|
|
|
- $result = EmployeeTeamPermission::from('employee_team_permission as a')
|
|
|
|
- ->leftJoin('employee as b','b.id','a.employee_id')
|
|
|
|
- ->where('team_id',$data['id'])
|
|
|
|
- ->select('b.id','b.emp_name','b.number as code')
|
|
|
|
- ->get()->toArray();
|
|
|
|
-
|
|
|
|
- return [true,$result];
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
public function employeeRole($data){
|
|
public function employeeRole($data){
|
|
$role_ids = [];
|
|
$role_ids = [];
|
|
$employee_ids = [];
|
|
$employee_ids = [];
|
|
@@ -425,7 +385,7 @@ class EmployeeService extends Service
|
|
|
|
|
|
$res = reset($res);
|
|
$res = reset($res);
|
|
if(! Hash::check($data['password'], $res['password'])) return [false,'密码错误!'];
|
|
if(! Hash::check($data['password'], $res['password'])) return [false,'密码错误!'];
|
|
- if($res['is_admin'] != Employee::IS_ADMIN) return [false,'非管理员账号!'];
|
|
|
|
|
|
+ if($res['is_admin'] != Employee::IS_ADMIN) return [false,'该账号不能登录!'];
|
|
if($res['state'] == Employee::NOT_USE) return [false,'账号停用!'];
|
|
if($res['state'] == Employee::NOT_USE) return [false,'账号停用!'];
|
|
|
|
|
|
return [true, ['id'=>$res['id'], 'name'=>$res['emp_name'], 'account' => $res['account']]];
|
|
return [true, ['id'=>$res['id'], 'name'=>$res['emp_name'], 'account' => $res['account']]];
|