getPdo(); $stmt = $pdo->prepare("SELECT COUNT(*) FROM channel_plans WHERE $whereSql"); $stmt->execute($params); $total = (int)$stmt->fetchColumn(); $offset = ($page - 1) * $limit; $stmt = $pdo->prepare( "SELECT id, channel_type, source_detail, industry, start_date, end_date, remark, status, created_at, updated_at FROM channel_plans WHERE $whereSql ORDER BY id DESC LIMIT $limit OFFSET $offset" ); $stmt->execute($params); $list = $stmt->fetchAll(); // 剩余天数:距时间窗口结束日(end_date)的天数,已过期为 0 $today = strtotime(date('Y-m-d')); foreach ($list as &$row) { $row['remaining_days'] = 0; if (!empty($row['end_date']) && strtotime($row['end_date']) !== false) { $diff = (int)ceil((strtotime($row['end_date']) - $today) / 86400); $row['remaining_days'] = max(0, $diff); } } unset($row); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);