['未知', '待发车', '在途(发往fbo港口)', '抵达发货港口', '在途(发往目的地仓库)', '抵达目的地', '售出'], 'en' => ['Unknown', 'Pending Departure', 'In Transit (to FBO Port)', 'Arrived at Shipping Port', 'In Transit (to Destination Warehouse)', 'Arrived at Destination', 'Sold'], 'ru' => ['Неизвестно', 'Ожидает отправки', 'В пути (к порту FBO)', 'Прибыл в порт отправки', 'В пути (к складу назначения)', 'Прибыл в пункт назначения', 'Продано'], 'ar' => ['غير معروف', 'في انتظار الشحن', 'في الطريق (إلى ميناء FBO)', 'وصل إلى ميناء الشحن', 'في الطريق (إلى مستودع الوجهة)', 'وصل إلى الوجهة', 'تم البيع'], ]; /** * Mask VIN number by showing only first 2 and last 6 characters */ private function maskVin($vin) { if (strlen($vin) <= 8) { return $vin; } return substr($vin, 0, 2) . str_repeat('*', strlen($vin) - 8) . substr($vin, -6); } /** * Get all vehicles with their locations */ public function index(Request $request) { $lang = $request->post('lang', 'zh'); // 接收请求参数(Webman自动注入) $page = $request->post('page', 1); // 默认第1页 $pageSize = $request->post('pageSize', 30); // 默认每页30条 switch ($lang) { case 'zh': $vehicles = Vehicle::with('location')->with('finalLocation') ->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); $hz = new Location(); break; case 'en': $vehicles = VehicleEn::with('location')->with('finalLocation')->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); $hz = new LocationEn(); break; case 'ru': $vehicles = VehicleRu::with('location')->with('finalLocation')->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); $hz = new LocationRu(); break; case 'ar': $vehicles = VehicleAr::with('location')->with('finalLocation')->offset(($page-1)*$pageSize) ->limit($pageSize)->get(); $hz = new LocationAr(); break; } // // $vehicles = Vehicle::with('location')->with('finalLocation')->get(); // $vehicles->each(function ($vehicle) use ($hz) { // if (isset($vehicle->vin)) { // $vehicle->vin = $this->maskVin($vehicle->vin); // } // // $vehicle->status = $this->status[$vehicle->status]??$this->status[0]; // // $location = Location::find($vehicle->locations_id); // // $vehicle->location_name = $location ? $location->name : ''; // // $final_location = Location::find($vehicle->final_locations_id); // // $vehicle->final_location_name = $final_location ? $final_location->name : ''; // $fbo_location = $hz->find($vehicle->fbo_locations_id); // $vehicle->fbo_destination = $fbo_location ? $fbo_location->name : ''; // if(!str_starts_with($vehicle['img_url'], 'http')){ // $ossservice = new OssService(); // $img_url = $ossservice->generatePrivateUrl($vehicle['img_url'],86400); // $vehicle['img_url'] = $img_url; // } // }); // =================================== new ===================================== start // 单独处理 locations $fboIds = $vehicles->pluck('fbo_locations_id')->toArray(); $fbo = $hz->whereIn('id', array_unique($fboIds))->get()->toArray(); $arr = []; foreach ($fbo as $value) { $arr[$value['id']] = $value; } $ossservice = null; // 组装数据 foreach ($vehicles as &$vehicle) { if (isset($vehicle->vin)) { $vehicle->vin = $this->maskVin($vehicle->vin); } $vehicle->purchase_location=''; $vehicle->procedure_location=''; $vehicle->fbo_destination = isset($arr[$vehicle->fbo_locations_id]) ? $arr[$vehicle->fbo_locations_id]['name'] : ''; $vehicle->status_val = $vehicle->status; if(is_numeric($vehicle->status)) { $vehicle->status = $this->status[$lang][$vehicle->status]??$this->status[$lang][0]; } if(!str_starts_with($vehicle['img_url'], 'http')){ $img_url = Cache::get('img_dib_'.$vehicle->id); if ($img_url) { $vehicle['img_url'] = $img_url; } else { $ossservice = empty($ossservice)?new OssService():$ossservice; $img_url = $ossservice->generatePrivateUrl($vehicle['img_url'],86400); $vehicle['img_url'] = $img_url; Cache::set('img_dib_'.$vehicle->id, $img_url, 86390); } } } unset($vehicle); // =================================== new ===================================== end $count = Vehicle::count(); $result = ['list' => $vehicles,'count'=>$count]; return Util::success($result); } /** * Get a specific vehicle with its location */ public function show(Request $request, $id) { $lang = $request->post('lang', 'zh'); switch ($lang) { case 'zh': $vehicle = Vehicle::with('location')->find($id); break; case 'en': $vehicle = VehicleEn::with('location')->find($id); break; case 'ru': $vehicle = VehicleRu::with('location')->find($id); break; case 'ar': $vehicle = VehicleAr::with('location')->find($id); break; } // $vehicle = Vehicle::with('location')->find($id); if (!$vehicle) { return Util::fail($vehicle,'Vehicle not found'); } if (isset($vehicle->vin)) { $vehicle->vin = $this->maskVin($vehicle->vin); } return Util::success($vehicle); } public function unset(Request $request, $id){ $id = $request->get('id',''); if(!empty($id)){ Cache::delete('img_dib_'.$id); }elseif($id == 'all'){ Cache::clear(); } return Util::success(); } }