refactor:拆分 API 路由与请求校验,统一 final 类和代码风格
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
|
||||
namespace App\Http\Controllers\Api\V1\Wallet;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Models\Player;
|
||||
use App\Lottery\ErrorCode;
|
||||
use App\Models\PlayerWallet;
|
||||
use App\Support\ApiResponse;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Support\CurrencyResolver;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use App\Http\Controllers\Controller;
|
||||
|
||||
/**
|
||||
* 【玩家】查询彩票侧钱包余额。
|
||||
@@ -22,7 +23,7 @@ use Illuminate\Http\Request;
|
||||
* - `available_balance`:`balance - frozen_balance`,表示当前可用于下注的整数最小货币单位(不为负)
|
||||
* - `main_balance`:主站钱包余额占位,接入主站 API 后再返回实数;当前固定 `null`
|
||||
*/
|
||||
class WalletBalanceController extends Controller
|
||||
final class WalletBalanceController extends Controller
|
||||
{
|
||||
private const WALLET_TYPE_LOTTERY = 'lottery';
|
||||
|
||||
@@ -68,16 +69,9 @@ class WalletBalanceController extends Controller
|
||||
*/
|
||||
private function resolveCurrencyCode(Request $request, Player $player): string|JsonResponse
|
||||
{
|
||||
$raw = $request->query('currency');
|
||||
if (is_string($raw) && $raw !== '') {
|
||||
$code = strtoupper(substr(trim($raw), 0, 16));
|
||||
} else {
|
||||
$fallback = $player->default_currency ?? config('lottery.default_currency', 'NPR');
|
||||
$code = strtoupper(substr(trim((string) $fallback), 0, 16));
|
||||
}
|
||||
$code = CurrencyResolver::resolve($request, $player, 'currency');
|
||||
|
||||
// 币种码:字母数字,长度 1–16,与 migrations 字段一致
|
||||
if (! preg_match('/^[A-Z0-9]{1,16}$/', $code)) {
|
||||
if (! CurrencyResolver::isValid($code)) {
|
||||
return ApiResponse::error(
|
||||
__('wallet.invalid_currency'),
|
||||
ErrorCode::WalletInvalidCurrency->value,
|
||||
|
||||
Reference in New Issue
Block a user