'channel']); [$page, $limit] = pageParams(); $channelType = trim($_REQUEST['channel_type'] ?? ''); $status = trim($_REQUEST['status'] ?? ''); $keyword = trim($_REQUEST['keyword'] ?? ''); $where = ['is_active = 1']; $params = []; if ($channelType !== '') { $where[] = 'channel_type = ?'; $params[] = $channelType; } if ($status !== '') { $where[] = 'status = ?'; $params[] = $status; } if ($keyword !== '') { $where[] = '(source_detail LIKE ? OR industry LIKE ? OR remark LIKE ?)'; $like = "%$keyword%"; array_push($params, $like, $like, $like); } $whereSql = implode(' AND ', $where); $pdo = DB::getInstance()->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, occurrence_address, industry, start_date, end_date, remark, status, cost, 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); } // cost 转数字(空为 null) $row['cost'] = ($row['cost'] === null || $row['cost'] === '') ? null : (float)$row['cost']; } unset($row); Response::success(['list' => $list, 'total' => $total, 'page' => $page, 'limit' => $limit]);