Zhouzhendong 6 vuotta sitten
vanhempi
commit
d89daab3b3

+ 27 - 38
app/Http/Controllers/PackageController.php

@@ -15,6 +15,30 @@ use Maatwebsite\Excel\Facades\Excel;
 
 class PackageController extends Controller
 {
+
+    public function conditionQuery(Request $request,$packages){
+        $today=Carbon::now()->subDays(15);
+        if ($request->input('logistic_number')){
+            $packages=$packages->where('logistic_number','like','%'.$request->input('logistic_number').'%')->where('created_at','>',$today->format('Y-m-d'));
+        }
+        if ($request->input('delivery_number')){
+            $packages=$packages->where('delivery_number','like','%'.$request->input('delivery_number').'%')->where('created_at','>',$today->format('Y-m-d'));
+        }
+        if ($request->input('created_at_start')){
+            $packages=$packages->where('created_at','>=',$request->input('created_at_start'));
+        }
+        if ($request->input('created_at_end')){
+            $packages=$packages->where('created_at','<=',$request->input('created_at_end'));
+        }
+        if ($request->input('owner_id')){
+            $packages=$packages->where('owner_id',$request->input('owner_id'));
+        }
+        if ($request->input('batch_number')){
+            $packages=$packages->where('batch_number','like','%'.$request->input('batch_number').'%')->where('created_at','>',$today->format('Y-m-d'));
+        }
+        return $packages;
+    }
+
     /**
      * Display a listing of the resource.
      *
@@ -25,25 +49,8 @@ class PackageController extends Controller
         if(!Gate::allows('称重管理-查询')){ return redirect(url('/'));  }
         if ($request->input()){
             $packages=Package::orderBy('id','DESC');
-            $today=Carbon::now()->subDays(15);
-            if ($request->input('logistic_number')){
-                $packages=$packages->where('logistic_number','like','%'.$request->input('logistic_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('delivery_number')){
-                $packages=$packages->where('delivery_number','like','%'.$request->input('delivery_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('created_at_start')){
-                $packages=$packages->where('created_at','>=',$request->input('created_at_start'));
-            }
-            if ($request->input('created_at_end')){
-                $packages=$packages->where('created_at','<=',$request->input('created_at_end'));
-            }
-            if ($request->input('owner_id')){
-                $packages=$packages->where('owner_id',$request->input('owner_id'));
-            }
-            if ($request->input('batch_number')){
-                $packages=$packages->where('batch_number','like','%'.$request->input('batch_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
+
+            $packages=$this->conditionQuery($request,$packages);
             $packages=$packages->paginate($request->input('paginate')?$request->input('paginate'):50);
             $owners=Owner::select('id','name')->get();
             return view('weight.package.index',['packages'=>$packages,'owners'=>$owners]);
@@ -137,28 +144,10 @@ class PackageController extends Controller
         if(!Gate::allows('称重管理-查询')){ return '没有权限';  }
         if ($id==-1){
             $id=[];
-            $today=Carbon::now()->subDays(15);
             ini_set('max_execution_time',2500);
             ini_set('memory_limit','1526M');
             $packages=Package::select('id');
-            if ($request->input('logistic_number')){
-                $packages=$packages->where('logistic_number','like','%'.$request->input('logistic_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('delivery_number')){
-                $packages=$packages->where('delivery_number','like','%'.$request->input('delivery_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('created_at_start')){
-                $packages=$packages->where('created_at','>=',$request->input('created_at_start'));
-            }
-            if ($request->input('created_at_end')){
-                $packages=$packages->where('created_at','<=',$request->input('created_at_end'));
-            }
-            if ($request->input('owner_id')){
-                $packages=$packages->where('owner_id',$request->input('owner_id'));
-            }
-            if ($request->input('batch_number')){
-                $packages=$packages->where('batch_number','like','%'.$request->input('batch_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
+            $packages=$this->conditionQuery($request,$packages);
             $packages=$packages->get();
             foreach ($packages as $package){
                 array_push($id,$package->id);

+ 10 - 18
app/Http/Controllers/WaybillFinancialExceptedController.php

@@ -11,10 +11,7 @@ use Illuminate\Support\Facades\Gate;
 
 class WaybillFinancialExceptedController extends Controller
 {
-    public function index(Request $request)
-    {
-        if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
-        $waybillFinancialSnapshots=WaybillFinancialExcepted::orderBy('id', 'DESC');
+    public function conditionQuery(Request $request,$waybillFinancialSnapshots){
         if ($request->input('created_at_start')){
             $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
         }
@@ -22,32 +19,27 @@ class WaybillFinancialExceptedController extends Controller
             $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
         }
         $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
+        return $waybillFinancialSnapshots;
+    }
+    public function index(Request $request)
+    {
+        if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
+        $waybillFinancialSnapshots=WaybillFinancialExcepted::orderBy('id', 'DESC');
+        $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
         return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'','excepted'=>true]);
     }
     public function indexZF(Request $request)
     {
         if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
         $waybillFinancialSnapshots=WaybillFinancialExcepted::orderBy('id', 'DESC')->where('json_content','like','%直发车%');
-        if ($request->input('created_at_start')){
-            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
-        }
-        if ($request->input('created_at_end')){
-            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
-        }
-        $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
+        $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
         return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'ZF','excepted'=>true]);
     }
     public function indexZX(Request $request)
     {
         if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
         $waybillFinancialSnapshots=WaybillFinancialExcepted::orderBy('id', 'DESC')->where('json_content','like','%专线%');
-        if ($request->input('created_at_start')){
-            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
-        }
-        if ($request->input('created_at_end')){
-            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
-        }
-        $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
+        $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
         return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'ZX','excepted'=>true]);
     }
 }

+ 10 - 18
app/Http/Controllers/WaybillFinancialSnapshotsController.php

@@ -12,10 +12,7 @@ use Maatwebsite\Excel\Facades\Excel;
 
 class WaybillFinancialSnapshotsController extends Controller
 {
-    public function index(Request $request)
-    {
-        if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
-        $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC');
+    public function conditionQuery(Request $request,$waybillFinancialSnapshots){
         if ($request->input('created_at_start')){
             $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
         }
@@ -23,6 +20,13 @@ class WaybillFinancialSnapshotsController extends Controller
             $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
         }
         $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
+        return $waybillFinancialSnapshots;
+    }
+    public function index(Request $request)
+    {
+        if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
+        $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC');
+        $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
         return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'']);
     }
 
@@ -30,13 +34,7 @@ class WaybillFinancialSnapshotsController extends Controller
     {
         if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
         $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC')->where('json_content','like','%直发车%');
-        if ($request->input('created_at_start')){
-            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
-        }
-        if ($request->input('created_at_end')){
-            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
-        }
-        $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
+        $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
         return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'ZF']);
     }
 
@@ -44,13 +42,7 @@ class WaybillFinancialSnapshotsController extends Controller
     {
         if(!Gate::allows('财务报表-查询')){ return redirect(url('/'));  }
         $waybillFinancialSnapshots=WaybillFinancialSnapshot::orderBy('id', 'DESC')->where('json_content','like','%专线%');
-        if ($request->input('created_at_start')){
-            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','>',$request->input('created_at_start'));
-        }
-        if ($request->input('created_at_end')){
-            $waybillFinancialSnapshots=$waybillFinancialSnapshots->where('created_at','<',$request->input('created_at_end'));
-        }
-        $waybillFinancialSnapshots=$waybillFinancialSnapshots->paginate(50);
+        $waybillFinancialSnapshots=$this->conditionQuery($request,$waybillFinancialSnapshots);
         return view('waybill.waybillFinancialSnapshot.index',['waybillFinancialSnapshots'=>$waybillFinancialSnapshots,'filterData'=>$request->input(),'type'=>'ZX']);
     }
 

+ 44 - 102
app/Http/Controllers/WaybillsController.php

@@ -27,53 +27,57 @@ use Ramsey\Uuid\Uuid;
 
 class WaybillsController extends Controller
 {
+    public function conditionQuery(Request $request,$waybills){
+        $today=Carbon::now()->subDays(15);
+        if ($request->input('waybill_number')){
+            $waybills =$waybills->where('waybill_number','like','%'.$request->input('waybill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
+        }
+        if ($request->input('carrier_bill')){
+            $waybills=$waybills->where('carrier_bill','like','%'.$request->input('carrier_bill').'%')->where('created_at','>',$today->format('Y-m-d'));
+        }
+        if ($request->input('carrier_id')){
+            $waybills=$waybills->where('carrier_id','=',$request->input('carrier_id'));
+        }
+        if ($request->input('owner_id')){
+            $waybills=$waybills->where('owner_id','=',$request->input('owner_id'));
+        }
+        if ($request->input('wms_bill_number')){
+            $waybills=$waybills->where('wms_bill_number','like','%'.$request->input('wms_bill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
+        }
+        if ($request->input('origination')){
+            $waybills=$waybills->where('origination','like','%'.$request->input('origination').'%')->where('created_at','>',$today->format('Y-m-d'));
+        }
+        if ($request->input('destination')){
+            $waybills=$waybills->where('destination','like','%'.$request->input('destination').'%')->where('created_at','>',$today->format('Y-m-d'));
+        }
+        if ($request->input('created_at_start')){
+            $waybills=$waybills->where('created_at','>',$request->input('created_at_start'));
+        }
+        if ($request->input('created_at_end')){
+            $waybills=$waybills->where('created_at','<',$request->input('created_at_end'));
+        }
+        if ($request->input('status')){
+            $waybills=$waybills->where('status',$request->input('status'));
+        }
+        $waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
+        if (!$waybills&&$request->input('waybill_number')){
+            $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
+                return $query->with('user');
+            }])->orderBy('id','DESC')->where('type','专线')->where('waybill_number',$request->input('waybill_number'))
+                ->paginate($request->input('paginate')?$request->input('paginate'):50);
+        }
+        return $waybills;
+    }
 
     public function index(Request $request)
     {
         if(!Gate::allows('运输管理-查询')){ return redirect(url('/'));  }
         $data=$request->input();
         if ($data != null ) {
-            $today=Carbon::now()->subDays(15);
             $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
                 return $query->with('user');
             }])->orderBy('id','DESC');
-            if ($request->input('waybill_number')){
-                $waybills =$waybills->where('waybill_number','like','%'.$request->input('waybill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('carrier_bill')){
-                $waybills=$waybills->where('carrier_bill','like','%'.$request->input('carrier_bill').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('carrier_id')){
-                $waybills=$waybills->where('carrier_id','=',$request->input('carrier_id'));
-            }
-            if ($request->input('owner_id')){
-                $waybills=$waybills->where('owner_id','=',$request->input('owner_id'));
-            }
-            if ($request->input('wms_bill_number')){
-                $waybills=$waybills->where('wms_bill_number','like','%'.$request->input('wms_bill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('origination')){
-                $waybills=$waybills->where('origination','like','%'.$request->input('origination').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('destination')){
-                $waybills=$waybills->where('destination','like','%'.$request->input('destination').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('created_at_start')){
-                $waybills=$waybills->where('created_at','>',$request->input('created_at_start'));
-            }
-            if ($request->input('created_at_end')){
-                $waybills=$waybills->where('created_at','<',$request->input('created_at_end'));
-            }
-            if ($request->input('status')){
-                $waybills=$waybills->where('status',$request->input('status'));
-            }
-            $waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
-            if (!$waybills&&$request->input('waybill_number')){
-                $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
-                    return $query->with('user');
-                }])->orderBy('id','DESC')->where('type','专线')->where('waybill_number',$request->input('waybill_number'))
-                    ->paginate($request->input('paginate')?$request->input('paginate'):50);
-            }
+            $waybills=$this->conditionQuery($request,$waybills);
             $carries = Carrier::get();
             $owners = Owner::get();
             return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'']);
@@ -92,41 +96,10 @@ class WaybillsController extends Controller
         if(!Gate::allows('运输管理-查询')){ return redirect(url('/'));  }
         $data=$request->input();
         if ($data != null ) {
-            $today=Carbon::now()->subDays(15);
             $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
                 return $query->with('user');
             }])->orderBy('id','DESC')->where('type','直发车');
-            if ($request->input('waybill_number')){
-                $waybills =$waybills->where('waybill_number','like','%'.$request->input('waybill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('carrier_bill')){
-                $waybills=$waybills->where('carrier_bill','like','%'.$request->input('carrier_bill').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('carrier_id')){
-                $waybills=$waybills->where('carrier_id','=',$request->input('carrier_id'));
-            }
-            if ($request->input('owner_id')){
-                $waybills=$waybills->where('owner_id','=',$request->input('owner_id'));
-            }
-            if ($request->input('wms_bill_number')){
-                $waybills=$waybills->where('wms_bill_number','like','$'.$request->input('wms_bill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('created_at_start')){
-                $waybills=$waybills->where('created_at','>',$request->input('created_at_start'));
-            }
-            if ($request->input('created_at_end')){
-                $waybills=$waybills->where('created_at','<',$request->input('created_at_end'));
-            }
-            if ($request->input('status')){
-                $waybills=$waybills->where('status',$request->input('status'));
-            }
-            $waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
-            if (!$waybills&&$request->input('waybill_number')){
-                $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
-                    return $query->with('user');
-                }])->orderBy('id','DESC')->where('type','专线')->where('waybill_number',$request->input('waybill_number'))
-                    ->paginate($request->input('paginate')?$request->input('paginate'):50);
-            }
+            $waybills=$this->conditionQuery($request,$waybills);
             $carries = Carrier::get();
             $owners = Owner::get();
             return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZF']);
@@ -145,41 +118,10 @@ class WaybillsController extends Controller
         if(!Gate::allows('运输管理-查询')){ return redirect(url('/'));  }
         $data=$request->input();
         if ($data != null ) {
-            $today=Carbon::now()->subDays(15);
             $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
                 return $query->with('user');
             }])->orderBy('id','DESC')->where('type','专线');
-            if ($request->input('waybill_number')){
-                $waybills =$waybills->where('waybill_number','like','%'.$request->input('waybill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('carrier_bill')){
-                $waybills=$waybills->where('carrier_bill','like','%'.$request->input('carrier_bill').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('carrier_id')){
-                $waybills=$waybills->where('carrier_id','=',$request->input('carrier_id'));
-            }
-            if ($request->input('owner_id')){
-                $waybills=$waybills->where('owner_id','=',$request->input('owner_id'));
-            }
-            if ($request->input('wms_bill_number')){
-                $waybills=$waybills->where('wms_bill_number','like','$'.$request->input('wms_bill_number').'%')->where('created_at','>',$today->format('Y-m-d'));
-            }
-            if ($request->input('created_at_start')){
-                $waybills=$waybills->where('created_at','>',$request->input('created_at_start'));
-            }
-            if ($request->input('created_at_end')){
-                $waybills=$waybills->where('created_at','<',$request->input('created_at_end'));
-            }
-            if ($request->input('status')){
-                $waybills=$waybills->where('status',$request->input('status'));
-            }
-            $waybills=$waybills->paginate($request->input('paginate')?$request->input('paginate'):50);
-            if (!$waybills&&$request->input('waybill_number')){
-                $waybills=Waybill::with(['owner', 'waybillAuditLogs' => function ($query) {
-                    return $query->with('user');
-                }])->orderBy('id','DESC')->where('type','专线')->where('waybill_number',$request->input('waybill_number'))
-                    ->paginate($request->input('paginate')?$request->input('paginate'):50);
-            }
+            $waybills=$this->conditionQuery($request,$waybills);
             $carries = Carrier::get();
             $owners = Owner::get();
             return view('waybill.index', ['waybills' => $waybills, 'carriers' => $carries, 'owners' => $owners,'filterData'=>$data,'uriType'=>'ZX']);