游戏-渠道管理-优化样式增强验证,新增关联删除
This commit is contained in:
47
app/common/service/GameChannelUserCount.php
Normal file
47
app/common/service/GameChannelUserCount.php
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user