GetPremiumWalletUsdtTrade.php 3.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <?php
  2. namespace App\Task;
  3. use App\Service\Premium\PremiumWalletServices;
  4. use App\Service\Premium\PremiumWalletTradeUsdtServices;
  5. use App\Model\Premium\PremiumWalletTradeList;
  6. use App\Library\Log;
  7. // use Swoole\Coroutine\WaitGroup;
  8. use Hyperf\Utils\Coroutine\Concurrent;
  9. class GetPremiumWalletUsdtTrade
  10. {
  11. public function execute()
  12. {
  13. try {
  14. $premiumWallet_services = new PremiumWalletServices();
  15. $list = $premiumWallet_services->getList(); //获取收款列表
  16. if(!empty($list)){
  17. try {
  18. // $this->log('getpremiumwalletusdttrade','-----------开始执行:拉取钱包交易列表数据,钱包总数:'.count($list).'个--------------');
  19. //协程通知
  20. // $wg = new WaitGroup();
  21. //协程数量
  22. $concurrent = new Concurrent(5);
  23. foreach ($list as $k => $v) {
  24. // $wg->add();
  25. // go(function () use ($wg,$v) {
  26. // $premiumWalletTradeUsdt_services = new PremiumWalletTradeUsdtServices();
  27. // $res = $this->handle($wg,$v,$premiumWalletTradeUsdt_services);
  28. // $wg->done();
  29. // });
  30. $concurrent->create(function () use ($v) {
  31. // sleep(1); //不容易被api限制
  32. $premiumWalletTradeUsdt_services = new PremiumWalletTradeUsdtServices();
  33. $res = $this->handle($v,$premiumWalletTradeUsdt_services);
  34. });
  35. }
  36. // $wg->wait();
  37. // $this->log('getpremiumwalletusdttrade','-----------结束执行:拉取钱包交易列表数据--------------');
  38. }catch (\Exception $e){
  39. $this->log('getpremiumwalletusdttrade','拉取失败'.$e->getMessage().'----------');
  40. }
  41. }else{
  42. // $this->log('getpremiumwalletusdttrade','-----------没有钱包需要拉取交易数据--------');
  43. }
  44. }catch (\Exception $e){
  45. // $this->log('getpremiumwalletusdttrade','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
  46. }
  47. }
  48. public function handle($v,$premiumWalletTradeUsdt_services){
  49. try {
  50. $start_time = PremiumWalletTradeList::where('transferto_address',$v['receive_wallet'])->where('coin_name','usdt')->orderBy('timestamp','desc')->value('timestamp');
  51. if(empty($start_time)){
  52. $start_time = 0;
  53. }
  54. $get_tx_time = strtotime($v['get_tx_time'])*1000-10;
  55. if($get_tx_time > $start_time){
  56. $start_time = $get_tx_time;
  57. }
  58. // 获取收款数据
  59. $res = $premiumWalletTradeUsdt_services->getList($v,$start_time);
  60. return ['code' => 200,'msg'=>'钱包地址:'.$v['receive_wallet'].',成功总数'.$res['success_count'].',失败总数'.$res['error_count']];
  61. }catch (\Exception $e){
  62. return ['code' => 400,'msg'=>$v['receive_wallet'].',拉取地址失败,'.$e->getMessage().'----------'];
  63. }
  64. }
  65. /**
  66. * 记入日志
  67. * @param $log_title [日志路径]
  68. * @param $message [内容,不支持数组]
  69. * @param $remarks [备注]
  70. */
  71. protected function log($log_title,$message,$remarks='info'){
  72. Log::get($remarks,$log_title)->info($message);
  73. }
  74. }