GetEnergyWalletTrxTrade.php 3.1 KB

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