|
@@ -113,7 +113,81 @@ class EmployeeService extends Service
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * 用户编辑
|
|
|
+ * 用户编辑(普通员工)
|
|
|
+ * @param $data
|
|
|
+ * @param $user
|
|
|
+ * @return array
|
|
|
+ */
|
|
|
+ public function employeeSampleEdit($data,$user){
|
|
|
+ list($status,$msg) = $this->employeeSampleRule($data);
|
|
|
+ if(!$status) return [$status,$msg];
|
|
|
+
|
|
|
+ try {
|
|
|
+ DB::beginTransaction();
|
|
|
+ $model = new Employee();
|
|
|
+ $model = $model->where('id',$data['id'])->first();
|
|
|
+ $model->card_no = $data['card_no'] ?? '';
|
|
|
+ $model->emp_name = $data['emp_name'] ?? '';
|
|
|
+ $model->mobile = $data['mobile'] ?? '';
|
|
|
+ $model->entry_time = $data['entry_time'] ?? '';
|
|
|
+ $model->birth_date = $data['birth_date']??'';
|
|
|
+ if($model->pic != $data['pic']){
|
|
|
+ // 使用正则表达式匹配特定路径部分并替换为空
|
|
|
+ $pattern = '/^https?:\/\/[^\/]+\/image\//';
|
|
|
+ $replacedUrl = preg_replace($pattern, '', $model->pic);
|
|
|
+ (new FileUploadService())->delLocalPublicFile($replacedUrl);
|
|
|
+ }
|
|
|
+ $model->pic = $data['pic'] ?? "";
|
|
|
+ if($data['pic'] != '') $model->is_device = 0;
|
|
|
+ if($data['password'] !== '********') $model->password = Hash::make($data['password']);
|
|
|
+ if(! empty($data['account'])) {
|
|
|
+ $model->account = $data['account'];
|
|
|
+ }else{
|
|
|
+ $model->account = $data['card_no'];
|
|
|
+ }
|
|
|
+ $model->save();
|
|
|
+
|
|
|
+ DB::commit();
|
|
|
+ }catch (\Exception $exception){
|
|
|
+ DB::rollBack();
|
|
|
+ return [false, $exception->getMessage()];
|
|
|
+ }
|
|
|
+
|
|
|
+ return [true,''];
|
|
|
+ }
|
|
|
+
|
|
|
+ public function employeeSampleRule($data){
|
|
|
+ if($this->isEmpty($data,'id')) return [false,'人员ID不存在'];
|
|
|
+ if($this->isEmpty($data,'number')) return [false,'工号不存在'];
|
|
|
+ if($this->isEmpty($data,'card_no')) return [false,'身份证号不存在'];
|
|
|
+ if($this->isEmpty($data,'emp_name')) return [false,'姓名不存在'];
|
|
|
+
|
|
|
+ $bool = Employee::where('del_time',0)
|
|
|
+ ->where('id', "<>", $data['id'])
|
|
|
+ ->where('account', $data['account'])
|
|
|
+ ->exists();
|
|
|
+ if($bool) return [false, "登录账号:" . $data['account'] ."已存在"];
|
|
|
+
|
|
|
+ $mobile = $data['mobile'] ?? "";
|
|
|
+ $number = $data['number'] ?? "";
|
|
|
+ $card_no = $data['card_no'] ?? "";
|
|
|
+ $bool = Employee::where('del_time',0)
|
|
|
+ ->where(function ($query) use ($mobile, $number, $card_no){
|
|
|
+ $query->where('number', $number);
|
|
|
+ $query->when(! empty($mobile), function ($query) use ($mobile) {
|
|
|
+ return $query->orWhere('mobile', $mobile);
|
|
|
+ });
|
|
|
+ $query->when(! empty($card_no), function ($query) use ($card_no) {
|
|
|
+ return $query->orWhere('card_no', $card_no);
|
|
|
+ });
|
|
|
+ })->exists();
|
|
|
+ if($bool) return [false,'工号、手机号码或身份证已存在,请核对以上信息'];
|
|
|
+
|
|
|
+ return [true,''];
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 用户编辑(全部字段)
|
|
|
* @param $data
|
|
|
* @param $user
|
|
|
* @return array
|
|
@@ -466,9 +540,9 @@ class EmployeeService extends Service
|
|
|
* @return array
|
|
|
*/
|
|
|
public function employeeRule($data, $is_add = true){
|
|
|
- if($this->isEmpty($data,'number')) return [false,'工号不存在!'];
|
|
|
- if($this->isEmpty($data,'card_no')) return [false,'身份证号不存在!'];
|
|
|
- if($this->isEmpty($data,'emp_name')) return [false,'姓名不存在!'];
|
|
|
+ if($this->isEmpty($data,'number')) return [false,'工号不存在'];
|
|
|
+ if($this->isEmpty($data,'card_no')) return [false,'身份证号不存在'];
|
|
|
+ if($this->isEmpty($data,'emp_name')) return [false,'姓名不存在'];
|
|
|
if(empty($data['depart'])) return [false,'部门不能为空'];
|
|
|
if(! empty($data['is_admin'])){
|
|
|
$id = $data['id'] ?? 0;
|