浏览代码

feat(payment): 添加小程序环境支持配置- 新增 Config 类用于管理支付插件配置
- 在 Extension 类中定义扩展 ID 常量
- 添加支持的小程序环境配置项(开发版、体验版、正式版)
- 根据请求头 env 参数过滤支付方式列表
- 当 env 为 release 或配置支持的环境时返回所有支付方式
- 否则返回空数组避免非预期支付方式展示

runphp 5 月之前
父节点
当前提交
7c4012dc8f
共有 4 个文件被更改,包括 61 次插入3 次删除
  1. 30 1
      config.php
  2. 19 0
      src/Config.php
  3. 10 2
      src/Controller/PaymentController.php
  4. 2 0
      src/Extension.php

+ 30 - 1
config.php

@@ -33,6 +33,35 @@ return json_decode(<<<'JSON'
     "display": true,
     "hidden": false,
     "_fc_drag_tag": "checkbox"
+  },
+  {
+    "type": "checkbox",
+    "field": "supported_envs",
+    "title": "支持的小程序环境",
+    "info": "选择在此插件中支持的小程序环境",
+    "options": [
+      {
+        "value": "develop",
+        "label": "开发版"
+      },
+      {
+        "value": "trial",
+        "label": "体验版"
+      },
+      {
+        "value": "release",
+        "label": "正式版"
+      }
+    ],
+    "$required": false,
+    "props": {
+      "_optionType": 1
+    },
+    "_fc_id": "id_supported_envs_checkbox",
+    "name": "ref_supported_envs",
+    "display": true,
+    "hidden": false,
+    "_fc_drag_tag": "checkbox"
   }
 ]
-JSON,true);
+JSON,true);

+ 19 - 0
src/Config.php

@@ -0,0 +1,19 @@
+<?php
+declare(strict_types=1);
+
+namespace SixShop\Payment;
+
+use SixShop\System\Trait\ConfigTrait;
+
+/**
+ * @property array{string: string} $supported_envs 支持的小程序环境
+ */
+class Config
+{
+    use ConfigTrait;
+
+    public function getExtensionID(): string
+    {
+        return Extension::EXTENSION_ID;
+    }
+}

+ 10 - 2
src/Controller/PaymentController.php

@@ -3,6 +3,8 @@ declare(strict_types=1);
 namespace SixShop\Payment\Controller;
 
 use SixShop\Core\Helper;
+use SixShop\Core\Request;
+use SixShop\Payment\Config;
 use SixShop\Payment\PaymentManager;
 use think\Response;
 use think\response\Json;
@@ -10,8 +12,14 @@ use function SixShop\Core\success_response;
 
 class PaymentController
 {
-    public function index(PaymentManager $paymentManager): Response
+    public function index(PaymentManager $paymentManager, Config $config, Request $request): Response
     {
-        return success_response($paymentManager->getAllPayment());
+        $env = $request->header('env', 'release');
+        if($env === 'release' || in_array($env, $config->supported_envs)) {
+            $payments = $paymentManager->getAllPayment();
+        } else {
+            $payments = [];
+        }
+        return success_response($payments);
     }
 }

+ 2 - 0
src/Extension.php

@@ -8,6 +8,8 @@ use SixShop\Payment\Hook\OrderHook;
 
 class Extension extends ExtensionAbstract
 {
+    public const string EXTENSION_ID = 'payment';
+
     public function getHooks(): array
     {
         return [