预约查询页面

This commit is contained in:
Jay Huang 2024-09-01 22:12:37 +08:00
parent 5c76db510c
commit 87e791e853
10 changed files with 89 additions and 68 deletions

View File

@ -1,54 +1,28 @@
<?php defined('BASEPATH') or exit('No direct script access allowed');
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class AppointmentSearch extends EA_Controller
{
/**
* AppointmentSearch constructor.
*/
public function __construct()
{
class AppointmentSearch extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->model('users_model');
$this->load->model('appointments_model');
$this->load->model('Appointment_model');
}
/**
* Search appointments by phone number.
*/
public function search_by_phone(): void
{
try {
$phone_number = request('phone_number', '');
public function search_by_phone() {
$this->security->get_csrf_hash(); // 获取CSRF Token
$phone_number = $this->input->post('phone_number');
if (empty($phone_number)) {
json_response([
'success' => false,
'message' => 'Phone number is required.'
]);
if (!$phone_number) {
echo json_encode(['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);
$appointments = $this->Appointment_model->get_appointments_by_phone($phone_number);
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);
if ($appointments) {
echo json_encode(['success' => true, 'appointments' => $appointments]);
} else {
echo json_encode(['success' => false, 'message' => 'No appointments found']);
}
}
}

View File

@ -32,9 +32,7 @@
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
border-top: 1px solid #EEE; background: #FAFAFA;">
Powered by
<a href="https://easyappointments.org" style="text-decoration: none;">
Easy!Appointments
</a>
<a href="https://www.tfe.com.hk/" target="_blank">TFE Group</a>
|
<a href="<?= $settings['company_link'] ?>" style="text-decoration: none;">
<?= e($settings['company_name']) ?>

View File

@ -175,9 +175,7 @@
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
border-top: 1px solid #EEE; background: #FAFAFA;">
Powered by
<a href="https://easyappointments.org" style="text-decoration: none;">
Easy!Appointments
</a>
<a href="https://www.tfe.com.hk/" target="_blank">TFE Group</a>
|
<a href="<?= e($settings['company_link']) ?>" style="text-decoration: none;">
<?= e($settings['company_name']) ?>

View File

@ -179,9 +179,7 @@
<div id="footer" style="padding: 10px; text-align: center; margin-top: 10px;
border-top: 1px solid #EEE; background: #FAFAFA;">
Powered by
<a href="https://easyappointments.org" style="text-decoration: none;">
Easy!Appointments
</a>
<a href="https://www.tfe.com.hk/" target="_blank">TFE Group</a>
|
<a href="<?= e($settings['company_link']) ?>" style="text-decoration: none;">
<?= e($settings['company_name']) ?>

View File

@ -74,7 +74,7 @@
<p>
<small>
Powered by
<a href="https://easyappointments.org">Easy!Appointments</a>
<a href="https://www.tfe.com.hk/" target="_blank">TFE Group</a>
</small>
</p>
</div>

View File

@ -74,7 +74,7 @@
<p>
<small>
Powered by
<a href="https://easyappointments.org">Easy!Appointments</a>
<a href="https://www.tfe.com.hk/" target="_blank">TFE Group</a>
</small>
</p>
</div>

View File

@ -74,7 +74,7 @@
<p>
<small>
Powered by
<a href="https://easyappointments.org">Easy!Appointments</a>
<a href="https://www.tfe.com.hk/" target="_blank">TFE Group</a>
</small>
</p>
</div>

View File

@ -89,19 +89,21 @@
'company_logo' => vars('company_logo'),
]); ?>
<div class="search-container-wrapper">
<h2 class="search-container-title"><?= lang('search_appointments_title') ?></h2>
<h2 class="search-container-title">查询预约信息</h2>
<div class="search-container">
<input type="text" id="phoneNumber" placeholder="<?= lang('enter_phone_number') ?>">
<button id="searchButton"><?= lang('search_button') ?></button>
<input type="text" id="phoneNumber" placeholder="请输入手机号">
<button id="searchButton">查询</button>
</div>
<div class="appointments-container" id="appointmentsContainer">
<h3><?= lang('appointment_results') ?></h3>
<h3>预约结果</h3>
<ul id="appointmentsList"></ul>
</div>
<div class="no-appointments" id="noAppointmentsMessage">
<?= lang('no_appointments_message') ?>
未找到预约信息。
</div>
</div>
</div>
<?php component('booking_footer', ['display_login_button' => vars('display_login_button')]); ?>
</div>
@ -145,19 +147,26 @@
<script src="<?= asset_url('assets/js/layouts/booking_layout.js') ?>"></script>
<script src="<?= asset_url('assets/js/http/localization_http_client.js') ?>"></script>
<script src="<?= asset_url('assets/js/http/customers_search_http_client.js') ?>"></script>
<script src="<?= asset_url('assets/js/pages/customers.js') ?>"></script>
<script>
document.getElementById('searchButton').addEventListener('click', function() {
var phoneNumber = document.getElementById('phoneNumber').value;
if (phoneNumber.trim() === '') {
alert('<?= lang('enter_valid_phone_number') ?>');
alert('请输入有效的手机号');
return;
}
fetch('/index.php/home_search/search_by_phone', {
// 发送请求前获取CSRF token
var csrfToken = document.querySelector('meta[name="csrf_token"]').getAttribute('content');
fetch('/index.php/appointmentSearch/search_by_phone', {
method: 'POST',
headers: {
'Content-Type': 'application/json'
'Content-Type': 'application/json',
'X-CSRF-TOKEN': csrfToken // 添加CSRF Token到请求头
},
body: JSON.stringify({ phone_number: phoneNumber })
})
@ -182,8 +191,7 @@
appointmentsList.innerHTML = '';
appointments.forEach(function(appointment) {
var listItem = document.createElement('li');
// 根据实际返回的预约信息字段进行调整
listItem.textContent = `Appointment on ${appointment.start_datetime} with provider ID ${appointment.id_users_provider}`;
listItem.textContent = `预约时间:${appointment.start_datetime}提供者ID${appointment.id_users_provider}`;
appointmentsList.appendChild(listItem);
});

View File

@ -192,7 +192,7 @@
</div>
<footer>
Powered by <a href="https://easyappointments.org">Easy!Appointments</a>
<a href="https://www.tfe.com.hk/" target="_blank">TFE Group</a>
</footer>
<?php component('js_vars_script'); ?>

View File

@ -0,0 +1,45 @@
/* ----------------------------------------------------------------------------
* Easy!Appointments - Online Appointment Scheduler
*
* @package EasyAppointments
* @author A.Tselegidis <alextselegidis@gmail.com>
* @copyright Copyright (c) Alex Tselegidis
* @license https://opensource.org/licenses/GPL-3.0 - GPLv3
* @link https://easyappointments.org
* @since v1.5.0
* ---------------------------------------------------------------------------- */
/**
* Customers HTTP client.
*
* This module implements the customers related HTTP requests.
*/
App.Http.Customers = (function () {
/**
* Search customers by keyword.
*
* @param {String} keyword
* @param {Number} [limit]
* @param {Number} [offset]
* @param {String} [orderBy]
*
* @return {Object}
*/
function search(keyword, limit = null, offset = null, orderBy = null) {
const url = App.Utils.Url.siteUrl('customers/search');
const data = {
csrf_token: vars('csrf_token'),
keyword,
limit,
offset,
order_by: orderBy,
};
return $.post(url, data);
}
return {
search,
};
})();