feat(tests): 添加结算相关功能的测试用例,增强代码覆盖率
This commit is contained in:
@@ -36,6 +36,10 @@ final class AgentGameSettlementRecorder
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->hasActiveShareLedger($item->id)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$player = $item->player;
|
||||
if ($player === null) {
|
||||
return;
|
||||
@@ -168,6 +172,20 @@ final class AgentGameSettlementRecorder
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
/** 原分账行存在且尚未被冲正时视为活跃,禁止重复入账。 */
|
||||
private function hasActiveShareLedger(int $ticketItemId): bool
|
||||
{
|
||||
return DB::table('share_ledger as sl')
|
||||
->where('sl.ticket_item_id', $ticketItemId)
|
||||
->whereNull('sl.reversal_of_id')
|
||||
->whereNotExists(function ($query): void {
|
||||
$query->selectRaw('1')
|
||||
->from('share_ledger as rev')
|
||||
->whereColumn('rev.reversal_of_id', 'sl.id');
|
||||
})
|
||||
->exists();
|
||||
}
|
||||
|
||||
private function normalizeRate(float $rate): float
|
||||
{
|
||||
return max(0.0, min(1.0, $rate));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
Reference in New Issue
Block a user