isEmpty()) { self::setError('评论不存在'); return false; } $comment->save([ 'is_show' => $params['status'], ]); } else { $comment = CommunityComment::findOrEmpty($params['id']); if ($comment->isEmpty()) { self::setError('评论不存在'); return false; } $comment->save([ 'status' => $params['status'], ]); } return true; } catch (\Exception $e) { self::setError($e->getMessage()); return false; } } public static function delete(array $params): bool { Db::startTrans(); try { if (($params['comment_type'] ?? '') === 'article') { $comment = ArticleComment::findOrEmpty($params['id']); if (!$comment->isEmpty()) { Article::where('id', $comment->article_id) ->where('comment_count', '>', 0) ->dec('comment_count') ->update(); $comment->delete(); } } else { $comment = CommunityComment::findOrEmpty($params['id']); if (!$comment->isEmpty()) { CommunityPost::where('id', $comment->post_id) ->where('comment_count', '>', 0) ->dec('comment_count') ->update(); $comment->delete(); } } Db::commit(); return true; } catch (\Throwable $e) { Db::rollback(); self::setError($e->getMessage()); return false; } } }