deploy: auto commit server changes 2026-06-12 17:51:57

This commit is contained in:
hajimi
2026-06-12 17:51:58 +08:00
parent f78db05d12
commit 4509279ac7
4 changed files with 168 additions and 13 deletions
@@ -3,18 +3,36 @@
namespace app\adminapi\logic\community;
use app\common\logic\BaseLogic;
use app\common\model\article\Article;
use app\common\model\article\ArticleComment;
use app\common\model\community\CommunityComment;
use app\common\model\community\CommunityPost;
use think\facade\Db;
class CommunityCommentLogic extends BaseLogic
{
public static function updateStatus(array $params): bool
{
try {
CommunityComment::update([
'id' => $params['id'],
'status' => $params['status'],
]);
if (($params['comment_type'] ?? '') === 'article') {
$comment = ArticleComment::findOrEmpty($params['id']);
if ($comment->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());
@@ -24,10 +42,31 @@ class CommunityCommentLogic extends BaseLogic
public static function delete(array $params)
{
$comment = CommunityComment::findOrEmpty($params['id']);
if (!$comment->isEmpty()) {
CommunityPost::where('id', $comment->post_id)->dec('comment_count')->update();
$comment->delete();
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();
} catch (\Throwable $e) {
Db::rollback();
self::setError($e->getMessage());
}
}
}