54 lines
1.5 KiB
PHP
54 lines
1.5 KiB
PHP
<?php defined('BASEPATH') or exit('No direct script access allowed');
|
|
|
|
class AppointmentSearch extends EA_Controller
|
|
{
|
|
/**
|
|
* AppointmentSearch constructor.
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
|
|
$this->load->model('users_model');
|
|
$this->load->model('appointments_model');
|
|
}
|
|
|
|
/**
|
|
* Search appointments by phone number.
|
|
*/
|
|
public function search_by_phone(): void
|
|
{
|
|
try {
|
|
$phone_number = request('phone_number', '');
|
|
|
|
if (empty($phone_number)) {
|
|
json_response([
|
|
'success' => false,
|
|
'message' => 'Phone number is required.'
|
|
]);
|
|
return;
|
|
}
|
|
|
|
// 查询ea_users表中id_roles为3的用户ID
|
|
$user = $this->users_model->get_user_by_phone($phone_number, 3);
|
|
|
|
if (!$user) {
|
|
json_response([
|
|
'success' => false,
|
|
'message' => 'No user found with this phone number.'
|
|
]);
|
|
return;
|
|
}
|
|
|
|
// 用用户ID查询ea_appointments表中的记录
|
|
$appointments = $this->appointments_model->get_appointments_by_user_id($user->id);
|
|
|
|
json_response([
|
|
'success' => true,
|
|
'appointments' => $appointments
|
|
]);
|
|
} catch (Throwable $e) {
|
|
json_exception($e);
|
|
}
|
|
}
|
|
} |