优化游戏配置信息展示-只显示当前渠道
This commit is contained in:
@@ -4,6 +4,7 @@ namespace app\admin\controller\game;
|
||||
|
||||
use Throwable;
|
||||
use app\common\controller\Backend;
|
||||
use support\think\Db;
|
||||
use support\Response;
|
||||
use Webman\Http\Request as WebmanRequest;
|
||||
|
||||
@@ -19,6 +20,21 @@ class Config extends Backend
|
||||
*/
|
||||
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 array $withJoinTable = ['channel'];
|
||||
@@ -36,6 +52,27 @@ class Config extends Backend
|
||||
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
|
||||
*/
|
||||
@@ -55,8 +92,15 @@ class Config extends Backend
|
||||
return $this->error($err);
|
||||
}
|
||||
|
||||
if ($this->dataLimit && $this->dataLimitFieldAutoFill) {
|
||||
$data[$this->dataLimitField] = $this->auth->id;
|
||||
if (!$this->auth->isSuperAdmin()) {
|
||||
$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;
|
||||
|
||||
Reference in New Issue
Block a user