This repository has been archived on 2026-06-20. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
carwash_order/get_daily_booking_duration.php
wsh5485 c64651d6c7 feat(移动端): 添加移动端导航菜单并优化响应式设计
refactor(预约统计): 修改查询逻辑只计算有效预约
2025-12-12 03:39:01 +08:00

29 lines
887 B
PHP

<?php
// 引入数据库连接文件
require 'db_connect.php';
// 获取请求参数
$date = $_GET['date'];
// 验证日期格式
if (!preg_match('/^\d{4}-\d{2}-\d{2}$/', $date)) {
echo json_encode(['error' => 'Invalid date format']);
exit;
}
try {
// 查询指定日期的总预约时长,只计算有效预约
$sql = "SELECT SUM(duration) as total_duration FROM bookings WHERE DATE(start_time) = ? AND status NOT IN ('已完成', '已取消')";
$stmt = $pdo->prepare($sql);
$stmt->execute([$date]);
$row = $stmt->fetch();
// 获取总时长,如果没有预约则返回0
$total_duration = $row['total_duration'] ? $row['total_duration'] : 0;
// 返回结果
echo json_encode(['total_duration' => $total_duration]);
} catch (PDOException $e) {
echo json_encode(['error' => 'Database query failed: ' . $e->getMessage()]);
}