Forráskód Böngészése

优化加载速度

Zhouzhendong 4 éve
szülő
commit
5bb984f53c
2 módosított fájl, 25 hozzáadás és 9 törlés
  1. 3 1
      app/Services/LogisticService.php
  2. 22 8
      app/Services/RejectedService.php

+ 3 - 1
app/Services/LogisticService.php

@@ -121,7 +121,9 @@ class LogisticService implements UserFilter
     function getIdArr(?int $userId = null): array
     {
         if (!$userId)$userId = Auth::id();
-        return array_column($this->getQuery($userId)->get()->toArray(),"id");
+        return $this->cacheService->getOrExecute("USER.{$userId}.LOGISTIC.ID", function () use ($userId) {
+            return array_column($this->getQuery($userId)->get()->toArray(),"id");
+        });
     }
     function getCodeArr(?int $userId): array
     {

+ 22 - 8
app/Services/RejectedService.php

@@ -10,6 +10,7 @@ use App\Services\common\QueryService;
 use Illuminate\Database\Eloquent\Builder;
 use Illuminate\Http\Request;
 use App\Traits\ServiceAppAop;
+use Illuminate\Pagination\Paginator;
 
 
 class RejectedService
@@ -25,19 +26,27 @@ class RejectedService
         $this->instant($this->cacheService,'CacheService');
         $this->instant($this->workOrderInterceptService,'WorkOrderInterceptService');
     }
-    private function  conditionQuery(array $param)
+    private function  conditionQuery(array $param, array $owners = null, array $logistics = null)
     {
-        $owners =  app("OwnerService")->getQuery()->select("id")->pluck("id")->toArray();
-        if (count($owners)==0){
-            $owners[] = [''];
+        if ($owners == null){
+            $owners =  app("OwnerService")->getIdArr();
+            if (count($owners)==0){
+                $owners[] = [''];
+            }
+        }
+        if ($logistics == null){
+            $logistics =  app("LogisticService")->getIdArr();
+            if (count($logistics)==0){
+                $logistics[] = [''];
+            }
         }
         $rejectedBills = RejectedBill::query()->with('user','owner', 'logistic', 'items.quality','record:logistic_number,record_at,location_at',
             'items.packageImages','items.commodityImages','items.uploadFiles','orderIssueRejectedBill:logistic_number_return')
             ->orderBy('rejected_bills.id', 'desc')
-            ->where(function ($query)use ($owners){
+            ->where(function ($query)use ($owners, $logistics){
                 /** @var Builder $query */
                 $query->whereIn('rejected_bills.id_owner', $owners)
-                    ->orWhereIn("rejected_bills.id_logistic_return",app("LogisticService")->getQuery());
+                    ->orWhereIn("rejected_bills.id_logistic_return", $logistics);
             });
         if (array_search("397",$owners)!==false){
             $rejectedBills->with(["items.barcode.commodity"=>function($query){
@@ -122,8 +131,13 @@ class RejectedService
 
     public function paginate(Request $request)
     {
-        return $this->cacheService->getOrExecute('RejectedsPaginate'.md5(json_encode($request->toArray())),function()use($request){
-            return $this->conditionQuery($request->input())->simplePaginate($request->paginate ?? 50);
+        $owners =  app("OwnerService")->getIdArr();
+        $logistics =  app("LogisticService")->getIdArr();
+        if (count($owners) == 0 && count($logistics) == 0){
+            return new Paginator([], 1);
+        }
+        return $this->cacheService->getOrExecute('RejectedsPaginate'.md5(json_encode($request->toArray())),function()use($request, $owners, $logistics){
+            return $this->conditionQuery($request->input(), $owners, $logistics)->simplePaginate($request->paginate ?? 50);
         },config('cache.expirations.oftenChange'));
     }