Company.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace Manage\Src;
  3. use Dever;
  4. use Manage\Src\Lib\Save;
  5. class Company extends Save
  6. {
  7. private $company = array();
  8. # 获取当前权限
  9. public function getAuth()
  10. {
  11. $auth = Dever::load('manage/auth')->info();
  12. if ($auth['company']) {
  13. return $auth['company'];
  14. }
  15. return false;
  16. }
  17. # 设置公司权限
  18. public function set($company_id)
  19. {
  20. $company_id = $company_id ? $company_id : Dever::input('company_id');
  21. $auth = $this->getAuth();
  22. if ($auth) {
  23. $auth = explode(',', $auth);
  24. if (in_array($company_id, $auth)) {
  25. return $this->_add('company', $company_id, 3600 * 24 * 365);
  26. }
  27. }
  28. return false;
  29. }
  30. # 获取公司权限
  31. public function get()
  32. {
  33. $company_id = $this->_get('company');
  34. /*
  35. if ($company_id) {
  36. $auth = $this->getAuth();
  37. if ($auth) {
  38. $auth = explode(',', $auth);
  39. if (!in_array($company_id, $auth)) {
  40. $company_id = false;
  41. }
  42. }
  43. }*/
  44. if (!$company_id) {
  45. $company = $this->getData();
  46. if ($company) {
  47. $company_id = $company['id'];
  48. $this->set($company_id);
  49. }
  50. }
  51. return $company_id;
  52. }
  53. # 获取公司列表
  54. public function getList()
  55. {
  56. $company_id = $this->get();
  57. $data = $this->getData();
  58. $result = array();
  59. if ($data && count($data) > 1) {
  60. foreach ($data as $k => $v) {
  61. if ($company_id && $company_id != $v['id']) {
  62. $result[] = $v;
  63. } else {
  64. $this->company = $v;
  65. }
  66. }
  67. }
  68. return $result;
  69. }
  70. # 获取当前公司
  71. public function getCur()
  72. {
  73. //print_r($this->company);die;
  74. if ($this->company) {
  75. return $this->company['name'];
  76. }
  77. return false;
  78. }
  79. private function getData()
  80. {
  81. $auth = $this->getAuth();
  82. $where = array();
  83. if ($auth) {
  84. $where['ids'] = $auth;
  85. return Dever::db('manage/company')->getOld($where);
  86. } else {
  87. return array();
  88. }
  89. }
  90. }