diff --git a/app/controller/VehicleController.php b/app/controller/VehicleController.php index 70fdf53..c2241a6 100644 --- a/app/controller/VehicleController.php +++ b/app/controller/VehicleController.php @@ -22,7 +22,7 @@ use support\Cache; class VehicleController { - protected $status = ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达仓库','售出']; + protected $status = ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达目的地','售出']; /** * Mask VIN number by showing only first 2 and last 6 characters */ @@ -105,7 +105,7 @@ class VehicleController } $vehicle->fbo_destination = isset($arr[$vehicle->fbo_locations_id]) ? $arr[$vehicle->fbo_locations_id]['name'] : ''; - + $vehicle->status = $this->status[$vehicle->status]??$this->status[0]; if(!str_starts_with($vehicle['img_url'], 'http')){ $img_url = Cache::get('img_'.$vehicle->id); if ($img_url) { diff --git a/plugin/admin/app/controller/LocationController.php b/plugin/admin/app/controller/LocationController.php index 8445225..71ea791 100644 --- a/plugin/admin/app/controller/LocationController.php +++ b/plugin/admin/app/controller/LocationController.php @@ -152,8 +152,24 @@ class LocationController extends Crud */ public function getAll() { + $lang = session('lang', 'zh-cn'); + switch ($lang) { + case 'zh-cn': + $hz = new \app\model\Location(); + break; - $locations = Location::get(); + case 'en': + $hz = new \app\model\LocationEn(); + break; + + case 'ru': + $hz = new \app\model\LocationRu(); + break; + case 'ar': + $hz = new \app\model\LocationAr(); + break; + } + $locations = $hz::get(); return Util::success($locations); } diff --git a/plugin/admin/app/controller/VehicleController.php b/plugin/admin/app/controller/VehicleController.php index bc0dfe2..583f494 100644 --- a/plugin/admin/app/controller/VehicleController.php +++ b/plugin/admin/app/controller/VehicleController.php @@ -10,6 +10,7 @@ use app\model\VehicleAr; use app\model\VehicleEn; use app\model\VehicleRu; use app\service\OssService; +use plugin\admin\app\common\Util; use plugin\admin\app\model\Location; use support\Log; use support\Request; @@ -33,9 +34,15 @@ class VehicleController extends Crud * 不需要鉴权的方法 * @var string[] */ - protected $noNeedAuth = ['detail']; + protected $noNeedAuth = ['detail', 'status']; - protected $status = ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达仓库','售出']; + protected $status = [ + 'zh-cn' => ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达目的地','售出'], +// 'zh' => ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达目的地','售出'], + 'en' => ['unknown','Awaiting departure','In transit (to FBO port)','Arriving at the port of shipment','In transit (to destination warehouse)','Arriving at the destination','Sold'], + 'ru' => ['Неизвестно','Ожидание отправления','В пути (в порт FBO)','Прибытие в порт отправления','В пути (отправлено на склад назначения)','Прибытие в пункт назначения','Продано'], + 'ar' => ['غير معروف','في انتظار سيارة','على الطريق ( ميناء FBO )','الوصول إلى ميناء الشحن','في الطريق ( مستودع الوجهة )','الوصول إلى الوجهة','بيع'], + ]; /** * @var Vehicle @@ -50,6 +57,13 @@ class VehicleController extends Crud { $this->model = new Vehicle; } + + public function status() + { + $lang = session('lang', 'zh-cn'); + $status = $this->status[$lang]; + return json(['code' => 0, 'msg' => 'success', 'data' => $status]); + } /** * 浏览 @@ -160,50 +174,7 @@ class VehicleController extends Crud // 如果是 POST 请求,处理数据保存和翻译 if ($request->method() === 'POST') { - // 获取表单数据 - $data = $request->all(); - $data['shipping_cycle'] = !empty($data['shipping_cycle'])?$data['shipping_cycle']:0; - - - // 保存主表数据 - $vehicle = new Vehicle(); - $vehicle->fill($data); - $vehicle->save(); - - Log::info('$request',$data); - // 处理多语言翻译 - $languages = ['en', 'ar', 'ru']; - $translationModels = [ - 'en' => VehicleEn::class, - 'ar' => VehicleAr::class, - 'ru' => VehicleRu::class - ]; - - // 创建翻译服务实例 - $translatorService = new \app\service\TranslatorService(); - - foreach ($languages as $lang) { - $translationModel = $translationModels[$lang]; - $translation = new $translationModel(); - - // 复制主表数据 - $translation->fill($data); - $translation->id = $vehicle->id; - - // 使用翻译服务处理需要翻译的字段 - $translatedData = $translatorService->vehicle($data, $lang); - Log::info($lang.':'.$vehicle->id,$translatedData); - - // 更新翻译后的字段 - $translation->brand = $translatedData['brand'] ?? $data['brand']; - $translation->model = $translatedData['model'] ?? $data['model']; - $translation->status = $translatedData['status'] ?? $data['status']; - $translation->purchase_location = $translatedData['purchase_location'] ?? $data['purchase_location']; - $translation->procedure_location = $translatedData['procedure_location'] ?? $data['procedure_location']; -// $translation->fbo_destination = $translatedData['fbo_destination'] ?? $data['fbo_destination']; - - $translation->save(); - } + $this->save($request); } return view('vehicle/insert', [ @@ -212,6 +183,70 @@ class VehicleController extends Crud ]); } + /** + * 保存 + */ + public function save(Request $request) + { + // 获取表单数据 + $data = $request->all(); + $data['shipping_cycle'] = !empty($data['shipping_cycle'])?$data['shipping_cycle']:0; + + + // 保存主表数据 + if(!empty($data['id'])){ + $vehicle = Vehicle::find($data['id']); + }else{ + $vehicle = new Vehicle(); + } + $vehicle->fill($data); + +// return json($vehicle); + $vehicle->save(); + + Log::info('$request',$data); + // 处理多语言翻译 + $languages = ['en', 'ar', 'ru']; + $translationModels = [ + 'en' => VehicleEn::class, + 'ar' => VehicleAr::class, + 'ru' => VehicleRu::class + ]; + + // 创建翻译服务实例 + $translatorService = new \app\service\TranslatorService(); + + foreach ($languages as $lang) { + $translationModel = $translationModels[$lang]; + if(!empty($data['id'])){ +// $vehicle = Vehicle::find($data['id']); + $translation = $translationModel::find($data['id']); + }else{ + $translation = new $translationModel(); + } + + // 复制主表数据 + $translation->fill($data); + $translation->id = $vehicle->id; + + // 使用翻译服务处理需要翻译的字段 + $translatedData = $translatorService->vehicle($data, $lang); + Log::info($lang.':'.$vehicle->id,$translatedData); + + // 更新翻译后的字段 + $translation->brand = $translatedData['brand'] ?? $data['brand']; + $translation->model = $translatedData['model'] ?? $data['model']; +// $translation->status = $translatedData['status'] ?? $data['status']; + $translation->purchase_location = $translatedData['purchase_location'] ?? $data['purchase_location']; + $translation->procedure_location = $translatedData['procedure_location'] ?? $data['procedure_location']; +// $translation->fbo_destination = $translatedData['fbo_destination'] ?? $data['fbo_destination']; + + $translation->save(); + } + } + + + /** * 更新 * @param Request $request @@ -258,6 +293,11 @@ class VehicleController extends Crud ]; $translations = array_merge($required_translations, $translations); } + + // 如果是 POST 请求,处理数据保存和翻译 + if ($request->method() === 'POST') { + $this->save($request); + } $data = Vehicle::where('id', $id)->first(); if (!$data) { @@ -338,42 +378,43 @@ class VehicleController extends Crud */ protected function afterQuery($items) { + $lang = session('lang', 'zh-cn'); + switch ($lang) { + case 'zh-cn': + $vehicle = new \app\model\Vehicle(); + $hz = new \app\model\Location(); + break; + + case 'en': + $vehicle = new \app\model\VehicleEn(); + $hz = new \app\model\LocationEn(); + break; + + case 'ru': + $vehicle = new \app\model\VehicleRu(); + $hz = new \app\model\LocationRu(); + break; + case 'ar': + $vehicle = new \app\model\VehicleAr(); + $hz = new \app\model\LocationAr(); + break; + } + foreach ($items as &$item) { - $location = Location::find($item->locations_id); -// $item->status = $this->status[$item->status]??$this->status[0]; + $item = $vehicle::find($item['id']); + $location = $hz::find($item->locations_id); + $item['status_txt'] = $this->status[$lang][$item->status]??$this->status[$lang][0]; // $item->status = "已到达迪拜仓库"; $item->location_name = $location ? $location->name : ''; - $final_location = Location::find($item->final_locations_id); + $final_location = $hz::find($item->final_locations_id); $item->final_location_name = $final_location ? $final_location->name : ''; - $fbo_location = Location::find($item->fbo_locations_id); + $fbo_location = $hz::find($item->fbo_locations_id); $item->fbo_location_name = $fbo_location ? $fbo_location->name : ''; - $lang = session('lang', 'zh-cn'); - switch ($lang) { - case 'zh-cn': - $vehicle = new \app\model\Vehicle(); - $hz = new \app\model\Location(); - break; - - case 'en': - $vehicle = new \app\model\VehicleEn(); - $hz = new \app\model\LocationEn(); - break; - - case 'ru': - $vehicle = new \app\model\VehicleRu(); - $hz = new \app\model\LocationRu(); - break; - case 'ar': - $vehicle = new \app\model\VehicleAr(); - $hz = new \app\model\LocationAr(); - break; - } - $location = $hz::find($item->locations_id); $item->location_name = $location ? $location->name : ''; - $car = $vehicle::find($item->id); - $item->status = $car ? $car->status : $item->status; +// $car = $vehicle::find($item->id); +// $item->status = $car ? $car->status : $item->status; $location = $hz::find($item->final_location_id); $item->final_location_name = $location ? $location->name : ''; $location = $hz::find($item->fbo_locations_id); diff --git a/plugin/admin/app/lang/ar/vehicle.php b/plugin/admin/app/lang/ar/vehicle.php index 83a4872..b138a90 100644 --- a/plugin/admin/app/lang/ar/vehicle.php +++ b/plugin/admin/app/lang/ar/vehicle.php @@ -31,6 +31,15 @@ return [ 'status_placeholder' => 'الرجاء اختيار الحالة', 'status_1' => 'طبيعي', 'status_0' => 'معطل', + 'status_pending' => 'في انتظار الشحن', + 'status_shipping_to_fbo' => 'في الطريق (إلى ميناء FBO)', + 'status_arrived_fbo' => 'وصل إلى ميناء FBO', + 'status_shipping_to_warehouse' => 'في الطريق (إلى المستودع)', + 'status_arrived_warehouse' => 'وصل إلى المستودع', + 'status_sold' => 'تم البيع', + 'self_owned' => 'مملوك ذاتي', + 'agent' => 'وكيل', + 'please_select' => 'الرجاء الاختيار', 'purchase_location' => 'موقع الشراء', 'purchase_location_placeholder' => 'الرجاء إدخال موقع الشراء', 'procedure_location' => 'موقع الإجراءات', diff --git a/plugin/admin/app/lang/en/vehicle.php b/plugin/admin/app/lang/en/vehicle.php index 4eeb621..c8b1417 100644 --- a/plugin/admin/app/lang/en/vehicle.php +++ b/plugin/admin/app/lang/en/vehicle.php @@ -31,6 +31,15 @@ return [ 'status_placeholder' => 'Please select status', 'status_1' => 'Normal', 'status_0' => 'Disabled', + 'status_pending' => 'Pending', + 'status_shipping_to_fbo' => 'In Transit (to FBO port)', + 'status_arrived_fbo' => 'Arrived at FBO port', + 'status_shipping_to_warehouse' => 'In Transit (to destination warehouse)', + 'status_arrived_warehouse' => 'Arrived at warehouse', + 'status_sold' => 'Sold', + 'self_owned' => 'Self-owned', + 'agent' => 'Agent', + 'please_select' => 'Please select', 'purchase_location' => 'Purchase Location', 'purchase_location_placeholder' => 'Please enter purchase location', 'procedure_location' => 'Procedure Location', diff --git a/plugin/admin/app/lang/ru/vehicle.php b/plugin/admin/app/lang/ru/vehicle.php index 1648937..a875cf3 100644 --- a/plugin/admin/app/lang/ru/vehicle.php +++ b/plugin/admin/app/lang/ru/vehicle.php @@ -30,6 +30,15 @@ return [ 'status_placeholder' => 'Выберите статус', 'status_1' => 'Нормальный', 'status_0' => 'Отключен', + 'status_pending' => 'Ожидает отправки', + 'status_shipping_to_fbo' => 'В пути (к порту FBO)', + 'status_arrived_fbo' => 'Прибыл в порт FBO', + 'status_shipping_to_warehouse' => 'В пути (к складу назначения)', + 'status_arrived_warehouse' => 'Прибыл на склад', + 'status_sold' => 'Продан', + 'self_owned' => 'Собственный', + 'agent' => 'Агент', + 'please_select' => 'Пожалуйста, выберите', 'purchase_location' => 'Место покупки', 'purchase_location_placeholder' => 'Введите место покупки', 'procedure_location' => 'Место оформления', diff --git a/plugin/admin/app/view/vehicle/index.html b/plugin/admin/app/view/vehicle/index.html index 0ced94c..3951345 100644 --- a/plugin/admin/app/view/vehicle/index.html +++ b/plugin/admin/app/view/vehicle/index.html @@ -98,7 +98,7 @@ {type: "checkbox", align: "center"}, {title: translations.id, align: "center", field: "id"}, {title: translations.vin, align: "center", field: "vin"}, - {title: translations.status, align: "center", field: "status"}, + {title: translations.status, align: "center", field: "status_txt"}, {title: translations.current_location, align: "center", field: "location_name"}, {title: translations.final_location, align: "center", field: "final_location_name"}, {title: translations.fbo_location, align: "center", field: "fbo_location_name"}, diff --git a/plugin/admin/app/view/vehicle/update.html b/plugin/admin/app/view/vehicle/update.html index 5bec0dc..6a8b5d8 100644 --- a/plugin/admin/app/view/vehicle/update.html +++ b/plugin/admin/app/view/vehicle/update.html @@ -26,7 +26,7 @@
@@ -48,16 +48,16 @@
- +
@@ -200,6 +200,34 @@ layer.msg('请求失败: ' + xhr.status); } }); + + //车辆状态 + $.ajax({ + url: '/app/admin/vehicle/status', + type: 'GET', + dataType: 'json', + success: function(res) { + if (res.code !== 0) { + layer.msg(res.msg || '加载失败'); + return; + } + + const select = $('#status'); + // select.empty().append(''); + + $.each(res.data, function(index, item){ + if(index != 0){ + select.append(``); + } + }); + + // 重新渲染下拉框 + form.render('select'); + }, + error: function(xhr) { + layer.msg('请求失败: ' + xhr.status); + } + }); } // 获取数据库记录