Quellcode durchsuchen

Weenier 168otc项目部署 0630

wesmiler vor 3 Jahren
Ursprung
Commit
4c7f4de6e6
1 geänderte Dateien mit 29 neuen und 9 gelöschten Zeilen
  1. 29 9
      app/Services/UsdtWalletService.php

+ 29 - 9
app/Services/UsdtWalletService.php

@@ -678,11 +678,6 @@ class UsdtWalletService extends BaseService
      */
      */
     public function getTrxBalance($address, $cache=false)
     public function getTrxBalance($address, $cache=false)
     {
     {
-        $cacheKey = "caches:wallet:balance:trx_{$address}";
-        if ($data = RedisService::get($cacheKey) && $cache) {
-            return $data;
-        }
-
         if (empty($address)) {
         if (empty($address)) {
             $this->error = '1018';
             $this->error = '1018';
             return false;
             return false;
@@ -693,6 +688,15 @@ class UsdtWalletService extends BaseService
             return false;
             return false;
         }
         }
 
 
+        $cacheKey = "caches:wallet:balance:trx_{$address}";
+        if ($data = RedisService::get($cacheKey) && $cache) {
+            return $data;
+        }
+
+        if(RedisService::get($cacheKey.'_lock') && $cache){
+            return false;
+        }
+
         try {
         try {
             $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
             $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
             $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
             $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
@@ -705,7 +709,8 @@ class UsdtWalletService extends BaseService
             $result = $trxWallet->balance($address);
             $result = $trxWallet->balance($address);
 
 
             $result = $result ? floatval($result) : '0.00';
             $result = $result ? floatval($result) : '0.00';
-            RedisService::set($cacheKey, $result, rand(3, 5));
+            RedisService::set($cacheKey, $result, rand(5, 10));
+            RedisService::set($cacheKey.'_lock', true, rand(5, 10));
             return $result;
             return $result;
 
 
         } catch (\Exception $exception) {
         } catch (\Exception $exception) {
@@ -736,6 +741,10 @@ class UsdtWalletService extends BaseService
             return $data;
             return $data;
         }
         }
 
 
+        if(RedisService::get($cacheKey.'_lock') && $cache){
+            return false;
+        }
+
         try {
         try {
             $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
             $headers = ["TRON-PRO-API-KEY" => $this->config['tron_api_key']];
             $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
             $api = new Api(new Client(['base_uri' => $this->config['tron_api_url'], 'headers' => $headers]));
@@ -748,7 +757,8 @@ class UsdtWalletService extends BaseService
             $result = $trxWallet->balance($address);
             $result = $trxWallet->balance($address);
 
 
             $result = $result ? floatval($result) : '0.00';
             $result = $result ? floatval($result) : '0.00';
-            RedisService::set($cacheKey, $result, rand(3, 5));
+            RedisService::set($cacheKey, $result, rand(5, 10));
+            RedisService::set($cacheKey.'_lock', true, rand(5, 10));
             return $result;
             return $result;
 
 
         } catch (\Exception $exception) {
         } catch (\Exception $exception) {
@@ -998,6 +1008,10 @@ class UsdtWalletService extends BaseService
             return $data;
             return $data;
         }
         }
 
 
+        if(RedisService::get($cacheKey.'_lock') && $cache){
+            return false;
+        }
+
         try {
         try {
             $url = $this->config['eth_api_url'] . '/' . $this->config['eth_api_key'];
             $url = $this->config['eth_api_url'] . '/' . $this->config['eth_api_key'];
             $headers = ["Content-Type" => 'application/json'];
             $headers = ["Content-Type" => 'application/json'];
@@ -1011,7 +1025,8 @@ class UsdtWalletService extends BaseService
             $result = $result ? json_decode($result, true) : [];
             $result = $result ? json_decode($result, true) : [];
             $balance = isset($result['result']) ? hexdec($result['result']) : 0.00;
             $balance = isset($result['result']) ? hexdec($result['result']) : 0.00;
             $balance = $balance ? floatval($balance/pow(10,18)) : '0.00';
             $balance = $balance ? floatval($balance/pow(10,18)) : '0.00';
-            RedisService::set($cacheKey, $balance, rand(3, 5));
+            RedisService::set($cacheKey, $balance, rand(5, 10));
+            RedisService::set($cacheKey.'_lock', true, rand(5, 10));
             return $balance;
             return $balance;
         } catch (\Exception $exception) {
         } catch (\Exception $exception) {
             $this->error = $exception->getMessage();
             $this->error = $exception->getMessage();
@@ -1052,6 +1067,10 @@ class UsdtWalletService extends BaseService
             return $data;
             return $data;
         }
         }
 
 
+        if(RedisService::get($cacheKey.'_lock') && $cache){
+            return false;
+        }
+
         try {
         try {
             $url = $this->config['eth_api_url'] . '/' . $this->config['eth_api_key'];
             $url = $this->config['eth_api_url'] . '/' . $this->config['eth_api_key'];
             $headers = ["Content-Type" => 'application/json'];
             $headers = ["Content-Type" => 'application/json'];
@@ -1069,7 +1088,8 @@ class UsdtWalletService extends BaseService
             $balance = $balance? floatval($balance/1000000) : '0.00';
             $balance = $balance? floatval($balance/1000000) : '0.00';
 
 
             $balance = $balance? $balance : '0.00';
             $balance = $balance? $balance : '0.00';
-            RedisService::set($cacheKey, $balance, rand(3, 5));
+            RedisService::set($cacheKey, $balance, rand(5, 10));
+            RedisService::set($cacheKey.'_lock', true, rand(5, 10));
             return $balance;
             return $balance;
         } catch (\Exception $exception) {
         } catch (\Exception $exception) {
             $this->error = $exception->getMessage();
             $this->error = $exception->getMessage();