|
@@ -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();
|
|
|
+ }
|
|
|
+ }
|
|
|
+}
|