- 在多个控制器中更新权限检查逻辑,确保管理员能够更灵活地管理代理和玩家。 - 在 AdminPlayerStoreController 中引入对玩家创建能力的验证,确保只有具备相应权限的管理员能够创建玩家。 - 更新请求验证逻辑,新增 credit_limit、rebate_rate 和 extra_rebate_rate 字段,以支持更细粒度的玩家管理。 - 在 AgentNodeProfileController 中添加对父代理能力授予的验证,确保子代理的权限在父代理范围内。 - 引入 AgentProfileFieldRules 以简化代理资料更新请求的规则定义,提升代码复用性。
140 lines
4.7 KiB
PHP
140 lines
4.7 KiB
PHP
<?php
|
|
|
|
use App\Models\Player;
|
|
use App\Support\PlayerAuthSource;
|
|
use App\Support\PlayerFundingMode;
|
|
use Database\Seeders\CurrencySeeder;
|
|
use Database\Seeders\LotterySettingsSeeder;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
config([
|
|
'lottery.player_auth.native.secret' => 'test-native-jwt-secret-32bytes!!',
|
|
'lottery.player_auth.native.ttl_seconds' => 3600,
|
|
'lottery.main_site.wallet_api_url' => null,
|
|
]);
|
|
$this->seed(CurrencySeeder::class);
|
|
$this->seed(LotterySettingsSeeder::class);
|
|
});
|
|
|
|
test('native player can login and access me', function (): void {
|
|
$site = DB::table('admin_sites')->where('is_default', true)->first();
|
|
$rootId = (int) DB::table('agent_nodes')->where('depth', 0)->value('id');
|
|
|
|
$player = Player::query()->create([
|
|
'site_code' => (string) $site->code,
|
|
'agent_node_id' => $rootId,
|
|
'site_player_id' => 'native:test-1',
|
|
'auth_source' => PlayerAuthSource::LOTTERY_NATIVE,
|
|
'funding_mode' => PlayerFundingMode::CREDIT,
|
|
'username' => 'agentplayer1',
|
|
'password_hash' => Hash::make('secret-pass'),
|
|
'nickname' => null,
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
]);
|
|
|
|
DB::table('player_credit_accounts')->insert([
|
|
'player_id' => $player->id,
|
|
'credit_limit' => 50000,
|
|
'used_credit' => 0,
|
|
'frozen_credit' => 0,
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$login = $this->postJson('/api/v1/player/auth/login', [
|
|
'site_code' => $site->code,
|
|
'username' => 'agentplayer1',
|
|
'password' => 'secret-pass',
|
|
]);
|
|
|
|
$login->assertOk();
|
|
$token = (string) $login->json('data.access_token');
|
|
expect($token)->not->toBe('');
|
|
|
|
$me = $this->withHeader('Authorization', 'Bearer '.$token)
|
|
->getJson('/api/v1/player/me');
|
|
|
|
$me->assertOk()
|
|
->assertJsonPath('data.id', $player->id)
|
|
->assertJsonPath('data.funding_mode', PlayerFundingMode::CREDIT)
|
|
->assertJsonPath('data.auth_source', PlayerAuthSource::LOTTERY_NATIVE);
|
|
});
|
|
|
|
test('credit player wallet transfer in is rejected', function (): void {
|
|
$site = DB::table('admin_sites')->where('is_default', true)->first();
|
|
$rootId = (int) DB::table('agent_nodes')->where('depth', 0)->value('id');
|
|
|
|
$player = Player::query()->create([
|
|
'site_code' => (string) $site->code,
|
|
'agent_node_id' => $rootId,
|
|
'site_player_id' => 'native:test-2',
|
|
'auth_source' => PlayerAuthSource::LOTTERY_NATIVE,
|
|
'funding_mode' => PlayerFundingMode::CREDIT,
|
|
'username' => 'agentplayer2',
|
|
'password_hash' => Hash::make('secret-pass'),
|
|
'nickname' => null,
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
]);
|
|
|
|
$auth = app(\App\Services\Player\PlayerNativeAuthService::class);
|
|
$token = $auth->issueToken($player);
|
|
|
|
$response = $this->withHeader('Authorization', 'Bearer '.$token)
|
|
->postJson('/api/v1/wallet/transfer-in', [
|
|
'amount' => 1000,
|
|
'idempotent_key' => 'native-ti-1',
|
|
'currency' => 'NPR',
|
|
]);
|
|
|
|
$response->assertJsonPath('code', 1011);
|
|
});
|
|
|
|
test('sso wallet player balance does not use credit when site credit mode on', function (): void {
|
|
$site = DB::table('admin_sites')->where('is_default', true)->first();
|
|
$extra = json_decode((string) ($site->extra_json ?? '{}'), true);
|
|
if (! is_array($extra)) {
|
|
$extra = [];
|
|
}
|
|
$extra['credit_line_mode'] = true;
|
|
DB::table('admin_sites')->where('id', $site->id)->update([
|
|
'extra_json' => json_encode($extra),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$player = Player::query()->create([
|
|
'site_code' => (string) $site->code,
|
|
'site_player_id' => 'sso-wallet-1',
|
|
'auth_source' => PlayerAuthSource::MAIN_SITE_SSO,
|
|
'funding_mode' => PlayerFundingMode::WALLET,
|
|
'username' => 'ssouser',
|
|
'nickname' => null,
|
|
'default_currency' => 'NPR',
|
|
'status' => 0,
|
|
]);
|
|
|
|
\App\Models\PlayerWallet::query()->create([
|
|
'player_id' => $player->id,
|
|
'wallet_type' => 'lottery',
|
|
'currency_code' => 'NPR',
|
|
'balance' => 12000,
|
|
'frozen_balance' => 0,
|
|
'status' => 0,
|
|
'version' => 0,
|
|
]);
|
|
|
|
$response = $this->withHeader('Authorization', 'Bearer dev:'.$player->id)
|
|
->getJson('/api/v1/wallet/balance?currency=NPR');
|
|
|
|
$response->assertOk()
|
|
->assertJsonPath('data.credit_line_mode', false)
|
|
->assertJsonPath('data.funding_mode', PlayerFundingMode::WALLET)
|
|
->assertJsonPath('data.available_balance', 12000);
|
|
});
|