HandleRechargeOrder.php 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. <?php
  2. namespace App\Task;
  3. use App\Model\Telegram\FmsWalletTradeList;
  4. use App\Model\Telegram\FmsRechargeOrder;
  5. use App\Model\Telegram\TelegramBotUser;
  6. use App\Model\Telegram\TelegramBot;
  7. use App\Library\Log;
  8. class HandleRechargeOrder
  9. {
  10. public function execute()
  11. {
  12. try {
  13. //['1' => '待充值','7' => '金额无对应订单','8' => '充值中','9' => '充值成功','4' => '充值失败','2' => '人工禁止','3' => '找不到用户'];
  14. $data = FmsWalletTradeList::from('fms_wallet_trade_list as a')
  15. ->where('a.process_status',1)
  16. ->select('a.rid','a.transferfrom_address','a.amount','a.coin_name','a.tx_hash')
  17. ->limit(100)
  18. ->get();
  19. if($data->count() > 0){
  20. foreach ($data as $k => $v) {
  21. $time = nowDate();
  22. //匹配金额
  23. $res = FmsRechargeOrder::where('recharge_coin_name',$v->coin_name)->where('need_pay_price',$v->amount)->where('status',0)->first();
  24. if(empty($res)){
  25. $save_data = [];
  26. $save_data['process_status'] = 7; //金额无对应套餐
  27. $save_data['process_comments'] = '金额无对应套餐'; //处理备注
  28. $save_data['process_time'] = $time; //处理时间
  29. FmsWalletTradeList::where('rid',$v->rid)->update($save_data);
  30. continue;
  31. }
  32. //查找用户
  33. $botUser = TelegramBotUser::where('bot_rid',$res['bot_rid'])->where('tg_uid',$res['recharge_tg_uid'])->first();
  34. if(empty($botUser)){
  35. $save_data = [];
  36. $save_data['process_status'] = 3; //找不到用户
  37. $save_data['process_comments'] = '找不到用户'; //处理备注
  38. $save_data['process_time'] = $time; //处理时间
  39. FmsWalletTradeList::where('rid',$v->rid)->update($save_data);
  40. continue;
  41. }
  42. $save_data = [];
  43. $save_data['status'] = 1;
  44. $save_data['complete_time'] = $time;
  45. $save_data['tx_hash'] = $v->tx_hash;
  46. FmsRechargeOrder::where('rid',$res['rid'])->update($save_data);
  47. $save_data = [];
  48. $save_data['cash_trx'] = $botUser['cash_trx'] + ($v->coin_name == 'trx' ?$res['recharge_pay_price']:0);
  49. $save_data['cash_usdt'] = $botUser['cash_usdt'] + ($v->coin_name == 'usdt' ?$res['recharge_pay_price']:0);
  50. $save_data['total_recharge_trx'] = $botUser['total_recharge_trx'] + ($v->coin_name == 'trx' ?$res['recharge_pay_price']:0);
  51. $save_data['total_recharge_usdt'] = $botUser['total_recharge_usdt'] + ($v->coin_name == 'usdt' ?$res['recharge_pay_price']:0);
  52. TelegramBotUser::where('rid',$botUser['rid'])->update($save_data);
  53. $save_data = [];
  54. $save_data['process_status'] = 9; //充值成功
  55. $save_data['process_comments'] = '充值成功'; //处理备注
  56. $save_data['process_time'] = $time; //处理时间
  57. $save_data['recharge_order_rid'] = $res['rid'];
  58. FmsWalletTradeList::where('rid',$v->rid)->update($save_data);
  59. $bot = TelegramBot::where('rid',$res['bot_rid'])->first();
  60. if(!empty($bot)){
  61. $replytext = "✅您的充值订单已成功!\n"
  62. ."➖➖➖➖➖➖➖➖\n"
  63. ."<b>订单号:</b>".$v->rid."\n"
  64. ."<b>充值币种:</b>".$v->coin_name."\n"
  65. ."<b>充值金额:</b>".$res['recharge_pay_price']."\n";
  66. //通知用户
  67. $sendmessageurl = 'https://api.telegram.org/bot'.$bot['bot_token'].'/sendMessage?chat_id='.$res['recharge_tg_uid'].'&text='.urlencode($replytext).'&parse_mode=HTML';
  68. Get_Pay($sendmessageurl);
  69. }
  70. }
  71. }else{
  72. // $this->log('shanduibonus','----------没有数据----------');
  73. }
  74. }catch (\Exception $e){
  75. // $this->log('shanduibonus','----------任务执行报错,请联系管理员。报错原因:----------'.$e->getMessage());
  76. }
  77. }
  78. /**
  79. * 记入日志
  80. * @param $log_title [日志路径]
  81. * @param $message [内容,不支持数组]
  82. * @param $remarks [备注]
  83. */
  84. protected function log($log_title,$message,$remarks='info'){
  85. Log::get($remarks,$log_title)->info($message);
  86. }
  87. }