|
@@ -73,14 +73,56 @@ class EmployeeService extends Service
|
|
|
return [true,'删除成功'];
|
|
|
}
|
|
|
|
|
|
- public function employeeList($data){
|
|
|
- $list = Employee::where('del_time',0)->select('id_card','emp_name','mobile','crt_time','account','is_admin','upd_time','id')->orderBy('id','desc');
|
|
|
+ public function employeeList($data,$user){
|
|
|
+ $model = Employee::where('del_time',0)
|
|
|
+ ->where('id','<>',Employee::SPECIAL_ADMIN)
|
|
|
+ ->select('account','upd_time','id','mark','crt_time','emp_name')
|
|
|
+ ->orderBy('id','desc');
|
|
|
+ if(! empty($data['account'])) $model->where('account', 'LIKE', '%'.$data['account'].'%');
|
|
|
+ if(! empty($data['mark'])) $model->where('mark', 'LIKE', '%'.$data['mark'].'%');
|
|
|
+ if(! empty($data['role'])) {
|
|
|
+ $emp = EmployeeRole::where('role_id',$data['role'])
|
|
|
+ ->select('employee_id')->get()->toArray();
|
|
|
+ $model->whereIn('id',array_column($emp,'employee_id'));
|
|
|
+ }
|
|
|
|
|
|
- $list = $this->limit($list,'',$data);
|
|
|
+ $list = $this->limit($model,'',$data);
|
|
|
|
|
|
- return [200,$list];
|
|
|
+ //组织数据
|
|
|
+ $list = $this->organizationEmployeeData($list);
|
|
|
+
|
|
|
+ return [true, $list];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function organizationEmployeeData($data) {
|
|
|
+ if (empty($data['data'])) return $data;
|
|
|
+
|
|
|
+ $res = DB::table('employee_role as a')
|
|
|
+ ->leftJoin('role as b','a.role_id','=','b.id')
|
|
|
+ ->where('a.del_time',0)
|
|
|
+ ->where('b.del_time',0)
|
|
|
+ ->whereIn("a.employee_id",array_column($data['data'],'id'))
|
|
|
+ ->select('a.employee_id','b.title','b.id')
|
|
|
+ ->get()->toArray();
|
|
|
+ $role = $role2 = [];
|
|
|
+ foreach ($res as $value){
|
|
|
+ if(isset($role[$value->employee_id])){
|
|
|
+ $role[$value->employee_id] .= ',' . $value->title;
|
|
|
+ }else{
|
|
|
+ $role[$value->employee_id] = $value->title;
|
|
|
+ }
|
|
|
+ $role2[$value->employee_id][] = $value->id;
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($data['data'] as $key => $value){
|
|
|
+ $data['data'][$key]['role'] = $role2[$value['id']] ?? [];
|
|
|
+ $data['data'][$key]['role_name'] = $role[$value['id']] ?? '';
|
|
|
+ $data['data'][$key]['crt_time'] = $value['crt_time'] ? date('Y-m-d',$value['crt_time']) : '';
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
}
|
|
|
|
|
|
+
|
|
|
public function employeeRule($data,$is_add = true){
|
|
|
if($this->isEmpty($data,'number')) return [false,'工号不存在!'];
|
|
|
if($this->isEmpty($data,'mobile')) return [false,'手机号不存在!'];
|