游戏-渠道管理-优化样式增强验证,新增关联删除

This commit is contained in:
2026-04-03 17:49:46 +08:00
parent 6b830f4e25
commit 28bd9f1a09
7 changed files with 578 additions and 26 deletions

View File

@@ -0,0 +1,47 @@
<?php
declare(strict_types=1);
namespace app\common\service;
use support\think\Db;
/**
* 按 game_user 表统计各渠道用户数,回写 game_channel.user_count
*/
class GameChannelUserCount
{
/**
* 统计 game_user.game_channel_id = 该渠道 id 的行数,更新 game_channel.user_count
*/
public static function syncFromGameUser(int|string|null $channelId): void
{
if ($channelId === null || $channelId === '') {
return;
}
if (is_numeric($channelId) && (float) $channelId < 1) {
return;
}
$count = Db::name('game_user')->where('game_channel_id', $channelId)->count();
Db::name('game_channel')->where('id', $channelId)->update(['user_count' => $count]);
}
/**
* @param list<int|string|null> $channelIds
*/
public static function syncChannels(array $channelIds): void
{
$seen = [];
foreach ($channelIds as $cid) {
if ($cid === null || $cid === '') {
continue;
}
$k = (string) $cid;
if (isset($seen[$k])) {
continue;
}
$seen[$k] = true;
self::syncFromGameUser($cid);
}
}
}