xielin před 5 roky
rodič
revize
b6ce758983
1 změnil soubory, kde provedl 13 přidání a 15 odebrání
  1. 13 15
      app/Console/Commands/Trace.php

+ 13 - 15
app/Console/Commands/Trace.php

@@ -92,13 +92,13 @@ class Trace extends Command
             $md5 = md5_file($zipPath);
             $this->line('------ZIP包MD5码:' . $md5);
 
-            $zipUrl = '/trace/' .$meta['patch_num'] . ".zip";
+            $zipUrl = '/trace/' . $meta['patch_num'] . ".zip";
             Storage::put($zipUrl, file_get_contents($zipPath));
             $data = [
                 'md5' => $md5,
-                'zip' => env('OSS_URL').'trace/' .$meta['patch_num'] . ".zip"
+                'zip' => env('OSS_URL') . 'trace/' . $meta['patch_num'] . ".zip"
             ];
-            $this->line('zip地址:' . env('OSS_URL').'trace/' .$meta['patch_num'] . ".zip");
+            $this->line('zip地址:' . env('OSS_URL') . 'trace/' . $meta['patch_num'] . ".zip");
             //$md5 = md5(time());
             $this->line('------开始上链:' . $md5);
             $row = $this->transcation($md5);
@@ -136,7 +136,7 @@ class Trace extends Command
 
     protected function transcation($md5)
     {
-        try{
+        try {
             $api = (new ChainFactory())->api(base_path());
             $walapi = (new WalletFactory())->api(base_path());
             $eos = (new EosRpc($api, $walapi));
@@ -158,33 +158,31 @@ class Trace extends Command
             if (isset($bobBalance[0])) {
                 $balaceB = $bobBalance[0];
             }
-            if (floatval($balaceA) == 0 && floatval($balaceB) == 0) {
-                $this->line("两个账号都没钱了,快充钱");
+            if (floatval($balaceA) < $coin || floatval($balaceB) < $coin) {
+                $this->line("有个账号没钱了,快充钱");
                 return false;
             }
             $this->line("准备打开钱包");
             $walapi->open($walletName);
             $this->line("钱包已打开");
             $this->line("准备解锁钱包");
-            $walapi->unlock([$walletName,$walletPassword]);
+            $walapi->unlock([$walletName, $walletPassword]);
             $this->line("钱包已解锁");
             $this->line("准备发起交易");
-            if ($balaceB >= $coin * 2) {
+            $rand = rand(0, 1);
+            if ($rand == 0) {
                 $trans = $eos->transfer($accountB, $accountA, $coin . " " . $coinCode, $md5, 'eosio.token', false);
-            }elseif ($balaceA >= $coin * 2) {
+            } elseif ($rand == 1) {
                 $trans = $eos->transfer($accountA, $accountB, $coin . " " . $coinCode, $md5, 'eosio.token', false);
-            }else{
-                $this->line('账号余额不足');
-                return false;
             }
-            Log::debug('transinfo:'.\GuzzleHttp\json_encode($trans));
+            Log::debug('transinfo:' . \GuzzleHttp\json_encode($trans));
             return [
                 'transaction_id' => $trans['transaction_id'] ?? '',
                 'block_num' => $trans['processed']['block_num'] ?? 0,
                 'block_time' => $trans['processed']['block_time'] ?? ''
             ];
-        }catch (\Exception $exception){
-            $this->line('上链失败:'.$exception->getMessage());
+        } catch (\Exception $exception) {
+            $this->line('上链失败:' . $exception->getMessage());
             return false;
         }
     }