rabin 1 week ago
parent
commit
614ca7d7f0

+ 41 - 3
app/Lib/Account.php

@@ -19,7 +19,30 @@ class Account
         return $data;
     }
 
-    public function get($account, $project = 'api')
+    # 同步某个项目下的账户信息
+    public function sync($project)
+    {
+        # 跨库了
+        //return Dever::db($project . '/account')->copy('api_account', ['a.sync' => 1], ['key', 'name']);
+        $col = '`key`,name,cdate';
+        $list = Dever::db('api/account')->select(['sync' => 1], ['col' => $col]);
+        Dever::db($project . '/account')->inserts(['field' => $col, 'value' => $list]);
+    }
+
+    # 根据应用功能获取账户列表
+    public function getList($key)
+    {
+        $func = Dever::db('api/app_func')->find(['key' => $key, 'status' => 1]);
+        if ($func) {
+            $work = Dever::db('api/app_func_work')->columns(['app_func_id' => $func['id'], 'status' => 1], 'platform_id');
+            $account = Dever::db('api/account')->select(['platform_id' => ['in', $work]]);
+            return $account;
+        }
+        return [];
+    }
+
+    # 获取某个项目的账户信息
+    public function get($account, $project = 'api', $setting = false)
     {
         if (is_array($account)) {
             return $account;
@@ -30,16 +53,31 @@ class Account
             $where = ['key' => $account];
         }
         $account = Dever::db('api/account')->find($where);
-        if ($project != 'api') {
+        if ($account && $project != 'api') {
             $info = Dever::db($project . '/account')->find(['key' => $account['key']]);
             if ($info) {
                 $info['app_id'] = $account['app_id'];
                 $info['platform_id'] = $account['platform_id'];
-                return $info;
+                $account = $info;
             } else {
                 Dever::error('账户无效');
             }
         }
+        if ($account && $setting) {
+            $account['setting'] = [];
+            $setting = Dever::db($project . '/account_setting')->select(['account_id' => $account['id']]);
+            if ($setting) {
+                foreach ($setting as $k => $v) {
+                    $info = Dever::db('api/platform_setting')->find($v['platform_setting_id']);
+                    if ($info) {
+                        $v['key'] = $info['key'];
+                        $account['setting'][$v['key']] = $v['value'];
+                    } else {
+                        Dever::error('account error');
+                    }
+                }
+            }
+        }
         return $account;
     }
 

+ 1 - 1
app/Lib/App.php

@@ -4,7 +4,7 @@ class App
 {
     public function update($db, $data)
     {
-        $func = Dever::db('api/app_func_work')->select(['app_func_id' => $data['id']]);
+        $func = Dever::db('api/app_func_work')->select(['app_id' => $data['app_id']]);
         if ($func) {
             $platform = [];
             Dever::db('api/app_platform')->delete(['app_id' => $data['app_id']]);

+ 12 - 2
manage/account.php

@@ -25,13 +25,19 @@ return [
             'platform_id' => [
                 'show' => 'Dever::db("api/platform")->find("{platform_id}")["name"]',
             ],
+            'sync' => [
+                'type' => 'switch',
+                'show'  => '{sync}',
+                'active_value' => 1,
+                'inactive_value' => 2,
+            ],
             'cdate',
         ],
         'button' => [
-            '新增' => ['fastadd', 'name,key,app_platform'],
+            '新增' => ['fastadd', 'name,key,sync,app_platform'],
         ],
         'data_button' => [
-            '设置' => ['edit', 'name,key,app_platform_name,api/account_setting,desc'],
+            '设置' => ['edit', 'name,key,sync,app_platform_name,api/account_setting,desc'],
             '证书' => ['route', [
                 'path' => 'api_manage/account_cert',
                 'param' => [
@@ -54,6 +60,10 @@ return [
                 'rules' => true,
             ],
             'key',
+            'sync' => [
+                'type' => 'radio',
+                'tip' => '开启后,子系统会自动同步该账户的设定,填入相应的子系统账户信息',
+            ],
             'app_platform' => [
                 'desc' => '【提交后不能更改】',
                 'rules' => true,

+ 1 - 1
manage/app_func.php

@@ -58,7 +58,7 @@ return [
             'api/app_func_work' => [
                 'name' => '功能接口',
                 'desc' => '设置功能包含的接口',
-                'where'  => ['app_func_id' => 'id'],
+                'where'  => ['app_func_id' => 'id', 'app_id' => 'app_id'],
             ],
 
             'spec_type' => [

+ 1 - 1
manage/platform_info.php

@@ -117,7 +117,7 @@ $config = [
 ];
 $id = Dever::input('id');
 $load = Dever::input('load');
-if (($load == '/api_manage/platform' || $load == '/api_manage/api') && !$id) {
+if (($load == '/api_manage/platform_info' || $load == '/api_manage/api') && !$id) {
     $config['update']['desc'] = '';
     unset($config['update']['tab']);
 }

+ 13 - 0
table/account.php

@@ -32,6 +32,16 @@ return [
             'name'      => '平台',
         ],
 
+        'sync' => [
+            'name'      => '自动同步',
+            'type'      => 'tinyint(1)',
+            'default'   => 2,
+            'value'     => [
+                1 => '开启',
+                2 => '关闭',
+            ],
+        ],
+
         'status' => [
             'name'      => '状态',
             'type'      => 'tinyint(1)',
@@ -42,4 +52,7 @@ return [
             ],
         ],
     ],
+    'index' => [
+        'search' => '`key`.unique',
+    ],
 ];

+ 3 - 0
table/app_func.php

@@ -72,4 +72,7 @@ return [
             'default'   => '1',
         ],
     ],
+    'index' => [
+        'search' => '`key`.unique',
+    ],
 ];

+ 5 - 0
table/app_func_work.php

@@ -3,6 +3,11 @@ return [
     'name' => '应用功能工作表',
     'order' => 'sort asc',
     'struct' => [
+        'app_id' => [
+            'name'      => '应用id',
+            'type'      => 'int(11)',
+        ],
+        
         'app_func_id' => [
             'name'      => '功能id',
             'type'      => 'int(11)',

+ 1 - 1
table/app_platform.php

@@ -6,7 +6,7 @@ return [
             'name'      => '应用id',
             'type'      => 'int(11)',
         ],
-
+        
         'platform_id' => [
             'name'      => '平台id',
             'type'      => 'int(11)',