Files
car_info/plugin/admin/app/controller/VehicleController.php
T

625 lines
27 KiB
PHP
Raw Normal View History

2025-04-30 11:30:08 +08:00
<?php
2025-05-06 17:16:37 +08:00
declare (strict_types = 1);
2025-04-30 11:30:08 +08:00
namespace plugin\admin\app\controller;
2025-05-07 14:19:47 +08:00
use app\model\LocationAr;
use app\model\LocationEn;
use app\model\LocationRu;
use app\model\VehicleAr;
use app\model\VehicleEn;
use app\model\VehicleRu;
2025-04-30 14:00:54 +08:00
use app\service\OssService;
2025-05-13 15:29:30 +08:00
use plugin\admin\app\common\Util;
2025-04-30 11:30:08 +08:00
use plugin\admin\app\model\Location;
2025-05-19 16:00:28 +08:00
use support\Cache;
2025-04-30 14:51:12 +08:00
use support\Log;
2025-04-30 11:30:08 +08:00
use support\Request;
use support\Response;
use plugin\admin\app\model\Vehicle;
use plugin\admin\app\controller\Crud;
use support\exception\BusinessException;
/**
* 车辆信息
*/
class VehicleController extends Crud
{
/**
* 不需要登录的方法
* @var string[]
*/
protected $noNeedLogin = ['detail'];
/**
* 不需要鉴权的方法
* @var string[]
*/
2025-05-19 09:14:51 +08:00
protected $noNeedAuth = ['detail', 'status', 'updateLogistics'];
2025-04-30 11:30:08 +08:00
2025-05-13 15:29:30 +08:00
protected $status = [
2025-06-11 09:43:55 +08:00
'zh-cn' => ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','已入库','售出', '待采购', '已付定金待提车'],
2025-05-13 15:29:30 +08:00
// 'zh' => ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达目的地','售出'],
2025-06-11 09:43:55 +08:00
'en' => ['unknown','Awaiting departure','In transit (to FBO port)','Arriving at the port of shipment','In transit (to destination warehouse)','Already in stock','Sold', 'To be purchased', 'Deposit paid, waiting to be picked up'],
'ru' => ['Неизвестно','Ожидание отправления','В пути (в порт FBO)','Прибытие в порт отправления','В пути (отправлено на склад назначения)','На складе','Продано', 'Ожидаемые закупки', 'Выплаченные авансы'],
2025-05-29 16:27:55 +08:00
'ar' => ['غير معروف', 'في انتظار الشحن', 'في الطريق (إلى ميناء FBO)', 'وصل إلى ميناء الشحن', 'في الطريق (إلى مستودع الوجهة)', 'وصل إلى الوجهة', 'تم البيع', 'في انتظار شراء', 'دفع عربون السيارة'],
2025-05-13 15:29:30 +08:00
];
2025-04-30 11:30:08 +08:00
/**
* @var Vehicle
*/
protected $model = null;
/**
* 构造函数
* @return void
*/
public function __construct()
{
$this->model = new Vehicle;
}
2025-05-13 15:29:30 +08:00
public function status()
{
$lang = session('lang', 'zh-cn');
2025-05-26 17:02:34 +08:00
$status = isset($this->status[$lang])?$this->status[$lang]:$this->status['zh-cn'];
2025-05-13 15:29:30 +08:00
return json(['code' => 0, 'msg' => 'success', 'data' => $status]);
}
2025-04-30 11:30:08 +08:00
/**
* 浏览
* @return Response
*/
public function index(): Response
{
2025-05-06 17:16:37 +08:00
$lang = session('lang', 'zh-cn');
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
2025-05-06 20:21:09 +08:00
$translations = array_merge($common, $translations); // 确保 common.php 的翻译优先
2025-05-06 17:16:37 +08:00
2025-05-06 20:21:09 +08:00
// 添加默认翻译,确保所有语言都有基本翻译
$required_translations = [
'title' => $lang === 'zh-cn' ? '车辆管理' : 'Vehicle Management', // 确保title翻译存在
'brand' => $lang === 'zh-cn' ? '车辆品牌' : 'Vehicle Brand',
'brand_placeholder' => $lang === 'zh-cn' ? '请输入车辆品牌' : 'Please enter vehicle brand',
'model' => $lang === 'zh-cn' ? '车辆型号' : 'Vehicle Model',
'model_placeholder' => $lang === 'zh-cn' ? '请输入车辆型号' : 'Please enter vehicle model',
'vin' => 'VIN',
'vin_placeholder' => $lang === 'zh-cn' ? '请输入车架号' : 'Please enter VIN',
'status' => $lang === 'zh-cn' ? '车辆状态' : 'Status',
'status_placeholder' => $lang === 'zh-cn' ? '请选择状态' : 'Please select status',
'purchase_location' => $lang === 'zh-cn' ? '买车地点' : 'Purchase Location',
'purchase_location_placeholder' => $lang === 'zh-cn' ? '请输入买车地点' : 'Please enter purchase location',
'procedure_location' => $lang === 'zh-cn' ? '手续办理地' : 'Procedure Location',
'procedure_location_placeholder' => $lang === 'zh-cn' ? '请输入手续办理地' : 'Please enter procedure location',
'fbo_location' => 'FBO Location',
'fbo_location_placeholder' => $lang === 'zh-cn' ? '请选择FBO目的地' : 'Please select FBO location',
'current_location' => $lang === 'zh-cn' ? '车辆所在地' : 'Current Location',
'current_location_placeholder' => $lang === 'zh-cn' ? '请选择车辆所在地' : 'Please select current location',
'final_location' => $lang === 'zh-cn' ? '最终目的地' : 'Final Location',
'final_location_placeholder' => $lang === 'zh-cn' ? '请选择最终目的地' : 'Please select final location',
'departure_time' => $lang === 'zh-cn' ? 'FBO发车时间' : 'FBO Departure Time',
'departure_time_placeholder' => $lang === 'zh-cn' ? '请选择发车时间' : 'Please select departure time',
'arrival_time' => $lang === 'zh-cn' ? 'FBO到达时间' : 'FBO Arrival Time',
'arrival_time_placeholder' => $lang === 'zh-cn' ? '请选择到达时间' : 'Please select arrival time',
'shipping_cycle' => $lang === 'zh-cn' ? '运输周期' : 'Shipping Cycle',
'shipping_cycle_placeholder' => $lang === 'zh-cn' ? '请输入运输周期' : 'Please enter shipping cycle',
'img_url' => $lang === 'zh-cn' ? '图片' : 'Image',
'img_url_placeholder' => $lang === 'zh-cn' ? '请输入图片URL' : 'Please enter image URL',
'operation' => $lang === 'zh-cn' ? '操作' : 'Operation',
'refresh' => $lang === 'zh-cn' ? '刷新' : 'Refresh',
'filter' => $lang === 'zh-cn' ? '筛选' : 'Filter',
'print' => $lang === 'zh-cn' ? '打印' : 'Print',
'export' => $lang === 'zh-cn' ? '导出' : 'Export',
'id' => 'ID',
'created_at' => $lang === 'zh-cn' ? '创建时间' : 'Created At',
'updated_at' => $lang === 'zh-cn' ? '更新时间' : 'Updated At'
];
// 合并翻译,确保语言文件中的翻译优先
$translations = array_merge($required_translations, $translations);
2025-05-07 14:19:47 +08:00
2025-05-06 18:20:49 +08:00
2025-05-06 17:16:37 +08:00
return view('vehicle/index', [
'lang' => $lang,
2025-05-06 20:21:09 +08:00
'translations' => $translations
2025-05-06 17:16:37 +08:00
]);
2025-04-30 11:30:08 +08:00
}
2025-05-19 09:14:51 +08:00
/**
* 浏览
* @return Response
*/
public function logistics(): Response
{
$lang = session('lang', 'zh-cn');
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
$translations = array_merge($common, $translations); // 确保 common.php 的翻译优先
// 添加默认翻译,确保所有语言都有基本翻译
$required_translations = [
'title' => $lang === 'zh-cn' ? '车辆管理' : 'Vehicle Management', // 确保title翻译存在
'brand' => $lang === 'zh-cn' ? '车辆品牌' : 'Vehicle Brand',
'brand_placeholder' => $lang === 'zh-cn' ? '请输入车辆品牌' : 'Please enter vehicle brand',
'model' => $lang === 'zh-cn' ? '车辆型号' : 'Vehicle Model',
'model_placeholder' => $lang === 'zh-cn' ? '请输入车辆型号' : 'Please enter vehicle model',
'vin' => 'VIN',
'vin_placeholder' => $lang === 'zh-cn' ? '请输入车架号' : 'Please enter VIN',
'status' => $lang === 'zh-cn' ? '车辆状态' : 'Status',
'status_placeholder' => $lang === 'zh-cn' ? '请选择状态' : 'Please select status',
'purchase_location' => $lang === 'zh-cn' ? '买车地点' : 'Purchase Location',
'purchase_location_placeholder' => $lang === 'zh-cn' ? '请输入买车地点' : 'Please enter purchase location',
'procedure_location' => $lang === 'zh-cn' ? '手续办理地' : 'Procedure Location',
'procedure_location_placeholder' => $lang === 'zh-cn' ? '请输入手续办理地' : 'Please enter procedure location',
'fbo_location' => 'FBO Location',
'fbo_location_placeholder' => $lang === 'zh-cn' ? '请选择FBO目的地' : 'Please select FBO location',
'current_location' => $lang === 'zh-cn' ? '车辆所在地' : 'Current Location',
'current_location_placeholder' => $lang === 'zh-cn' ? '请选择车辆所在地' : 'Please select current location',
'final_location' => $lang === 'zh-cn' ? '最终目的地' : 'Final Location',
'final_location_placeholder' => $lang === 'zh-cn' ? '请选择最终目的地' : 'Please select final location',
'departure_time' => $lang === 'zh-cn' ? 'FBO发车时间' : 'FBO Departure Time',
'departure_time_placeholder' => $lang === 'zh-cn' ? '请选择发车时间' : 'Please select departure time',
'arrival_time' => $lang === 'zh-cn' ? 'FBO到达时间' : 'FBO Arrival Time',
'arrival_time_placeholder' => $lang === 'zh-cn' ? '请选择到达时间' : 'Please select arrival time',
'shipping_cycle' => $lang === 'zh-cn' ? '运输周期' : 'Shipping Cycle',
'shipping_cycle_placeholder' => $lang === 'zh-cn' ? '请输入运输周期' : 'Please enter shipping cycle',
'img_url' => $lang === 'zh-cn' ? '图片' : 'Image',
'img_url_placeholder' => $lang === 'zh-cn' ? '请输入图片URL' : 'Please enter image URL',
'operation' => $lang === 'zh-cn' ? '操作' : 'Operation',
'refresh' => $lang === 'zh-cn' ? '刷新' : 'Refresh',
'filter' => $lang === 'zh-cn' ? '筛选' : 'Filter',
'print' => $lang === 'zh-cn' ? '打印' : 'Print',
'export' => $lang === 'zh-cn' ? '导出' : 'Export',
'id' => 'ID',
'created_at' => $lang === 'zh-cn' ? '创建时间' : 'Created At',
'updated_at' => $lang === 'zh-cn' ? '更新时间' : 'Updated At'
];
// 合并翻译,确保语言文件中的翻译优先
$translations = array_merge($required_translations, $translations);
return view('vehicle/logistics', [
'lang' => $lang,
'translations' => $translations
]);
}
2025-04-30 11:30:08 +08:00
/**
* 插入
* @param Request $request
* @return Response
* @throws BusinessException
*/
public function insert(Request $request): Response
{
2025-05-06 17:16:37 +08:00
$lang = session('lang', 'zh-cn');
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
$translations = array_merge($translations, $common);
2025-05-06 18:20:49 +08:00
// 只在中文时使用默认翻译
if ($lang === 'zh-cn') {
$required_translations = [
'brand' => '车辆品牌',
'brand_placeholder' => '请输入车辆品牌',
'model' => '车辆型号',
'model_placeholder' => '请输入车辆型号',
'vin' => '车架号',
'vin_placeholder' => '请输入车架号',
'status' => '车辆状态',
'status_placeholder' => '请选择状态',
'purchase_location' => '买车地点',
'purchase_location_placeholder' => '请输入买车地点',
'procedure_location' => '手续办理地',
'procedure_location_placeholder' => '请输入手续办理地',
'fbo_location' => 'FBO目的地',
'fbo_location_placeholder' => '请选择FBO目的地',
'current_location' => '车辆所在地',
'current_location_placeholder' => '请选择车辆所在地',
'final_location' => '最终目的地',
'final_location_placeholder' => '请选择最终目的地',
'departure_time' => 'FBO发车时间',
'departure_time_placeholder' => '请选择发车时间',
'arrival_time' => 'FBO到达时间',
'arrival_time_placeholder' => '请选择到达时间',
'shipping_cycle' => '运输周期',
'shipping_cycle_placeholder' => '请输入运输周期',
'img_url' => '图片',
'img_url_placeholder' => '请输入图片URL'
];
$translations = array_merge($required_translations, $translations);
}
2025-05-09 16:04:16 +08:00
// 如果是 POST 请求,处理数据保存和翻译
if ($request->method() === 'POST') {
2025-05-13 15:29:30 +08:00
$this->save($request);
}
2025-05-09 16:04:16 +08:00
2025-05-13 15:29:30 +08:00
return view('vehicle/insert', [
'lang' => $lang,
'translations' => $translations
]);
}
2025-05-09 16:04:16 +08:00
2025-05-13 15:29:30 +08:00
/**
* 保存
*/
public function save(Request $request)
{
// 获取表单数据
$data = $request->all();
$data['shipping_cycle'] = !empty($data['shipping_cycle'])?$data['shipping_cycle']:0;
2025-05-13 15:29:56 +08:00
$lang = session('lang', 'zh-cn');
list($vehicleModel,$local) = $this->getModel($lang);
2025-05-13 15:29:30 +08:00
// 保存主表数据
if(!empty($data['id'])){
2025-05-13 15:29:56 +08:00
$vehicle = $vehicleModel::find($data['id']);
2025-05-28 13:12:33 +08:00
Cache::delete('img_dib_'.$data['id']);
2025-05-13 15:29:30 +08:00
}else{
2025-05-13 15:29:56 +08:00
$vehicle =$vehicleModel;
2025-05-13 15:29:30 +08:00
}
$vehicle->fill($data);
$vehicle->save();
2025-05-09 16:04:16 +08:00
2025-05-13 15:29:30 +08:00
// 处理多语言翻译
2025-05-13 15:29:56 +08:00
$languages = ['zh-cn' => 'cn', 'en' => 'en', 'ar' => 'ar', 'ru' => 'ru'];
2025-05-13 15:29:30 +08:00
$translationModels = [
2025-05-13 15:29:56 +08:00
'cn' => Vehicle::class,
2025-05-13 15:29:30 +08:00
'en' => VehicleEn::class,
'ar' => VehicleAr::class,
'ru' => VehicleRu::class
];
2025-05-13 15:29:56 +08:00
//删除已保存的模型
unset($translationModels[$lang]);
2025-05-28 17:57:30 +08:00
$sourceLang = $languages[$lang];
2025-05-28 17:55:16 +08:00
unset($languages[$lang]);
2025-05-09 16:04:16 +08:00
2025-06-24 08:56:44 +08:00
$data_t = $data;
unset($data['brand']);
unset($data['model']);
unset($data['purchase']);
unset($data['procedure_location']);
unset($data['fbo_destination']);
2025-06-24 08:59:42 +08:00
foreach ($translationModels as $modelC) {
$model = new $modelC();
if(!empty($data_t['id'])){
$vehicleT = $model::find($data_t['id']);
}else{
$vehicleT = $model;
}
$vehicleT->fill($data_t);
$vehicleT->save();
}
if(empty($data_t['id'])){
$data['id'] = $vehicle->id;
2025-06-24 08:56:44 +08:00
}
2025-05-13 15:29:30 +08:00
// 创建翻译服务实例
$translatorService = new \app\service\TranslatorService();
2025-05-28 17:55:16 +08:00
foreach ($languages as $lang) {
$translatorService->queue($data,$sourceLang,'vehicle',$data['id']?:null,$lang);
}
2025-04-30 11:30:08 +08:00
}
2025-05-13 15:29:30 +08:00
2025-04-30 11:30:08 +08:00
/**
* 更新
* @param Request $request
* @return Response
* @throws BusinessException
*/
public function update(Request $request): Response
{
2025-05-06 17:16:37 +08:00
$id = $request->input('id');
$lang = session('lang', 'zh-cn');
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
$translations = array_merge($translations, $common);
2025-05-06 18:20:49 +08:00
// 只在中文时使用默认翻译
if ($lang === 'zh-cn') {
$required_translations = [
'brand' => '车辆品牌',
'brand_placeholder' => '请输入车辆品牌',
'model' => '车辆型号',
'model_placeholder' => '请输入车辆型号',
'vin' => '车架号',
'vin_placeholder' => '请输入车架号',
'status' => '车辆状态',
'status_placeholder' => '请选择状态',
'purchase_location' => '买车地点',
'purchase_location_placeholder' => '请输入买车地点',
'procedure_location' => '手续办理地',
'procedure_location_placeholder' => '请输入手续办理地',
'fbo_location' => 'FBO目的地',
'fbo_location_placeholder' => '请选择FBO目的地',
'current_location' => '车辆所在地',
'current_location_placeholder' => '请选择车辆所在地',
'final_location' => '最终目的地',
'final_location_placeholder' => '请选择最终目的地',
'departure_time' => 'FBO发车时间',
'departure_time_placeholder' => '请选择发车时间',
'arrival_time' => 'FBO到达时间',
'arrival_time_placeholder' => '请选择到达时间',
'shipping_cycle' => '运输周期',
'shipping_cycle_placeholder' => '请输入运输周期',
'img_url' => '图片',
'img_url_placeholder' => '请输入图片URL'
];
$translations = array_merge($required_translations, $translations);
}
2025-05-13 15:29:30 +08:00
// 如果是 POST 请求,处理数据保存和翻译
if ($request->method() === 'POST') {
$this->save($request);
}
2025-05-06 18:20:49 +08:00
2025-05-06 17:16:37 +08:00
$data = Vehicle::where('id', $id)->first();
if (!$data) {
return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']);
2025-04-30 11:30:08 +08:00
}
2025-05-06 17:16:37 +08:00
return view('vehicle/update', [
'id' => $id,
'data' => $data,
'lang' => $lang,
'translations' => $translations
]);
2025-05-19 09:14:51 +08:00
} /**
* 更新
* @param Request $request
* @return Response
* @throws BusinessException
*/
public function updateLogistics(Request $request): Response
{
$id = $request->input('id');
$lang = session('lang', 'zh-cn');
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
$translations = array_merge($translations, $common);
// 只在中文时使用默认翻译
if ($lang === 'zh-cn') {
$required_translations = [
'brand' => '车辆品牌',
'brand_placeholder' => '请输入车辆品牌',
'model' => '车辆型号',
'model_placeholder' => '请输入车辆型号',
'vin' => '车架号',
'vin_placeholder' => '请输入车架号',
'status' => '车辆状态',
'status_placeholder' => '请选择状态',
'purchase_location' => '买车地点',
'purchase_location_placeholder' => '请输入买车地点',
'procedure_location' => '手续办理地',
'procedure_location_placeholder' => '请输入手续办理地',
'fbo_location' => 'FBO目的地',
'fbo_location_placeholder' => '请选择FBO目的地',
'current_location' => '车辆所在地',
'current_location_placeholder' => '请选择车辆所在地',
'final_location' => '最终目的地',
'final_location_placeholder' => '请选择最终目的地',
'departure_time' => 'FBO发车时间',
'departure_time_placeholder' => '请选择发车时间',
'arrival_time' => 'FBO到达时间',
'arrival_time_placeholder' => '请选择到达时间',
'shipping_cycle' => '运输周期',
'shipping_cycle_placeholder' => '请输入运输周期',
'img_url' => '图片',
'img_url_placeholder' => '请输入图片URL'
];
$translations = array_merge($required_translations, $translations);
}
$data = Vehicle::where('id', $id)->first();
if (!$data) {
return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']);
}
2025-05-27 15:19:44 +08:00
// 如果是 POST 请求,处理数据保存和翻译
if ($request->method() == 'POST') {
$this->save($request);
return json(['code' => 0, 'msg' => '保存成功']);
}
2025-05-19 09:14:51 +08:00
return view('vehicle/updateLogistics', [
'id' => $id,
'data' => $data,
'lang' => $lang,
'translations' => $translations
]);
2025-04-30 11:30:08 +08:00
}
/**
* 详情
* @param Request $request
* @return Response
* @throws BusinessException
*/
public function detail(Request $request): Response
{
2025-05-06 17:16:37 +08:00
$id = $request->input('id');
$lang = session('lang', 'zh-cn');
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
$translations = array_merge($translations, $common);
2025-05-06 18:20:49 +08:00
// 只在中文时使用默认翻译
if ($lang === 'zh-cn') {
$required_translations = [
'brand' => '车辆品牌',
'brand_placeholder' => '请输入车辆品牌',
'model' => '车辆型号',
'model_placeholder' => '请输入车辆型号',
'vin' => '车架号',
'vin_placeholder' => '请输入车架号',
'status' => '车辆状态',
'status_placeholder' => '请选择状态',
'purchase_location' => '买车地点',
'purchase_location_placeholder' => '请输入买车地点',
'procedure_location' => '手续办理地',
'procedure_location_placeholder' => '请输入手续办理地',
'fbo_location' => 'FBO目的地',
'fbo_location_placeholder' => '请选择FBO目的地',
'current_location' => '车辆所在地',
'current_location_placeholder' => '请选择车辆所在地',
'final_location' => '最终目的地',
'final_location_placeholder' => '请选择最终目的地',
'departure_time' => 'FBO发车时间',
'departure_time_placeholder' => '请选择发车时间',
'arrival_time' => 'FBO到达时间',
'arrival_time_placeholder' => '请选择到达时间',
'shipping_cycle' => '运输周期',
'shipping_cycle_placeholder' => '请输入运输周期',
'img_url' => '图片',
'img_url_placeholder' => '请输入图片URL'
];
$translations = array_merge($required_translations, $translations);
}
2025-05-19 16:00:28 +08:00
// $data = Vehicle::where('id', $id)->first();
list($vehicleModel,$local) = $this->getModel($lang);
$data = $vehicleModel::where('id', $id)->first();
2025-05-06 17:16:37 +08:00
if (!$data) {
return json(['code' => 1, 'msg' => $translations['data_not_found'] ?? '数据不存在']);
}
2025-05-26 17:43:55 +08:00
$img_url = Cache::get('img_dib_'.$data->id);
if ($img_url) {
2025-05-26 17:46:17 +08:00
$data['img_url'] = $img_url;
2025-05-26 17:43:55 +08:00
} else {
$ossservice = empty($ossservice)?new OssService():$ossservice;
$img_url = $ossservice->generatePrivateUrl($data['img_url'],86400);
2025-05-26 17:46:17 +08:00
$data['img_url'] = $img_url;
2025-05-26 17:43:55 +08:00
Cache::set('img_dib_'.$data->id, $img_url, 86390);
}
2025-05-06 17:16:37 +08:00
return view('vehicle/detail', [
'data' => $data,
'lang' => $lang,
'translations' => $translations
]);
2025-04-30 11:30:08 +08:00
}
/**
* 查询后置处理,添加位置信息
* @param mixed $items
* @return mixed
*/
protected function afterQuery($items)
{
2025-05-13 15:29:30 +08:00
$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;
}
2025-05-26 17:43:55 +08:00
$ossservice = null;
2025-04-30 11:30:08 +08:00
foreach ($items as &$item) {
2025-05-13 15:29:30 +08:00
$item = $vehicle::find($item['id']);
$location = $hz::find($item->locations_id);
$item['status_txt'] = $this->status[$lang][$item->status]??$this->status[$lang][0];
2025-04-30 11:30:08 +08:00
$item->location_name = $location ? $location->name : '';
2025-05-13 15:29:30 +08:00
$final_location = $hz::find($item->final_locations_id);
2025-04-30 11:30:08 +08:00
$item->final_location_name = $final_location ? $final_location->name : '';
2025-05-13 15:29:30 +08:00
$fbo_location = $hz::find($item->fbo_locations_id);
2025-04-30 11:30:08 +08:00
$item->fbo_location_name = $fbo_location ? $fbo_location->name : '';
2025-04-30 14:00:54 +08:00
2025-05-07 14:19:47 +08:00
$location = $hz::find($item->locations_id);
$item->location_name = $location ? $location->name : '';
$location = $hz::find($item->fbo_locations_id);
$item->fbo_location_name = $location ? $location->name : '';
2025-05-26 17:02:34 +08:00
try {
2025-05-26 17:43:55 +08:00
$img_url = Cache::get('img_dib_'.$item->id);
2025-05-26 17:02:34 +08:00
if ($img_url) {
2025-05-28 10:19:23 +08:00
$item['img_url_full'] = $img_url;
2025-05-26 17:02:34 +08:00
} else {
2025-05-26 17:43:55 +08:00
$ossservice = empty($ossservice)?new OssService():$ossservice;
2025-05-26 17:02:34 +08:00
$img_url = $ossservice->generatePrivateUrl($item['img_url'],86400);
2025-05-28 10:19:23 +08:00
$item['img_url_full'] = $img_url;
2025-05-26 17:43:55 +08:00
Cache::set('img_dib_'.$item->id, $img_url, 86390);
2025-05-26 17:02:34 +08:00
}
} catch (\Exception $e) {
Log::error("Vehicle image URL generation failed:", [
'error' => $e->getMessage(),
'original_url' => $item['img_url'],
'error_code' => $e->getCode(),
'trace' => $e->getTraceAsString()
]);
2025-04-30 14:09:13 +08:00
}
2025-04-30 14:00:54 +08:00
}
2025-04-30 14:09:13 +08:00
2025-04-30 11:30:08 +08:00
return $items;
}
2025-05-06 20:21:09 +08:00
2025-05-13 15:29:56 +08:00
2025-05-06 20:21:09 +08:00
/**
2025-05-13 15:29:56 +08:00
* @param $lang
* @return array
*/
protected function getModel($lang){
switch ($lang) {
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;
default:
$vehicle = new \app\model\Vehicle();
$hz = new \app\model\Location();
break;
}
return array($vehicle, $hz);
}
/**
2025-05-06 20:21:09 +08:00
* 获取翻译
* @param Request $request
* @return Response
*/
public function getTranslations(Request $request): Response
{
$lang = session('lang', 'zh-cn');
$translations = (array)require __DIR__ . '/../lang/' . $lang . '/vehicle.php';
$common = (array)require __DIR__ . '/../lang/' . $lang . '/common.php';
$translations = array_merge($translations, $common);
return json(['code' => 0, 'msg' => 'success', 'data' => $translations]);
}
2025-04-30 11:30:08 +08:00
}