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 => '平安银行', + ]; + } +}