Ver Fonte

人员手机号唯一

cqp há 13 horas atrás
pai
commit
5a55694b9d
1 ficheiros alterados com 13 adições e 0 exclusões
  1. 13 0
      app/Service/EmployeeService.php

+ 13 - 0
app/Service/EmployeeService.php

@@ -14,6 +14,7 @@ use App\Model\Role;
 use App\Model\RoleMenu;
 use App\Model\RoleMenuButton;
 use App\Model\WorkRangeDetails;
+use App\Model\WxEmployee;
 use Illuminate\Support\Facades\DB;
 use Illuminate\Support\Facades\Hash;
 use Mockery\Exception;
@@ -212,6 +213,8 @@ class EmployeeService extends Service
             DB::beginTransaction();
             $model = new Employee();
             $model = $model->where('id',$data['id'])->first();
+            $oldMobile = $model->mobile ?? "";
+            $newMobile = $data['mobile'] ?? "";
             $model->number = $data['number'] ?? "";
             $model->title = $data['title'] ?? "";
             $model->mobile = $data['mobile'] ?? "";
@@ -233,6 +236,11 @@ class EmployeeService extends Service
             }
             $model->save();
 
+            if (trim((string)$oldMobile) !== trim((string)$newMobile)) {
+                //如果修改了手机号 清空微信小程序关联关系
+                WxEmployee::where('employee_id', $model->id)->delete();
+            }
+
             $time = time();
             EmployeeDepartPermission::where('employee_id',$data['id'])->delete();
             if(isset($data['depart'])){
@@ -426,6 +434,8 @@ class EmployeeService extends Service
             ]);
             EmployeeDepartPermission::whereIn('employee_id',$data['id'])->delete();
             EmployeeWorkRange::whereIn('employee_id',$data['id'])->delete();
+            //清空微信小程序关联关系
+            WxEmployee::whereIn('employee_id', $data['id'])->delete();
 
             $old = EmployeeFile::where('del_time',0)
                 ->whereIn('employee_id',$data['id'])
@@ -914,6 +924,9 @@ class EmployeeService extends Service
 
         if(! $is_add){
             if(empty($data['id'])) return [false,'ID不能为空'];
+            $exists = Employee::where('id', $data['id'])->where('del_time', 0)->exists();
+            if (!$exists) return [false, '账号不存在或已被删除'];
+
             // 编辑模式:排除自身 ID 记录
             $query->where('id', '<>', $data['id']);
         } else {