Bladeren bron

货主数据隔离分割

Zhouzhendong 4 jaren geleden
bovenliggende
commit
622d26bdc9

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

@@ -24,7 +24,7 @@ class InventoryController extends Controller
         if(!Gate::allows("库存管理-库存")){ return redirect(url('/'));  }
         $oracleActTransactingLogs=app('inventoryService')->paginate($request->input());
         $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
-        $owners=Owner::filterAuthorities()->select(['code', 'name'])->get();
+        $owners = app("OwnerService")->getIntersectPermitting(["code", "name"]);
         $isTotalStock=false;
         $page = $request->page ?? 1;
         return view('inventory.statement.changeInventory',compact('oracleActTransactingLogs','page','owners','isTotalStock'));
@@ -37,7 +37,7 @@ class InventoryController extends Controller
         $service = app('AllInventoryService');
         $oracleActTransactingLogs= $service->paginate($request->input());
         $oracleActTransactingLogs=json_encode($oracleActTransactingLogs);
-        $owners=Owner::filterAuthorities()->select(['code', 'name'])->get();
+        $owners = app("OwnerService")->getIntersectPermitting(["code", "name"]);
         $isTotalStock=true;
         $page = $request->page ?? 1;
         return view('inventory.statement.changeInventory',compact('oracleActTransactingLogs','page','owners','isTotalStock'));

+ 1 - 1
app/Http/Controllers/RejectedController.php

@@ -479,7 +479,7 @@ class RejectedController extends Controller
         if(!Gate::allows('退货管理-查询')){ return redirect(url('/'));  }
         $paginateParams = $this->getAnalyzeSearchParams($request);
         $rejectedBills =  RejectedAnalyzeOwner::findBy($paginateParams);
-        $owners = Owner::filterAuthorities()->get();
+        $owners = app("OwnerService")->getIntersectPermitting();
         $qualityLabels = QualityLabel::all();
         return view('rejected.search.analyze',compact('rejectedBills','owners',
             'paginateParams','qualityLabels'));

+ 3 - 12
app/Owner.php

@@ -6,7 +6,6 @@ use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Database\Eloquent\Model;
 use Illuminate\Database\Eloquent\Relations\BelongsToMany;
 use Illuminate\Database\Eloquent\Relations\HasMany;
-use Illuminate\Support\Facades\Auth;
 
 /**
  * @method static orderBy(string $string, string $string1)
@@ -64,20 +63,12 @@ class Owner extends Model
         1 => "是"
     ];
 
-    public static function filterAuthorities(){
-        $user=Auth::user();
-        $query = (new static)->newQuery();
-        if(!$user){
-            return $query->where('id','0');
-        }
-        return $query->whereIn('id',app("OwnerService")->getIdArr());
-    }
-
     /**
      * 退货管理里,客户审核的代码,是拼音+日期+计数,计数的后缀就是checking_count
-     * @return int|mixed
+     * @return mixed
      */
-    public function getIncreasedCheckingCount(){
+    public function getIncreasedCheckingCount(): mixed
+    {
         $this['checking_count']=$this['checking_count']+1;
         $this->update();
         return $this['checking_count'];

+ 1 - 2
app/Services/InventoryAccountService.php

@@ -41,8 +41,7 @@ class InventoryAccountService
             ->sql();
     }
     private function conditionQuery($queryParam){
-        $ownerIds=app('OwnerService')->getSelection();
-        $inventories=InventoryAccount::query()->with(['owner','creator'])->orderBy('id','desc')->whereIn('owner_id',$ownerIds);
+        $inventories=InventoryAccount::query()->with(['owner','creator'])->orderBy('id','desc')->whereIn('owner_id',app("OwnerService")->getQuery());
         $columnQueryRules=[
             'owner' => ['alias'=>'owner_id','multi' => ','],
             'type' => ['multi' => ','],

+ 3 - 4
app/Services/InventoryCompareService.php

@@ -129,20 +129,19 @@ class InventoryCompareService
         return $inventoryCompares;
     }
     private function conditionQueryInventoryCompare(array $param){
-        $ownerIds=app('OwnerService')->getSelection();
         $differ=$param['differ']??'';
         if ($differ=='有'){
             $inventoryCompares = InventoryCompare::query()->with(['owner','commodity'=>function($query){
                 $query->with('barcodes');
-            }])->where('differ','>',0)->orderByDesc('id')->whereIn('inventory_compares.owner_id',$ownerIds);
+            }])->where('differ','>',0)->orderByDesc('id')->whereIn('inventory_compares.owner_id',app("OwnerService")->getQuery());
         }elseif ($differ=='无'){
             $inventoryCompares = InventoryCompare::query()->with(['owner','commodity'=>function($query){
                 $query->with('barcodes');
-            }])->where('differ','<',0)->orderByDesc('id')->whereIn('inventory_compares.owner_id',$ownerIds);
+            }])->where('differ','<',0)->orderByDesc('id')->whereIn('inventory_compares.owner_id',app("OwnerService")->getQuery());
         }else{
             $inventoryCompares = InventoryCompare::query()->with(['owner','commodity'=>function($query){
                 $query->with('barcodes');
-            }])->orderByDesc('id')->whereIn('inventory_compares.owner_id',$ownerIds);
+            }])->orderByDesc('id')->whereIn('inventory_compares.owner_id',app("OwnerService")->getQuery());
         }
         unset($param['differ']);
         $columnQueryRules=[

+ 5 - 5
app/Services/InventoryService.php

@@ -18,7 +18,7 @@ class InventoryService
     use ModelSearchWay;
     protected $modelClass=Inventory::class;
     public function getSql(array $params,$page=null,$paginate=null){
-        $ownerCodes=Owner::filterAuthorities()->select('code')->get();
+        $ownerCodes = app("OwnerService")->getCodeArr();
         $date_start=$params['date_start'] ?? null;
         $range = $params['range'] ?? null;
         if ($range)$date_start=date('Y-m-d',strtotime('-'.$range." day"));
@@ -56,7 +56,7 @@ class InventoryService
             $sql .= ' and TOCustomerID in (';
             foreach ($ownerCodes as $index => $data){
                 if ($index != 0)$sql .= ',';
-                $sql .= "'".$data['code']."'";
+                $sql .= "'".$data."'";
             }
             $sql .= ') ';
         }
@@ -80,7 +80,7 @@ class InventoryService
             $sql .= ' and FMCUSTOMERID in (';
             foreach ($ownerCodes as $index => $data){
                 if ($index != 0)$sql .= ',';
-                $sql .= "'".$data['code']."'";
+                $sql .= "'".$data."'";
             }
             $sql .= ') ';
         }
@@ -105,7 +105,7 @@ class InventoryService
             $sql .= ' and FMCUSTOMERID in (';
             foreach ($ownerCodes as $index => $data){
                 if ($index != 0)$sql .= ',';
-                $sql .= "'".$data['code']."'";
+                $sql .= "'".$data."'";
             }
             $sql .= ') ';
         }
@@ -130,7 +130,7 @@ class InventoryService
             $sql .= ' and TOCustomerID in (';
             foreach ($ownerCodes as $index => $data){
                 if ($index != 0)$sql .= ',';
-                $sql .= "'".$data['code']."'";
+                $sql .= "'".$data."'";
             }
             $sql .= ') ';
         }

+ 0 - 7
app/Services/OwnerService.php

@@ -51,13 +51,6 @@ class OwnerService implements UserFilter
         }, config('cache.expirations.owners'));
     }
 
-    public function getSelection($column = ['id'])
-    {
-        return $this->cacheService->getOrExecute('OwnersAll_' . md5(json_encode($column)), function () use ($column) {
-            return Owner::filterAuthorities()->select($column)->get();
-        }, config('cache.expirations.owners'));
-    }
-
     /**
      *同步WMS全部货主至WAS
      */

+ 1 - 2
app/Services/RealtimePendingOrdersService.php

@@ -42,7 +42,6 @@ class RealtimePendingOrdersService
     {
         $start = $start ?? date('Y-m-d 00:00:00');
         $end = $end ?? date('Y-m-d 23:59:59');
-        $ownerIds = app('OwnerService')->getSelection();
         $builders = Order::query()->selectRaw("warehouses.code," .
             "count(case wms_status when '创建订单' then 1 end) as createOrder, " .
             "count(case wms_status when '分配完成' then 1 end) as assignedComplete, " .
@@ -54,7 +53,7 @@ class RealtimePendingOrdersService
             ->whereIn('wms_status', ['创建订单', '分配完成', '部分分配', '部分装箱', '播种完成'])
             ->leftJoin('warehouses', 'orders.warehouse_id', 'warehouses.id')
             ->groupBy('warehouse_id');
-        if ($ownerIds) $builders->whereIn('owner_id', $ownerIds);
+        $builders->whereIn('owner_id', app("OwnerService")->getQuery());
         return $builders->get();
     }
 }