diff --git a/application/controllers/Customers.php b/application/controllers/Customers.php index 9809957a..498d0e72 100755 --- a/application/controllers/Customers.php +++ b/application/controllers/Customers.php @@ -202,6 +202,65 @@ class Customers extends EA_Controller } } + /** + * Filter customers by the provided keyword. + */ + public function search_by_phone(): void + { + + $phoneNumber = request('phone_number', ''); + if (empty($phoneNumber)) { + // 返回错误信息 + echo json_encode(['success' => false, 'message' => 'Invalid phone number']); + return; + } + + // 查询数据库中的预约信息 + $appointments = $this->appointments_model->get_appointments_by_phone($phoneNumber); + foreach ($appointments as &$appointment) { + $this->appointments_model->load($appointment, ['service', 'provider']); + } + + if (!empty($appointments)) { + // 返回预约信息 + echo json_encode(['success' => true, 'appointments' => $appointments]); + } else { + // 如果没有找到预约信息 + echo json_encode(['success' => false, 'message' => 'No appointments found']); + } + } + + public function cancel(): void + { + try { + $appointmentId = request('appointmentId'); + + // 查找指定的预约记录 + $appointment = $this->appointments_model->find($appointmentId); + + if ($appointment) { + // 更新状态为 '取消' + $appointment['status'] = '取消'; + + // 保存更新后的预约记录 + $this->appointments_model->save($appointment); + + json_response([ + 'success' => true, + 'id' => $appointmentId, + ]); + } else { + // 处理预约记录不存在的情况 + json_response([ + 'success' => false, + 'message' => '預約記錄不存在。', + ], 404); + } + } catch (Throwable $e) { + json_exception($e); + } + } + /** * Store a new customer. */ diff --git a/application/models/Appointments_model.php b/application/models/Appointments_model.php index ce769cef..5c4d9052 100755 --- a/application/models/Appointments_model.php +++ b/application/models/Appointments_model.php @@ -649,7 +649,7 @@ class Appointments_model extends EA_Model ->like('providers.phone_number', $phone_number) ->or_like('customers.phone_number', $phone_number) ->group_end() - ->where('appointments.start_datetime >=', date('Y-m-d H:i:s')) // 过滤掉当天00点之前的预约 + // ->where('appointments.start_datetime >=', date('Y-m-d H:i:s')) // 过滤掉当天00点之前的预约 ->limit($limit) ->offset($offset) ->order_by($order_by) @@ -662,4 +662,5 @@ class Appointments_model extends EA_Model return $appointments; } + } diff --git a/application/views/layouts/home_search_layout.php b/application/views/layouts/home_search_layout.php index 3569ddbf..1e75b471 100755 --- a/application/views/layouts/home_search_layout.php +++ b/application/views/layouts/home_search_layout.php @@ -1,5 +1,6 @@ + @@ -7,9 +8,9 @@ - + - + @@ -38,9 +39,11 @@ flex-direction: column; min-height: 44.2vh; } + .search-container-title { color: #666666; } + .search-container { display: flex; flex-direction: column; @@ -49,6 +52,7 @@ max-width: 400px; margin-bottom: 20px; } + .search-container input { width: 100%; padding: 10px; @@ -56,6 +60,7 @@ border-radius: 5px; border: 1px solid #ccc; } + .search-container button { padding: 10px 20px; background-color: #429a82; @@ -65,12 +70,15 @@ cursor: pointer; width: 100%; } + .appointments-container { display: none; width: 100%; max-width: 600px; margin-top: 20px; + padding: 0 12px; } + .no-appointments { display: none; color: red; @@ -81,140 +89,219 @@ -
-
-
- vars('company_name'), - 'company_logo' => vars('company_logo'), - ]); ?> -
-

查询预约信息

-
- - +
+
+
+ vars('company_name'), + 'company_logo' => vars('company_logo'), + ]); ?> +
+

查询预约信息

+
+ + +
+
+

预约结果

+
    +
    +
    + 未找到预约信息。 +
    -
    -

    预约结果

    -
      -
      -
      - 未找到预约信息。 -
      -
      vars('display_login_button')]); ?>
      -
      +
      - - vars('cookie_notice_content')]); ?> - + + vars('cookie_notice_content')]); ?> + - - vars('terms_and_conditions_content'), - ]); ?> - + + vars('terms_and_conditions_content'), + ]); ?> + - - vars('privacy_policy_content')]); ?> - + + vars('privacy_policy_content')]); ?> + - - - - - - - - - - + + + + + + + + + + - - - - - - - - - - - + + + + + + + + + + - - - + appointmentsList.innerHTML = ''; + appointments.forEach(function(appointment) { + var listItem = document.createElement('li'); - - + // 创建服务名称和提供者姓名的 div + var serviceDiv = document.createElement('div'); + serviceDiv.textContent = `${appointment.service.name} - ${appointment.provider.last_name}${appointment.provider.first_name}`; - vars('google_analytics_code')]); ?> - vars('matomo_analytics_url'), - 'matomo_analytics_site_id' => vars('matomo_analytics_site_id'), -]); ?> + // 创建预约时间的 div + var timeDiv = document.createElement('div'); + timeDiv.textContent = `開始時間:${appointment.start}`; - + // 创建结束时间的 div + var endDiv = document.createElement('div'); + endDiv.textContent = `結束時間:${appointment.end}`; + + // 创建状态的 div + var statusDiv = document.createElement('div'); + statusDiv.textContent = `狀態:${appointment.status}`; + + // 将每个 div 添加到 li 中 + listItem.appendChild(serviceDiv); + listItem.appendChild(timeDiv); + listItem.appendChild(endDiv); + listItem.appendChild(statusDiv); + + // 如果状态是“已预约”,添加取消预约按钮 + if (appointment.status === '已預約') { + var cancelButton = document.createElement('button'); + cancelButton.textContent = '取消預約'; + cancelButton.className = 'btn btn-danger'; // 添加一些样式类名 + cancelButton.addEventListener('click', function() { + // 确认对话框 + var confirmCancel = confirm('您確定要取消這個預約嗎?'); + + if (confirmCancel) { + // 添加取消预约的逻辑 + // 例如,发起一个请求到服务器取消预约 + console.log(`取消預約:${appointment.id}`); + // 这里可以添加实际的请求代码 + const url = App.Utils.Url.siteUrl('customers/cancel'); + + const data = { + csrf_token: vars('csrf_token'), + appointmentId: appointment.id, + }; + + $.post(url, data).done((data) => { + // console.log('data',response); + if (data.success) { + //重新加载 + doSearch(); + alert('取消預約成功。'); + } else { + alert('取消預約失敗。'); + } + }); + } + }); + listItem.appendChild(cancelButton); + } + + // 将 li 添加到 ul 或 ol 列表中 + appointmentsList.appendChild(listItem); + }); + + appointmentsContainer.style.display = 'block'; + document.getElementById('noAppointmentsMessage').style.display = 'none'; + } + + function showNoAppointmentsMessage() { + document.getElementById('appointmentsContainer').style.display = 'none'; + document.getElementById('noAppointmentsMessage').style.display = 'block'; + } + + + + + + vars('google_analytics_code')]); ?> + vars('matomo_analytics_url'), + 'matomo_analytics_site_id' => vars('matomo_analytics_site_id'), + ]); ?> + + + \ No newline at end of file diff --git a/vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/HTML/4.17.0,f474c0a322b208e83d22d3aef33ecb184bc71d31,1.ser b/vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/HTML/4.17.0,f474c0a322b208e83d22d3aef33ecb184bc71d31,1.ser new file mode 100644 index 00000000..e2c42925 Binary files /dev/null and b/vendor/ezyang/htmlpurifier/library/HTMLPurifier/DefinitionCache/Serializer/HTML/4.17.0,f474c0a322b208e83d22d3aef33ecb184bc71d31,1.ser differ