123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- <?php
- namespace App\Console\Commands;
- use Illuminate\Console\Command;
- use Illuminate\Support\Facades\DB;
- use Telegram\Bot\Api;
- use App\Models\Telegram\TelegramBot;
- use App\Models\Transit\TransitWallet;
- use App\Models\Transit\TransitWalletTradeList;
- class TransitTgNotice extends Command
- {
- /**
- * The name and signature of the console command.
- *
- * @var string
- */
- protected $signature = 'TransitTgNotice:notice';
- /**
- * The console command description.
- *
- * @var string
- */
- protected $description = '闪兑tg通知';
- /**
- * Create a new command instance.
- *
- * @return void
- */
- public function __construct()
- {
- parent::__construct();
- }
- /**
- * Execute the console command.
- *
- * @return mixed
- */
- public function handle()
- {
- // llog('','transittgnotice');
- $data = TransitWalletTradeList::from('transit_wallet_trade_list as a')
- ->leftJoin('transit_wallet as b','a.transferto_address','b.receive_wallet')
- ->leftJoin('telegram_bot as c','b.bot_rid','c.rid')
- ->where('a.tg_notice_status_receive','N')
- ->orWhere('a.tg_notice_status_send','N')
- ->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')
- ->limit(5)
- ->get();
-
- if($data->count() > 0){
- foreach ($data as $k => $v) {
-
- if(empty($v->bot_token)){
- $save_data = [];
- $save_data['tg_notice_status_receive'] = 'Y';
- $save_data['tg_notice_status_send'] = 'Y';
- TransitWalletTradeList::where('rid',$v->rid)->update($save_data);
- continue;
- }
-
- $telegram = new Api($v->bot_token);
-
- $notice_receive = 'N';
- $notice_send = 'N';
-
- //['6' => '黑钱包','7' => '转入金额不符','8' => '转帐中','9' => '转账成功','1' => '待兑换','10' => '余额不足','5' => '币种无效','2' => '交易失败','0' => '待确认'];
- //接收的通知,某些状态才通知
- if($v->tg_notice_status_receive == 'N' && in_array($v->process_status, [1,8,9,10])){
- $replytext = '有新的闪兑交易:'.PHP_EOL
- .'--------------------------------------'.PHP_EOL
- .'转入交易哈希:'.$v->tx_hash .PHP_EOL
- .'转入钱包地址:'.$v->transferfrom_address .PHP_EOL
- .'转入币名:'.$v->coin_name .PHP_EOL
- .'转入金额:'.$v->amount .PHP_EOL;
-
- $url = 'https://tronscan.io/#/transaction/'.$v->tx_hash;
-
- //内联按钮
- $keyboard = [
- 'inline_keyboard' => [
- [
- ['text' => '查看转入交易', 'url' => $url]
- ]
- ]
- ];
-
- $encodedKeyboard = json_encode($keyboard);
-
- $receivelist = explode(',',$v->tg_notice_obj_receive);
-
- foreach ($receivelist as $x => $y) {
- $response = $telegram->sendMessage([
- 'chat_id' => $y,
- 'text' => $replytext,
- 'reply_markup' => $encodedKeyboard
- ]);
- }
-
- $notice_receive = 'Y';
- }
-
- //回款的通知,某些状态才通知
- if($v->tg_notice_status_send == 'N' && $v->process_status == 9 && !empty($v->tg_notice_obj_send) && $v->tg_notice_obj_send != ''){
- $replytext = '✅闪兑成功,认准24小时自动回TRX地址(点击复制):`'.$v->receive_wallet.'`'.PHP_EOL
- .'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'.PHP_EOL
- // .'转入交易哈希:'.substr($v->tx_hash,0,6).'========'.substr($v->tx_hash,-6,6) .PHP_EOL
- .'转入钱包地址:'.substr($v->transferfrom_address,0,6).'========'.substr($v->transferfrom_address,-6,6) .PHP_EOL
- .'转入币名:'.$v->coin_name .PHP_EOL
- .'转入金额:'.$v->amount .PHP_EOL
- .'~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~'.PHP_EOL
- // .'回款交易哈希:'.substr($v->sendback_tx_hash,0,6).'========'.substr($v->sendback_tx_hash,-6,6).PHP_EOL
- .'回款币名:'.$v->sendback_coin_name .PHP_EOL
- .'回款金额:'.$v->sendback_amount .PHP_EOL;
-
- $url = 'https://tronscan.io/#/transaction/'.$v->sendback_tx_hash;
-
- //内联按钮
- $keyboard = [
- 'inline_keyboard' => [
- [
- ['text' => '查看回款交易', 'url' => $url]
- ]
- ]
- ];
-
- $encodedKeyboard = json_encode($keyboard);
-
- $sendlist = explode(',',$v->tg_notice_obj_send);
-
- foreach ($sendlist as $x => $y) {
- $response = $telegram->sendMessage([
- 'chat_id' => $y,
- 'text' => $replytext,
- 'parse_mode' => 'MarkDown',
- 'reply_markup' => $encodedKeyboard
- ]);
- }
-
- $notice_send = 'Y';
-
- //['6' => '黑钱包','7' => '转入金额不符','8' => '转帐中','9' => '转账成功','1' => '待兑换','10' => '余额不足','5' => '币种无效','2' => '交易失败','0' => '待确认'];
- //某些状态直接改为Y,其他状态不改,避免还没闪兑成功发不出去通知
- }elseif(in_array($v->process_status, [6,7,10,5,2])){
- $notice_send = 'Y';
- $notice_receive = 'Y';
- }
-
- if($notice_send == 'Y' || $notice_receive = 'Y'){
- $save_data = [];
- $save_data['tg_notice_status_receive'] = $notice_receive == 'Y' ? 'Y' : $v->tg_notice_status_receive;
- $save_data['tg_notice_status_send'] = $notice_send == 'Y' ? 'Y' : $v->tg_notice_status_send;
- TransitWalletTradeList::where('rid',$v->rid)->update($save_data);
- }
- }
- }
- }
- }
|