Просмотр исходного кода

Merge branch 'wangyang'

# Conflicts:
#	app/Http/Controllers/TestController.php
zhouzhendong 4 лет назад
Родитель
Сommit
86dff446c0
5 измененных файлов с 37 добавлено и 3 удалено
  1. 2 2
      app/Http/Controllers/UserController.php
  2. 13 1
      app/User.php
  3. 5 0
      app/UserOwnerGroup.php
  4. 5 0
      app/UserWorkgroup.php
  5. 12 0
      app/Utils/helpers.php

+ 2 - 2
app/Http/Controllers/UserController.php

@@ -185,7 +185,7 @@ class UserController extends Controller
         $work_id = [];
         $treeData = $request->input('treeData')??[];
         foreach ($treeData as $v){
-            if (strrpos($v,'g') != 'FALSE') array_push($work_id, mb_substr($v,1));
+            if (strrpos($v,'g') === 0) array_push($work_id, mb_substr($v,1));
         }
         if ($work_id)$user->workGroups()->sync($work_id);
         //项目组
@@ -233,7 +233,7 @@ class UserController extends Controller
         $params = $request->all();
         $work_id = [];
         foreach ($params['workGroups'] as $v){
-            if (strrpos($v,'g') != 'FALSE') array_push($work_id, mb_substr($v,1));
+            if (strrpos($v,'g') === 0 ) array_push($work_id, mb_substr($v,1));
         }
         /* @var $user User */
         $user = User::query()->find($params['id']);

+ 13 - 1
app/User.php

@@ -119,8 +119,20 @@ class User extends Authenticatable
             });
             return $ownerIds;
         }
-        return array_column(DB::table("owner_role")->whereIn("role_id",
+        //原查询
+        $old_owner=  array_column(DB::table("owner_role")->whereIn("role_id",
             array_column($this->roles->toArray(),"id"))->get()->toArray(),"owner_id");
+        //兼容
+        $new_owner = $this->ownerGroups()->with(['owners:id,user_owner_group_id'])->get();
+        $new_work= $this->workGroups()->with(['owners:id,user_workgroup_id'])->get();
+
+        foreach ($new_owner as $v){
+            $ownerIds = array_merge($ownerIds, array_column($v->owners->toArray(),'id'));
+        }
+        foreach ($new_work as $v){
+            $ownerIds = array_merge($ownerIds, array_column($v->owners->toArray(),'id'));
+        }
+        return  array_unique(array_merge($ownerIds, $old_owner));
     }
     function getPermittingWorkgroupIds($allowAll=false){
         $workgroupIds=[];

+ 5 - 0
app/UserOwnerGroup.php

@@ -18,4 +18,9 @@ class UserOwnerGroup extends Model
     {
         return $this->morphToMany(User::class, 'user_authable');
     }
+
+    public function owners()
+    {
+        return $this->hasMany(Owner::class);
+    }
 }

+ 5 - 0
app/UserWorkgroup.php

@@ -50,4 +50,9 @@ class UserWorkgroup extends Model
     {
         return $this->morphToMany(User::class, 'user_authable');
     }
+
+    public function owners()
+    {
+        return $this->hasMany(Owner::class);
+    }
 }

+ 12 - 0
app/Utils/helpers.php

@@ -110,3 +110,15 @@ function getMacAddr($type = PHP_OS):string
     unset($temp_array);
     return $mac_addr;
 }
+
+//2021-09-03 oracle 链接
+function getOciConnect()
+{
+    $username = config('database.connections.oracle.username');
+    $password = config('database.connections.oracle.password');
+    $host = config('database.connections.oracle.host');
+    $service_name = config('database.connections.oracle.service_name');
+    $charset = config('database.connections.oracle.charset');
+    return oci_connect($username,$password,$host.'/'.$service_name,$charset);
+}
+