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.
300 lines
9.7 KiB
300 lines
9.7 KiB
<?php
|
|
declare(strict_types = 1);
|
|
|
|
namespace App\Http\Controllers\Hospital;
|
|
|
|
|
|
use App\Exceptions\GeneralException;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Models\Admin\BuildingDistribution;
|
|
use App\Models\Admin\Department;
|
|
use App\Models\Admin\DepartmentCategory;
|
|
use App\Models\Admin\Doctor;
|
|
use App\Models\Admin\HealthLecture;
|
|
use App\Models\Admin\Info;
|
|
use App\Models\Admin\Navigation;
|
|
use App\Models\Admin\News;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class IntroduceController extends Controller
|
|
{
|
|
|
|
/**
|
|
* 获取科室列表
|
|
* @return JsonResponse
|
|
*/
|
|
public function deptLists(): JsonResponse
|
|
{
|
|
$category_lists = DepartmentCategory::select('id as category_id', 'name as category_name')
|
|
->orderBy('sort', 'DESC')
|
|
->orderBy('id', 'ASC')
|
|
->get();
|
|
$category_lists = $category_lists->keyBy('category_id')->map(function ($value) { return (array)$value; })->toArray();
|
|
|
|
$department_lists = Department::select('dept_id', 'dept_name', 'category_id')
|
|
->where('is_enable', 1)
|
|
->orderBy('sort', 'DESC')
|
|
->orderBy('id', 'ASC')
|
|
->get();
|
|
|
|
foreach ($department_lists as $v) {
|
|
$category_lists[$v->category_id]['item_lists'][] = [
|
|
'dept_id' => $v->dept_id,
|
|
'dept_name' => $v->dept_name,
|
|
'introduction' => $v->introduction ?: ''
|
|
];
|
|
}
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', array_values($category_lists));
|
|
}
|
|
|
|
/**
|
|
* 科室详情
|
|
* @param Request $request
|
|
* @param string $dept_id
|
|
* @return JsonResponse
|
|
* @throws GeneralException
|
|
*/
|
|
public function deptDetails(Request $request, string $dept_id): JsonResponse
|
|
{
|
|
$department_details = Department::where('dept_id', $dept_id)
|
|
->where('is_enable', 1)
|
|
->first();
|
|
|
|
if (empty($department_details)) {
|
|
throw new GeneralException('找不到该科室信息');
|
|
}
|
|
|
|
$details = [
|
|
'dept_id' => $department_details->dept_id,
|
|
'dept_name' => $department_details->dept_name,
|
|
'category_id' => $department_details->category_id,
|
|
'category_name' => $department_details->departmentCategory->name,
|
|
'introduction' => $department_details->introduction ?: '',
|
|
];
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $details);
|
|
}
|
|
|
|
/**
|
|
* 获取医生列表
|
|
* @return JsonResponse
|
|
*/
|
|
public function doctorLists(): JsonResponse
|
|
{
|
|
$doctor_lists = Doctor::select('dept_id', 'doctor_id', 'doctor_name', 'doctor_title', 'doctor_specialty', 'avatar as doctor_avatar', 'is_expert', 'sort',)
|
|
->where('is_enable', 1)
|
|
->orderBy('is_expert', 'DESC')
|
|
->orderBy('sort', 'DESC')
|
|
->orderBy('id', 'ASC')
|
|
->get();
|
|
|
|
foreach ($doctor_lists as $k => $v) {
|
|
$doctor_lists[$k]['dept_name'] = $v->department->dept_name ?? '';
|
|
$doctor_lists[$k]['doctor_avatar'] = getAdminUploadImageUrl($v['doctor_avatar']);
|
|
}
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $doctor_lists->toArray());
|
|
}
|
|
|
|
/**
|
|
* 获取医生详情
|
|
* @param Request $request
|
|
* @param string $doctor_id
|
|
* @return JsonResponse
|
|
* @throws GeneralException
|
|
*/
|
|
public function doctorDetails(Request $request, string $doctor_id): JsonResponse
|
|
{
|
|
$doctor_details = Doctor::where('doctor_id', $doctor_id)
|
|
->where('is_enable', 1)
|
|
->first();
|
|
|
|
if (empty($doctor_details)) {
|
|
throw new GeneralException('找不到该科室信息');
|
|
}
|
|
|
|
$details = [
|
|
'dept_id' => $doctor_details->dept_id,
|
|
'dept_name' => $doctor_details->department->dept_name,
|
|
'doctor_id' => $doctor_details->doctor_id,
|
|
'doctor_name' => $doctor_details->doctor_name,
|
|
'doctor_title' => $doctor_details->doctor_title,
|
|
'doctor_specialty' => $doctor_details->doctor_specialty,
|
|
'avatar' => getAdminUploadImageUrl($doctor_details->avatar),
|
|
'introduction' => $doctor_details->introduction ?: '',
|
|
'is_expert' => $doctor_details->is_expert,
|
|
];
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $details);
|
|
}
|
|
|
|
/**
|
|
* 医院简介
|
|
* @return JsonResponse
|
|
* @throws GeneralException
|
|
*/
|
|
public function info(): JsonResponse
|
|
{
|
|
$info = Info::find(1);
|
|
|
|
if (empty($info)) {
|
|
throw new GeneralException('找不到医院信息');
|
|
}
|
|
|
|
$info = [
|
|
'name' => $info->name,
|
|
'level' => $info->level ?: '',
|
|
'address' => $info->address ?: '',
|
|
'telephone' => $info->telephone ?: '',
|
|
'email' => $info->email ?: '',
|
|
'logo' => getAdminUploadImageUrl($info->logo),
|
|
'website' => $info->website ?: '',
|
|
'description' => !empty($info['description']) ? html_entity_decode($info['description']) : ''
|
|
];
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $info);
|
|
}
|
|
|
|
/**
|
|
* 获取医院导航信息
|
|
* @throws GeneralException
|
|
*/
|
|
public function navigationDetails(Request $request): JsonResponse
|
|
{
|
|
$navigation_details = Navigation::select('area_id', 'area_name', 'longitude', 'latitude', 'address', 'telephone', 'traffic', 'guide')
|
|
->where('area_id', '01')
|
|
->where('is_enable', 1)
|
|
->first();
|
|
|
|
if (empty($navigation_details)) {
|
|
throw new GeneralException('找不到导航信息');
|
|
}
|
|
|
|
$details = $navigation_details->toArray();
|
|
$details['traffic'] = !empty($details['traffic']) ? html_entity_decode($details['traffic']) : '';
|
|
$details['guide'] = !empty($details['guide']) ? html_entity_decode($details['guide']) : '';
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $details);
|
|
}
|
|
|
|
/**
|
|
* 获取新闻动态列表
|
|
* @throws GeneralException
|
|
*/
|
|
public function newLists(Request $request): JsonResponse
|
|
{
|
|
$new_lists = News::select('title', 'image', 'sort', 'published_at')
|
|
->where('is_display', 1)
|
|
->where('published_at', '<=', date('Y-m-d H:i:s'))
|
|
->orderBy('sort', 'DESC')
|
|
->orderBy('id', 'DESC')
|
|
->get()
|
|
->toArray();
|
|
|
|
if (empty($new_lists)) {
|
|
throw new GeneralException('找不到新闻动态');
|
|
}
|
|
|
|
foreach ($new_lists as $v) {
|
|
$v['image'] = getAdminUploadImageUrl($v['image']);
|
|
}
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $new_lists);
|
|
}
|
|
|
|
/**
|
|
* 获取新闻动态详情
|
|
* @param Request $request
|
|
* @param int $new_id
|
|
* @return JsonResponse
|
|
* @throws GeneralException
|
|
*/
|
|
public function newDetails(Request $request, int $new_id): JsonResponse
|
|
{
|
|
$details = News::select('title', 'image', 'sort', 'published_at', 'content')
|
|
->where('id', $new_id)
|
|
->where('is_display', 1)
|
|
->where('published_at', '<=', date('Y-m-d H:i:s'))
|
|
->first()
|
|
->toArray();
|
|
|
|
if (empty($details)) {
|
|
throw new GeneralException('找不到该新闻动态信息');
|
|
}
|
|
|
|
$details['image'] = getAdminUploadImageUrl($details['image']);
|
|
$details['content'] = !empty($details['content']) ? html_entity_decode($details['content']) : '';
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $details);
|
|
}
|
|
|
|
/**
|
|
* 获取宣讲列表
|
|
* @throws GeneralException
|
|
*/
|
|
public function healthLectureLists(Request $request): JsonResponse
|
|
{
|
|
$lecture_lists = HealthLecture::select('title', 'speaker', 'lecture_date', 'sort')
|
|
->where('is_display', 1)
|
|
->orderBy('sort', 'DESC')
|
|
->orderBy('lecture_date', 'DESC')
|
|
->orderBy('id', 'DESC')
|
|
->get()
|
|
->toArray();
|
|
|
|
if (empty($lecture_lists)) {
|
|
throw new GeneralException('找不到健康宣讲内容');
|
|
}
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $lecture_lists);
|
|
}
|
|
|
|
/**
|
|
* 获取宣讲详情
|
|
* @param Request $request
|
|
* @param int $lecture_id
|
|
* @return JsonResponse
|
|
* @throws GeneralException
|
|
*/
|
|
public function healthLectureDetails(Request $request, int $lecture_id): JsonResponse
|
|
{
|
|
$details = HealthLecture::select('title', 'speaker', 'lecture_date', 'sort', 'content')
|
|
->where('id', $lecture_id)
|
|
->where('is_display', 1)
|
|
->first()
|
|
->toArray();
|
|
|
|
if (empty($details)) {
|
|
throw new GeneralException('找不到该新闻动态信息');
|
|
}
|
|
|
|
$details['content'] = !empty($details['content']) ? html_entity_decode($details['content']) : '';
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $details);
|
|
}
|
|
|
|
/**
|
|
* 获取医院楼群信息
|
|
* @throws GeneralException
|
|
*/
|
|
public function buildingDetails(Request $request): JsonResponse
|
|
{
|
|
$building_lists = BuildingDistribution::select('name', 'description', 'image', 'sort')
|
|
->where('is_display', 1)
|
|
->get()
|
|
->toArray();
|
|
|
|
if (empty($building_lists)) {
|
|
throw new GeneralException('找不到医院楼群信息');
|
|
}
|
|
|
|
foreach ($building_lists as $k => $v) {
|
|
$building_lists[$k]['image'] = getAdminUploadImageUrl($v['image']);
|
|
}
|
|
|
|
return jsonResponse(Response::HTTP_OK, 'success.', $building_lists);
|
|
}
|
|
}
|
|
|