Files
laravel_swoole/app/Http/Controllers/System/Api/Dictionary.php
2026-02-08 22:38:13 +08:00

60 lines
1.4 KiB
PHP

<?php
namespace App\Http\Controllers\System\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\System\DictionaryService;
class Dictionary extends Controller
{
protected $dictionaryService;
public function __construct(DictionaryService $dictionaryService)
{
$this->dictionaryService = $dictionaryService;
}
public function index()
{
$dictionaries = $this->dictionaryService->getAll();
return response()->json([
'code' => 200,
'message' => 'success',
'data' => $dictionaries
]);
}
public function getByCode(Request $request)
{
$code = $request->input('code');
$items = $this->dictionaryService->getItemsByCode($code);
return response()->json([
'code' => 200,
'message' => 'success',
'data' => [
'code' => $code,
'items' => $items,
]
]);
}
public function show(int $id)
{
$dictionary = $this->dictionaryService->getById($id);
if (!$dictionary) {
return response()->json([
'code' => 404,
'message' => '字典不存在',
'data' => null
], 404);
}
return response()->json([
'code' => 200,
'message' => 'success',
'data' => $dictionary
]);
}
}