浏览代码

上帝视角

sugangqiang 2 年之前
父节点
当前提交
8f6c0caa31
共有 3 个文件被更改,包括 26 次插入3 次删除
  1. 7 0
      app/common.php
  2. 14 3
      app/common/api/EnterpriseApi.php
  3. 5 0
      sys_config.json

+ 7 - 0
app/common.php

@@ -469,3 +469,10 @@ function getCacheById($key, $field, $fieldKey = null) {
         return $result[$fieldKey];
     return $result;
 }
+
+function getJsonConfig($filepath, $field) {
+    if (file_exists($filepath)) {
+        return json_decode(file_get_contents($filepath), true)[$field];
+    }
+    return null;
+}

+ 14 - 3
app/common/api/EnterpriseApi.php

@@ -24,7 +24,7 @@ class EnterpriseApi {
         $company_info = CompanyApi::getOne($companyId);
         $where = [];
         $whereRaw = "";
-        if ($company_info['code'] != 'super') {
+        if ($company_info['code'] != 'super' && !self::chkUserInSuperusers()) {
             $where[] = ['type', '=', session('user')['type']];
             if (session('user')['type'] == 1) {
                 $whr[] = ["companyId", "=", $companyId];
@@ -198,7 +198,7 @@ class EnterpriseApi {
         $company_info = CompanyApi::getOne($companyId);
         $where = [];
         $whereRaw = "";
-        if ($company_info['code'] != 'super') {
+        if ($company_info['code'] != 'super' && !self::chkUserInSuperusers()) {
             $where[] = ['type', '=', session('user')['type']];
             if (session('user')['type'] == 1) {
                 $whr[] = ["companyId", "=", $companyId];
@@ -343,7 +343,7 @@ class EnterpriseApi {
         $company_info = CompanyApi::getOne($companyId);
         $where = [];
         $whereRaw = "";
-        if ($company_info['code'] != 'super') {
+        if ($company_info['code'] != 'super' && !self::chkUserInSuperusers()) {
             $where[] = ['type', '=', session('user')['type']];
             if (session('user')['type'] == 1) {
                 $whr[] = ["companyId", "=", $companyId];
@@ -534,4 +534,15 @@ class EnterpriseApi {
         return EnterpriseRecord::findOrEmpty($id);
     }
 
+    private static function getSuperusersForEnterprise() {
+        $superusers = getJsonConfig("../sys_config.json", "super_users_for_enterprise");
+        return $superusers;
+    }
+
+    private static function chkUserInSuperusers() {
+        $superusers = self::getSuperusersForEnterprise();
+        $account = session("user")["account"];
+        return in_array($account, $superusers);
+    }
+
 }

+ 5 - 0
sys_config.json

@@ -0,0 +1,5 @@
+{
+    "super_users_for_enterprise": [
+		"admin","rs08"
+	]
+}