deploy: auto commit server changes 2026-06-12 17:51:57
This commit is contained in:
@@ -0,0 +1,14 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\controller\community;
|
||||
|
||||
use app\adminapi\controller\BaseAdminController;
|
||||
use app\adminapi\lists\community\CommentAccountLists;
|
||||
|
||||
class CommentAccountController extends BaseAdminController
|
||||
{
|
||||
public function lists()
|
||||
{
|
||||
return $this->dataLists(new CommentAccountLists());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,96 @@
|
||||
<?php
|
||||
|
||||
namespace app\adminapi\lists\community;
|
||||
|
||||
use app\adminapi\lists\BaseAdminDataLists;
|
||||
use app\common\lists\ListsSearchInterface;
|
||||
use app\common\model\user\User;
|
||||
use think\facade\Db;
|
||||
|
||||
class CommentAccountLists extends BaseAdminDataLists implements ListsSearchInterface
|
||||
{
|
||||
public function setSearch(): array
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function lists(): array
|
||||
{
|
||||
$query = User::where('account', 'like', 'ai_comment_%');
|
||||
$keyword = trim((string) ($this->params['keyword'] ?? ''));
|
||||
$isDisable = $this->params['is_disable'] ?? '';
|
||||
if ($keyword !== '') {
|
||||
$query->where('id|sn|nickname|account', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
if ($isDisable !== '') {
|
||||
$query->where('is_disable', (int) $isDisable);
|
||||
}
|
||||
|
||||
$lists = $query
|
||||
->field('id,sn,nickname,avatar,account,is_disable,create_time')
|
||||
->order('id', 'desc')
|
||||
->limit($this->limitOffset, $this->limitLength)
|
||||
->select()
|
||||
->toArray();
|
||||
|
||||
$userIds = array_map('intval', array_column($lists, 'id'));
|
||||
$articleCounts = [];
|
||||
$communityCounts = [];
|
||||
if (!empty($userIds)) {
|
||||
$articleRows = Db::name('article_comment')
|
||||
->field('user_id, COUNT(*) AS count')
|
||||
->whereIn('user_id', $userIds)
|
||||
->whereNull('delete_time')
|
||||
->group('user_id')
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($articleRows as $row) {
|
||||
$articleCounts[(int) $row['user_id']] = (int) $row['count'];
|
||||
}
|
||||
|
||||
$communityRows = Db::name('community_comment')
|
||||
->field('user_id, COUNT(*) AS count')
|
||||
->whereIn('user_id', $userIds)
|
||||
->whereNull('delete_time')
|
||||
->group('user_id')
|
||||
->select()
|
||||
->toArray();
|
||||
foreach ($communityRows as $row) {
|
||||
$communityCounts[(int) $row['user_id']] = (int) $row['count'];
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($lists as &$item) {
|
||||
$item['persona_label'] = $this->resolvePersonaLabel((string) $item['nickname']);
|
||||
$item['article_comment_count'] = $articleCounts[(int) $item['id']] ?? 0;
|
||||
$item['community_comment_count'] = $communityCounts[(int) $item['id']] ?? 0;
|
||||
$item['total_comment_count'] = $item['article_comment_count'] + $item['community_comment_count'];
|
||||
$item['create_time'] = is_numeric($item['create_time']) ? date('Y-m-d H:i:s', (int) $item['create_time']) : $item['create_time'];
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
public function count(): int
|
||||
{
|
||||
$query = User::where('account', 'like', 'ai_comment_%');
|
||||
$keyword = trim((string) ($this->params['keyword'] ?? ''));
|
||||
$isDisable = $this->params['is_disable'] ?? '';
|
||||
if ($keyword !== '') {
|
||||
$query->where('id|sn|nickname|account', 'like', '%' . $keyword . '%');
|
||||
}
|
||||
if ($isDisable !== '') {
|
||||
$query->where('is_disable', (int) $isDisable);
|
||||
}
|
||||
return $query->count();
|
||||
}
|
||||
|
||||
protected function resolvePersonaLabel(string $nickname): string
|
||||
{
|
||||
if (str_contains($nickname, '·')) {
|
||||
$parts = explode('·', $nickname, 2);
|
||||
return $parts[1] ?: '-';
|
||||
}
|
||||
return '-';
|
||||
}
|
||||
}
|
||||
@@ -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'],
|
||||
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)
|
||||
{
|
||||
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)->dec('comment_count')->update();
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,28 +8,34 @@ use app\common\model\community\CommunityComment;
|
||||
class CommunityCommentValidate extends BaseValidate
|
||||
{
|
||||
protected $rule = [
|
||||
'id' => 'require|checkComment',
|
||||
'comment_type' => 'require|in:article,post',
|
||||
'id' => 'require|number|checkComment',
|
||||
'status' => 'require|in:0,1',
|
||||
];
|
||||
|
||||
protected $message = [
|
||||
'comment_type.require' => '评论类型不能为空',
|
||||
'comment_type.in' => '评论类型错误',
|
||||
'id.require' => '评论id不能为空',
|
||||
'status.require' => '状态不能为空',
|
||||
];
|
||||
|
||||
public function sceneDelete()
|
||||
{
|
||||
return $this->only(['id']);
|
||||
return $this->only(['comment_type', 'id']);
|
||||
}
|
||||
|
||||
public function sceneStatus()
|
||||
{
|
||||
return $this->only(['id', 'status']);
|
||||
return $this->only(['comment_type', 'id', 'status']);
|
||||
}
|
||||
|
||||
public function checkComment($value)
|
||||
public function checkComment($value, $rule, $data)
|
||||
{
|
||||
$comment = CommunityComment::findOrEmpty($value);
|
||||
$commentType = $data['comment_type'] ?? '';
|
||||
$comment = $commentType === 'article'
|
||||
? \app\common\model\article\ArticleComment::findOrEmpty($value)
|
||||
: CommunityComment::findOrEmpty($value);
|
||||
if ($comment->isEmpty()) {
|
||||
return '评论不存在';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user