瀏覽代碼

为用户添加可见货主

ajun 4 年之前
父節點
當前提交
176bfe6d0b
共有 1 個文件被更改,包括 14 次插入2 次删除
  1. 14 2
      app/User.php

+ 14 - 2
app/User.php

@@ -111,7 +111,8 @@ class User extends Authenticatable
         });
         return $authorities;
     }
-    function getPermittingOwnerIdsAttribute(){
+    function getPermittingOwnerIdsAttribute(): array
+    {
         $ownerIds=[];
         if($this->isSuperAdmin()||Gate::allows('货主-可见全部')){
             $owners=Owner::query()->whereNull('deleted_at')->get();
@@ -135,7 +136,8 @@ class User extends Authenticatable
         }
         return  array_unique(array_merge($ownerIds, $old_owner));
     }
-    function getPermittingWorkgroupIds($allowAll=false){
+    function getPermittingWorkgroupIds($allowAll=false): array
+    {
         $workgroupIds=[];
         if ($this->isSuperAdmin()||$allowAll){
             $workgroups=UserWorkgroup::all();
@@ -151,6 +153,7 @@ class User extends Authenticatable
         }
         return $workgroupIds;
     }
+
     function getPermittingLaborCompanyIdsAttribute(): array
     {
         $labor_company_ids=array();
@@ -170,6 +173,15 @@ class User extends Authenticatable
         return array_unique($labor_company_ids);
     }
 
+    // 用户可见货主
+    public function getPermittingLogisticIdsAttribute(): array
+    {
+        if ($this->isSuperAdmin()){
+            return Logistic::query()->get()->map(function($logistic){return $logistic->id;})->toArray();
+        }
+        return $this->logistics()->get()->map(function($logistic){return $logistic->id;})->toArray();
+    }
+
     public function workGroups()
     {
         return $this->morphedByMany(UserWorkgroup::class, 'user_authable');