fbo港口
This commit is contained in:
@@ -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']);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\model\Location;
|
||||
use app\util\Util;
|
||||
use support\Request;
|
||||
|
||||
class LocationController
|
||||
{
|
||||
/**
|
||||
* Get all locations that have vehicles
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$locations = Location::hasVehicles()
|
||||
->with('vehicles')
|
||||
->get()
|
||||
->map(function ($location) {
|
||||
$location->vehicle_count = $location->vehicles->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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
<?php
|
||||
|
||||
namespace app\controller;
|
||||
|
||||
use app\model\Vehicle;
|
||||
use app\util\Util;
|
||||
use support\Request;
|
||||
|
||||
class VehicleController
|
||||
{
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
});
|
||||
$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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user