SystemCache.Class.php 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. <?php
  2. /**
  3. * 缓存企业与小程序数据
  4. * Created by PhpStorm.
  5. * User: XiaoMing
  6. * Date: 2019/12/9
  7. * Time: 16:31
  8. */
  9. namespace JinDouYun\Cache;
  10. use Mall\Framework\Cache\Redis;
  11. use Mall\Framework\Core\ResultWrapper;
  12. use Mall\Framework\Factory;
  13. /**
  14. * Class SystemCache
  15. * @package JinDouYun\Cache
  16. */
  17. class SystemCache
  18. {
  19. private static $enterpriseRelationWxAppIdKey = 'enterpriseRelationWxAppIdMapping';
  20. private static $paymentKey = 'paymentMapping';//支付配置
  21. private static $byteDanceSettingKey = 'byteDanceSettingMapping';//字节跳动配置
  22. private static $printNumKey = 'printNum';//打印次数
  23. private static $uriRelNameKey = 'uriRelName';//url=>name
  24. /**
  25. * @var Redis
  26. */
  27. public $cache;
  28. /**
  29. * SystemCache constructor.
  30. * @throws \Exception
  31. */
  32. public function __construct()
  33. {
  34. $this->cache = Factory::cache('mapping');
  35. }
  36. /**
  37. * @param $data
  38. * @param $enterpriseId
  39. * @return mixed
  40. */
  41. public function cacheEnterpriseRelationWxAppId($data, $enterpriseId)
  42. {
  43. $result = $this->cache->hset(self::$enterpriseRelationWxAppIdKey, $enterpriseId, $data);
  44. return $result;
  45. }
  46. /**
  47. * 获取企业授权的小程序信息
  48. * @param $enterpriseId
  49. * @return string
  50. */
  51. public function getAppIdByEnterpriseId($enterpriseId)
  52. {
  53. $result = $this->cache->hget(self::$enterpriseRelationWxAppIdKey, $enterpriseId);
  54. if (!$result) {
  55. return '';
  56. }
  57. return $result;
  58. }
  59. /**
  60. * 缓存支付配置
  61. * @param $data
  62. * @param $enterpriseId
  63. * @return mixed
  64. */
  65. public function cachePayment($data, $enterpriseId)
  66. {
  67. if (is_array($data)) {
  68. $data = json_encode($data);
  69. }
  70. $result = $this->cache->hset(self::$paymentKey, $enterpriseId, $data);
  71. return $result;
  72. }
  73. /**
  74. * @param $enterpriseId
  75. * @param string $type
  76. * @return array|mixed
  77. */
  78. public function getPayment($enterpriseId)
  79. {
  80. $result = $this->cache->hget(self::$paymentKey, $enterpriseId);
  81. if (!$result) {
  82. return [];
  83. }
  84. if (!empty($result)) {
  85. $result = json_decode($result, true);
  86. }
  87. return $result;
  88. }
  89. /**
  90. * 字节跳动设置
  91. * @param string $data
  92. * @param int $enterpriseId
  93. * @return bool|int
  94. */
  95. public function cacheByteDanceSetting(string $data, int $enterpriseId)
  96. {
  97. return $this->cache->hset(self::$byteDanceSettingKey, $enterpriseId, $data);
  98. }
  99. /**
  100. * 获取字节跳动设置
  101. * @param int $enterpriseId
  102. * @return string
  103. */
  104. public function getByteDanceSetting(int $enterpriseId)
  105. {
  106. $result = $this->cache->hget(self::$byteDanceSettingKey, $enterpriseId);
  107. if (!$result) {
  108. return '';
  109. }
  110. return $result;
  111. }
  112. /**
  113. * Doc: (des="获取打印次数")
  114. * User: XMing
  115. * Date: 2020/11/14
  116. * Time: 11:48 上午
  117. * @param int $enterpriseId
  118. * @param $no
  119. * @return int
  120. */
  121. public function getObjectPrintNum(int $enterpriseId,$no)
  122. {
  123. return $this->cache->zscore(self::$printNumKey.'::'.$enterpriseId,$no);
  124. }
  125. /**
  126. * Doc: (des="删除打印次数")
  127. * User: XMing
  128. * Date: 2020/11/14
  129. * Time: 12:05 下午
  130. * @param int $enterpriseId
  131. * @param $no
  132. * @return bool
  133. */
  134. public function delObjectPrintNum(int $enterpriseId,$no)
  135. {
  136. return $this->cache->zrem(self::$printNumKey.'::'.$enterpriseId,$no);
  137. }
  138. /**
  139. * Doc: (des="设置打印次数")
  140. * User: XMing
  141. * Date: 2020/11/14
  142. * Time: 11:49 上午
  143. * @param int $enterpriseId
  144. * @param $no
  145. * @param int $value
  146. * @return bool
  147. */
  148. public function setObjectPrintNum(int $enterpriseId,$no,$value)
  149. {
  150. return $this->cache->zadd(self::$printNumKey.'::'.$enterpriseId,$value,$no);
  151. }
  152. /**
  153. * Doc: (des="混存url与name")
  154. * User: XMing
  155. * Date: 2020/11/14
  156. * Time: 6:47 下午
  157. * @param string $uri
  158. * @param string $name
  159. */
  160. public function setUriRelName(string $uri,string $name)
  161. {
  162. return $this->cache->hset(self::$uriRelNameKey,strtolower($uri),$name);
  163. }
  164. /**
  165. * Doc: (des="删除uri")
  166. * User: XMing
  167. * Date: 2020/11/14
  168. * Time: 6:51 下午
  169. * @param string $uri
  170. */
  171. public function delUriRelName(string $uri)
  172. {
  173. return $this->cache->hdel(self::$uriRelNameKey,strtolower($uri));
  174. }
  175. /**
  176. * Doc: (des="")
  177. * User: XMing
  178. * Date: 2020/11/14
  179. * Time: 6:53 下午
  180. * @param string $uri
  181. */
  182. public function getUriRelName(string $uri)
  183. {
  184. $name = $this->cache->hget(self::$uriRelNameKey,strtolower($uri));
  185. if ($name == false){
  186. return '';
  187. }
  188. return $name;
  189. }
  190. }