feat: 添加货币格式化功能,更新多个控制器以支持金额和余额的格式化显示,增强 API 响应的可读性

This commit is contained in:
2026-05-13 11:59:50 +08:00
parent 805847954d
commit d8e9fa5f4c
8 changed files with 60 additions and 22 deletions

View File

@@ -9,6 +9,7 @@ use Illuminate\Http\Request;
use App\Models\TransferOrder;
use App\Support\PaginationTrait;
use Illuminate\Http\JsonResponse;
use App\Support\CurrencyFormatter;
use App\Http\Controllers\Controller;
/**
@@ -123,16 +124,21 @@ final class WalletLogsController extends Controller
private function formatTxn(WalletTxn $txn): array
{
$currency = $txn->wallet?->currency_code ?? '';
$amount = (int) $txn->amount;
$balanceAfter = (int) $txn->balance_after;
return [
'log_id' => $txn->txn_no,
'type' => $this->bizToPublicType((string) $txn->biz_type),
'biz_type' => $txn->biz_type,
'amount' => $this->signedAmount($txn),
'amount_abs' => (int) $txn->amount,
'amount_formatted' => CurrencyFormatter::fromMinor($amount),
'amount_abs' => $amount,
'amount_abs_formatted' => CurrencyFormatter::fromMinor($amount),
'direction' => (int) $txn->direction === 1 ? 'in' : 'out',
'currency_code' => $currency,
'balance_after' => (int) $txn->balance_after,
'balance_after' => $balanceAfter,
'balance_after_formatted' => CurrencyFormatter::fromMinor($balanceAfter),
'ref_id' => $txn->biz_no,
'idempotent_key' => $txn->idempotent_key,
'external_ref_no' => $txn->external_ref_no,
@@ -162,12 +168,15 @@ final class WalletLogsController extends Controller
*/
private function formatPendingOrder(TransferOrder $order): array
{
$amount = (int) $order->amount;
return [
'transfer_no' => $order->transfer_no,
'direction' => $order->direction,
'type' => $order->direction === 'in' ? 'transfer_in' : 'transfer_out',
'currency_code' => $order->currency_code,
'amount' => (int) $order->amount,
'amount' => $amount,
'amount_formatted' => CurrencyFormatter::fromMinor($amount),
'status' => $order->status,
'fail_reason' => $order->fail_reason,
'idempotent_key' => $order->idempotent_key,