From 7308a7d663f5749d96512c6a343cfae6a5906976 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E9=9D=99?= Date: Mon, 11 Apr 2022 17:27:47 +0800 Subject: [PATCH] =?UTF-8?q?=E9=93=B6=E8=A1=8C=E6=9E=9A=E4=B8=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Http/Controllers/UserBankController.php | 17 +---- app/Enums/Bank.php | 64 +++++++++++++++++++ 2 files changed, 66 insertions(+), 15 deletions(-) create mode 100644 app/Enums/Bank.php diff --git a/app/Endpoint/Api/Http/Controllers/UserBankController.php b/app/Endpoint/Api/Http/Controllers/UserBankController.php index 9cc56a76..9a45f112 100644 --- a/app/Endpoint/Api/Http/Controllers/UserBankController.php +++ b/app/Endpoint/Api/Http/Controllers/UserBankController.php @@ -3,6 +3,7 @@ namespace App\Endpoint\Api\Http\Controllers; use App\Endpoint\Api\Http\Resources\UserBankResource; +use App\Enums\Bank; use App\Models\UserBank; use Illuminate\Http\Request; @@ -11,21 +12,7 @@ class UserBankController extends Controller public function options(Request $request) { return response()->json([ - 'banks' => [ - '中国建设银行', - '中国农业银行', - '中国工商银行', - '中国银行', - '交通银行', - '招商银行', - '民生银行', - '兴业银行', - '中信实业银行', - '上海浦东发展银行', - '光大银行', - '邮政储蓄银行', - '平安银行', - ], + 'banks' => array_values(Bank::banks()), ]); } diff --git a/app/Enums/Bank.php b/app/Enums/Bank.php new file mode 100644 index 00000000..a9fc372e --- /dev/null +++ b/app/Enums/Bank.php @@ -0,0 +1,64 @@ +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 => '平安银行', + ]; + } +}