request->get('type', '')); $idRaw = trim((string)$this->request->get('id', '')); if (!$type) { return $this->fail('参数错误:type'); } switch ($type) { case 'policy': { // policy 用 id 字段传 type 字符串 $policy = IndexLogic::getPolicyByType($idRaw); if (!$policy) { return $this->fail('内容不存在'); } return $this->data([ 'type' => 'policy', 'id' => $idRaw, 'title' => (string)($policy['title'] ?? ''), 'content' => (string)($policy['content'] ?? ''), 'create_time' => '', ]); } case 'article': { $id = (int)$idRaw; if ($id <= 0) return $this->fail('参数错误:id'); $info = Article::where('id', $id) ->where('is_show', 1) ->find(); if (!$info) return $this->fail('内容不存在'); return $this->data([ 'type' => 'article', 'id' => $id, 'title' => (string)($info['title'] ?? ''), 'content' => (string)($info['content'] ?? ''), 'create_time' => (string)($info['create_time'] ?? ''), ]); } case 'popup': { $id = (int)$idRaw; if ($id <= 0) return $this->fail('参数错误:id'); $info = PagePopup::where('id', $id) ->where('status', 1) ->find(); if (!$info) return $this->fail('内容不存在'); return $this->data([ 'type' => 'popup', 'id' => $id, 'title' => (string)($info['title'] ?: $info['name']), 'content' => (string)($info['content'] ?? ''), 'create_time' => (string)($info['create_time'] ?? ''), ]); } default: return $this->fail('暂不支持的 type:' . $type); } } }