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( 'doctors.dept_id', 'departments.dept_name', 'doctors.doctor_id', 'doctors.doctor_name', 'doctors.doctor_title', 'doctors.doctor_specialty', 'doctors.avatar as doctor_avatar', 'doctors.is_expert', 'doctors.sort', ) ->join('departments', 'doctors.dept_id', '=', 'departments.dept_id') ->where('doctors.is_enable', 1) ->orderBy('doctors.sort', 'DESC') ->orderBy('doctors.is_expert', 'DESC') ->orderBy('doctors.id', 'ASC') ->get() ->toArray(); foreach ($doctor_lists as $k => $v) { $doctor_lists[$k]['doctor_avatar'] = $v['doctor_avatar'] ?: ''; } return jsonResponse(Response::HTTP_OK, 'success.', $doctor_lists); } /** * 获取医生详情 * @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' => $doctor_details->avatar ?: '', 'introduction' => $doctor_details->introduction ?: '', 'is_expert' => $doctor_details->is_expert, ]; return jsonResponse(Response::HTTP_OK, 'success.', $details); } /** * 获取医院导航信息 * @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', 1) ->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); } }