初始化项目
This commit is contained in:
75
app/Http/Controllers/System/Api/City.php
Normal file
75
app/Http/Controllers/System/Api/City.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\System\Api;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Services\System\CityService;
|
||||
|
||||
class City extends Controller
|
||||
{
|
||||
protected $cityService;
|
||||
|
||||
public function __construct(CityService $cityService)
|
||||
{
|
||||
$this->cityService = $cityService;
|
||||
}
|
||||
|
||||
public function tree()
|
||||
{
|
||||
$tree = $this->cityService->getCachedTree();
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'message' => 'success',
|
||||
'data' => $tree
|
||||
]);
|
||||
}
|
||||
|
||||
public function provinces()
|
||||
{
|
||||
$provinces = $this->cityService->getProvinces();
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'message' => 'success',
|
||||
'data' => $provinces
|
||||
]);
|
||||
}
|
||||
|
||||
public function cities(int $provinceId)
|
||||
{
|
||||
$cities = $this->cityService->getCities($provinceId);
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'message' => 'success',
|
||||
'data' => $cities
|
||||
]);
|
||||
}
|
||||
|
||||
public function districts(int $cityId)
|
||||
{
|
||||
$districts = $this->cityService->getDistricts($cityId);
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'message' => 'success',
|
||||
'data' => $districts
|
||||
]);
|
||||
}
|
||||
|
||||
public function show(int $id)
|
||||
{
|
||||
$city = $this->cityService->getById($id);
|
||||
if (!$city) {
|
||||
return response()->json([
|
||||
'code' => 404,
|
||||
'message' => '城市不存在',
|
||||
'data' => null
|
||||
], 404);
|
||||
}
|
||||
|
||||
return response()->json([
|
||||
'code' => 200,
|
||||
'message' => 'success',
|
||||
'data' => $city
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user