'cat 参数须为 popular/red/blue'], JSON_UNESCAPED_UNICODE); exit; } $pdo = db(); $st = $pdo->prepare('SELECT * FROM categories WHERE key = ? LIMIT 1'); $st->execute([$cat]); $catRow = $st->fetch(); if (!$catRow) { http_response_code(404); echo json_encode(['error' => '分类不存在'], JSON_UNESCAPED_UNICODE); exit; } $out = []; $st = $pdo->prepare('SELECT * FROM nav_blocks WHERE cat_id = ? ORDER BY sort ASC, id ASC'); $st->execute([(int)$catRow['id']]); $blocks = $st->fetchAll(); $itemSt = $pdo->prepare('SELECT * FROM nav_items WHERE block_id = ? ORDER BY sort ASC, id ASC LIMIT 15'); foreach ($blocks as $b) { $itemSt->execute([(int)$b['id']]); $items = []; foreach ($itemSt->fetchAll() as $it) { $items[] = [ 'label' => (string)$it['label'], 'url' => (string)$it['url'], 'note' => (string)$it['note'], ]; } $out[] = ['title' => (string)$b['title'], 'items' => $items]; } echo json_encode($out, JSON_UNESCAPED_UNICODE);