feat(tests): 添加结算相关功能的测试用例,增强代码覆盖率
Some checks failed
lotterLaravel CI / test (push) Has been cancelled
lotterLaravel E2E / e2e-api (push) Has been cancelled

This commit is contained in:
2026-06-30 11:41:49 +08:00
parent c83343e989
commit 200269196e
7 changed files with 508 additions and 31 deletions

View File

@@ -27,26 +27,25 @@ final class AgentSettlementPeriodCloseService
{
AgentSettlementProductionGuard::assertProductionCloseAllowed();
$period = DB::table('settlement_periods')->where('id', $periodId)->first();
if ($period === null) {
throw ValidationException::withMessages([
'period' => ['period_not_found'],
]);
}
return DB::transaction(function () use ($periodId): array {
$period = DB::table('settlement_periods')->where('id', $periodId)->lockForUpdate()->first();
if ($period === null) {
throw ValidationException::withMessages([
'period' => ['period_not_found'],
]);
}
if ((string) $period->status === 'closed' || (string) $period->status === 'completed') {
throw ValidationException::withMessages([
'period' => ['period_already_closed'],
]);
}
if ((string) $period->status === 'closed' || (string) $period->status === 'completed') {
throw ValidationException::withMessages([
'period' => ['period_already_closed'],
]);
}
$adminSiteId = (int) $period->admin_site_id;
[$periodStart, $periodEnd] = AgentSettlementPeriodWindow::boundStrings(
(string) $period->period_start,
(string) $period->period_end,
);
return DB::transaction(function () use ($periodId, $period, $adminSiteId, $periodStart, $periodEnd): array {
$adminSiteId = (int) $period->admin_site_id;
[$periodStart, $periodEnd] = AgentSettlementPeriodWindow::boundStrings(
(string) $period->period_start,
(string) $period->period_end,
);
try {
$aggregate = $this->aggregator->aggregate($adminSiteId, $periodStart, $periodEnd);
} catch (\InvalidArgumentException $e) {