CommissionCache.Class.php 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <?php
  2. /**
  3. * 分销商cache
  4. * Created by PhpStorm.
  5. * User: haoren
  6. * Date: 2020/07/22
  7. * Time: 15:00
  8. */
  9. namespace JinDouYun\Cache;
  10. use Mall\Framework\Cache\Redis;
  11. use Mall\Framework\Factory;
  12. class CommissionCache
  13. {
  14. /**
  15. * @var Redis
  16. */
  17. private $cache;
  18. private $enterpriseId;
  19. private $userCenterId;
  20. private static $settingCacheKey = 'CommissionSetting';
  21. private static $businessmanGradeCacheKey = 'BusinessmanGrade';
  22. private static $businessmanStatisticsCacheKey = 'BusinessmanStatistics';
  23. private static $businessmanSubCacheKey = 'BusinessmanSub';
  24. public function __construct($enterpriseId, $userCenterId = false)
  25. {
  26. $this->enterpriseId = $enterpriseId;
  27. $this->userCenterId = $userCenterId;
  28. $this->cache = Factory::cache('mapping');
  29. }
  30. /**---------------------------------------------分销设置------------------------------------------------**/
  31. /**
  32. * 保存设置
  33. * @param $value
  34. * @return bool
  35. */
  36. public function saveSetting($value)
  37. {
  38. $data = json_encode($value);
  39. $result = $this->cache->hset(self::$settingCacheKey, $this->enterpriseId, $data);
  40. if (!$result) {
  41. return false;
  42. }
  43. return true;
  44. }
  45. /**
  46. * 查询设置
  47. * @param bool $field
  48. * @return mixed|string
  49. */
  50. public function getSetting($field = false)
  51. {
  52. $result = $this->cache->hget(self::$settingCacheKey, $this->enterpriseId);
  53. if (!$result) return [];
  54. $returnData = json_decode($result, true);
  55. if($field){
  56. return $returnData[$field];
  57. }
  58. return $returnData;
  59. }
  60. /**
  61. * 删除
  62. */
  63. public function delSetting()
  64. {
  65. $this->cache->hdel(self::$settingCacheKey, $this->enterpriseId);
  66. }
  67. /*********************************************** 分销商等级 ************************************************/
  68. /**
  69. * 添加
  70. * @param $userCenterId
  71. * @param $value $缓存的字段
  72. * @return mixed
  73. */
  74. public function saveBusinessmanGrade($userCenterId, $value)
  75. {
  76. $data = json_encode($value);
  77. return $this->cache->hset(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId, $data);
  78. }
  79. /**
  80. * 查询
  81. * @param $userCenterId
  82. * @return mixed
  83. */
  84. public function getBusinessmanGrade($userCenterId)
  85. {
  86. $result = $this->cache->hget(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId);
  87. if (!$result) return [];
  88. return json_decode($result, true);
  89. }
  90. /**
  91. * 删除
  92. * @param $userCenterId
  93. * @return mixed
  94. */
  95. public function delBusinessmanGrade($userCenterId)
  96. {
  97. if($userCenterId === true){
  98. return $this->cache->del(self::$businessmanGradeCacheKey."::".$this->enterpriseId);
  99. }
  100. return $this->cache->hdel(self::$businessmanGradeCacheKey."::".$this->enterpriseId, $userCenterId);
  101. }
  102. /********************************************分销商升级条件统计*********************************************/
  103. /**
  104. * 保存
  105. * @param $userCenterId
  106. * @param $value
  107. * @return bool
  108. */
  109. public function saveBusinessmanStatistics($userCenterId, $value)
  110. {
  111. $data = json_encode($value);
  112. $result = $this->cache->hset(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId, $userCenterId, $data);
  113. if (!$result) {
  114. return false;
  115. }
  116. return true;
  117. }
  118. /**
  119. * 查询
  120. * @param $userCenterId
  121. * @return mixed
  122. */
  123. public function getBusinessmanStatistics($userCenterId)
  124. {
  125. $result = $this->cache->hget(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId, $userCenterId);
  126. if (!$result) return [];
  127. return json_decode($result, true);
  128. }
  129. /**
  130. * 删除
  131. * @param $userCenterId
  132. * @return mixed
  133. */
  134. public function delBusinessmanStatistics($userCenterId)
  135. {
  136. if($userCenterId === true){
  137. return $this->cache->del(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId);
  138. }
  139. return $this->cache->hdel(self::$businessmanStatisticsCacheKey."::".$this->enterpriseId, $userCenterId);
  140. }
  141. /********************************************分销商下级人数统计*********************************************/
  142. /**
  143. * 保存
  144. * @param $userCenterId
  145. * @param $value
  146. * @return bool
  147. */
  148. public function saveBusinessmanSub($userCenterId, $value)
  149. {
  150. $data = json_encode($value);
  151. return $this->cache->hset(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId, $data);
  152. }
  153. /**
  154. * 查询
  155. * @param $userCenterId
  156. * @return mixed
  157. */
  158. public function getBusinessmanSub($userCenterId)
  159. {
  160. $result = $this->cache->hget(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId);
  161. if (!$result) return [];
  162. return json_decode($result, true);
  163. }
  164. /**
  165. * 删除
  166. * @param $userCenterId
  167. * @return mixed
  168. */
  169. public function delBusinessmanSub($userCenterId)
  170. {
  171. if($userCenterId === true){
  172. return $this->cache->del(self::$businessmanSubCacheKey."::".$this->enterpriseId);
  173. }
  174. return $this->cache->hdel(self::$businessmanSubCacheKey."::".$this->enterpriseId, $userCenterId);
  175. }
  176. }