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 @@ -