123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326 |
- <?php
- namespace Jindouyun\Cache;
- use http\Exception;
- use Mall\Framework\Factory;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\ErrorCode;
- class RoleAclCache
- {
- private $cache;
- protected $StaffRelationRoleKey = 'staffRelationRole';
- protected $RoleRelationAclKey = 'roleRelationAcl';
- protected $staffRelationDataFieldKey = 'staffUidRelationDataField';
- protected $staffIdRelationUidKey = 'staffIdRelationUid';
- protected $uidRelationStaffIdKey = 'uidRelationStaffIdKey';
- protected $shopIdRelationWarehouseIdKey = 'shopIdRelationWarehouseId';
- protected $authority = 'Authority';
- protected $Administrator = 'AdministratorRole';
- protected $authorityBindRole = 'AuthorityBindRole';
- public function __construct()
- {
- $this->cache = Factory::cache('user');
- }
-
-
- public function cacheStaffAndRole($enterpriseId, $uid, $roleId)
- {
- $this->cache->zadd($this->StaffRelationRoleKey.'::'.$enterpriseId, $roleId, $uid);
- }
-
- public function getRoleIdOfStaff($enterpriseId, $uid)
- {
- $result = $this->cache->zrange($this->StaffRelationRoleKey.'::'.$enterpriseId, 0,-1, true);
- return isset($result[$uid]) ? (int)$result[$uid] : '';
- }
-
- public function deleteStaffRelationRole($enterpriseId, $uid)
- {
- $this->cache->zrem($this->StaffRelationRoleKey.'::'.$enterpriseId , $uid);
- }
-
-
-
- public function cacheRoleIdAndAcl($enterpriseId, $roleId, $aclData = [])
- {
- return $this->cache->hset($this->RoleRelationAclKey.'::'.$enterpriseId, $roleId, json_encode($aclData));
- }
-
- public function delRoleIdAndAcl($enterpriseId, $roleId)
- {
- return $this->cache->hdel($this->RoleRelationAclKey.'::'.$enterpriseId, $roleId);
- }
-
- public function getRoleIdAndAcl($enterpriseId, $roleId)
- {
- $aclResult = $this->cache->hget($this->RoleRelationAclKey.'::'.$enterpriseId, $roleId);
- return !empty($aclResult) ? json_decode($aclResult, true) : [];
- }
-
-
-
- public function cacheStaffUidAndDataField($enterpriseId, $userCenterId, $dataField = [])
- {
- return $this->cache->hset($this->staffRelationDataFieldKey.'::'.$enterpriseId, $userCenterId, json_encode($dataField));
- }
-
- public function delStaffUidAndDataField($enterpriseId, $userCenterId)
- {
- return $this->cache->hdel($this->staffRelationDataFieldKey.'::'.$enterpriseId, $userCenterId);
- }
-
- public function getStaffUidAndDataField($enterpriseId, $userCenterId)
- {
- $dataField = $this->cache->hget($this->staffRelationDataFieldKey.'::'.$enterpriseId, $userCenterId);
- return !empty($dataField) ? json_decode($dataField, true) : [];
- }
-
-
-
- public function cacheStaffIdAndUserCenterId($enterpriseId, $userCenterId, $staffId)
- {
- return $this->cache->hset($this->staffIdRelationUidKey.'::'.$enterpriseId, $userCenterId, $staffId);
- }
-
- public function getStaffIdAndUserCenterId($enterpriseId, $userCenterId)
- {
- $staffId = $this->cache->hget($this->staffIdRelationUidKey.'::'.$enterpriseId, $userCenterId);
- return $staffId ? $staffId : '';
- }
-
-
-
- public function cacheUserCenterIdAndStaffId($enterpriseId, $staffId, $userCenterId)
- {
- return $this->cache->hset($this->uidRelationStaffIdKey.'::'.$enterpriseId, $staffId, $userCenterId);
- }
-
- public function getUserCenterIdAndStaffId($enterpriseId, $staffId)
- {
- $userCenterId = $this->cache->hget($this->uidRelationStaffIdKey.'::'.$enterpriseId, $staffId);
- return $userCenterId ? $userCenterId : '';
- }
-
-
-
- public function cacheShopIdAndWarehouseId($enterpriseId, $shopId, $warehouseId)
- {
- return $this->cache->hset($this->shopIdRelationWarehouseIdKey.'::'.$enterpriseId, $shopId, $warehouseId);
- }
-
- public function getShopIdAndWarehouseId($enterpriseId, $shopId)
- {
- $warehouseId = $this->cache->hget($this->shopIdRelationWarehouseIdKey.'::'.$enterpriseId, $shopId);
- return $warehouseId ? $warehouseId : '';
- }
-
-
-
- public function addAuthority($value)
- {
- return $this->cache->sadd($this->authority, strtolower($value));
- }
-
- public function getAuthority($value)
- {
- return $this->cache->sismember($this->authority, strtolower($value));
- }
-
- public function delAuthority($value)
- {
- return $this->cache->srem($this->authority, strtolower($value));
- }
-
- public function addAdministrator($enterpriseId, $value)
- {
- return $this->cache->sadd($this->Administrator.'::'.$enterpriseId, $value);
- }
-
- public function getAdministrator($enterpriseId, $value)
- {
- return $this->cache->sismember($this->Administrator.'::'.$enterpriseId, $value);
- }
-
- public function delAdministrator($enterpriseId, $value)
- {
- return $this->cache->srem($this->Administrator.'::'.$enterpriseId, $value);
- }
-
- public function addAuthorityBindRole($enterpriseId, $roleId, $value)
- {
- return $this->cache->sadd($this->authorityBindRole.'::'.$enterpriseId.'::'.$roleId, strtolower($value));
- }
-
- public function getAuthorityBindRole($enterpriseId, $roleId, $value)
- {
- return $this->cache->sismember($this->authorityBindRole.'::'.$enterpriseId.'::'.$roleId, strtolower($value));
- }
-
- public function delAuthorityBindRole($enterpriseId, $roleId, $value = '')
- {
- if($value){
- return $this->cache->srem($this->authorityBindRole.'::'.$enterpriseId.'::'.$roleId, strtolower($value));
- }else{
- return $this->cache->del($this->authorityBindRole.'::'.$enterpriseId.'::'.$roleId);
- }
- }
- }
|