Browse Source

feat: set primary domain

Jackson Dou 1 year ago
parent
commit
950498e36b

+ 41 - 0
src/admin/api/accounts.php

@@ -0,0 +1,41 @@
+<?php
+
+require 'application.php';
+
+@header('Content-Type: application/json; charset=UTF-8');
+if (!checkRefererHost()) exit('{"code":403}');
+
+$act = get('act');
+
+switch ($act) {
+    case 'add':
+        break;
+    case 'primary-domain':
+        $account_id = post('account_id', 0);
+        if (empty($account_id)) {
+            send_response(-1, $msg = 'need account_id');
+        }
+        $domain = post('domain', null);
+        if (empty($domain)) {
+            send_response(-1, $msg = 'need domain');
+        }
+        $AccountInfo = $DB->find('account', '*', array('account_id' => $account_id), null, 1);
+        if (empty($AccountInfo)) {
+            send_response(-1, $msg = 'account not found');
+        }
+        $DomainInfo = $DB->find('account_domain', 'domain_id', array('domain_account_id' => $account_id, 'domain_name' => $domain), null, 1);
+        if (empty($DomainInfo)) {
+            send_response(-1, $msg = 'domain not found');
+        }
+        // set the primary domain
+        $result = $DB->update('account', array('account_domain' => $domain), array('account_id' => $account_id));
+        if ($result) {
+            send_response(200, array('account_domain' => $domain), 'success');
+        } else {
+            send_response(-1, $msg = 'error');
+        }
+        break;
+    default:
+        send_response(-4, $msg = 'No Act');
+        break;
+}

+ 2 - 0
src/admin/api/clients.php

@@ -35,6 +35,7 @@ switch ($act) {
         } else {
         } else {
             send_response(-1, $msg = 'error');
             send_response(-1, $msg = 'error');
         }
         }
+        break;
     case 'edit':
     case 'edit':
         $client_id = post('client_id');
         $client_id = post('client_id');
         $client_password = post('client_password', '');
         $client_password = post('client_password', '');
@@ -65,6 +66,7 @@ switch ($act) {
         } else {
         } else {
             send_response(-1, $msg = 'error');
             send_response(-1, $msg = 'error');
         }
         }
+        break;
     default:
     default:
         send_response(-4, $msg = 'No Act');
         send_response(-4, $msg = 'No Act');
         break;
         break;

+ 1 - 0
src/admin/controllers/accounts/sync.php

@@ -37,6 +37,7 @@ if ($AccountInfo['account_status'] == 1) {
     $DomainList = array();
     $DomainList = array();
 }
 }
 if (count($DomainList) > 0) {
 if (count($DomainList) > 0) {
+    // import all domains
     foreach($DomainList as &$item) {
     foreach($DomainList as &$item) {
         // 格式 ("abc.com",1234)
         // 格式 ("abc.com",1234)
         $item = '("' . $item . '",' .$account_id . ')';
         $item = '("' . $item . '",' .$account_id . ')';

+ 42 - 2
src/admin/views/accounts/details.php

@@ -50,7 +50,7 @@
                 </div>
                 </div>
                 <div class="col-md-4 col-sm-6">
                 <div class="col-md-4 col-sm-6">
                     <div class="d-flex justify-content-between align-items-center">
                     <div class="d-flex justify-content-between align-items-center">
-                        <b>Main Domain:</b>
+                        <b><?php echo $lang->I18N('Primary Domain'); ?>: </b>
                         <span><?php echo $AccountInfo['account_domain']; ?></span>
                         <span><?php echo $AccountInfo['account_domain']; ?></span>
                     </div>
                     </div>
                 </div>
                 </div>
@@ -152,7 +152,10 @@
             <ul class="list-group">
             <ul class="list-group">
             <?php foreach ($AccountDomainList as $domain): ?>
             <?php foreach ($AccountDomainList as $domain): ?>
                 <li class="list-group-item">
                 <li class="list-group-item">
-                    <span class="pull-right"><a href="accounts.php?action=goftp&account_id=<?php echo $account_id; ?>&domain=<?php echo $domain['domain_name']; ?>" target="_blank"><i class="fa fa-file-import"></i></a></span>
+                    <span class="pull-right">
+                        <button class="btn btn-info btn-xs" onclick="setPrimaryDomain(<?php echo $account_id; ?>, '<?php echo $domain['domain_name']; ?>');"><i class="fa fa-globe"></i> <?php echo $lang->I18N('Set As Primary Domain'); ?></button>
+                        <a class="btn btn-primary btn-xs" href="accounts.php?action=goftp&account_id=<?php echo $account_id; ?>&domain=<?php echo $domain['domain_name']; ?>" target="_blank"><i class="fa fa-file-import"></i> <?php echo $lang->I18N('File Manager'); ?></a>
+                    </span>
                     <a href="http://<?php echo $domain['domain_name']; ?>" target="_blank" ref="noreferrer noopener"><?php echo $domain['domain_name']; ?></a>
                     <a href="http://<?php echo $domain['domain_name']; ?>" target="_blank" ref="noreferrer noopener"><?php echo $domain['domain_name']; ?></a>
                 </li>
                 </li>
                 <?php endforeach; ?>
                 <?php endforeach; ?>
@@ -164,3 +167,40 @@
         <?php endif; ?>
         <?php endif; ?>
     </div>
     </div>
 </div>
 </div>
+
+<script>
+    function setPrimaryDomain(account_id, domain) {
+        layer.confirm('将 ' + domain + ' 设置为主域名 ?', {
+            icon: 3,
+            btn: ['确定', '取消']
+        }, function() {
+            var ii = layer.load(2);
+            $.ajax({
+                type: 'POST',
+                url: 'api/accounts.php?act=primary-domain',
+                dataType: 'json',
+                data: {
+                    account_id: account_id,
+                    domain: domain
+                },
+                success: function(data) {
+                    layer.close(ii);
+                    if (data.code == 200) {
+                        layer.msg('主域设置成功');
+                        setTimeout(function() {
+                            window.location.href = window.location.href;
+                        }, 500);
+                    } else {
+                        layer.alert(data.msg, {
+                            icon: 1
+                        });
+                    }
+                },
+                error: function(data) {
+                    layer.close(ii);
+                    layer.msg('服务器错误');
+                }
+            });
+        });
+    }
+</script>

+ 1 - 1
src/admin/views/sidebar.php

@@ -7,7 +7,7 @@
             <?php echo $AdminInfo['admin_fname'] . " " . $AdminInfo['admin_lname']; ?>
             <?php echo $AdminInfo['admin_fname'] . " " . $AdminInfo['admin_lname']; ?>
         </a>
         </a>
     </div> -->
     </div> -->
-    <div class="sidebar hidden-sm hidden-xs">
+    <div class="sidebar hidden-xs">
         <div class="panel panel-default">
         <div class="panel panel-default">
             <!-- <div class="panel-heading"><span class="panel-title">菜单</span></div> -->
             <!-- <div class="panel-heading"><span class="panel-title">菜单</span></div> -->
             <div class="list-group">
             <div class="list-group">

+ 2 - 0
src/core/language/zh-CN/language.php

@@ -138,6 +138,8 @@ return array(
     'Account Settings'    => '账户配置',
     'Account Settings'    => '账户配置',
     'System Settings'     => '系统配置',
     'System Settings'     => '系统配置',
     'Control Panel'       => '控制面板',
     'Control Panel'       => '控制面板',
+    'Primary Domain'        => '主域名',
+    'Set As Primary Domain' => '设为主域名',
     'File Manager'        => '文件管理',
     'File Manager'        => '文件管理',
     'Company Name'        => '公司名称',
     'Company Name'        => '公司名称',
     'Company'             => '公司',
     'Company'             => '公司',