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

@@ -12,12 +12,15 @@ use App\Models\TicketOrder;
use App\Models\SettlementBatch;
use Illuminate\Support\Facades\DB;
use App\Lottery\SettlementBatchStatus;
use App\Services\AgentSettlement\GameSettlementReversalService;
use App\Services\Ticket\TicketWalletService;
use App\Support\PlayerFundingMode;
final class SettlementBatchWorkflowService
{
public function __construct(
private readonly TicketWalletService $wallet,
private readonly GameSettlementReversalService $gameSettlementReversal,
) {}
public function approve(SettlementBatch $batch, AdminUser $admin, ?string $remark = null): SettlementBatch
@@ -62,6 +65,11 @@ final class SettlementBatchWorkflowService
$itemIds = $locked->details()->pluck('ticket_item_id')->map(fn ($id) => (int) $id)->all();
if ($itemIds !== []) {
$items = TicketItem::query()->whereIn('id', $itemIds)->get();
foreach ($items as $item) {
$this->gameSettlementReversal->reverseTicketItem($item);
}
TicketItem::query()
->whereIn('id', $itemIds)
->update([
@@ -69,6 +77,7 @@ final class SettlementBatchWorkflowService
'win_amount' => 0,
'jackpot_win_amount' => 0,
'settled_at' => null,
'agent_settled_at' => null,
]);
}
@@ -153,6 +162,9 @@ final class SettlementBatchWorkflowService
continue;
}
$player = Player::query()->whereKey((int) $entry['player_id'])->firstOrFail();
if (PlayerFundingMode::usesCredit($player)) {
continue;
}
$this->wallet->creditSettlementPayout(
$player,
(string) $entry['currency_code'],