Ver código fonte

Weenier 168otc项目部署 0630

wesmiler 3 anos atrás
pai
commit
ffb7064e6f

+ 1 - 1
app/Http/Controllers/Api/IndexController.php

@@ -76,7 +76,7 @@ class IndexController extends webApp
     public function config()
     {
         // 交易参数
-        $trade = ConfigService::make()->getConfigByGroup(5);
+        $trade = ConfigService::make()->getConfigOptionByGroup(5);
         return message(1010, true,  compact('trade'));
     }
 }

+ 28 - 0
app/Services/ConfigService.php

@@ -97,6 +97,34 @@ class ConfigService extends BaseService
     }
 
     /**
+     * 获取配置选项值
+     * @param $groupId
+     * @return array|mixed
+     */
+    public function getConfigOptionByGroup($groupId){
+        $cacheKey = "caches:config:groups:value_{$groupId}";
+        $datas = RedisService::get($cacheKey);
+        if($datas){
+            return $datas;
+        }
+        $datas = $this->model::where(['config_group_id'=> $groupId, 'status'=> 1])
+            ->select('title','code','value')
+            ->orderBy('sort','asc')
+            ->get()
+            ->keyBy('code');
+        $datas = $datas? $datas->toArray() : [];
+        $result = [];
+        if($datas){
+            foreach ($datas as $k => $v){
+                $result[$k] = $v['value'];
+            }
+            RedisService::set($cacheKey, $result, 30);
+        }
+
+        return $result;
+    }
+
+    /**
      * 获取单个配置
      * @param $groupId
      * @return mixed