feat: 添加货币格式化功能,更新多个控制器以支持金额和余额的格式化显示,增强 API 响应的可读性
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\CurrencyResolver;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
/**
|
||||
@@ -53,14 +54,19 @@ final class WalletBalanceController extends Controller
|
||||
|
||||
$balance = (int) $wallet->balance;
|
||||
$frozen = (int) $wallet->frozen_balance;
|
||||
$available = max(0, $balance - $frozen);
|
||||
|
||||
return ApiResponse::success([
|
||||
'balance' => $balance,
|
||||
'available_balance' => max(0, $balance - $frozen),
|
||||
'balance_formatted' => CurrencyFormatter::fromMinor($balance),
|
||||
'available_balance' => $available,
|
||||
'available_balance_formatted' => CurrencyFormatter::fromMinor($available),
|
||||
'main_balance' => null,
|
||||
'main_balance_formatted' => null,
|
||||
'currency_code' => $wallet->currency_code,
|
||||
'wallet_type' => $wallet->wallet_type,
|
||||
'frozen_balance' => $frozen,
|
||||
'frozen_balance_formatted' => CurrencyFormatter::fromMinor($frozen),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user