TransitTgNotice.php.bak 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. <?php
  2. namespace App\Console\Commands;
  3. use Illuminate\Console\Command;
  4. use Illuminate\Support\Facades\DB;
  5. use Telegram\Bot\Api;
  6. use App\Models\Telegram\TelegramBot;
  7. use App\Models\Transit\TransitWallet;
  8. use App\Models\Transit\TransitWalletTradeList;
  9. class TransitTgNotice extends Command
  10. {
  11. /**
  12. * The name and signature of the console command.
  13. *
  14. * @var string
  15. */
  16. protected $signature = 'TransitTgNotice:notice';
  17. /**
  18. * The console command description.
  19. *
  20. * @var string
  21. */
  22. protected $description = '闪兑tg通知';
  23. /**
  24. * Create a new command instance.
  25. *
  26. * @return void
  27. */
  28. public function __construct()
  29. {
  30. parent::__construct();
  31. }
  32. /**
  33. * Execute the console command.
  34. *
  35. * @return mixed
  36. */
  37. public function handle()
  38. {
  39. // llog('','transittgnotice');
  40. $data = TransitWalletTradeList::from('transit_wallet_trade_list as a')
  41. ->leftJoin('transit_wallet as b','a.transferto_address','b.receive_wallet')
  42. ->leftJoin('telegram_bot as c','b.bot_rid','c.rid')
  43. ->where('a.tg_notice_status_receive','N')
  44. ->orWhere('a.tg_notice_status_send','N')
  45. ->select('a.rid','a.tx_hash','a.transferfrom_address','a.coin_name','a.amount','a.process_status','a.tg_notice_status_receive','a.tg_notice_status_send','a.sendback_coin_name','a.sendback_tx_hash','a.sendback_amount','b.tg_notice_obj_receive','b.tg_notice_obj_send','c.bot_token','b.receive_wallet')
  46. ->limit(5)
  47. ->get();
  48. if($data->count() > 0){
  49. foreach ($data as $k => $v) {
  50. if(empty($v->bot_token)){
  51. $save_data = [];
  52. $save_data['tg_notice_status_receive'] = 'Y';
  53. $save_data['tg_notice_status_send'] = 'Y';
  54. TransitWalletTradeList::where('rid',$v->rid)->update($save_data);
  55. continue;
  56. }
  57. $telegram = new Api($v->bot_token);
  58. $notice_receive = 'N';
  59. $notice_send = 'N';
  60. //['6' => '黑钱包','7' => '转入金额不符','8' => '转帐中','9' => '转账成功','1' => '待兑换','10' => '余额不足','5' => '币种无效','2' => '交易失败','0' => '待确认'];
  61. //接收的通知,某些状态才通知
  62. if($v->tg_notice_status_receive == 'N' && in_array($v->process_status, [1,8,9,10])){
  63. $replytext = '有新的闪兑交易:'.PHP_EOL
  64. .'--------------------------------------'.PHP_EOL
  65. .'转入交易哈希:'.$v->tx_hash .PHP_EOL
  66. .'转入钱包地址:'.$v->transferfrom_address .PHP_EOL
  67. .'转入币名:'.$v->coin_name .PHP_EOL
  68. .'转入金额:'.$v->amount .PHP_EOL;
  69. $url = 'https://tronscan.io/#/transaction/'.$v->tx_hash;
  70. //内联按钮
  71. $keyboard = [
  72. 'inline_keyboard' => [
  73. [
  74. ['text' => '查看转入交易', 'url' => $url]
  75. ]
  76. ]
  77. ];
  78. $encodedKeyboard = json_encode($keyboard);
  79. $receivelist = explode(',',$v->tg_notice_obj_receive);
  80. foreach ($receivelist as $x => $y) {
  81. $response = $telegram->sendMessage([
  82. 'chat_id' => $y,
  83. 'text' => $replytext,
  84. 'reply_markup' => $encodedKeyboard
  85. ]);
  86. }
  87. $notice_receive = 'Y';
  88. }
  89. //回款的通知,某些状态才通知
  90. if($v->tg_notice_status_send == 'N' && $v->process_status == 9 && !empty($v->tg_notice_obj_send) && $v->tg_notice_obj_send != ''){
  91. $replytext = '✅闪兑成功,认准24小时自动回TRX地址(点击复制):`'.$v->receive_wallet.'`'.PHP_EOL
  92. .'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'.PHP_EOL
  93. // .'转入交易哈希:'.substr($v->tx_hash,0,6).'========'.substr($v->tx_hash,-6,6) .PHP_EOL
  94. .'转入钱包地址:'.substr($v->transferfrom_address,0,6).'========'.substr($v->transferfrom_address,-6,6) .PHP_EOL
  95. .'转入币名:'.$v->coin_name .PHP_EOL
  96. .'转入金额:'.$v->amount .PHP_EOL
  97. .'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'.PHP_EOL
  98. // .'回款交易哈希:'.substr($v->sendback_tx_hash,0,6).'========'.substr($v->sendback_tx_hash,-6,6).PHP_EOL
  99. .'回款币名:'.$v->sendback_coin_name .PHP_EOL
  100. .'回款金额:'.$v->sendback_amount .PHP_EOL;
  101. $url = 'https://tronscan.io/#/transaction/'.$v->sendback_tx_hash;
  102. //内联按钮
  103. $keyboard = [
  104. 'inline_keyboard' => [
  105. [
  106. ['text' => '查看回款交易', 'url' => $url]
  107. ]
  108. ]
  109. ];
  110. $encodedKeyboard = json_encode($keyboard);
  111. $sendlist = explode(',',$v->tg_notice_obj_send);
  112. foreach ($sendlist as $x => $y) {
  113. $response = $telegram->sendMessage([
  114. 'chat_id' => $y,
  115. 'text' => $replytext,
  116. 'parse_mode' => 'MarkDown',
  117. 'reply_markup' => $encodedKeyboard
  118. ]);
  119. }
  120. $notice_send = 'Y';
  121. //['6' => '黑钱包','7' => '转入金额不符','8' => '转帐中','9' => '转账成功','1' => '待兑换','10' => '余额不足','5' => '币种无效','2' => '交易失败','0' => '待确认'];
  122. //某些状态直接改为Y,其他状态不改,避免还没闪兑成功发不出去通知
  123. }elseif(in_array($v->process_status, [6,7,10,5,2])){
  124. $notice_send = 'Y';
  125. $notice_receive = 'Y';
  126. }
  127. if($notice_send == 'Y' || $notice_receive = 'Y'){
  128. $save_data = [];
  129. $save_data['tg_notice_status_receive'] = $notice_receive == 'Y' ? 'Y' : $v->tg_notice_status_receive;
  130. $save_data['tg_notice_status_send'] = $notice_send == 'Y' ? 'Y' : $v->tg_notice_status_send;
  131. TransitWalletTradeList::where('rid',$v->rid)->update($save_data);
  132. }
  133. }
  134. }
  135. }
  136. }