Browse Source

fix:支付方式

super-yimizi 4 days ago
parent
commit
b297b91a6b
2 changed files with 28 additions and 10 deletions
  1. 23 1
      application/api/controller/Base.php
  2. 5 9
      application/api/controller/Common.php

+ 23 - 1
application/api/controller/Base.php

@@ -13,7 +13,7 @@ class Base extends Api
     protected $noNeedRight = ['*'];
     //设置返回的会员字段
     protected $allowFields = ['id', 'username', 'nickname', 'mobile', 'avatar', 'score', 'level', 'bio', 'balance', 'money', 'gender'];
-
+    protected $platformKey;
     public function _initialize()
     {
 
@@ -29,6 +29,15 @@ class Base extends Api
         parent::_initialize();
         Config::set('default_return_type', 'json');
         Auth::instance()->setAllowFields($this->allowFields);
+        $platform = $this->request->header('platform');
+         // 需要转换   前段穿 DouyinMiniProgram  后端配置是   douyin_mini_program
+        $platformKey = $this->convertPlatformName($platform);
+        $this->platformKey = $platformKey;
+        $platformConfig = shop_config('shop.platform.' . $platformKey);
+
+        if (empty($platformConfig['status']) || !$platformConfig['status']) {
+            $this->error('暂不支持该平台,请前往商城配置启用对应平台');
+        }
 
         //判断站点状态
         // if (isset($config['openedsite']) && !in_array('uniapp', explode(',', $config['openedsite']))) {
@@ -45,4 +54,17 @@ class Base extends Api
         // Lang::load(ADDON_PATH . 'shop/lang/' . $lang . '/' . str_replace('.', '/', $controllername) . '.php');
     }
 
+     /**
+     * 转换平台名称格式
+     * 将前端驼峰命名转换为后端下划线格式
+     *
+     * @param string $platform
+     * @return string
+     */
+    protected function convertPlatformName($platform)
+    {
+        // 将驼峰命名转换为下划线格式
+        return strtolower(preg_replace('/([A-Z])/', '_$1', lcfirst($platform)));
+    }
+
 }

+ 5 - 9
application/api/controller/Common.php

@@ -29,13 +29,6 @@ class Common extends Base
     protected $noNeedLogin = ['init', 'area', 'getBannerList','getDataByIndex'];
 
     protected $noNeedRight = '*';
-   
-    protected function convertPlatformName($platform)
-    {
-        // 将驼峰命名转换为下划线格式
-        return strtolower(preg_replace('/([A-Z])/', '_$1', lcfirst($platform)));
-    }
-
 
     /**
      * 初始化
@@ -98,8 +91,8 @@ class Common extends Base
         $defaultCategoryImg   =   $arrGoodsConfig['default_category_img']??"";
         $data['default_category_img'] = !empty($defaultCategoryImg)? cdnurl($defaultCategoryImg, true) :'';
        
-        $platformKey = $this->convertPlatformName($platform);
-        $arrPlatformConfigs = ShopConfigService::getConfigs('shop.platform.' . $platformKey, false);
+        $platformKey = $this->platformKey;
+        $arrPlatformConfigs = shop_config('shop.platform.' . $platformKey);
         // app 处理
         if ($platform == ChannelEnum::CHANNEL_IOS_APP){
             // 微信appid
@@ -126,6 +119,9 @@ class Common extends Base
         $data['feedback_type'] = FeedbackEnum::getFeedbackTypeMap();
         // 性别
         $data['gender'] = UserEnum::getGenderMap();    
+        $data['platform'] = [
+            'payment' => $arrPlatformConfigs['payment']['methods'] ?? [],
+        ];
 
         $this->success('', $data);
     }