wugg 8 months ago
parent
commit
6298dfad6a
1 changed files with 16 additions and 8 deletions
  1. 16 8
      app/bug/listener/RoleEvent.php

+ 16 - 8
app/bug/listener/RoleEvent.php

@@ -29,7 +29,7 @@ class RoleEvent
         $type=$event["type"];
         $id=$event["info_id"];
        try {
-        $info = WorkRole::where('id', $id)->findOrEmpty();
+        $info = WorkRole::withTrashed()->where('id', $id)->findOrEmpty();
 
         if ($info->isEmpty()) {
             return false;
@@ -71,22 +71,30 @@ class RoleEvent
 
     private function roleOn($event){
          $action = (new WorkAction)->GetBelongActionByIdArrs($event->action);
-        $info=$this->model->where('id',$event->belong_role_id)->findOrEmpty();
+        $info=$this->model->with(["RoleInfo"])->where('id',$event->belong_role_id)->findOrEmpty();
         $info->role_name = $event->role_name;
         $info->role_level = $event->level;
         $info->companyNo = $event->companyNo;
         $info->status = 1;
         $isSave = $info->save();
         if($isSave){
-            $info->RoleInfo()->save( [
+        	if(is_null($info->RoleInfo)){
+        		$info->RoleInfo()->save( [
+	                        'action_conllect' => $action,
+	                        'action_data' => [],
+	                        'private_data' => [],
+	                        'role_id' => $info->id,
+	                        'status' => 1
+	                    ]);
+	        }else$info->RoleInfo->save( [
                         'action_conllect' => $action,
                         'action_data' => [],
                         'private_data' => [],
-                        'role_id' => $info->id,
-                        'status' => 1
                     ]);
-            $event->belong_role_id =$info->id;
-            $event->save();
+        	if($event->belong_role_id==0){
+        		$event->belong_role_id =$info->id;
+		        $event->save();
+	        }
         }
         return $isSave;
     }
@@ -97,7 +105,7 @@ class RoleEvent
                 return $isSave;
     }
     private function roleDelete($eventId){
-                $info=$this->model->where('id',$eventId)->findOrEmpty();
+                $info=$this->model->with(["RoleInfo"])->where('id',$eventId)->findOrEmpty();
                 $isSave = $info->together(['RoleInfo'])->delete();
                 return $isSave;
     }