164 lines
4.5 KiB
PHP
164 lines
4.5 KiB
PHP
<?php
|
|
|
|
namespace plugin\admin\app\controller;
|
|
|
|
use app\service\OssService;
|
|
use plugin\admin\app\model\Location;
|
|
use support\Log;
|
|
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[]
|
|
*/
|
|
protected $noNeedAuth = ['detail'];
|
|
|
|
protected $status = ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达仓库','售出'];
|
|
|
|
/**
|
|
* @var Vehicle
|
|
*/
|
|
protected $model = null;
|
|
|
|
/**
|
|
* 构造函数
|
|
* @return void
|
|
*/
|
|
public function __construct()
|
|
{
|
|
$this->model = new Vehicle;
|
|
}
|
|
|
|
/**
|
|
* 浏览
|
|
* @return Response
|
|
*/
|
|
public function index(): Response
|
|
{
|
|
return view('vehicle/index');
|
|
}
|
|
|
|
/**
|
|
* 插入
|
|
* @param Request $request
|
|
* @return Response
|
|
* @throws BusinessException
|
|
*/
|
|
public function insert(Request $request): Response
|
|
{
|
|
if ($request->method() === 'POST') {
|
|
return parent::insert($request);
|
|
}
|
|
return view('vehicle/insert');
|
|
}
|
|
|
|
/**
|
|
* 更新
|
|
* @param Request $request
|
|
* @return Response
|
|
* @throws BusinessException
|
|
*/
|
|
public function update(Request $request): Response
|
|
{
|
|
if ($request->method() === 'POST') {
|
|
return parent::update($request);
|
|
}
|
|
return view('vehicle/update');
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* 详情
|
|
* @param Request $request
|
|
* @return Response
|
|
* @throws BusinessException
|
|
*/
|
|
public function detail(Request $request): Response
|
|
{
|
|
return view('vehicle/detail');
|
|
}
|
|
|
|
/**
|
|
* 查询
|
|
* @param Request $request
|
|
* @return Response
|
|
* @throws BusinessException
|
|
*/
|
|
/* public function list(Request $request)
|
|
{
|
|
[$where, $format, $limit, $field, $order] = $this->selectInput($request);
|
|
return json($where);
|
|
$query = $this->doSelect($where, $field, $order);
|
|
$data = $this->doFormat($query, $format, $limit);
|
|
// foreach ($data['data'] as &$value) {
|
|
// $value['locations'] = Location::find($value['locations_id'])->name;
|
|
// }
|
|
// $data = json_decode(json_encode($data), true);
|
|
return $data;
|
|
}*/
|
|
|
|
/**
|
|
* 查询后置处理,添加位置信息
|
|
* @param mixed $items
|
|
* @return mixed
|
|
*/
|
|
protected function afterQuery($items)
|
|
{
|
|
foreach ($items as &$item) {
|
|
$location = Location::find($item->locations_id);
|
|
$item->status = $this->status[$item->status]??$this->status[0];
|
|
$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 : '';
|
|
|
|
// if(!str_starts_with($item['img_url'], 'http')){
|
|
// $ossservice = new OssService();
|
|
// $img_url = $ossservice->generatePrivateUrl($item['img_url'], 3600);
|
|
// $item['img_url'] = $img_url;
|
|
// }
|
|
|
|
|
|
if(!str_starts_with($item['img_url'], 'http')){
|
|
try {
|
|
$ossservice = new OssService();
|
|
// 使用更短的过期时间(5分钟)
|
|
$img_url = $ossservice->generatePrivateUrl($item['img_url'], 300);
|
|
Log::info("Vehicle image URL generation:", [
|
|
'original_url' => $item['img_url'],
|
|
'generated_url' => $img_url,
|
|
'current_time' => time()
|
|
]);
|
|
$item['img_url'] = $img_url;
|
|
} 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()
|
|
]);
|
|
}
|
|
}
|
|
}
|
|
|
|
return $items;
|
|
}
|
|
}
|