123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206 |
- <?php
- /**
- * 分销商cache
- * Created by PhpStorm.
- * User: haoren
- * Date: 2020/07/22
- * Time: 15:00
- */
- namespace JinDouYun\Cache;
- use Mall\Framework\Cache\Redis;
- use Mall\Framework\Factory;
- class CommissionCache
- {
- /**
- * @var Redis
- */
- 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');
- }
- /**---------------------------------------------分销设置------------------------------------------------**/
- /**
- * 保存设置
- * @param $value
- * @return bool
- */
- public function saveSetting($value)
- {
- $data = json_encode($value);
- $result = $this->cache->hset(self::$settingCacheKey, $this->enterpriseId, $data);
- if (!$result) {
- return false;
- }
- return true;
- }
- /**
- * 查询设置
- * @param bool $field
- * @return mixed|string
- */
- 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);
- }
- /*********************************************** 分销商等级 ************************************************/
- /**
- * 添加
- * @param $userCenterId
- * @param $value $缓存的字段
- * @return mixed
- */
- public function saveBusinessmanGrade($userCenterId, $value)
- {
- $data = json_encode($value);
- return $this->cache->hset(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId, $data);
- }
- /**
- * 查询
- * @param $userCenterId
- * @return mixed
- */
- public function getBusinessmanGrade($userCenterId)
- {
- $result = $this->cache->hget(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId);
- if (!$result) return [];
- return json_decode($result, true);
- }
- /**
- * 删除
- * @param $userCenterId
- * @return mixed
- */
- public function delBusinessmanGrade($userCenterId)
- {
- if($userCenterId === true){
- return $this->cache->del(self::$businessmanGradeCacheKey."::".$this->enterpriseId);
- }
- return $this->cache->hdel(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId);
- }
- /********************************************分销商升级条件统计*********************************************/
- /**
- * 保存
- * @param $userCenterId
- * @param $value
- * @return bool
- */
- 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;
- }
- /**
- * 查询
- * @param $userCenterId
- * @return mixed
- */
- public function getBusinessmanStatistics($userCenterId)
- {
- $result = $this->cache->hget(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId, $userCenterId);
- if (!$result) return [];
- return json_decode($result, true);
- }
- /**
- * 删除
- * @param $userCenterId
- * @return mixed
- */
- public function delBusinessmanStatistics($userCenterId)
- {
- if($userCenterId === true){
- return $this->cache->del(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId);
- }
- return $this->cache->hdel(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId, $userCenterId);
- }
- /********************************************分销商下级人数统计*********************************************/
- /**
- * 保存
- * @param $userCenterId
- * @param $value
- * @return bool
- */
- public function saveBusinessmanSub($userCenterId, $value)
- {
- $data = json_encode($value);
- return $this->cache->hset(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId, $data);
- }
- /**
- * 查询
- * @param $userCenterId
- * @return mixed
- */
- public function getBusinessmanSub($userCenterId)
- {
- $result = $this->cache->hget(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId);
- if (!$result) return [];
- return json_decode($result, true);
- }
- /**
- * 删除
- * @param $userCenterId
- * @return mixed
- */
- public function delBusinessmanSub($userCenterId)
- {
- if($userCenterId === true){
- return $this->cache->del(self::$businessmanSubCacheKey."::".$this->enterpriseId);
- }
- return $this->cache->hdel(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId);
- }
- }
|