123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081 |
- <?php
- namespace JinDouYun\Cache;
- use Mall\Framework\Core\ErrorCode;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Factory;
- class MerchantCache
- {
- private $cache;
- private $enterpriseId;
- private $userCenterId;
- private $cacheKey = 'Merchant';
- public function __construct($enterpriseId = false, $userCenterId = false)
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- $this->cache = Factory::cache('mapping');
- }
-
-
- public function addMerchant($merchantId, $merchantData)
- {
- $data = json_encode($merchantData);
- $result = $this->cache->hset($this->cacheKey, $merchantId, $data);
- if(!$result){
- return false;
- }
- return true;
- }
-
- public function getMerchant($merchantId, $key = false)
- {
- $result = $this->cache->hget($this->cacheKey, $merchantId);
- if (!$result) return [];
- $returnData = json_decode($result, true);
- if($key){
- return $returnData[$key];
- }
- return $returnData;
- }
-
- public function delMerchant($merchantId = false)
- {
- if($merchantId){
- $this->cache->hdel($this->cacheKey, $merchantId);
- }else{
- $this->cache->del($this->cacheKey);
- }
- }
- }
|