mirror of
https://github.com/v2board/v2board.git
synced 2024-11-10 17:49:11 +08:00
50 lines
1.6 KiB
PHP
50 lines
1.6 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Guest;
|
|
|
|
use App\Models\Order;
|
|
use App\Services\OrderService;
|
|
use App\Services\PaymentService;
|
|
use App\Services\TelegramService;
|
|
use Illuminate\Http\Request;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class PaymentController extends Controller
|
|
{
|
|
public function notify($method, $uuid, Request $request)
|
|
{
|
|
try {
|
|
$paymentService = new PaymentService($method, null, $uuid);
|
|
$verify = $paymentService->notify($request->input());
|
|
if (!$verify) abort(500, 'verify error');
|
|
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
|
|
abort(500, 'handle error');
|
|
}
|
|
die(isset($paymentService->customResult) ? $paymentService->customResult : 'success');
|
|
} catch (\Exception $e) {
|
|
abort(500, 'fail');
|
|
}
|
|
}
|
|
|
|
private function handle($tradeNo, $callbackNo)
|
|
{
|
|
$order = Order::where('trade_no', $tradeNo)->first();
|
|
if (!$order) {
|
|
abort(500, 'order is not found');
|
|
}
|
|
if ($order->status === 1) return true;
|
|
$orderService = new OrderService($order);
|
|
if (!$orderService->paid($callbackNo)) {
|
|
return false;
|
|
}
|
|
$telegramService = new TelegramService();
|
|
$message = sprintf(
|
|
"💰成功收款%s元\n———————————————\n订单号:%s",
|
|
$order->total_amount / 100,
|
|
$order->trade_no
|
|
);
|
|
$telegramService->sendMessageWithAdmin($message);
|
|
return true;
|
|
}
|
|
}
|