123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- <?php
- namespace JinDouYun\Cache;
- use http\Exception;
- use Mall\Framework\Factory;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\ErrorCode;
- class ShopCache
- {
- private $cache;
- protected $EnterpriseRelationShopKey = 'EnterpriseRelationShop';
- protected $EnterpriseSalesAreaKey = 'EnterpriseSalesArea';
- protected $shopToken = 'ShopToken';
- public function __construct()
- {
- $this->cache = Factory::cache('default');
- }
-
- public function cacheEnterpriseAndShop($enterpriseId, $shopData)
- {
- if( empty($shopData) ){
- return ResultWrapper::fail('要缓存的数据为空', ErrorCode::$paramError);
- }
-
- self::cleanUserRelationEnterprise($enterpriseId);
- $pipe = $this->cache->multi();
- foreach ($shopData as $key => $value){
- $writeCache = $this->cache->sadd($this->EnterpriseRelationShopKey.'::'.$enterpriseId, $value['id']);
- }
- $pipe->exec();
- }
-
- public function isHaveShopId($enterpriseId, $shopId)
- {
- $result = $this->cache->sismember($this->EnterpriseRelationShopKey.'::'.$enterpriseId, $shopId);
- return $result;
- }
-
- public function cleanUserRelationEnterprise($enterpriseId)
- {
- $result = $this->cache->del($this->EnterpriseRelationShopKey.'::'.$enterpriseId);
- }
-
- public function cacheEnterpriseSalesArea($enterpriseId,$salesArea=[]) {
- $this->cache->hset($this->EnterpriseSalesAreaKey, $enterpriseId, json_encode(array_unique($salesArea)));
- }
-
- public function getEnterpriseSalesArea($enterpriseId) {
- return $this->cache->hget($this->EnterpriseSalesAreaKey, $enterpriseId);
- }
-
- public function setShopToken($enterpriseId, $shopId, $token)
- {
- return $this->cache->zadd($this->shopToken.'::'.$enterpriseId, $shopId, $token);
- }
-
- public function getShopToken($enterpriseId, $token)
- {
- return $this->cache->zscore($this->shopToken.'::'.$enterpriseId, $token);
- }
- }
|