no message

This commit is contained in:
hajimi
2026-06-11 12:15:29 +08:00
parent 10ebe39c30
commit 96efa1d905
5859 changed files with 815501 additions and 5 deletions
@@ -0,0 +1,85 @@
<?php
namespace app\api\controller;
use app\common\model\article\Article;
use app\common\model\popup\PagePopup;
use app\api\logic\IndexLogic;
use think\response\Json;
/**
* 通用富文本内容
* GET /api/content/detail?type=xxx&id=xxx
*
* 支持的 type:
* - policy 协议(id 实际为 type 字符串:service/privacy 等,由 IndexLogic::getPolicyByType 处理)
* - article 资讯文章
* - popup 弹窗自带的富文本内容(直接取 page_popup.content
* - custom 自定义页面(暂未启用,留扩展位)
*/
class ContentController extends BaseApiController
{
public array $notNeedLogin = ['detail'];
public function detail(): Json
{
$type = trim((string)$this->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);
}
}
}