Просмотр исходного кода

Merge branch 'master' into zengjun

ajun 5 лет назад
Родитель
Сommit
3a9faaf31b

+ 3 - 3
app/Http/Controllers/InventoryCompareController.php

@@ -93,7 +93,7 @@ class InventoryCompareController extends Controller
     function inventoryCompare(Request $request,OwnerService $ownerService){
         if (!Gate::allows('库存管理-库存-库存对比')){return redirect(url('/')); }
         $owners = $ownerService->getSelection();
-        $inventoryCompares=app('inventoryCompareService')->getInventoryCompare($request->all());
+        $inventoryCompares=app('InventoryCompareService')->getInventoryCompare($request->all());
         $param = $request->input();
         return view('inventory.statement.inventoryCompare',compact('owners','inventoryCompares','param'));
     }
@@ -134,10 +134,10 @@ class InventoryCompareController extends Controller
         if ($request->checkAllSign){
             $params = $request->input();
             unset($params['checkAllSign']);
-            $sql=app('inventoryCompareService')->getSql($params);
+            $sql=app('InventoryCompareService')->getSql($params);
 //            dd($sql);
         }else{
-            $sql=app('inventoryCompareService')->getSql(['id'=>$request->data]);
+            $sql=app('InventoryCompareService')->getSql(['id'=>$request->data]);
         }
         $post = Http::post(config('go.export.url'),['type'=>'inventoryCompare','sql'=>$sql]);
         if ($post->status() == 500){

+ 1 - 5
app/Http/Controllers/OrderController.php

@@ -40,11 +40,7 @@ class OrderController extends Controller
         $orders = $result['orders'];
         $orderIssueNos =  $orderService->返回有问题件的订单号($orders);
         $commodities = $result['commodities'];
-        $customers=OracleBasCustomer::query()->select('customerid','descr_c')
-            ->where('customer_type','OW')
-            ->where('active_flag','Y')
-            ->whereIn('customerid',$codes)
-            ->get();
+        $customers=app('OracleBasCustomerService')->getCustomers($codes);
         $page = $request["page"] ?? 1;
         $codes=DB::connection('oracle')->table('BAS_CODES')->select('code','codename_c')->where('codeid','SO_STS')->orderBy('code','asc')->get();
         $orderIssueType = OrderIssueType::all();

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

@@ -538,7 +538,7 @@ class TestController extends Controller
             LogService::log(__METHOD__,'重新分配商品',json_encode($commodityTag,JSON_UNESCAPED_UNICODE));
 
             app('InventoryAccountMissionService')->batchUpdateItself('commodity_id', $commodityTag);//批量更新库存盘点任务
-            app('inventoryCompareService')->batchUpdateItself('commodity_id', $commodityTag);//批量更新库存对比
+            app('InventoryCompareService')->batchUpdateItself('commodity_id', $commodityTag);//批量更新库存对比
             app('InventoryDailyLogService')->batchUpdateItself('commodity_id', $commodityTag);//批量更新库存每日记录
             app('ProcessesContentService')->batchUpdateItself('commodity_id', $commodityTag);//批量更新二次加工内容单
             app('StoreCheckingReceiveItemService')->batchUpdateItself('commodity_id', $commodityTag);//批量更新入库盘收一体
@@ -637,7 +637,7 @@ where (commodities.owner_id,commodity_barcodes.code) in (select commodities.owne
         }
         if (count($updateCommodities) > 0){
             app('InventoryAccountMissionService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存盘点任务
-            app('inventoryCompareService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存对比
+            app('InventoryCompareService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存对比
             app('InventoryDailyLogService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新库存每日记录
             app('ProcessesContentService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新二次加工内容单
             app('StoreCheckingReceiveItemService')->batchUpdateItself('commodity_id', $updateCommodities);//批量更新入库盘收一体

+ 2 - 2
app/Imports/InventoryCompareImport.php

@@ -25,7 +25,7 @@ class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultip
     public function __construct()
     {
 //            $this->owner_id=$owner_id;
-            app()->singleton('inventoryCompareService',InventoryCompareService::class);
+            app()->singleton('InventoryCompareService',InventoryCompareService::class);
     }
 
     public function Collection(Collection $collection)
@@ -160,7 +160,7 @@ class InventoryCompareImport implements ToCollection, WithHeadingRow, WithMultip
             }
 //            if(empty($exception)){
                 /** @var InventoryCompareService $service */
-                $service = app('inventoryCompareService');
+                $service = app('InventoryCompareService');
                 $inventoryCompare= $service->createInventoryCompares($inventoryCompares);
                 if (!$inventoryCompare) array_push($exception, ['创建库存对比失败!']);
 //            }

+ 3 - 1
app/Providers/AppServiceProvider.php

@@ -12,6 +12,7 @@ use App\Services\common\DataHandlerService;
 use App\Services\DepositoryService;
 use App\Services\InventoryAccountMissionService;
 use App\Services\InventoryCompareService;
+use App\Services\OracleBasCustomerService;
 use App\Services\OracleBasSkuService;
 use App\Services\OracleDocAsnDetailService;
 use App\Services\OracleDOCOrderHeaderService;
@@ -64,7 +65,7 @@ class AppServiceProvider extends ServiceProvider
     {
         //
         app()->singleton('OrderIssuePerformanceService',OrderIssuePerformanceService::class);
-        app()->singleton('inventoryCompareService',InventoryCompareService::class);
+        app()->singleton('InventoryCompareService',InventoryCompareService::class);
     }
 
     /**
@@ -122,6 +123,7 @@ class AppServiceProvider extends ServiceProvider
         app()->singleton('StoreCheckingReceiveService',StoreCheckingReceiveService::class);
         app()->singleton('StoreCheckingReceiveItemService',StoreCheckingReceiveItemService::class);
         app()->singleton('CommodityBarcodeService',CommodityBarcodeService::class);
+        app()->singleton('OracleBasCustomerService',OracleBasCustomerService::class);
         app()->singleton('OracleBasSkuService',OracleBasSkuService::class);
         app()->singleton('OracleDocAsnDetailService',OracleDocAsnDetailService::class);
         app()->singleton('InventoryAccountMissionService',InventoryAccountMissionService::class);

+ 3 - 2
app/Services/CacheService.php

@@ -8,13 +8,14 @@ use Illuminate\Support\Facades\Cache;
 
 class CacheService
 {
-    function getOrExecute(String $key, $func){
+    function getOrExecute(String $key, $func, $expiration=null){
         $results = Cache::get($key);
         if(!$results){
             if(!$func||gettype($func)!='object') throw new \Exception('执行函数类型错误');
             $results = $func();
             if(!$results)return null;
-            Cache::put($key, $results, config('cache.expirations.default'));
+            if(!$expiration) $expiration=config('cache.expirations.default');
+            Cache::put($key, $results, $expiration);
         }
         return $results;
     }

+ 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){

+ 15 - 0
app/Services/OracleBasCustomerService.php

@@ -6,6 +6,11 @@ use App\OracleBasCustomer;
 
 Class OracleBasCustomerService
 {
+    /** @var CacheService $cacheService */
+    private $cacheService;
+    function __construct(){
+        $this->cacheService=app('CacheService');
+    }
     public function getWareHouse($customerIDs = null)
     {
         if(!$customerIDs){
@@ -13,5 +18,15 @@ Class OracleBasCustomerService
         }
         return  OracleBasCustomer::query()->where('Customer_Type','WH')->get();
     }
+    public function getCustomers($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')
+                ->whereIn('customerid',$codes)
+                ->get();
+        },config('cache.expirations.owners'));
+    }
 
 }

+ 24 - 12
app/Services/OwnerService.php

@@ -9,17 +9,27 @@ use Illuminate\Support\Facades\Auth;
 
 Class OwnerService
 {
+    /** @var CacheService $cacheService */
+    private $cacheService;
+    function __construct(){
+        $this->cacheService=app('CacheService');
+    }
     /*
      * array | string $column
      * 默认一些select字段,可传递string 或 array来指定select字段
      */
     public function getSelection($column = ['id', 'name'])
     {
-        return Owner::filterAuthorities()->select($column)->get();
+        return $this->cacheService->getOrExecute('OwnersAll_IdName',function()use($column){
+            return Owner::filterAuthorities()->select($column)->get();
+        },config('cache.expirations.owners'));
+
     }
     public function getSelectionId($column = ['id'])
     {
-        return Owner::filterAuthorities()->select($column)->get();
+        return $this->cacheService->getOrExecute('OwnersAll_Id',function()use($column){
+            return Owner::filterAuthorities()->select($column)->get();
+        },config('cache.expirations.owners'));
     }
     /**
      *同步WMS全部货主至WAS
@@ -55,18 +65,20 @@ Class OwnerService
     }
 
     public function first(array $params, array $rules =[]){
-        $owner = Owner::query();
-        foreach ($params as $column => $value){
-            if (!isset($rules[$column]))$owner->where($column, $value);
-            else{
-                switch ($rules[$column]){
-                    case "or":
-                        $owner->orWhere($column, $value);
-                        break;
+        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);
+                else{
+                    switch ($rules[$column]){
+                        case "or":
+                            $owner->orWhere($column, $value);
+                            break;
+                    }
                 }
             }
-        }
-        return $owner->first();
+            return $owner->first();
+        },config('cache.expirations.rarelyChange'));
     }
 
     public function create(array $params){

+ 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')

+ 4 - 0
config/cache.php

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

+ 1 - 1
resources/views/layouts/menu.blade.php

@@ -28,7 +28,7 @@
                     <span class="fa fa-balance-scale" style="color: #1b7234"></span>
                     称重管理</a></li> @endcan
         @can('库存管理')
-            <li class="nav-item"><a href="{{url("inventory/statement/changeInventory?range=1")}}" class="nav-link"
+            <li class="nav-item"><a href="{{url('inventory/statement/allInventory')}}" class="nav-link"
                                     :class="{active:isActive('inventory',1)}">
                     <span class="fa fa-list-alt" style="color: #32721b"></span>
                     库存管理</a></li> @endcan

+ 2 - 2
resources/views/order/issue/index.blade.php

@@ -732,7 +732,7 @@
                     {name: '退回中', value: '退回中'}];
                 let imported_status = [{name:'导入未处理',value:'导入未处理'},{name:'导入已梳理',value:'导入已处理'}]
                 let data = [[
-                    {name: 'created_at_start', type: 'dateTime', tip: '订单开始日期'},
+                    {name: 'created_at_start', type: 'dateTime', tip: '登记开始日期'},
                     {
                         name: 'owner_id',
                         type: 'select_multiple_select',
@@ -752,7 +752,7 @@
                     {name: 'logistic_number_return', type: 'input', tip: '退回单号:前或后加百分号为单个模糊搜索,否则为多条件精确搜索', placeholder: '退回单号'},
                     {name: 'send_client_code', type: 'input', tip: '二次订单号:前或后加百分号为单个模糊搜索,否则为多条件精确搜索', placeholder: '二次订单号'},
                 ], [
-                    {name: 'created_at_end', type: 'dateTime', tip: '订单结束日期'},
+                    {name: 'created_at_end', type: 'dateTime', tip: '登记结束日期'},
                     {name: 'consignee_name', type: 'input', tip: '收货人名称:前或后加百分号为单个模糊搜索,否则为多条件精确搜索', placeholder: '收货人名称'},
                     {name: 'consignee_phone', type: 'input', tip: '收货人电话:前或后加百分号为单个模糊搜索,否则为多条件精确搜索', placeholder: '收货人电话'},
                     {name: 'good_barcode', type: 'input', tip: '条码:前或后加 百分号为单个模糊搜索,否则为多条件精确搜索', placeholder: '条码'},

+ 0 - 0
tests/CacheService/GetOrExecuteTest/GetOrExecuteTest.php → tests/Services/CacheService/GetOrExecuteTest/GetOrExecuteTest.php