diff --git a/application/controllers/AppointmentSearch.php b/application/controllers/AppointmentSearch.php new file mode 100644 index 00000000..3fda4d63 --- /dev/null +++ b/application/controllers/AppointmentSearch.php @@ -0,0 +1,54 @@ +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); + } + } +} \ No newline at end of file diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index 6c4644c1..7d84f5f0 100755 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.php @@ -628,4 +628,12 @@ class Appointments_model extends EA_Model $appointment = $decoded_request; } + + + public function get_appointments_by_user_id($user_id) + { + return $this->db->where('id_users_customer', $user_id) + ->get('ea_appointments') + ->result(); + } } diff --git a/application/models/Users_model.php b/application/models/Users_model.php index 3606b662..9d4b7c2a 100755 --- a/application/models/Users_model.php +++ b/application/models/Users_model.php @@ -430,4 +430,12 @@ class Users_model extends EA_Model return $this->db->get_where('user_settings', ['username' => $username])->num_rows() === 0; } + + public function get_user_by_phone($phone_number, $role_id) + { + return $this->db->where('phone', $phone_number) + ->where('id_roles', $role_id) + ->get('ea_users') + ->row(); + } } diff --git a/application/views/components/booking_footer.php b/application/views/components/booking_footer.php index 19f5ce6a..c4bc49cd 100755 --- a/application/views/components/booking_footer.php +++ b/application/views/components/booking_footer.php @@ -8,7 +8,10 @@