车辆多语言修复

This commit is contained in:
2025-05-13 15:29:30 +08:00
parent af0e8bc62f
commit 21b19109d0
8 changed files with 198 additions and 86 deletions
+2 -2
View File
@@ -22,7 +22,7 @@ use support\Cache;
class VehicleController class VehicleController
{ {
protected $status = ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达仓库','售出']; protected $status = ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达目的地','售出'];
/** /**
* Mask VIN number by showing only first 2 and last 6 characters * 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->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')){ if(!str_starts_with($vehicle['img_url'], 'http')){
$img_url = Cache::get('img_'.$vehicle->id); $img_url = Cache::get('img_'.$vehicle->id);
if ($img_url) { if ($img_url) {
@@ -152,8 +152,24 @@ class LocationController extends Crud
*/ */
public function getAll() 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); return Util::success($locations);
} }
@@ -10,6 +10,7 @@ use app\model\VehicleAr;
use app\model\VehicleEn; use app\model\VehicleEn;
use app\model\VehicleRu; use app\model\VehicleRu;
use app\service\OssService; use app\service\OssService;
use plugin\admin\app\common\Util;
use plugin\admin\app\model\Location; use plugin\admin\app\model\Location;
use support\Log; use support\Log;
use support\Request; use support\Request;
@@ -33,9 +34,15 @@ class VehicleController extends Crud
* 不需要鉴权的方法 * 不需要鉴权的方法
* @var string[] * @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 * @var Vehicle
@@ -51,6 +58,13 @@ class VehicleController extends Crud
$this->model = new Vehicle; $this->model = new Vehicle;
} }
public function status()
{
$lang = session('lang', 'zh-cn');
$status = $this->status[$lang];
return json(['code' => 0, 'msg' => 'success', 'data' => $status]);
}
/** /**
* 浏览 * 浏览
* @return Response * @return Response
@@ -160,14 +174,34 @@ class VehicleController extends Crud
// 如果是 POST 请求,处理数据保存和翻译 // 如果是 POST 请求,处理数据保存和翻译
if ($request->method() === 'POST') { if ($request->method() === 'POST') {
$this->save($request);
}
return view('vehicle/insert', [
'lang' => $lang,
'translations' => $translations
]);
}
/**
* 保存
*/
public function save(Request $request)
{
// 获取表单数据 // 获取表单数据
$data = $request->all(); $data = $request->all();
$data['shipping_cycle'] = !empty($data['shipping_cycle'])?$data['shipping_cycle']:0; $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 = new Vehicle();
}
$vehicle->fill($data); $vehicle->fill($data);
// return json($vehicle);
$vehicle->save(); $vehicle->save();
Log::info('$request',$data); Log::info('$request',$data);
@@ -184,7 +218,12 @@ class VehicleController extends Crud
foreach ($languages as $lang) { foreach ($languages as $lang) {
$translationModel = $translationModels[$lang]; $translationModel = $translationModels[$lang];
if(!empty($data['id'])){
// $vehicle = Vehicle::find($data['id']);
$translation = $translationModel::find($data['id']);
}else{
$translation = new $translationModel(); $translation = new $translationModel();
}
// 复制主表数据 // 复制主表数据
$translation->fill($data); $translation->fill($data);
@@ -197,7 +236,7 @@ class VehicleController extends Crud
// 更新翻译后的字段 // 更新翻译后的字段
$translation->brand = $translatedData['brand'] ?? $data['brand']; $translation->brand = $translatedData['brand'] ?? $data['brand'];
$translation->model = $translatedData['model'] ?? $data['model']; $translation->model = $translatedData['model'] ?? $data['model'];
$translation->status = $translatedData['status'] ?? $data['status']; // $translation->status = $translatedData['status'] ?? $data['status'];
$translation->purchase_location = $translatedData['purchase_location'] ?? $data['purchase_location']; $translation->purchase_location = $translatedData['purchase_location'] ?? $data['purchase_location'];
$translation->procedure_location = $translatedData['procedure_location'] ?? $data['procedure_location']; $translation->procedure_location = $translatedData['procedure_location'] ?? $data['procedure_location'];
// $translation->fbo_destination = $translatedData['fbo_destination'] ?? $data['fbo_destination']; // $translation->fbo_destination = $translatedData['fbo_destination'] ?? $data['fbo_destination'];
@@ -206,11 +245,7 @@ class VehicleController extends Crud
} }
} }
return view('vehicle/insert', [
'lang' => $lang,
'translations' => $translations
]);
}
/** /**
* 更新 * 更新
@@ -259,6 +294,11 @@ class VehicleController extends Crud
$translations = array_merge($required_translations, $translations); $translations = array_merge($required_translations, $translations);
} }
// 如果是 POST 请求,处理数据保存和翻译
if ($request->method() === 'POST') {
$this->save($request);
}
$data = Vehicle::where('id', $id)->first(); $data = Vehicle::where('id', $id)->first();
if (!$data) { if (!$data) {
return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']); return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']);
@@ -338,16 +378,6 @@ class VehicleController extends Crud
*/ */
protected function afterQuery($items) protected function afterQuery($items)
{ {
foreach ($items as &$item) {
$location = Location::find($item->locations_id);
// $item->status = $this->status[$item->status]??$this->status[0];
// $item->status = "已到达迪拜仓库";
$item->location_name = $location ? $location->name : '';
$final_location = Location::find($item->final_locations_id);
$item->final_location_name = $final_location ? $final_location->name : '';
$fbo_location = Location::find($item->fbo_locations_id);
$item->fbo_location_name = $fbo_location ? $fbo_location->name : '';
$lang = session('lang', 'zh-cn'); $lang = session('lang', 'zh-cn');
switch ($lang) { switch ($lang) {
case 'zh-cn': case 'zh-cn':
@@ -370,10 +400,21 @@ class VehicleController extends Crud
break; break;
} }
foreach ($items as &$item) {
$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 = $hz::find($item->final_locations_id);
$item->final_location_name = $final_location ? $final_location->name : '';
$fbo_location = $hz::find($item->fbo_locations_id);
$item->fbo_location_name = $fbo_location ? $fbo_location->name : '';
$location = $hz::find($item->locations_id); $location = $hz::find($item->locations_id);
$item->location_name = $location ? $location->name : ''; $item->location_name = $location ? $location->name : '';
$car = $vehicle::find($item->id); // $car = $vehicle::find($item->id);
$item->status = $car ? $car->status : $item->status; // $item->status = $car ? $car->status : $item->status;
$location = $hz::find($item->final_location_id); $location = $hz::find($item->final_location_id);
$item->final_location_name = $location ? $location->name : ''; $item->final_location_name = $location ? $location->name : '';
$location = $hz::find($item->fbo_locations_id); $location = $hz::find($item->fbo_locations_id);
+9
View File
@@ -31,6 +31,15 @@ return [
'status_placeholder' => 'الرجاء اختيار الحالة', 'status_placeholder' => 'الرجاء اختيار الحالة',
'status_1' => 'طبيعي', 'status_1' => 'طبيعي',
'status_0' => 'معطل', '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' => 'موقع الشراء',
'purchase_location_placeholder' => 'الرجاء إدخال موقع الشراء', 'purchase_location_placeholder' => 'الرجاء إدخال موقع الشراء',
'procedure_location' => 'موقع الإجراءات', 'procedure_location' => 'موقع الإجراءات',
+9
View File
@@ -31,6 +31,15 @@ return [
'status_placeholder' => 'Please select status', 'status_placeholder' => 'Please select status',
'status_1' => 'Normal', 'status_1' => 'Normal',
'status_0' => 'Disabled', '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' => 'Purchase Location',
'purchase_location_placeholder' => 'Please enter purchase location', 'purchase_location_placeholder' => 'Please enter purchase location',
'procedure_location' => 'Procedure Location', 'procedure_location' => 'Procedure Location',
+9
View File
@@ -30,6 +30,15 @@ return [
'status_placeholder' => 'Выберите статус', 'status_placeholder' => 'Выберите статус',
'status_1' => 'Нормальный', 'status_1' => 'Нормальный',
'status_0' => 'Отключен', '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' => 'Место покупки',
'purchase_location_placeholder' => 'Введите место покупки', 'purchase_location_placeholder' => 'Введите место покупки',
'procedure_location' => 'Место оформления', 'procedure_location' => 'Место оформления',
+1 -1
View File
@@ -98,7 +98,7 @@
{type: "checkbox", align: "center"}, {type: "checkbox", align: "center"},
{title: translations.id, align: "center", field: "id"}, {title: translations.id, align: "center", field: "id"},
{title: translations.vin, align: "center", field: "vin"}, {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.current_location, align: "center", field: "location_name"},
{title: translations.final_location, align: "center", field: "final_location_name"}, {title: translations.final_location, align: "center", field: "final_location_name"},
{title: translations.fbo_location, align: "center", field: "fbo_location_name"}, {title: translations.fbo_location, align: "center", field: "fbo_location_name"},
+36 -8
View File
@@ -26,7 +26,7 @@
<label class="layui-form-label"><?= $translations['classify'] ?? '分类' ?></label> <label class="layui-form-label"><?= $translations['classify'] ?? '分类' ?></label>
<div class="layui-input-block"> <div class="layui-input-block">
<select name="classify" lay-filter="category" id="classify" required> <select name="classify" lay-filter="category" id="classify" required>
<option value=""><?= $translations['please_select'] ?? '请选择分类' ?></option> <option value=""><?= $translations['classify_placeholder'] ?? '请选择分类' ?></option>
<option value="1"><?= $translations['self_owned'] ?? '自主' ?></option> <option value="1"><?= $translations['self_owned'] ?? '自主' ?></option>
<option value="2"><?= $translations['agent'] ?? '代理' ?></option> <option value="2"><?= $translations['agent'] ?? '代理' ?></option>
</select> </select>
@@ -48,16 +48,16 @@
</div> </div>
<div class="layui-form-item"> <div class="layui-form-item">
<label class="layui-form-label required"><?= $translations['status'] ?? '车辆状态' ?></label> <label class="layui-form-label required"><?= $translations['status'] ?? '状态' ?></label>
<div class="layui-input-block"> <div class="layui-input-block">
<select name="status" lay-filter="category" required lay-verify="required" id="status" required> <select name="status" lay-filter="category" required lay-verify="required" id="status" required>
<option value=""><?= $translations['please_select'] ?? '请选择状态' ?></option> <option value=""><?= $translations['please_select'] ?? '请选择状态' ?></option>
<option value="1"><?= $translations['status_pending'] ?? '待发车' ?></option> <!-- <option value="1"><?= $translations['status_pending'] ?? '待发车' ?></option>-->
<option value="2"><?= $translations['status_shipping_to_fbo'] ?? '在途(发往fbo港口)' ?></option> <!-- <option value="2"><?= $translations['status_shipping_to_fbo'] ?? '在途(发往fbo港口)' ?></option>-->
<option value="3"><?= $translations['status_arrived_fbo'] ?? '抵达发货港口' ?></option> <!-- <option value="3"><?= $translations['status_arrived_fbo'] ?? '抵达发货港口' ?></option>-->
<option value="4"><?= $translations['status_shipping_to_warehouse'] ?? '在途(发往目的地仓库)' ?></option> <!-- <option value="4"><?= $translations['status_shipping_to_warehouse'] ?? '在途(发往目的地仓库)' ?></option>-->
<option value="5"><?= $translations['status_arrived_warehouse'] ?? '抵达仓库' ?></option> <!-- <option value="5"><?= $translations['status_arrived_warehouse'] ?? '抵达目的地' ?></option>-->
<option value="6"><?= $translations['status_sold'] ?? '售出' ?></option> <!-- <option value="6"><?= $translations['status_sold'] ?? '售出' ?></option>-->
</select> </select>
</div> </div>
</div> </div>
@@ -200,6 +200,34 @@
layer.msg('请求失败: ' + xhr.status); 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('<option value="">请选择状态</option>');
$.each(res.data, function(index, item){
if(index != 0){
select.append(`<option value="${index}">${item}</option>`);
}
});
// 重新渲染下拉框
form.render('select');
},
error: function(xhr) {
layer.msg('请求失败: ' + xhr.status);
}
});
} }
// 获取数据库记录 // 获取数据库记录