feat: 添加货币格式化功能,更新多个控制器以支持金额和余额的格式化显示,增强 API 响应的可读性
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Admin\Risk;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Models\Draw;
|
||||
use App\Models\RiskPool;
|
||||
use App\Models\RiskPoolLockLog;
|
||||
use App\Support\AdminApiList;
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\AdminApiList;
|
||||
use App\Models\RiskPoolLockLog;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
|
||||
|
||||
/**
|
||||
* GET /api/v1/admin/draws/{draw}/risk-pools/{number_4d} — 单号码风险池详情 + 占用流水。
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Support\ApiResponse;
|
||||
use App\Models\TransferOrder;
|
||||
use App\Support\PaginationTrait;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\TransferOrderListRequest;
|
||||
|
||||
@@ -96,6 +97,7 @@ final class TransferOrderListController extends Controller
|
||||
private function formatRow(TransferOrder $o): array
|
||||
{
|
||||
$p = $o->player;
|
||||
$amount = (int) $o->amount;
|
||||
|
||||
return [
|
||||
'id' => $o->id,
|
||||
@@ -107,7 +109,8 @@ final class TransferOrderListController extends Controller
|
||||
'nickname' => $p?->nickname,
|
||||
'direction' => $o->direction,
|
||||
'currency_code' => $o->currency_code,
|
||||
'amount' => (int) $o->amount,
|
||||
'amount' => $amount,
|
||||
'amount_formatted' => CurrencyFormatter::fromMinor($amount),
|
||||
'idempotent_key' => $o->idempotent_key,
|
||||
'status' => $o->status,
|
||||
'external_ref_no' => $o->external_ref_no,
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Models\WalletTxn;
|
||||
use App\Support\ApiResponse;
|
||||
use App\Support\PaginationTrait;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\Admin\WalletTransactionListRequest;
|
||||
|
||||
@@ -100,6 +101,9 @@ final class WalletTransactionListController extends Controller
|
||||
private function formatRow(WalletTxn $t): array
|
||||
{
|
||||
$p = $t->player;
|
||||
$amount = (int) $t->amount;
|
||||
$balanceBefore = (int) $t->balance_before;
|
||||
$balanceAfter = (int) $t->balance_after;
|
||||
|
||||
return [
|
||||
'id' => $t->id,
|
||||
@@ -112,15 +116,17 @@ final class WalletTransactionListController extends Controller
|
||||
'biz_type' => $t->biz_type,
|
||||
'biz_no' => $t->biz_no,
|
||||
'direction' => (int) $t->direction,
|
||||
'amount' => (int) $t->amount,
|
||||
'balance_before' => (int) $t->balance_before,
|
||||
'balance_after' => (int) $t->balance_after,
|
||||
'amount' => $amount,
|
||||
'amount_formatted' => CurrencyFormatter::fromMinor($amount),
|
||||
'balance_before' => $balanceBefore,
|
||||
'balance_before_formatted' => CurrencyFormatter::fromMinor($balanceBefore),
|
||||
'balance_after' => $balanceAfter,
|
||||
'balance_after_formatted' => CurrencyFormatter::fromMinor($balanceAfter),
|
||||
'status' => $t->status,
|
||||
'external_ref_no' => $t->external_ref_no,
|
||||
'idempotent_key' => $t->idempotent_key,
|
||||
'remark' => $t->remark,
|
||||
'created_at' => $t->created_at?->toIso8601String(),
|
||||
/** 展示用「完成时间」;无业务终态时可与 created_at 相同 */
|
||||
'updated_at' => $t->updated_at?->toIso8601String(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ use App\Models\JackpotPool;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
/**
|
||||
@@ -25,10 +26,13 @@ final class JackpotSummaryController extends Controller
|
||||
->where('status', 1)
|
||||
->first();
|
||||
|
||||
$amountMinor = $pool !== null ? (int) $pool->current_amount : 0;
|
||||
|
||||
return ApiResponse::success([
|
||||
'currency_code' => $currency,
|
||||
'enabled' => $pool !== null,
|
||||
'current_amount_minor' => $pool !== null ? (int) $pool->current_amount : 0,
|
||||
'current_amount_minor' => $amountMinor,
|
||||
'current_amount_formatted' => CurrencyFormatter::fromMinor($amountMinor),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ use App\Support\ApiResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\PaginationTrait;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Support\CurrencyFormatter;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
/**
|
||||
@@ -42,6 +43,11 @@ final class TicketItemsIndexController extends Controller
|
||||
$paginator = $query->paginate(perPage: $perPage, page: $page);
|
||||
|
||||
$items = collect($paginator->items())->map(function (TicketItem $row): array {
|
||||
$totalBet = (int) $row->total_bet_amount;
|
||||
$actualDeduct = (int) $row->actual_deduct_amount;
|
||||
$winAmount = (int) $row->win_amount;
|
||||
$jackpotWin = (int) $row->jackpot_win_amount;
|
||||
|
||||
return [
|
||||
'ticket_no' => $row->ticket_no,
|
||||
'order_no' => $row->order?->order_no,
|
||||
@@ -49,11 +55,15 @@ final class TicketItemsIndexController extends Controller
|
||||
'currency_code' => $row->order?->currency_code,
|
||||
'play_code' => $row->play_code,
|
||||
'original_number' => $row->original_number,
|
||||
'total_bet_amount' => (int) $row->total_bet_amount,
|
||||
'actual_deduct_amount' => (int) $row->actual_deduct_amount,
|
||||
'total_bet_amount' => $totalBet,
|
||||
'total_bet_amount_formatted' => CurrencyFormatter::fromMinor($totalBet),
|
||||
'actual_deduct_amount' => $actualDeduct,
|
||||
'actual_deduct_amount_formatted' => CurrencyFormatter::fromMinor($actualDeduct),
|
||||
'status' => $row->status,
|
||||
'win_amount' => (int) $row->win_amount,
|
||||
'jackpot_win_amount' => (int) $row->jackpot_win_amount,
|
||||
'win_amount' => $winAmount,
|
||||
'win_amount_formatted' => CurrencyFormatter::fromMinor($winAmount),
|
||||
'jackpot_win_amount' => $jackpotWin,
|
||||
'jackpot_win_amount_formatted' => CurrencyFormatter::fromMinor($jackpotWin),
|
||||
'placed_at' => $row->order?->created_at?->toIso8601String(),
|
||||
'updated_at' => $row->updated_at?->toIso8601String(),
|
||||
];
|
||||
|
||||
@@ -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),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -18,7 +18,7 @@ final class AdminMessage
|
||||
/**
|
||||
* 取通用管理后台错误的用户可见文案(lang/{locale}/admin.php)。
|
||||
*
|
||||
* @param string $key 语言包键名,如 'unauthenticated', 'permission_denied'
|
||||
* @param string $key 语言包键名,如 'unauthenticated', 'permission_denied'
|
||||
*/
|
||||
public static function get(Request $request, string $key): string
|
||||
{
|
||||
@@ -38,7 +38,7 @@ final class AdminMessage
|
||||
/**
|
||||
* 取错误码对应的用户可见文案。
|
||||
*
|
||||
* @param int $code {@see ErrorCode} 管理端段(8110–8114)
|
||||
* @param int $code {@see ErrorCode} 管理端段(8110–8114)
|
||||
*/
|
||||
public static function errorCode(Request $request, int $code): string
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user