فهرست منبع

LogisticService OwnerService WarehouseService
cache保存时间随机 600+rand(0,100)

ajun 5 سال پیش
والد
کامیت
285ecaea56
4فایلهای تغییر یافته به همراه9 افزوده شده و 5 حذف شده
  1. 1 1
      app/Services/LogisticService.php
  2. 2 1
      app/Services/OwnerService.php
  3. 4 2
      app/Services/WarehouseService.php
  4. 2 1
      config/cache.php

+ 1 - 1
app/Services/LogisticService.php

@@ -95,7 +95,7 @@ Class LogisticService
         $collect = collect();
         if(count($codes) == 0) return $collect;
         foreach ($codes as $code) {
-            $collect->push(Cache::remember("getLogisticByCodes_{$code}", null, function()use($code){
+            $collect->push(Cache::remember("getLogisticByCodes_{$code}", config('database.cache.expirations.rand'), function()use($code){
                 $logistic = Logistic::query()->where('code',$code)->first();
                 if($logistic)return $logistic;
                 $baseCustomers = OracleBasCustomer::query()

+ 2 - 1
app/Services/OwnerService.php

@@ -222,10 +222,11 @@ Class OwnerService
         $collect = collect();
         if(count($codes) == 0)return $collect;
         foreach ($codes as $code) {
-            $collect->push(Cache::remember("getOwnerByCodes_{$code}", null, function ()use($code){
+            $collect->push(Cache::remember("getOwnerByCodes_{$code}", config('database.cache.expirations.rand'), function ()use($code){
                 $owner = Owner::query()->where('code',$code)->first();
                 if($owner) return $owner;
                 $basCustomer = OracleBasCustomer::query()->where('Customer_Type','OW')->where('CustomerID', $code)->first();
+                if(!$basCustomer)return null;
                 return Owner::query()->create(['name'=>$basCustomer['descr_c'],'code'=>$basCustomer['customerid']]);
             }));
         }

+ 4 - 2
app/Services/WarehouseService.php

@@ -7,6 +7,7 @@ use App\Owner;
 use App\Warehouse;
 use Illuminate\Support\Collection;
 use Carbon\Carbon;
+use Illuminate\Support\Facades\Cache;
 
 Class WarehouseService
 {
@@ -109,12 +110,13 @@ Class WarehouseService
         $collect = collect();
         if(count($codes)==0)return $collect;
         foreach ($codes as $code) {
-            $collect->push($this->cacheService->getOrExecute("WareHouse_{$code}",function()use($code){
+            $collect->push(Cache::remember("WareHouse_{$code}",config('database.cache.expirations.rand'),function()use($code){
                 $wareHouse =  Warehouse::query()->where('code',$code)->first();
                 if($wareHouse)return $wareHouse;
                 $bas_customer = OracleBasCustomer::query()->selectRaw('Customer_Type,CustomerId,Descr_C')->where('CustomerId',$code)->where('Customer_Type','WH')->first();
+                if(!$bas_customer) return null;
                 return Warehouse::query()->create(['name'=>$bas_customer['descr_c'],'code'=>$bas_customer['customerid']]);
-            }),config('cache.expirations.forever'));
+            }));
         }
         return $collect;
     }

+ 2 - 1
config/cache.php

@@ -10,7 +10,8 @@ return [
         'rarelyChange'=>60,
         'commonFrequent'=>20,
         'owners'=>20,
-        'forever' =>null
+        'forever' =>null,
+        'rand'=>600+rand(0,100)
     ],
     /*
     |--------------------------------------------------------------------------