在多个玩家相关控制器中引入 AdminSiteScope,确保管理员在执行操作前具备相应的接入站点权限。更新 Player 相关请求以支持 site_code 参数,增强权限验证逻辑,确保系统安全性与灵活性。同时,新增 AdminUser 模型方法以获取可访问的站点 ID 列表,优化权限管理。
83 lines
3.0 KiB
PHP
83 lines
3.0 KiB
PHP
<?php
|
||
|
||
namespace App\Services\Integration;
|
||
|
||
/**
|
||
* 运行时主站接入配置(由库表或 legacy env 解析而来)。
|
||
*/
|
||
final readonly class PartnerSiteConfig
|
||
{
|
||
public const SOURCE_DATABASE = 'database';
|
||
|
||
public const SOURCE_LEGACY_ENV = 'legacy_env';
|
||
|
||
public function __construct(
|
||
public string $siteCode,
|
||
public bool $enabled,
|
||
public ?string $walletApiUrl,
|
||
public string $walletDebitPath,
|
||
public string $walletCreditPath,
|
||
public string $walletBalancePath,
|
||
public ?string $ssoJwtSecret,
|
||
public ?string $walletApiKey,
|
||
public int $walletTimeoutSeconds,
|
||
public string $source,
|
||
) {}
|
||
|
||
public function hasWalletApi(): bool
|
||
{
|
||
return is_string($this->walletApiUrl) && trim($this->walletApiUrl) !== '';
|
||
}
|
||
|
||
public function hasSsoSecret(): bool
|
||
{
|
||
return is_string($this->ssoJwtSecret) && $this->ssoJwtSecret !== '';
|
||
}
|
||
|
||
/**
|
||
* 可安全写入 Cache 的数组形态(避免 readonly 对象序列化产生 __PHP_Incomplete_Class)。
|
||
*
|
||
* @return array<string, mixed>
|
||
*/
|
||
public function toCacheArray(): array
|
||
{
|
||
return [
|
||
'site_code' => $this->siteCode,
|
||
'enabled' => $this->enabled,
|
||
'wallet_api_url' => $this->walletApiUrl,
|
||
'wallet_debit_path' => $this->walletDebitPath,
|
||
'wallet_credit_path' => $this->walletCreditPath,
|
||
'wallet_balance_path' => $this->walletBalancePath,
|
||
'sso_jwt_secret' => $this->ssoJwtSecret,
|
||
'wallet_api_key' => $this->walletApiKey,
|
||
'wallet_timeout_seconds' => $this->walletTimeoutSeconds,
|
||
'source' => $this->source,
|
||
];
|
||
}
|
||
|
||
/**
|
||
* @param array<string, mixed> $data
|
||
*/
|
||
public static function fromCacheArray(array $data): self
|
||
{
|
||
return new self(
|
||
siteCode: (string) ($data['site_code'] ?? ''),
|
||
enabled: (bool) ($data['enabled'] ?? false),
|
||
walletApiUrl: isset($data['wallet_api_url']) && is_string($data['wallet_api_url']) && $data['wallet_api_url'] !== ''
|
||
? $data['wallet_api_url']
|
||
: null,
|
||
walletDebitPath: (string) ($data['wallet_debit_path'] ?? '/wallet/debit-for-lottery'),
|
||
walletCreditPath: (string) ($data['wallet_credit_path'] ?? '/wallet/credit-from-lottery'),
|
||
walletBalancePath: (string) ($data['wallet_balance_path'] ?? '/wallet/balance'),
|
||
ssoJwtSecret: isset($data['sso_jwt_secret']) && is_string($data['sso_jwt_secret']) && $data['sso_jwt_secret'] !== ''
|
||
? $data['sso_jwt_secret']
|
||
: null,
|
||
walletApiKey: isset($data['wallet_api_key']) && is_string($data['wallet_api_key']) && $data['wallet_api_key'] !== ''
|
||
? $data['wallet_api_key']
|
||
: null,
|
||
walletTimeoutSeconds: max(1, (int) ($data['wallet_timeout_seconds'] ?? 10)),
|
||
source: (string) ($data['source'] ?? self::SOURCE_DATABASE),
|
||
);
|
||
}
|
||
}
|