diff --git a/app/Http/Controllers/Guest/OrderController.php b/app/Http/Controllers/Guest/OrderController.php index 967b294b..842632dc 100644 --- a/app/Http/Controllers/Guest/OrderController.php +++ b/app/Http/Controllers/Guest/OrderController.php @@ -3,6 +3,7 @@ namespace App\Http\Controllers\Guest; use App\Services\OrderService; +use App\Services\TelegramService; use Illuminate\Http\Request; use App\Http\Controllers\Controller; use App\Models\Order; @@ -160,6 +161,16 @@ class OrderController extends Controller abort(500, 'order is not found'); } $orderService = new OrderService($order); - return $orderService->success($callbackNo); + if (!$orderService->success($callbackNo)) { + return false; + } + $telegramService = new TelegramService(); + $message = sprintf( + "💰成功收款%s元\n———————————————\n订单号:%s", + $order->total_amount / 100, + $order->trade_no + ); + $telegramService->sendMessageWithAdmin($message); + return true; } } diff --git a/app/Http/Controllers/User/TicketController.php b/app/Http/Controllers/User/TicketController.php index 6efebf64..2b2f652b 100644 --- a/app/Http/Controllers/User/TicketController.php +++ b/app/Http/Controllers/User/TicketController.php @@ -7,6 +7,7 @@ use App\Http\Requests\User\TicketSave; use App\Http\Requests\User\TicketWithdraw; use App\Jobs\SendTelegramJob; use App\Models\User; +use App\Services\TelegramService; use Illuminate\Http\Request; use App\Models\Ticket; use App\Models\TicketMessage; @@ -180,21 +181,10 @@ class TicketController extends Controller abort(500, '工单创建失败'); } DB::commit(); - $this->sendNotify($ticket, $ticketMessage); + $telegramService = new TelegramService(); + $telegramService->sendMessageWithAdmin("📮工单提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$ticketMessage->message}`"); return response([ 'data' => true ]); } - - private function sendNotify(Ticket $ticket, TicketMessage $ticketMessage) - { - if (!config('v2board.telegram_bot_enable', 0)) return; - $users = User::where('is_admin', 1) - ->where('telegram_id', '!=', NULL) - ->get(); - foreach ($users as $user) { - $text = "📮工单提醒 #{$ticket->id}\n———————————————\n主题:\n`{$ticket->subject}`\n内容:\n`{$ticketMessage->message}`"; - SendTelegramJob::dispatch($user->telegram_id, $text); - } - } } diff --git a/app/Services/TelegramService.php b/app/Services/TelegramService.php index 9005915f..d4fbbf52 100644 --- a/app/Services/TelegramService.php +++ b/app/Services/TelegramService.php @@ -1,6 +1,7 @@ where('telegram_id', '!=', NULL) + ->get(); + foreach ($users as $user) { + SendTelegramJob::dispatch($user->telegram_id, $message); + } + } }