新增全局流水号

This commit is contained in:
2026-08-25 05:33:01 +08:00
parent 90fd59b647
commit 07c4e969c3
33 changed files with 1176 additions and 73 deletions
+3 -1
View File
@@ -16,7 +16,8 @@ final class LedgerResult {
public readonly int $transaction_id,
public readonly bool $replayed,
public readonly array $entries,
public readonly array $balances
public readonly array $balances,
public readonly string $flow_number = ''
) {}
public function balance(int $user_id, AssetType|string $asset): int {
@@ -31,6 +32,7 @@ final class LedgerResult {
'replayed' => $this->replayed,
'entries' => $this->entries,
'balances' => $this->balances,
'flow_number' => $this->flow_number,
];
}
}
+12 -1
View File
@@ -409,6 +409,16 @@ final class LedgerService {
throw new \RuntimeException('ledger_business_mutation_failed');
}
}
$flow_number = \AKSRT\Finance\FinancialFlowService::get_instance()->record_ledger(
$command,
$transaction_id,
$written_entries,
$created_at
);
if (is_wp_error($flow_number)) {
throw new LedgerAbort($flow_number);
}
$result = new LedgerResult($transaction_id, false, $written_entries, $projected_balances, $flow_number);
if ($wpdb->query('COMMIT') === false) {
throw new \RuntimeException('ledger_commit_failed');
}
@@ -479,7 +489,8 @@ final class LedgerService {
$balances[$entry['user_id']][(string) $entry['asset']] = $entry['balance_after_minor'];
}
unset($entry);
return new LedgerResult($transaction_id, $replayed, (array) $entries, $balances);
$flow_number = \AKSRT\Finance\FinancialFlowService::get_instance()->number_for_ledger_transaction($transaction_id);
return new LedgerResult($transaction_id, $replayed, (array) $entries, $balances, $flow_number);
}
private function db_error(int $errno, string $detail = ''): \WP_Error {