usdt 充值入金实现

时间:2020-07-30作者:klpeng分类:区块链技术浏览:1240评论:0

主要命令:

getnewaddress 


扫描脚本如下:


<?php
 
namespace app\common\controller;
 
 
use app\admin\controller\usdts\Coins;
use app\v2\model\AssetMode;
use app\v2\model\UsersAccountLog;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Db;
use think\Exception;
 
class Usdt extends Command
{
    protected function configure()
    {
        $this->setName('usdt')
            ->setDescription('充值');
    }
 
    protected function execute(Input $input, Output $output){
        //每隔1000ms触发一次
        $id = \swoole_timer_tick(5000, function ($timer_id) {
            try{
                $log=[];
                $user_asset=[];
                $account_log=[];
                file_put_contents('usdt.log',date('Y-m-d H:i:s').'进入充值'.PHP_EOL,FILE_APPEND);
                $user=Db::name('users')->where(['status'=>1,'token_address'=>['<>','']])->select();
                foreach ($user as $k=>$v){
                    sleep(2);
                    $user_address=(new Coins())->listtransactions($v['token_address']);
                    file_put_contents('usdt.log',json_encode($user_address,true).PHP_EOL,FILE_APPEND);
                    if (!empty($user_address)){
                        $user_txids=Db::name('recharge')->where(['user_id'=>$v['id']])->column('usdt_order_num');
                        file_put_contents('usdt.log','有交易信息'.PHP_EOL,FILE_APPEND);
                        $txids=$user_address[0]['txid'];
                        $last_txid=$txids;
//                        $last_txid=end($txids);
                        if (!in_array($last_txid,$user_txids)){
                            $transaction=(new Coins())->gettransaction($last_txid);
                            file_put_contents('usdt.log','交易记录存在'.json_encode($transaction).PHP_EOL,FILE_APPEND);
                            if (is_array($transaction)){
                                if ($transaction['referenceaddress']==$v['token_address']){
                                    if ($transaction['valid']){
                                        file_put_contents('usdt.log','交易记录存在11'.PHP_EOL,FILE_APPEND);
                                        $log[]=[
                                            'user_id'=>$v['id'],
                                            'order_num'=>Checking::ordeSnByUnique('order_num',Db::name('recharge')),
                                            'usdt_order_num'=>$last_txid,
                                            'money'=>$transaction['amount'],
                                            'sender'=>$transaction['sendingaddress'],
                                            'recipient'=>$transaction['referenceaddress'],
                                            'status'=>2,
                                            'create_time'=>date('YmdHis'),
                                            'qr_time'=>date('YmdHis'),
                                            'block_time'=>date('Y-m-d H:i:s',$transaction['blocktime']),
                                            'block_t_time'=>$transaction['blocktime']
                                        ];
                                        $account_log[]=[
                                            'user_id'=>$v['id'],
                                            'money'=>$transaction['amount'],
                                            'type'=>1,
                                            'message'=>'充值',
                                            'status'=>2,
                                            'class'=>2,
                                            'create_time'=>date('YmdHis')
                                        ];
                                        $user_asset[]=[
                                            'user_id'=>$v['id'],
                                            'usdt'=>['inc',$transaction['amount']]
                                        ];
                                    }
                                }
                                file_put_contents('usdt.log',date('Y-m-d H:i:s').'交易无效'.PHP_EOL,FILE_APPEND);
                            }
                        }
                    }
                }
                if (!empty($log)){
                    Db::name('recharge')->insertAll($log);
                }
                if (!empty($user_asset)){
                    $asset= new AssetMode();
                    $asset->isUpdate(true)->saveAll($user_asset);
                }
                if (!empty($account_log)){
                    $asset= new UsersAccountLog();
                    $asset->isUpdate(true)->saveAll($account_log);
                }
            }catch (Exception $exception){
                file_put_contents('usdt.log',date('Y-m-d H:i:s').$exception->getMessage().PHP_EOL,FILE_APPEND);
            }
        });
    }
}


打赏
文章版权声明:除非注明,否则均为彭超的博客原创文章,转载或复制请以超链接形式并注明出处。
相关推荐

发表评论:

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。

猜你喜欢