feat: 增强玩家管理功能,集成接入站点权限控制
在多个玩家相关控制器中引入 AdminSiteScope,确保管理员在执行操作前具备相应的接入站点权限。更新 Player 相关请求以支持 site_code 参数,增强权限验证逻辑,确保系统安全性与灵活性。同时,新增 AdminUser 模型方法以获取可访问的站点 ID 列表,优化权限管理。
This commit is contained in:
73
app/Models/AdminSite.php
Normal file
73
app/Models/AdminSite.php
Normal file
@@ -0,0 +1,73 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
/**
|
||||
* 后台站点 / 主站接入配置({@see $table admin_sites})。
|
||||
*
|
||||
* `code` 对外即 JWT 与钱包回调中的 `site_code`,创建后不可修改。
|
||||
*/
|
||||
final class AdminSite extends Model
|
||||
{
|
||||
protected $table = 'admin_sites';
|
||||
|
||||
protected $fillable = [
|
||||
'code',
|
||||
'name',
|
||||
'currency_code',
|
||||
'status',
|
||||
'is_default',
|
||||
'extra_json',
|
||||
'wallet_api_url',
|
||||
'wallet_debit_path',
|
||||
'wallet_credit_path',
|
||||
'wallet_balance_path',
|
||||
'wallet_api_key_encrypted',
|
||||
'sso_jwt_secret_encrypted',
|
||||
'wallet_timeout_seconds',
|
||||
'iframe_allowed_origins',
|
||||
'lottery_h5_base_url',
|
||||
'notes',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'status' => 'integer',
|
||||
'is_default' => 'boolean',
|
||||
'extra_json' => 'array',
|
||||
'iframe_allowed_origins' => 'array',
|
||||
'wallet_timeout_seconds' => 'integer',
|
||||
];
|
||||
}
|
||||
|
||||
public function isEnabled(): bool
|
||||
{
|
||||
return (int) $this->status === 1;
|
||||
}
|
||||
|
||||
public function decryptedSsoJwtSecret(): ?string
|
||||
{
|
||||
return $this->decryptSecret($this->sso_jwt_secret_encrypted);
|
||||
}
|
||||
|
||||
public function decryptedWalletApiKey(): ?string
|
||||
{
|
||||
return $this->decryptSecret($this->wallet_api_key_encrypted);
|
||||
}
|
||||
|
||||
private function decryptSecret(?string $encrypted): ?string
|
||||
{
|
||||
if (! is_string($encrypted) || $encrypted === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
return decrypt($encrypted);
|
||||
} catch (\Throwable) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -114,6 +114,28 @@ final class AdminUser extends Authenticatable
|
||||
return $this->roles()->where('admin_roles.slug', self::ROLE_SUPER_ADMIN)->exists();
|
||||
}
|
||||
|
||||
/**
|
||||
* 可访问的 admin_sites.id 列表;`null` 表示不限制(超管)。
|
||||
*
|
||||
* @return list<int>|null
|
||||
*/
|
||||
public function accessibleAdminSiteIds(): ?array
|
||||
{
|
||||
if ($this->isSuperAdmin()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$ids = DB::table('admin_user_site_roles')
|
||||
->where('admin_user_id', $this->id)
|
||||
->distinct()
|
||||
->pluck('site_id')
|
||||
->map(static fn ($id): int => (int) $id)
|
||||
->values()
|
||||
->all();
|
||||
|
||||
return $ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* 仅来自「直接授权」的 menu_action.permission_code(默认站点,含 site_id 为 null 的历史行)。
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user