- 在多个控制器中引入 SettlementPartyEnrichment 服务,以优化代理结算和账单的处理逻辑。 - 更新 AgentSettlementBillIndexController 和 AgentSettlementBillShowController,支持根据账单 ID 和关键字进行查询。 - 在 AgentSettlementPeriodCloseController 中添加对站点管理权限的验证,确保只有具备相应权限的管理员能够关闭账期。 - 在 AgentSettlementPeriodIndexController 中更新账期数据的返回格式,提升数据的完整性和可用性。 - 引入对相对占成比例的支持,增强代理资料的管理能力,确保数据一致性。
101 lines
3.4 KiB
PHP
101 lines
3.4 KiB
PHP
<?php
|
|
|
|
use App\Models\AdminUser;
|
|
use App\Services\AgentSettlement\SettlementPaymentService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
test('payment record uses counterparty as payer when player wins', function (): void {
|
|
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
|
|
$periodId = (int) DB::table('settlement_periods')->insertGetId([
|
|
'admin_site_id' => $siteId,
|
|
'period_start' => now()->subWeek(),
|
|
'period_end' => now(),
|
|
'status' => 'closed',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$billId = (int) DB::table('settlement_bills')->insertGetId([
|
|
'settlement_period_id' => $periodId,
|
|
'bill_type' => 'player',
|
|
'owner_type' => 'player',
|
|
'owner_id' => 1,
|
|
'counterparty_type' => 'agent',
|
|
'counterparty_id' => 1,
|
|
'net_amount' => -500,
|
|
'unpaid_amount' => 500,
|
|
'paid_amount' => 0,
|
|
'status' => 'confirmed',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$admin = AdminUser::query()->create([
|
|
'username' => 'pay_dir_super',
|
|
'name' => 'PayDir',
|
|
'email' => null,
|
|
'password' => Hash::make('secret-strong'),
|
|
'status' => 0,
|
|
]);
|
|
grantSuperAdminRole($admin);
|
|
|
|
app(SettlementPaymentService::class)->recordPayment($billId, 500, (int) $admin->id, [
|
|
'method' => 'cash',
|
|
]);
|
|
|
|
$record = DB::table('payment_records')->where('settlement_bill_id', $billId)->first();
|
|
expect($record)->not->toBeNull();
|
|
expect((string) $record->payer_type)->toBe('agent');
|
|
expect((int) $record->payer_id)->toBe(1);
|
|
expect((string) $record->payee_type)->toBe('player');
|
|
expect((int) $record->payee_id)->toBe(1);
|
|
});
|
|
|
|
test('payment record uses owner as payer when player loses', function (): void {
|
|
$siteId = (int) DB::table('admin_sites')->where('is_default', true)->value('id');
|
|
$periodId = (int) DB::table('settlement_periods')->insertGetId([
|
|
'admin_site_id' => $siteId,
|
|
'period_start' => now()->subWeek(),
|
|
'period_end' => now(),
|
|
'status' => 'closed',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$billId = (int) DB::table('settlement_bills')->insertGetId([
|
|
'settlement_period_id' => $periodId,
|
|
'bill_type' => 'player',
|
|
'owner_type' => 'player',
|
|
'owner_id' => 1,
|
|
'counterparty_type' => 'agent',
|
|
'counterparty_id' => 1,
|
|
'net_amount' => 800,
|
|
'unpaid_amount' => 800,
|
|
'paid_amount' => 0,
|
|
'status' => 'confirmed',
|
|
'created_at' => now(),
|
|
'updated_at' => now(),
|
|
]);
|
|
|
|
$admin = AdminUser::query()->create([
|
|
'username' => 'pay_dir_super2',
|
|
'name' => 'PayDir2',
|
|
'email' => null,
|
|
'password' => Hash::make('secret-strong'),
|
|
'status' => 0,
|
|
]);
|
|
grantSuperAdminRole($admin);
|
|
|
|
app(SettlementPaymentService::class)->recordPayment($billId, 800, (int) $admin->id);
|
|
|
|
$record = DB::table('payment_records')->where('settlement_bill_id', $billId)->first();
|
|
expect((string) $record->payer_type)->toBe('player');
|
|
expect((int) $record->payer_id)->toBe(1);
|
|
expect((string) $record->payee_type)->toBe('agent');
|
|
expect((int) $record->payee_id)->toBe(1);
|
|
});
|