This commit is contained in:
2025-04-30 10:53:02 +08:00
commit 701b9a909f
1007 changed files with 353274 additions and 0 deletions
+28
View File
@@ -0,0 +1,28 @@
<?php
namespace app\controller;
use support\Request;
class IndexController
{
public function index(Request $request)
{
static $readme;
if (!$readme) {
$readme = file_get_contents(base_path('README.md'));
}
return $readme;
}
public function view(Request $request)
{
return view('index/view', ['name' => 'webman']);
}
public function json(Request $request)
{
return json(['code' => 0, 'msg' => 'ok']);
}
}
+42
View File
@@ -0,0 +1,42 @@
<?php
namespace app\controller;
use app\model\Location;
use util\Util;
use support\Request;
class LocationController
{
/**
* Get all locations that have vehicles
*/
public function index(Request $request)
{
$locations = Location::with('vehicles')
->with('fboVehicles')
->get()
->map(function ($location) {
$location->vehicle_count = $location->vehicles->count();
$location->fbo_vehicle_count = $location->fboVehicles->count();
return $location;
});
return Util::success($locations);
}
/**
* Get a specific location with its vehicles
*/
public function show(Request $request, $id)
{
$location = Location::hasVehicles()
->with('vehicles')
->find($id);
if (!$location) {
return Util::fail(null, 'Location not found or has no vehicles');
}
return Util::success($location);
}
}
+56
View File
@@ -0,0 +1,56 @@
<?php
namespace app\controller;
//use support\Request;
//use support\Log;
//use Webman\Http\Response;
use app\service\OssService;
use Shopwwi\WebmanFilesystem\Facade\Storage;
use support\Log;
use support\Request;
use util\Util;
class UploadController
{
/**
* 不需要登录的方法
*/
protected $noNeedLogin = ['uploadImage'];
// 上传单文件图片
public function uploadImage(Request $request)
{
try {
$file = $request->file('files');
if (!$file || !$file->isValid()) {
return Util::fail($file,'上传失败');
}
$result = Storage::adapter('oss')
->path('lingke_crm/'.date('Ymd'))
->size(1024*1024*5)
->extYes(['image/jpeg','image/png'])
->extNo(['image/gif'])
->upload($file);
$ossservice = new OssService();
$data = [
'path' => $result->file_name,
'original_name' => $result->origin_name,
'image_url' => $ossservice->generatePrivateUrl($result->file_name)
];
return Util::success($data,'上传成功');
}catch (\Throwable $e){
Log::error('文件上传失败: ' . $e->getMessage());
return Util::fail([],'file:'.$e->getFile().'line:'.$e->getLine().'message:'.$e->getMessage());
}
}
}
+62
View File
@@ -0,0 +1,62 @@
<?php
namespace app\controller;
use app\model\Vehicle;
use plugin\admin\app\model\Location;
use util\Util;
use support\Request;
class VehicleController
{
protected $status = ['未知','待发车','在途(发往fbo港口)','抵达发货港口','在途(发往目的地仓库)','抵达仓库','售出'];
/**
* Mask VIN number by showing only first 2 and last 6 characters
*/
private function maskVin($vin)
{
if (strlen($vin) <= 8) {
return $vin;
}
return substr($vin, 0, 2) . str_repeat('*', strlen($vin) - 8) . substr($vin, -6);
}
/**
* Get all vehicles with their locations
*/
public function index(Request $request)
{
$vehicles = Vehicle::with('location')->with('finalLocation')->get();
$vehicles->each(function ($vehicle) {
if (isset($vehicle->vin)) {
$vehicle->vin = $this->maskVin($vehicle->vin);
}
$vehicle->status = $this->status[$vehicle->status]??$this->status[0];
// $location = Location::find($vehicle->locations_id);
// $vehicle->location_name = $location ? $location->name : '';
// $final_location = Location::find($vehicle->final_locations_id);
// $vehicle->final_location_name = $final_location ? $final_location->name : '';
$fbo_location = Location::find($vehicle->fbo_locations_id);
$vehicle->fbo_destination = $fbo_location ? $fbo_location->name : '';
});
$result = ['list' => $vehicles,'count'=>count($vehicles)];
return Util::success($result);
}
/**
* Get a specific vehicle with its location
*/
public function show(Request $request, $id)
{
$vehicle = Vehicle::with('location')->find($id);
if (!$vehicle) {
return Util::fail($vehicle,'Vehicle not found');
}
if (isset($vehicle->vin)) {
$vehicle->vin = $this->maskVin($vehicle->vin);
}
return Util::success($vehicle);
}
}