dever 1 year ago
parent
commit
ae2f85c385
4 changed files with 165 additions and 0 deletions
  1. 12 0
      database/company.php
  2. 96 0
      src/Company.php
  3. 31 0
      src/Lib/Save.php
  4. 26 0
      template/default/inc/nav.php

+ 12 - 0
database/company.php

@@ -84,5 +84,17 @@ return array
             'order' => array('id' => 'desc'),
             'col' => '*|id',
         ),
+
+        'getOld' => array
+        (
+            'type' => 'one',
+            'option' => array
+            (
+                'ids' => array('yes-id', 'in'),
+                'state' => 1,
+            ),
+            'order' => array('id' => 'asc'),
+            'col' => '*',
+        ),
     ),
 );

+ 96 - 0
src/Company.php

@@ -0,0 +1,96 @@
+<?php
+namespace Manage\Src;
+
+use Dever;
+use Manage\Src\Save;
+
+class Company extends Save
+{
+    private $company = array();
+    # 获取当前权限
+    public function getAuth()
+    {
+        $auth = Dever::load('manage/auth')->info();
+        if ($auth['company']) {
+            
+            return $auth['company'];
+        }
+
+        return false;
+    }
+
+    # 设置公司权限
+    public function set($company_id)
+    {
+        $auth = $this->getAuth();
+        if ($auth) {
+            $auth = explode(',', $auth);
+            if (in_array($company_id, $auth)) {
+                return $ths->_add('company', $company_id, 3600 * 24 * 365);
+            }
+        }
+        return false;
+    }
+
+    # 获取公司权限
+    public function get()
+    {
+        $company_id = $this->_get('company');
+        /*
+        if ($company_id) {
+            $auth = $this->getAuth();
+            if ($auth) {
+                $auth = explode(',', $auth);
+                if (!in_array($company_id, $auth)) {
+                    $company_id = false;
+                }
+            }
+        }*/
+        if (!$company_id) {
+            $company = $this->getData();
+            if ($company) {
+                $company_id = $company['id'];
+                $this->set($company_id);
+            }
+        }
+        return $company_id;
+    }
+
+    # 获取公司列表
+    public function getList()
+    {
+        $company_id = $this->get();
+        $data = $this->getData();
+
+        $result = array();
+        if ($data) {
+            foreach ($data as $k => $v) {
+                if ($company_id && $company_id != $v['id']) {
+                    $result[] = $v;
+                } else {
+                    $this->company = $v;
+                }
+            }
+        }
+
+        return $result;
+    }
+
+    # 获取当前公司
+    public function getCur()
+    {
+        return $this->company;
+    }
+
+    private function getData()
+    {
+        $auth = $this->getAuth();
+        $where = array();
+        if ($auth) {
+            $where['ids'] = $auth;
+            return Dever::db('manage/company')->getOld($where);
+        } else {
+            return array();
+        }
+    }
+}

+ 31 - 0
src/Lib/Save.php

@@ -0,0 +1,31 @@
+<?php
+namespace Manage\Src\Lib;
+
+use Dever;
+use Dever\Session\Oper;
+
+class Save
+{
+    /**
+     * __construct
+     *
+     * @return mixed
+     */
+    public function __construct()
+    {
+        $this->save = new Oper(false, 'session');
+        $this->name = 'manage';
+    }
+
+    # 设置公司权限
+    public function _add($name, $value, $time)
+    {
+        return $this->save->add($this->name . '_' . $name, $value, $time);
+    }
+
+    # 获取公司权限
+    public function _get($name)
+    {
+        return $this->save->get($this->name . '_' . $name);
+    }
+}

+ 26 - 0
template/default/inc/nav.php

@@ -21,6 +21,7 @@ $view
  
 //->fetch('#edit@href', 'edit')
 
+/*
 ->fetch('.auth-top@style', 'display:none')
 # 项目列表
 ->loop
@@ -45,6 +46,31 @@ $view
             ),
         ),
 	)
+)*/
+
+# 项目列表
+->loop
+(
+    '.auth-top',
+    'manage/company.get',  
+    array
+    ( 
+        
+        'span|0' => '<{$v.name}>', 
+
+        'ul' => array 
+        (
+            'li|$v.child' => array
+            (   
+                'a' => array 
+                (
+                    'html' => '$v1.name',
+                    'data-id' => '$v1.id',
+                    'onclick' => 'topMenu($(this))',
+                )
+            ),
+        ),
+    )
 )
 
 # display