Parcourir la source

快递公司,标签,货主,退货页的缓存

LD il y a 5 ans
Parent
commit
03add59a1d

+ 13 - 4
app/Services/LogisticService.php

@@ -9,14 +9,23 @@ use Illuminate\Support\Facades\Auth;
 
 Class LogisticService
 {
+    /** @var CacheService $cacheService */
+    private $cacheService;
+    function __construct(){
+        $this->cacheService=app('CacheService');
+    }
     public function getSelection($column = ['id','name']){
-        return Logistic::query()->select($column)->get();
+        return $this->cacheService->getOrExecute('LogisticAll_idName',function()use($column){
+            return Logistic::query()->select($column)->get();
+        },config('cache.expirations.persistent'));
     }
 
     public function firstOrCreate(array $params, array $values = null){
-        $logistic = Logistic::query();
-        if ($values)return $logistic->firstOrCreate($params, $values);
-        return $logistic->firstOrCreate($params);
+        return $this->cacheService->getOrExecute('LogisticFirstOrCreate'.md5(json_encode($params).json_encode($values)),function()use($params,$values){
+            $logistic = Logistic::query();
+            if ($values)return $logistic->firstOrCreate($params, $values);
+            return $logistic->firstOrCreate($params);
+        },config('cache.expirations.commonFrequent'));
     }
 
     public function getByWmsOrders($orderHeaders){

+ 1 - 1
app/Services/OracleBasCustomerService.php

@@ -20,7 +20,7 @@ Class OracleBasCustomerService
     }
     public function getCustomers($codes)
     {
-        return $this->cacheService->getOrExecute('OwnersAll_Id',function()use($codes){
+        return $this->cacheService->getOrExecute('OracleBasCustomersAll'.md5(json_encode($codes)),function()use($codes){
             return OracleBasCustomer::query()->select('customerid','descr_c')
                 ->where('customer_type','OW')
                 ->where('active_flag','Y')

+ 1 - 1
app/Services/OwnerService.php

@@ -65,7 +65,7 @@ Class OwnerService
     }
 
     public function first(array $params, array $rules =[]){
-        return $this->cacheService->getOrExecute('OwnersFirst'.md5(json_encode($params)),function()use($params,$rules){
+        return $this->cacheService->getOrExecute('OwnersFirst'.md5(json_encode($params),json_encode($rules)),function()use($params,$rules){
             $owner = Owner::query();
             foreach ($params as $column => $value){
                 if (!isset($rules[$column]))$owner->where($column, $value);

+ 8 - 1
app/Services/QualityLabelService.php

@@ -6,8 +6,15 @@ use App\QualityLabel;
 
 Class QualityLabelService
 {
+    /** @var CacheService $cacheService */
+    private $cacheService;
+    function __construct(){
+        $this->cacheService=app('CacheService');
+    }
     public function get(){
-        return QualityLabel::get();
+        return $this->cacheService->getOrExecute('QualityLabelAll',function(){
+            return QualityLabel::get();
+        },config('cache.expirations.rarelyChange'));
     }
 
 }

+ 12 - 2
app/Services/RejectedService.php

@@ -4,6 +4,7 @@ namespace App\Services;
 
 use App\Exports\RejectedExport;
 use App\Logistic;
+use App\OracleBasCustomer;
 use App\OracleDOCASNDetail;
 use App\OracleDOCASNHeader;
 use App\OracleDOCOrderHeader;
@@ -18,6 +19,11 @@ use Illuminate\Support\Facades\Auth;
 
 class RejectedService
 {
+    /** @var CacheService $cacheService */
+    private $cacheService;
+    function __construct(){
+        $this->cacheService=app('CacheService');
+    }
     private function conditionQuery(array $param)
     {
         $user = Auth::user();
@@ -95,12 +101,16 @@ class RejectedService
 
     public function paginate(Request $request)
     {
-        return $this->conditionQuery($request->input())->paginate($request->paginate ?? 50);
+        return $this->cacheService->getOrExecute('RejectedsPaginate'.md5(json_encode($request->toArray())),function()use($request){
+            return $this->conditionQuery($request->input())->paginate($request->paginate ?? 50);
+        },config('cache.expirations.oftenChange'));
     }
 
     public function get(Request $request)
     {
-        return $this->conditionQuery($request->input())->get();
+        return $this->cacheService->getOrExecute('Rejecteds'.md5(json_encode($request->toArray())),function()use($request){
+            return $this->conditionQuery($request->input())->get();
+        },config('cache.expirations.oftenChange'));
     }
     public function getSql(array $param){
         $sql = $this->conditionQuery($param)->selectRaw('rejected_bills.*')->whereNull('rejected_bills.deleted_at')

+ 2 - 0
config/cache.php

@@ -6,7 +6,9 @@ return [
 
     'expirations'=>[
         'default'=>10,
+        'oftenChange'=>5,
         'rarelyChange'=>60,
+        'commonFrequent'=>20,
         'owners'=>20,
     ],
     /*