GetFmsWalletTrxUsdtTrade.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. <?php
  2. namespace App\Task;
  3. use App\Service\Fms\FmsWalletServices;
  4. use App\Service\Fms\FmsWalletTradeTrxServices;
  5. use App\Service\Fms\FmsWalletTradeUsdtServices;
  6. use App\Model\Telegram\FmsWalletTradeList;
  7. use App\Library\Log;
  8. // use Swoole\Coroutine\WaitGroup;
  9. use Hyperf\Utils\Coroutine\Concurrent;
  10. class GetFmsWalletTrxUsdtTrade
  11. {
  12. public function execute()
  13. {
  14. try {
  15. $fmsWallet_services = new FmsWalletServices();
  16. $list = $fmsWallet_services->getList(); //获取收款列表
  17. if(!empty($list)){
  18. try {
  19. // $this->log('getfmswallettrxtrade','-----------开始执行:拉取钱包交易列表数据,钱包总数:'.count($list).'个--------------');
  20. //协程通知
  21. // $wg = new WaitGroup();
  22. //协程数量
  23. $concurrent = new Concurrent(5);
  24. foreach ($list as $k => $v) {
  25. // $wg->add();
  26. // go(function () use ($wg,$v) {
  27. // $fmsWalletTradeTrx_services = new FmsWalletTradeTrxServices();
  28. // $res = $this->handle($wg,$v,$fmsWalletTradeTrx_services);
  29. // $fmsWalletTradeUsdt_services = new FmsWalletTradeUsdtServices();
  30. // $res = $this->handleUsdt($wg,$v,$fmsWalletTradeUsdt_services);
  31. // $wg->done();
  32. // });
  33. $concurrent->create(function () use ($v) {
  34. // sleep(1); //不容易被api限制
  35. $fmsWalletTradeTrx_services = new FmsWalletTradeTrxServices();
  36. $res = $this->handle($v,$fmsWalletTradeTrx_services);
  37. $fmsWalletTradeUsdt_services = new FmsWalletTradeUsdtServices();
  38. $res = $this->handleUsdt($v,$fmsWalletTradeUsdt_services);
  39. });
  40. }
  41. // $wg->wait();
  42. // $this->log('getfmswallettrxtrade','-----------结束执行:拉取钱包交易列表数据--------------');
  43. }catch (\Exception $e){
  44. $this->log('getfmswallettrxtrade','拉取失败'.$e->getMessage().'----------');
  45. }
  46. }else{
  47. // $this->log('getfmswallettrxtrade','-----------没有钱包需要拉取交易数据--------');
  48. }
  49. }catch (\Exception $e){
  50. $this->log('getfmswallettrxtrade','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
  51. }
  52. }
  53. public function handle($v,$fmsWalletTradeTrx_services){
  54. try {
  55. $start_time = FmsWalletTradeList::where('transferto_address',$v['recharge_wallet_addr'])->where('coin_name','trx')->orderBy('timestamp','desc')->value('timestamp');
  56. if(empty($start_time)){
  57. $start_time = 0;
  58. }
  59. $get_tx_time = strtotime($v['get_tx_time'])*1000-10;
  60. if($get_tx_time > $start_time){
  61. $start_time = $get_tx_time;
  62. }
  63. // 获取收款数据-通过trongrid获取===选一种拉取就行
  64. $res = $fmsWalletTradeTrx_services->getListByGrid($v,$start_time);
  65. // 获取收款数据-通过tronscan获取===选一种拉取就行
  66. $res = $fmsWalletTradeTrx_services->getList($v,$start_time,thirteenTime());
  67. return ['code' => 200,'msg'=>'success'];
  68. }catch (\Exception $e){
  69. return ['code' => 400,'msg'=>$v['recharge_wallet_addr'].',拉取地址失败,'.$e->getMessage().'----------'];
  70. }
  71. }
  72. public function handleUsdt($v,$fmsWalletTradeUsdt_services){
  73. try {
  74. $start_time = FmsWalletTradeList::where('transferto_address',$v['recharge_wallet_addr'])->where('coin_name','usdt')->orderBy('timestamp','desc')->value('timestamp');
  75. if(empty($start_time)){
  76. $start_time = 0;
  77. }
  78. $get_tx_time = strtotime($v['get_tx_time'])*1000-10;
  79. if($get_tx_time > $start_time){
  80. $start_time = $get_tx_time;
  81. }
  82. // $this->log('getfmswallettrxtrade','拉usdt'.$v['recharge_wallet_addr'].$start_time);
  83. // 获取收款数据
  84. $res = $fmsWalletTradeUsdt_services->getList($v,$start_time);
  85. return ['code' => 200,'msg'=>'充值钱包地址:'.$v['recharge_wallet_addr'].',成功总数'.$res['success_count'].',失败总数'.$res['error_count']];
  86. }catch (\Exception $e){
  87. return ['code' => 400,'msg'=>$v['recharge_wallet_addr'].',拉取地址失败,'.$e->getMessage().'----------'];
  88. }
  89. }
  90. /**
  91. * 记入日志
  92. * @param $log_title [日志路径]
  93. * @param $message [内容,不支持数组]
  94. * @param $remarks [备注]
  95. */
  96. protected function log($log_title,$message,$remarks='info'){
  97. Log::get($remarks,$log_title)->info($message);
  98. }
  99. }