优化游戏配置信息展示-只显示当前渠道

This commit is contained in:
2026-04-02 11:37:07 +08:00
parent e9122c5850
commit 262906c46d

View File

@@ -4,6 +4,7 @@ namespace app\admin\controller\game;
use Throwable; use Throwable;
use app\common\controller\Backend; use app\common\controller\Backend;
use support\think\Db;
use support\Response; use support\Response;
use Webman\Http\Request as WebmanRequest; use Webman\Http\Request as WebmanRequest;
@@ -19,6 +20,21 @@ class Config extends Backend
*/ */
protected ?object $model = null; protected ?object $model = null;
/**
* 数据范围:非超管仅本人 + 下级角色组内管理员game_config 无 admin_id通过 channel_id 关联 game_channel.admin_id 限定
*/
protected bool|string|int $dataLimit = 'parent';
/**
* 列表/删除等条件字段为 channel_id见 {@see getDataLimitAdminIds()} 实际返回渠道 ID
*/
protected string $dataLimitField = 'channel_id';
/**
* 表无 admin_id勿自动写入
*/
protected bool $dataLimitFieldAutoFill = false;
protected string|array $defaultSortField = 'group,desc'; protected string|array $defaultSortField = 'group,desc';
protected array $withJoinTable = ['channel']; protected array $withJoinTable = ['channel'];
@@ -36,6 +52,27 @@ class Config extends Backend
return null; return null;
} }
/**
* 将「可访问管理员 ID」转为「其负责的渠道 ID」供 queryBuilder 使用 channel_id IN (...)
*
* @return list<int|string>
*/
protected function getDataLimitAdminIds(): array
{
if (!$this->dataLimit || !$this->auth || $this->auth->isSuperAdmin()) {
return [];
}
$adminIds = parent::getDataLimitAdminIds();
if ($adminIds === []) {
return [];
}
$channelIds = Db::name('game_channel')->where('admin_id', 'in', $adminIds)->column('id');
if ($channelIds === []) {
return [-1];
}
return array_values(array_unique($channelIds));
}
/** /**
* @throws Throwable * @throws Throwable
*/ */
@@ -55,8 +92,15 @@ class Config extends Backend
return $this->error($err); return $this->error($err);
} }
if ($this->dataLimit && $this->dataLimitFieldAutoFill) { if (!$this->auth->isSuperAdmin()) {
$data[$this->dataLimitField] = $this->auth->id; $allowedChannelIds = $this->getDataLimitAdminIds();
$cid = $data['channel_id'] ?? null;
if ($cid === null || $cid === '') {
return $this->error(__('Parameter %s can not be empty', ['channel_id']));
}
if ($allowedChannelIds !== [] && !in_array($cid, $allowedChannelIds)) {
return $this->error(__('You have no permission'));
}
} }
$result = false; $result = false;