first(); if($block_info->{'num'}>=$block_info->{'analyze'} - 5 || true){ $tron_block = TronRPC::CreationTron()->getBlockByNum(); }else{ $tron_block=$block_info->{'num'}; } if ($block_info->{'analyze'} + 6 < $tron_block) { $analyze = $block_info->{'analyze'} + 1; $block_deal = TronRPC::CreationTron()->getBlockById($analyze); if (empty($block_deal)) return false; DB::beginTransaction(); if (!empty($block_deal['transactions'])) { //USDT 合约地址 0xdac17f958d2ee523a2206206994597c13d831ec7 $hy_address = '41a614f803b6fd780986a42c78ec9c7f77e6ded13c'; foreach ($block_deal['transactions'] as $t_key=>$deal_info) { if(empty($deal_info['ret'][0]['contractRet']) || $deal_info['ret'][0]['contractRet']!='SUCCESS'){ continue; } $block_item = []; $pay_data=$deal_info['raw_data']['contract'][0]['parameter']['value']; $my_hy_address=empty($pay_data['contract_address']) ?'':$pay_data['contract_address']; if ( $my_hy_address == $hy_address) { if(empty($pay_data['data']))continue; $input = $pay_data['data']; $to = '41'.substr($input, 32, 40); $value = substr($input, 72); $money = Utils::int2fund(Utils::hex2dec('0x' . $value), 6); $to = TronRPC::CreationTron()->getBase58CheckAddress(hex2bin($to)); $block_item = [ 'm_id' => 0, 'coin_id' => 4, 'coin_name' => 'USDT', 'block_num' => $block_info->{'analyze'} + 1, 'money' => $money, 'from_a' => TronRPC::CreationTron()->getBase58CheckAddress(hex2bin($pay_data['owner_address'])), 'hash' => $deal_info['txID'], 'to_a' => $to, 'pay_at' => date('Y-m-d H:i:s'), 'fee_limit' =>empty($deal_info['raw_data']['fee_limit'])?0:$deal_info['raw_data']['fee_limit'], ]; } if (!empty($block_item)) { $member_coin = Member::whereIn('address', [$block_item['to_a'],$block_item['from_a']])->select(['id','address'])->first(); if (!empty($member_coin)) { $block_item['m_id'] = $member_coin->{'id'}; $block_item['to_type'] = $block_item['to_a']==$member_coin->{'address'}?1:2; $item_num = BlockItems::where('m_id', $block_item['m_id'])->where('hash', $block_item['hash'])->where('coin_id', $block_item['coin_id'])->count(); if($item_num<=0){ BlockItems::create($block_item); } } } } } BlockInfo::where('id', 1)->update(['analyze' => $block_info->{'analyze'} + 1, 'num' => $tron_block]); DB::commit(); return true; } return false; } }