OrderCache.Class.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: phperstar
  5. * Date: 2020/11/6
  6. * Time: 11:22 AM
  7. */
  8. namespace Service\Order\Cache;
  9. use function FastRoute\TestFixtures\empty_options_cached;
  10. use Mall\Framework\Factory;
  11. class OrderCache
  12. {
  13. /**
  14. * 连接id和店铺id映射关系缓存
  15. *
  16. * @var
  17. */
  18. static $webstockConnect = 'webstockConnect';
  19. /**
  20. * 判断所有表名缓存是否存在
  21. *
  22. * @param string $databaseName 库名
  23. *
  24. * @return bool
  25. */
  26. static function allTableNameCacheIsExists($databaseName){
  27. $result = Factory::cache('backend')->has(self::$allTableName.'::'.$databaseName);
  28. return $result;
  29. }
  30. /**
  31. * 缓存制定库下的所有表名
  32. *
  33. * @param string $dataBaseName 当前数据库库名
  34. * @param array $allTableNameData 当前库中所有表名数据
  35. */
  36. static function allTableNameCache($databaseName, $allTableNameData)
  37. {
  38. if(empty($allTableNameData)){
  39. return false;
  40. }
  41. $pipe = Factory::cache('backend')->multi();
  42. foreach ($allTableNameData as $key => $value){
  43. $writeCache = Factory::cache('backend')->sadd(self::$allTableName.'::'.$databaseName, $value['TABLE_NAME']);
  44. }
  45. $pipe->exec();
  46. }
  47. /**
  48. * 添加新的连接到缓存中
  49. * @param int webstockFromId 连接来源标识id
  50. * @param string shopMake 店铺标识
  51. *
  52. * @return bool
  53. */
  54. static function addWebstockFromIdAndShopId($platfrom,$shopId,$userId,$fromId)
  55. {
  56. $key = self::$webstockConnect.'::'.$platfrom.'::'.$shopId;
  57. // 用户和webstock链接映射关系
  58. $writeCache = Factory::cache('default')->hset($key, $userId, $fromId);
  59. return $key;
  60. }
  61. /**
  62. * 获取店铺对应的webstock id标识
  63. * @param string shopMake 店铺标识
  64. *
  65. * @return bool
  66. */
  67. static function getWebstockFromIdAndShopId($platfrom,$shopId)
  68. {
  69. $key = self::$webstockConnect.'::'.$platfrom.'::'.$shopId;
  70. return Factory::cache('default')->hvalues($key);
  71. }
  72. }