123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- <?php
- namespace JinDouYun\Cache;
- use Mall\Framework\Cache\Redis;
- use Mall\Framework\Factory;
- class PriceCache
- {
-
- private static $nationSalePriceTableKey = 'nationSalePrice::';
-
- private static $customerAdjTableKey = 'customerAdj::';
-
- private static $customerTypeAdiTableKey = 'customerTypeAdi::';
-
- private static $priceTrend = 'priceTrend_';
-
- private $onlineEnterpriseId;
-
- private $cache;
-
- public function __construct($enterpriseId)
- {
- $this->onlineEnterpriseId = $enterpriseId;
- $this->cache = Factory::cache('mapping');
- }
-
-
- public function setNationSalePrice(int $goodsId, $value)
- {
- return $this->cache->hset(self::$nationSalePriceTableKey . $this->onlineEnterpriseId, $goodsId, json_encode($value));
- }
-
- public function getNationSalePrice(int $goodsId)
- {
- $result = $this->cache->hget(self::$nationSalePriceTableKey . $this->onlineEnterpriseId, $goodsId);
- if (empty($result)) {
- return [];
- }
- $result = json_decode($result, true);
- return $result;
- }
-
- public function delNationSalePrice(int $goodsId)
- {
- return $this->cache->hdel(self::$nationSalePriceTableKey . $this->onlineEnterpriseId, $goodsId);
- }
-
-
- public function setCustomerAdj(int $goodsId, int $customerId, $value)
- {
- return $this->cache->hset(self::$customerAdjTableKey . $this->onlineEnterpriseId, $customerId . '_' . $goodsId, json_encode($value));
- }
-
- public function getCustomerAdj(int $goodsId, int $customerId)
- {
- $result = $this->cache->hget(self::$customerAdjTableKey . $this->onlineEnterpriseId, $customerId . '_' . $goodsId);
- if (empty($result)) {
- return [];
- }
- $result = json_decode($result, true);
- return $result;
- }
-
- public function delCustomerAdj(int $goodsId,int $customerId)
- {
- return $this->cache->hdel(self::$customerAdjTableKey . $this->onlineEnterpriseId, $customerId . '_' . $goodsId);
- }
-
-
- public function setCustomerTypeAdj(int $goodsId, int $customerType, $value)
- {
- return $this->cache->hset(self::$customerTypeAdiTableKey.$this->onlineEnterpriseId,$customerType.'_'.$goodsId,json_encode($value));
- }
-
- public function getCustomerTypeAdj(int $goodsId, int $customerType)
- {
- $result = $this->cache->hget(self::$customerTypeAdiTableKey . $this->onlineEnterpriseId, $customerType . '_' . $goodsId);
- if (empty($result)) {
- return [];
- }
- $result = json_decode($result, true);
- return $result;
- }
-
- public function delCustomerTypeAdj(int $goodsId, int $customerType)
- {
- return $this->cache->hdel(self::$customerTypeAdiTableKey . $this->onlineEnterpriseId, $customerType . '_' . $goodsId);
- }
-
- public function setPriceTrend(int $goodsId,string $value,int $ttl = 60): bool
- {
- return $this->cache->set(self::$priceTrend . $this->onlineEnterpriseId.'_'.$goodsId,$value,$ttl);
- }
-
- public function getPriceTrend(int $goodsId)
- {
- return [];
- $result = $this->cache->get(self::$priceTrend . $this->onlineEnterpriseId.'_'.$goodsId);
- if (empty($result)){
- return [];
- }
- return $result;
- }
- }
|