123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- namespace JinDouYun\Cache;
- use Mall\Framework\Cache\Redis;
- use Mall\Framework\Factory;
- class CommissionCache
- {
-
- private $cache;
- private $enterpriseId;
- private $userCenterId;
- private static $settingCacheKey = 'CommissionSetting';
- private static $businessmanGradeCacheKey = 'BusinessmanGrade';
- private static $businessmanStatisticsCacheKey = 'BusinessmanStatistics';
- private static $businessmanSubCacheKey = 'BusinessmanSub';
- public function __construct($enterpriseId, $userCenterId = false)
- {
- $this->enterpriseId = $enterpriseId;
- $this->userCenterId = $userCenterId;
- $this->cache = Factory::cache('mapping');
- }
-
-
- public function saveSetting($value)
- {
- $data = json_encode($value);
- $result = $this->cache->hset(self::$settingCacheKey, $this->enterpriseId, $data);
- if (!$result) {
- return false;
- }
- return true;
- }
-
- public function getSetting($field = false)
- {
- $result = $this->cache->hget(self::$settingCacheKey, $this->enterpriseId);
- if (!$result) return [];
- $returnData = json_decode($result, true);
- if($field){
- return $returnData[$field];
- }
- return $returnData;
- }
-
- public function delSetting()
- {
- $this->cache->hdel(self::$settingCacheKey, $this->enterpriseId);
- }
-
-
- public function saveBusinessmanGrade($userCenterId, $value)
- {
- $data = json_encode($value);
- return $this->cache->hset(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId, $data);
- }
-
- public function getBusinessmanGrade($userCenterId)
- {
- $result = $this->cache->hget(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId);
- if (!$result) return [];
- return json_decode($result, true);
- }
-
- public function delBusinessmanGrade($userCenterId)
- {
- if($userCenterId === true){
- return $this->cache->del(self::$businessmanGradeCacheKey."::".$this->enterpriseId);
- }
- return $this->cache->hdel(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId);
- }
-
-
- public function saveBusinessmanStatistics($userCenterId, $value)
- {
- $data = json_encode($value);
- $result = $this->cache->hset(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId, $userCenterId, $data);
- if (!$result) {
- return false;
- }
- return true;
- }
-
- public function getBusinessmanStatistics($userCenterId)
- {
- $result = $this->cache->hget(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId, $userCenterId);
- if (!$result) return [];
- return json_decode($result, true);
- }
-
- public function delBusinessmanStatistics($userCenterId)
- {
- if($userCenterId === true){
- return $this->cache->del(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId);
- }
- return $this->cache->hdel(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId, $userCenterId);
- }
-
-
- public function saveBusinessmanSub($userCenterId, $value)
- {
- $data = json_encode($value);
- return $this->cache->hset(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId, $data);
- }
-
- public function getBusinessmanSub($userCenterId)
- {
- $result = $this->cache->hget(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId);
- if (!$result) return [];
- return json_decode($result, true);
- }
-
- public function delBusinessmanSub($userCenterId)
- {
- if($userCenterId === true){
- return $this->cache->del(self::$businessmanSubCacheKey."::".$this->enterpriseId);
- }
- return $this->cache->hdel(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId);
- }
- }
|