123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176 |
- <?php
- /**
- * Created by PhpStorm.
- * User: wxj
- * Date: 2020-03-24
- * Time: 15:11
- */
- namespace JinDouYun\Cache;
- use http\Exception;
- use Mall\Framework\Factory;
- use Mall\Framework\Core\ResultWrapper;
- use Mall\Framework\Core\ErrorCode;
- class TempSaveCache
- {
- private $cache;
- protected $vipCardTemporarySaveKey = 'vipCardTempSave';//会员卡暂存
- protected $goodsTemporarySaveKey = 'goodsTempSave';//商品暂存
- protected $customerTempSaveKey = 'customerTempSave';//客户暂存
- protected $shopTempSaveKey = 'shopTempSave';//商铺暂存
- public function __construct()
- {
- $this->cache = Factory::cache('default');
- }
- /**
- * 会员卡暂存
- * @param $enterpriseId
- * @param $userCenterId
- * @param $data
- * @return ResultWrapper
- */
- public function saveVipCard($enterpriseId, $userCenterId, $data)
- {
- if (empty($data)) {
- return ResultWrapper::fail('要缓存的数据为空', ErrorCode::$paramError);
- }
- return $this->cache->hset($this->vipCardTemporarySaveKey . '::' . $enterpriseId, $userCenterId, json_encode($data));
- }
- /**
- * 获取会员卡暂存数据
- * @param $enterpriseId
- * @param $userCenterId
- * @return boolean
- */
- public function getVipCard($enterpriseId, $userCenterId)
- {
- $data = $this->cache->hget($this->vipCardTemporarySaveKey . '::' . $enterpriseId, $userCenterId);
- return $data ? json_decode($data, true) : [];
- }
- /**
- * 删除会员卡暂存数据
- * @param $enterpriseId
- * @param $userCenterId
- */
- public function delVipCard($enterpriseId, $userCenterId)
- {
- $result = $this->cache->hdel($this->vipCardTemporarySaveKey . '::' . $enterpriseId, $userCenterId);
- }
- /**
- * 客户暂存
- * @param $enterpriseId
- * @param $userCenterId
- * @param $data
- * @return ResultWrapper
- */
- public function saveCustomer($enterpriseId, $userCenterId, $data)
- {
- if (empty($data)) {
- return ResultWrapper::fail('要缓存的数据为空', ErrorCode::$paramError);
- }
- return $this->cache->hset($this->customerTempSaveKey . '::' . $enterpriseId, $userCenterId, json_encode($data));
- }
- /**
- * 获取客户暂存数据
- * @param $enterpriseId
- * @param $userCenterId
- * @return boolean
- */
- public function getCustomer($enterpriseId, $userCenterId)
- {
- $data = $this->cache->hget($this->customerTempSaveKey . '::' . $enterpriseId, $userCenterId);
- return $data ? json_decode($data, true) : [];
- }
- /**
- * 删除客户暂存数据
- * @param $enterpriseId
- * @param $userCenterId
- */
- public function delCustomer($enterpriseId, $userCenterId)
- {
- $result = $this->cache->hdel($this->customerTempSaveKey . '::' . $enterpriseId, $userCenterId);
- }
- /**
- * 商铺暂存
- * @param $enterpriseId
- * @param $userCenterId
- * @param $data
- * @return ResultWrapper
- */
- public function saveShop($enterpriseId, $userCenterId, $data)
- {
- if (empty($data)) {
- return ResultWrapper::fail('要缓存的数据为空', ErrorCode::$paramError);
- }
- return $this->cache->hset($this->shopTempSaveKey . '::' . $enterpriseId, $userCenterId, json_encode($data));
- }
- /**
- * 获取商铺暂存数据
- * @param $enterpriseId
- * @param $userCenterId
- * @return boolean
- */
- public function getShop($enterpriseId, $userCenterId)
- {
- $data = $this->cache->hget($this->shopTempSaveKey . '::' . $enterpriseId, $userCenterId);
- return $data ? json_decode($data, true) : [];
- }
- /**
- * 删除商铺暂存数据
- * @param $enterpriseId
- * @param $userCenterId
- */
- public function delShop($enterpriseId, $userCenterId)
- {
- $result = $this->cache->hdel($this->shopTempSaveKey . '::' . $enterpriseId, $userCenterId);
- }
- /**
- * 商品暂存
- * @param $enterpriseId
- * @param $userCenterId
- * @param $data
- * @return ResultWrapper
- */
- public function saveGoods($enterpriseId, $userCenterId, $data)
- {
- if (empty($data)) {
- return ResultWrapper::fail('要缓存的数据为空', ErrorCode::$paramError);
- }
- return $this->cache->hset($this->goodsTemporarySaveKey . '::' . $enterpriseId, $userCenterId, json_encode($data));
- }
- /**
- * 获取商品暂存数据
- * @param $enterpriseId
- * @param $userCenterId
- * @return boolean
- */
- public function getGoods($enterpriseId, $userCenterId)
- {
- $data = $this->cache->hget($this->goodsTemporarySaveKey . '::' . $enterpriseId, $userCenterId);
- return $data ? json_decode($data, true) : [];
- }
- /**
- * 删除商品暂存数据
- * @param $enterpriseId
- * @param $userCenterId
- */
- public function delGoods($enterpriseId, $userCenterId)
- {
- $result = $this->cache->hdel($this->goodsTemporarySaveKey . '::' . $enterpriseId, $userCenterId);
- }
- }
|