车辆多语言修复
This commit is contained in:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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' => 'موقع الإجراءات',
|
||||
|
||||
@@ -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',
|
||||
|
||||
@@ -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' => 'Место оформления',
|
||||
|
||||
@@ -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"},
|
||||
|
||||
@@ -26,7 +26,7 @@
|
||||
<label class="layui-form-label"><?= $translations['classify'] ?? '分类' ?></label>
|
||||
<div class="layui-input-block">
|
||||
<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="2"><?= $translations['agent'] ?? '代理' ?></option>
|
||||
</select>
|
||||
@@ -48,16 +48,16 @@
|
||||
</div>
|
||||
|
||||
<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">
|
||||
<select name="status" lay-filter="category" required lay-verify="required" id="status" required>
|
||||
<option value=""><?= $translations['please_select'] ?? '请选择状态' ?></option>
|
||||
<option value="1"><?= $translations['status_pending'] ?? '待发车' ?></option>
|
||||
<option value="2"><?= $translations['status_shipping_to_fbo'] ?? '在途(发往fbo港口)' ?></option>
|
||||
<option value="3"><?= $translations['status_arrived_fbo'] ?? '抵达发货港口' ?></option>
|
||||
<option value="4"><?= $translations['status_shipping_to_warehouse'] ?? '在途(发往目的地仓库)' ?></option>
|
||||
<option value="5"><?= $translations['status_arrived_warehouse'] ?? '抵达仓库' ?></option>
|
||||
<option value="6"><?= $translations['status_sold'] ?? '售出' ?></option>
|
||||
<!-- <option value="1"><?= $translations['status_pending'] ?? '待发车' ?></option>-->
|
||||
<!-- <option value="2"><?= $translations['status_shipping_to_fbo'] ?? '在途(发往fbo港口)' ?></option>-->
|
||||
<!-- <option value="3"><?= $translations['status_arrived_fbo'] ?? '抵达发货港口' ?></option>-->
|
||||
<!-- <option value="4"><?= $translations['status_shipping_to_warehouse'] ?? '在途(发往目的地仓库)' ?></option>-->
|
||||
<!-- <option value="5"><?= $translations['status_arrived_warehouse'] ?? '抵达目的地' ?></option>-->
|
||||
<!-- <option value="6"><?= $translations['status_sold'] ?? '售出' ?></option>-->
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
@@ -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('<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);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// 获取数据库记录
|
||||
|
||||
Reference in New Issue
Block a user