Procházet zdrojové kódy

feat(payment): 根据环境配置过滤支付方式

- 修改支付方式获取逻辑,支持按环境过滤
- 使用 array_column 重构数据结构便于处理
- 遍历支付方式并根据支持的环境进行筛选
- 返回过滤后的支付方式列表
runphp před 4 měsíci
rodič
revize
c1f6e5b92d
1 změnil soubory, kde provedl 7 přidání a 5 odebrání
  1. 7 5
      src/Controller/PaymentController.php

+ 7 - 5
src/Controller/PaymentController.php

@@ -15,11 +15,13 @@ class PaymentController
     public function index(PaymentManager $paymentManager, Config $config, Request $request): Response
     {
         $env = $request->header('env', 'release');
-        if($env === 'release' || in_array($env, $config->supported_envs)) {
-            $payments = $paymentManager->getAllPayment();
-        } else {
-            $payments = [];
+        $payments = array_column($paymentManager->getAllPayment(), null,'id');
+        $result = [];
+        foreach ($payments as $id => $payment) {
+            if (in_array($env, $config->getConfig('supported_env_'.$id))) {
+                $result[] = $payment;
+            }
         }
-        return success_response($payments);
+        return success_response($result);
     }
 }