生产城市

This commit is contained in:
2025-06-10 14:47:46 +08:00
parent 9a993028d7
commit 69b0bc4fd5
2 changed files with 54 additions and 12 deletions
+47
View File
@@ -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);
}
+7 -12
View File
@@ -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);
}