银行枚举
parent
b9fa29ac14
commit
7308a7d663
|
|
@ -3,6 +3,7 @@
|
||||||
namespace App\Endpoint\Api\Http\Controllers;
|
namespace App\Endpoint\Api\Http\Controllers;
|
||||||
|
|
||||||
use App\Endpoint\Api\Http\Resources\UserBankResource;
|
use App\Endpoint\Api\Http\Resources\UserBankResource;
|
||||||
|
use App\Enums\Bank;
|
||||||
use App\Models\UserBank;
|
use App\Models\UserBank;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
|
|
||||||
|
|
@ -11,21 +12,7 @@ class UserBankController extends Controller
|
||||||
public function options(Request $request)
|
public function options(Request $request)
|
||||||
{
|
{
|
||||||
return response()->json([
|
return response()->json([
|
||||||
'banks' => [
|
'banks' => array_values(Bank::banks()),
|
||||||
'中国建设银行',
|
|
||||||
'中国农业银行',
|
|
||||||
'中国工商银行',
|
|
||||||
'中国银行',
|
|
||||||
'交通银行',
|
|
||||||
'招商银行',
|
|
||||||
'民生银行',
|
|
||||||
'兴业银行',
|
|
||||||
'中信实业银行',
|
|
||||||
'上海浦东发展银行',
|
|
||||||
'光大银行',
|
|
||||||
'邮政储蓄银行',
|
|
||||||
'平安银行',
|
|
||||||
],
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,64 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Enums;
|
||||||
|
|
||||||
|
enum Bank {
|
||||||
|
case CCB;
|
||||||
|
case ABC;
|
||||||
|
case ICBC;
|
||||||
|
case BOC;
|
||||||
|
case COMM;
|
||||||
|
case CMB;
|
||||||
|
case CMBC;
|
||||||
|
case CIB;
|
||||||
|
case CITIC;
|
||||||
|
case SPDB;
|
||||||
|
case CEB;
|
||||||
|
case PSBC;
|
||||||
|
case PINGANBK;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return string
|
||||||
|
*/
|
||||||
|
public function bankName(): string
|
||||||
|
{
|
||||||
|
return static::banks()[$this->name];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $bankName
|
||||||
|
* @return static
|
||||||
|
*/
|
||||||
|
public static function tryFromBankName(string $bankName): ?static
|
||||||
|
{
|
||||||
|
foreach (static::cases() as $enum) {
|
||||||
|
if ($enum->bankName() === $bankName) {
|
||||||
|
return $enum;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public static function banks(): array
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
static::CCB->name => '中国建设银行',
|
||||||
|
static::ABC->name => '中国农业银行',
|
||||||
|
static::ICBC->name => '中国工商银行',
|
||||||
|
static::BOC->name => '中国银行',
|
||||||
|
static::COMM->name => '交通银行',
|
||||||
|
static::CMB->name => '招商银行',
|
||||||
|
static::CMBC->name => '民生银行',
|
||||||
|
static::CIB->name => '兴业银行',
|
||||||
|
static::CITIC->name => '中信实业银行',
|
||||||
|
static::SPDB->name => '上海浦东发展银行',
|
||||||
|
static::CEB->name => '光大银行',
|
||||||
|
static::PSBC->name => '邮政储蓄银行',
|
||||||
|
static::PINGANBK->name => '平安银行',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue