|
@@ -21,55 +21,38 @@ use Illuminate\Support\Facades\Hash;
|
|
|
*/
|
|
|
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];
|
|
|
- $first = SysMenu::where('emp_id',$data['emp_id'])->where('del_time',0)->first();
|
|
|
- if(!empty($first))return [false,'工号已存在!'];
|
|
|
|
|
|
$model = new Employee();
|
|
|
$model = $model->where('id',$data['id'])->first();
|
|
|
-
|
|
|
$model->id_card = $data['id_card']??'';
|
|
|
- $model->emp_id = $data['emp_id'] ;
|
|
|
+ $model->number = $data['number'] ;
|
|
|
$model->mobile = $data['mobile'];
|
|
|
$model->emp_name = $data['emp_name'];
|
|
|
- $model->state = 1;
|
|
|
-// $model->crt_id = $user->id;
|
|
|
-// $model->crt_time = time();
|
|
|
$model->is_admin = $data['is_admin'];
|
|
|
if($model->is_admin == 1){
|
|
|
$model->account = $data['account'];
|
|
|
if($data['password'] !== '********'){
|
|
|
$model->password = Hash::make($data['password']);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
$model->save();
|
|
|
return [true,'保存成功!'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function employeeAdd($data,$user){
|
|
|
-
|
|
|
-
|
|
|
-// if($this->isEmpty($data,'title')) return [201,'名称不存在!'];
|
|
|
list($status,$msg) = $this->employeeRule($data);
|
|
|
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->id_card = $data['id_card']??'';
|
|
|
- $model->emp_id = $data['emp_id'] ;
|
|
|
+ $model->number = $data['number'] ;
|
|
|
$model->mobile = $data['mobile'];
|
|
|
$model->emp_name = $data['emp_name'];
|
|
|
$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'];
|
|
|
if($model->is_admin == 1){
|
|
|
$model->account = $data['account'];
|
|
@@ -78,7 +61,6 @@ class EmployeeService extends Service
|
|
|
$model->save();
|
|
|
|
|
|
return [true,'保存成功!'];
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public function employeeDel($data){
|
|
@@ -92,23 +74,37 @@ class EmployeeService extends Service
|
|
|
}
|
|
|
|
|
|
public function employeeList($data){
|
|
|
- $list = Employee::where('del_time',0)->select('id_card','emp_name','mobile','emp_name','crt_time','account','is_admin','upd_time','id')->orderBy('id','desc');
|
|
|
+ $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($list,'',$data);
|
|
|
|
|
|
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,'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,''];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public function roleEdit($data){
|
|
|
list($status,$msg) = $this->roleRule($data);
|
|
|
if(!$status) return [$status,$msg];
|
|
@@ -167,7 +163,6 @@ class EmployeeService extends Service
|
|
|
return [true,''];
|
|
|
}
|
|
|
|
|
|
-
|
|
|
public function departEdit($data){
|
|
|
list($status,$msg) = $this->departRule($data);
|
|
|
if(!$status) return [$status,$msg];
|