From 69b0bc4fd5360f9ac6bb5c942f8f5c2e1f7a8143 Mon Sep 17 00:00:00 2001 From: "HESU\\HESU" <1696136552@qq.com> Date: Tue, 10 Jun 2025 14:47:46 +0800 Subject: [PATCH] =?UTF-8?q?=E7=94=9F=E4=BA=A7=E5=9F=8E=E5=B8=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controller/LocationController.php | 47 +++++++++++++++++++++++++++ app/controller/VehicleController.php | 19 ++++------- 2 files changed, 54 insertions(+), 12 deletions(-) diff --git a/app/controller/LocationController.php b/app/controller/LocationController.php index dac3aaa..d8425b1 100644 --- a/app/controller/LocationController.php +++ b/app/controller/LocationController.php @@ -3,6 +3,7 @@ namespace app\controller; use app\model\Location; +use app\model\Vehicle; use util\Util; use support\Request; @@ -22,6 +23,52 @@ class LocationController $location->count = ($location->vehicle_count > 0) ? $location->vehicle_count : $location->fbo_vehicle_count; return $location; }); + foreach ($locations as &$location) { + unset($location->vehicles); + unset($location->fboVehicles); + } + return Util::success($locations); + } + + /** + * Get all locations that have vehicles + */ + public function production(Request $request) + { + $where = []; + $status = $request->post('status', 4); + if($status == 1){ + $status = [5,6]; + }elseif ($status == 2){ + $status = [4]; + }elseif ($status == 3){ + $status = [1,2,3,7,8]; + $where[] = ['vin' ,'<>', null]; + }elseif ($status == 4){ + $status = [1,2,3,7,8]; + $where[] = ['vin' ,'=', null]; + } + $vehicles = Vehicle::select('locations_id')->where($where)->whereNotNull('locations_id'); + if(!empty($status)){ + $vehicles = $vehicles->whereIn('status',$status); + } + $locations_id = $vehicles->groupBy('locations_id')->get(); + $locations_id = $locations_id->pluck('locations_id')->toArray(); + + $locations = Location::with('vehicles') + ->with('fboVehicles') + ->whereIn('id',$locations_id) + ->get() + ->map(function ($location) { + $location->vehicle_count = $location->vehicles->count(); + $location->fbo_vehicle_count = $location->fboVehicles->count(); + $location->count = ($location->vehicle_count > 0) ? $location->vehicle_count : $location->fbo_vehicle_count; + return $location; + }); + foreach ($locations as &$location) { + unset($location->vehicles); + unset($location->fboVehicles); + } return Util::success($locations); } diff --git a/app/controller/VehicleController.php b/app/controller/VehicleController.php index e2d020d..7feef0a 100644 --- a/app/controller/VehicleController.php +++ b/app/controller/VehicleController.php @@ -272,22 +272,22 @@ class VehicleController switch ($lang) { case 'zh': - $vehicles = Vehicle::with('location')->with('finalLocation')->where(['locations_id' => $id])->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); + $vehicles = Vehicle::where(['locations_id' => $id])->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); $hz = new Location(); break; case 'en': - $vehicles = VehicleEn::with('location')->with('finalLocation')->where(['locations_id' => $id])->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); + $vehicles = VehicleEn::where(['locations_id' => $id])->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); $hz = new LocationEn(); break; case 'ru': - $vehicles = VehicleRu::with('location')->with('finalLocation')->where(['locations_id' => $id])->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); + $vehicles = VehicleRu::where(['locations_id' => $id])->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); $hz = new LocationRu(); break; case 'ar': - $vehicles = VehicleAr::with('location')->with('finalLocation')->where(['locations_id' => $id])->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); + $vehicles = VehicleAr::where(['locations_id' => $id])->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); $hz = new LocationAr(); break; } @@ -316,17 +316,12 @@ class VehicleController }else{ $vehicle['img_url'] = ''; } - if(!empty($vehicle['ship_id'])){ - $vehicle['ship'] = LogisticsShip::find($vehicle['ship_id'])->toArray(); - } } unset($vehicle); - $logisticsShip = LogisticsShip::where(['id' => $id])->first(); - $logisticsShipHis = LogisticsShipHis::where(['ship_id'=> $id])->get(); - - $count = Vehicle::where(['ship_id' => $id])->count(); - $result = ['list' => $vehicles,'ship' => $logisticsShip,'ship_his' => $logisticsShipHis,'count'=>$count]; + $location = $hz::where(['id' => $id])->first(); + $count = Vehicle::where(['locations_id' => $id])->count(); + $result = ['list' => $vehicles,'location' => $location,'count'=>$count]; return Util::success($result); }