更新 AdminJackpotPoolUpdateController 校验规则,禁止传入 current_amount。 优化 AdminRiskPoolManualStatusController:更新奖池状态后同步 Redis 状态。 在 TransferOrderReconcileController 中新增 completeCredit 方法,用于处理卡住的转账订单对账。 调整 TransferOrderListController:优化转账订单处理条件。 在 TicketItemsIndexController 中实现支持时区的日期筛选,提升日期处理准确性。 扩展 JackpotPool 模型,新增 adjustments 关联关系。 改进票据与钱包相关服务中的错误处理和事务管理。
111 lines
3.8 KiB
PHP
111 lines
3.8 KiB
PHP
<?php
|
|
|
|
use App\Models\AdminUser;
|
|
use App\Models\AuditLog;
|
|
use App\Models\JackpotPool;
|
|
use App\Models\JackpotPoolAdjustment;
|
|
use Database\Seeders\CurrencySeeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
|
|
uses(RefreshDatabase::class);
|
|
|
|
beforeEach(function (): void {
|
|
$this->seed(CurrencySeeder::class);
|
|
});
|
|
|
|
function jackpotAdjustAdminToken(): string
|
|
{
|
|
$admin = AdminUser::query()->create([
|
|
'username' => 'jackpot_adjust_admin',
|
|
'name' => 'Jackpot Adjust',
|
|
'email' => null,
|
|
'password' => Hash::make('secret-strong'),
|
|
'status' => 0,
|
|
]);
|
|
grantSuperAdminRole($admin);
|
|
|
|
return $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
|
|
}
|
|
|
|
test('admin cannot set current_amount via pool update', function (): void {
|
|
$pool = JackpotPool::query()->where('currency_code', 'NPR')->firstOrFail();
|
|
$token = jackpotAdjustAdminToken();
|
|
|
|
$this->withHeader('Authorization', 'Bearer '.$token)
|
|
->putJson('/api/v1/admin/jackpot/pools/'.$pool->id, [
|
|
'current_amount' => 9_999_999,
|
|
])
|
|
->assertStatus(422);
|
|
});
|
|
|
|
test('admin can apply jackpot pool balance adjustment with ledger row', function (): void {
|
|
$pool = JackpotPool::query()->where('currency_code', 'NPR')->firstOrFail();
|
|
$pool->forceFill(['current_amount' => 1_000])->save();
|
|
$token = jackpotAdjustAdminToken();
|
|
|
|
$this->withHeader('Authorization', 'Bearer '.$token)
|
|
->postJson('/api/v1/admin/jackpot/pools/'.$pool->id.'/adjustments', [
|
|
'amount_delta' => 500,
|
|
'reason' => 'manual top-up after reconciliation',
|
|
])
|
|
->assertOk()
|
|
->assertJsonPath('data.pool.current_amount', 1_500)
|
|
->assertJsonPath('data.adjustment.amount_delta', 500)
|
|
->assertJsonPath('data.adjustment.balance_before', 1_000)
|
|
->assertJsonPath('data.adjustment.balance_after', 1_500);
|
|
|
|
expect(JackpotPoolAdjustment::query()->where('jackpot_pool_id', $pool->id)->count())->toBe(1);
|
|
|
|
expect(
|
|
AuditLog::query()
|
|
->where('module_code', 'jackpot')
|
|
->where('action_code', 'adjust_balance')
|
|
->exists(),
|
|
)->toBeTrue();
|
|
});
|
|
|
|
test('admin jackpot adjustment rejects negative balance', function (): void {
|
|
$pool = JackpotPool::query()->where('currency_code', 'NPR')->firstOrFail();
|
|
$pool->forceFill(['current_amount' => 100])->save();
|
|
$token = jackpotAdjustAdminToken();
|
|
|
|
$this->withHeader('Authorization', 'Bearer '.$token)
|
|
->postJson('/api/v1/admin/jackpot/pools/'.$pool->id.'/adjustments', [
|
|
'amount_delta' => -200,
|
|
'reason' => 'correction',
|
|
])
|
|
->assertStatus(422);
|
|
|
|
expect((int) $pool->fresh()->current_amount)->toBe(100);
|
|
});
|
|
|
|
test('admin can list jackpot pool adjustments', function (): void {
|
|
$pool = JackpotPool::query()->where('currency_code', 'NPR')->firstOrFail();
|
|
$admin = AdminUser::query()->create([
|
|
'username' => 'adj_list_admin',
|
|
'name' => 'List',
|
|
'email' => null,
|
|
'password' => Hash::make('secret-strong'),
|
|
'status' => 0,
|
|
]);
|
|
grantSuperAdminRole($admin);
|
|
$token = $admin->createToken('test', ['*'], now()->addDay())->plainTextToken;
|
|
|
|
JackpotPoolAdjustment::query()->create([
|
|
'adjustment_no' => 'JA_TEST_1',
|
|
'jackpot_pool_id' => $pool->id,
|
|
'admin_user_id' => $admin->id,
|
|
'amount_delta' => 50,
|
|
'balance_before' => 0,
|
|
'balance_after' => 50,
|
|
'reason' => 'seed',
|
|
]);
|
|
|
|
$this->withHeader('Authorization', 'Bearer '.$token)
|
|
->getJson('/api/v1/admin/jackpot/pools/'.$pool->id.'/adjustments')
|
|
->assertOk()
|
|
->assertJsonPath('data.total', 1)
|
|
->assertJsonPath('data.items.0.adjustment_no', 'JA_TEST_1');
|
|
});
|