feat: allow editing community post content

This commit is contained in:
hajimi
2026-08-02 20:11:15 +08:00
parent 115a859dd3
commit 71f3b1c6d7
7 changed files with 125 additions and 2 deletions
@@ -21,6 +21,16 @@ class CommunityPostController extends BaseAdminController
return $this->data($result);
}
public function editContent()
{
$params = (new CommunityPostValidate())->post()->goCheck('editContent');
$result = CommunityPostLogic::editContent($params);
if (true === $result) {
return $this->success('保存成功', [], 1, 1);
}
return $this->fail(CommunityPostLogic::getError());
}
public function updateStatus()
{
$params = (new CommunityPostValidate())->post()->goCheck('status');
@@ -50,6 +50,27 @@ class CommunityPostLogic extends BaseLogic
}
}
public static function editContent(array $params): bool
{
$post = CommunityPost::findOrEmpty($params['id']);
if ($post->isEmpty()) {
self::setError('帖子不存在');
return false;
}
try {
$post->content = (string) $params['content'];
$post->save();
if ((int) $post->status === 1) {
KbSyncService::enqueue('post', 'post', (int) $post->id, 'upsert', 30);
}
return true;
} catch (\Exception $e) {
self::setError($e->getMessage());
return false;
}
}
public static function setTop(array $params): bool
{
try {
@@ -17,11 +17,14 @@ class CommunityPostValidate extends BaseValidate
'sort' => 'require|integer|egt:0|elt:1000000',
'is_topic' => 'require|in:0,1',
'category_id' => 'require|integer|egt:0|checkCategory',
'content' => 'require|max:16000',
];
protected $message = [
'id.require' => '帖子id不能为空',
'status.require' => '状态不能为空',
'content.require' => '帖子内容不能为空',
'content.max' => '帖子内容不能超过16000个字符',
];
public function sceneDetail()
@@ -39,6 +42,11 @@ class CommunityPostValidate extends BaseValidate
return $this->only(['id', 'status']);
}
public function sceneEditContent()
{
return $this->only(['id', 'content']);
}
public function sceneTop()
{
return $this->only(['id', 'is_top']);