You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
60 lines
2.0 KiB
60 lines
2.0 KiB
|
2 days ago
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers\Miniapp;
|
||
|
|
|
||
|
|
use App\Http\Controllers\Controller;
|
||
|
|
use App\Models\MiniappUser;
|
||
|
|
use App\Models\Teacher;
|
||
|
|
use App\Support\ApiResponse;
|
||
|
|
use App\Support\Miniapp\MiniappPresenter;
|
||
|
|
use Illuminate\Http\JsonResponse;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
|
||
|
|
class TeacherController extends Controller
|
||
|
|
{
|
||
|
|
use ApiResponse;
|
||
|
|
|
||
|
|
public function show(Request $request, int $teacher): JsonResponse
|
||
|
|
{
|
||
|
|
/** @var MiniappUser $user */
|
||
|
|
$user = $request->user();
|
||
|
|
$payload = MiniappPresenter::userPayload($user);
|
||
|
|
|
||
|
|
if (! ($payload['can_see_radar'] ?? false)) {
|
||
|
|
return $this->fail('无权查看老师详情', 403);
|
||
|
|
}
|
||
|
|
|
||
|
|
$model = Teacher::query()
|
||
|
|
->with(['university', 'researchDirections', 'starLevelItem', 'statusItem'])
|
||
|
|
->findOrFail($teacher);
|
||
|
|
|
||
|
|
return $this->ok([
|
||
|
|
'id' => $model->id,
|
||
|
|
'name' => $model->name,
|
||
|
|
'department' => $model->department,
|
||
|
|
'bio' => $model->bio,
|
||
|
|
'title' => $model->title,
|
||
|
|
'city' => $model->city,
|
||
|
|
'phone' => $model->phone,
|
||
|
|
'email' => $model->email,
|
||
|
|
'university_name' => $model->displayUniversityName(),
|
||
|
|
'research_direction' => $model->researchDirections->pluck('name')->join('、') ?: null,
|
||
|
|
'research_directions' => $model->researchDirections->map(fn ($d) => [
|
||
|
|
'id' => $d->id,
|
||
|
|
'name' => $d->name,
|
||
|
|
])->values()->all(),
|
||
|
|
'star_level_item' => $model->starLevelItem ? [
|
||
|
|
'id' => $model->starLevelItem->id,
|
||
|
|
'label' => $model->starLevelItem->label,
|
||
|
|
'value' => $model->starLevelItem->value,
|
||
|
|
] : null,
|
||
|
|
'status_item' => $model->statusItem ? [
|
||
|
|
'id' => $model->statusItem->id,
|
||
|
|
'label' => $model->statusItem->label,
|
||
|
|
'value' => $model->statusItem->value,
|
||
|
|
] : null,
|
||
|
|
'is_partner' => (bool) $model->is_partner,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|