预约查询页面

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 class AppointmentSearch extends CI_Controller {
{
/** public function __construct() {
* AppointmentSearch constructor.
*/
public function __construct()
{
parent::__construct(); parent::__construct();
$this->load->model('Appointment_model');
$this->load->model('users_model');
$this->load->model('appointments_model');
} }
/** public function search_by_phone() {
* Search appointments by phone number. $this->security->get_csrf_hash(); // 获取CSRF Token
*/ $phone_number = $this->input->post('phone_number');
public function search_by_phone(): void
{
try {
$phone_number = request('phone_number', '');
if (empty($phone_number)) { if (!$phone_number) {
json_response([ echo json_encode(['success' => false, 'message' => 'Phone number is required']);
'success' => false,
'message' => 'Phone number is required.'
]);
return; return;
} }
// 查询ea_users表中id_roles为3的用户ID $appointments = $this->Appointment_model->get_appointments_by_phone($phone_number);
$user = $this->users_model->get_user_by_phone($phone_number, 3);
if (!$user) { if ($appointments) {
json_response([ echo json_encode(['success' => true, 'appointments' => $appointments]);
'success' => false, } else {
'message' => 'No user found with this phone number.' echo json_encode(['success' => false, 'message' => 'No appointments found']);
]);
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);
} }
} }
} }

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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