deploy: auto commit repo-root changes 2026-06-13 00:17:26

This commit is contained in:
hajimi
2026-06-13 00:17:26 +08:00
parent 16b8d0365a
commit c3385b0e04
6 changed files with 160 additions and 258 deletions
@@ -9,6 +9,21 @@ use think\facade\Db;
class CommentAccountLists extends BaseAdminDataLists implements ListsSearchInterface
{
protected const PERSONA_LABELS = [
'数据派',
'老球迷',
'教练视角',
'夜班编辑',
'伤停控',
'赔率派',
'更衣室派',
'球探派',
'解说腔',
'主队党',
'模型党',
'资讯控',
];
public function setSearch(): array
{
return [];
@@ -61,7 +76,7 @@ class CommentAccountLists extends BaseAdminDataLists implements ListsSearchInter
}
foreach ($lists as &$item) {
$item['persona_label'] = $this->resolvePersonaLabel((string) $item['nickname']);
$item['persona_label'] = $this->resolvePersonaLabel((string) $item['account'], (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'];
@@ -85,12 +100,16 @@ class CommentAccountLists extends BaseAdminDataLists implements ListsSearchInter
return $query->count();
}
protected function resolvePersonaLabel(string $nickname): string
protected function resolvePersonaLabel(string $account, string $nickname): string
{
if (str_contains($nickname, '·')) {
$parts = explode('·', $nickname, 2);
return $parts[1] ?: '-';
}
if (preg_match('/(\d+)$/', $account, $matches)) {
$index = max(1, (int) $matches[1]);
return self::PERSONA_LABELS[($index - 1) % count(self::PERSONA_LABELS)] ?? '-';
}
return '-';
}
}
@@ -13,8 +13,41 @@ use think\facade\Db;
class ArticleAiCommentService
{
private const VIRTUAL_ACCOUNT_PREFIX = 'ai_comment_';
private const VIRTUAL_NICKNAME_PREFIX = 'AI评论员';
private const VIRTUAL_POOL_SIZE = 20;
private const VIRTUAL_NICKNAME_PREFIXES = [
'看台',
'深夜',
'边线',
'北区',
'南看台',
'东门',
'西街',
'慢热',
'小酒馆',
'补时',
'角旗',
'传中',
'临场',
'半场',
'球门后',
'旧球鞋',
'赛点',
'风向',
'追球',
'回防',
];
private const VIRTUAL_NICKNAME_SUFFIXES = [
'阿泽',
'小顾',
'老韩',
'阿凯',
'小唐',
'阿林',
'阿松',
'阿北',
'阿岳',
'阿诚',
];
public static function tick(int $seedLimit = 10, int $processLimit = 20): array
{
@@ -158,12 +191,32 @@ class ArticleAiCommentService
protected static function ensureVirtualUsers(int $targetCount = self::VIRTUAL_POOL_SIZE): array
{
$existing = User::where('account', 'like', self::VIRTUAL_ACCOUNT_PREFIX . '%')
$existingRows = User::where('account', 'like', self::VIRTUAL_ACCOUNT_PREFIX . '%')
->order('id', 'asc')
->column('id');
->field('id,account,nickname')
->select()
->toArray();
$existing = array_values(array_map('intval', $existing));
$existing = [];
foreach ($existingRows as $row) {
$existing[] = (int) $row['id'];
}
$missing = max(0, $targetCount - count($existing));
$now = time();
foreach ($existingRows as $row) {
$index = self::parseAccountIndex((string) ($row['account'] ?? ''));
if ($index <= 0) {
continue;
}
$expectedNickname = self::buildVirtualNickname($index);
if (($row['nickname'] ?? '') !== $expectedNickname) {
User::update([
'id' => (int) $row['id'],
'nickname' => $expectedNickname,
'update_time' => $now,
]);
}
}
if ($missing > 0) {
$avatar = (string) Config::get('project.default_image.user_avatar', '');
$passwordSalt = (string) Config::get('project.unique_identification', 'sport-era');
@@ -177,7 +230,7 @@ class ArticleAiCommentService
'sn' => $sn,
'avatar' => $avatar,
'real_name' => '',
'nickname' => self::VIRTUAL_NICKNAME_PREFIX . str_pad((string) $accountIndex, 2, '0', STR_PAD_LEFT),
'nickname' => self::buildVirtualNickname($accountIndex),
'account' => self::VIRTUAL_ACCOUNT_PREFIX . str_pad((string) $accountIndex, 4, '0', STR_PAD_LEFT),
'password' => $password,
'mobile' => '',
@@ -196,6 +249,22 @@ class ArticleAiCommentService
return $existing;
}
protected static function buildVirtualNickname(int $index): string
{
$zeroBased = max(0, $index - 1);
$prefix = self::VIRTUAL_NICKNAME_PREFIXES[$zeroBased % count(self::VIRTUAL_NICKNAME_PREFIXES)];
$suffix = self::VIRTUAL_NICKNAME_SUFFIXES[intdiv($zeroBased, count(self::VIRTUAL_NICKNAME_PREFIXES)) % count(self::VIRTUAL_NICKNAME_SUFFIXES)];
return $prefix . $suffix;
}
protected static function parseAccountIndex(string $account): int
{
if (!preg_match('/(\d+)$/', $account, $matches)) {
return 0;
}
return (int) $matches[1];
}
protected static function resolveTaskCount(array $article): int
{
$commentCount = (int) ($article['comment_count'] ?? 0);