2021-04-28 16:56:08 +08:00
|
|
|
<?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
|
|
|
|
{
|
2021-05-07 00:17:55 +08:00
|
|
|
public function notify($method, $uuid, Request $request)
|
2021-04-28 16:56:08 +08:00
|
|
|
{
|
2021-04-29 00:39:45 +08:00
|
|
|
try {
|
2021-05-07 00:17:55 +08:00
|
|
|
$paymentService = new PaymentService($method, null, $uuid);
|
2021-04-29 00:39:45 +08:00
|
|
|
$verify = $paymentService->notify($request->input());
|
|
|
|
if (!$verify) abort(500, 'verify error');
|
|
|
|
if (!$this->handle($verify['trade_no'], $verify['callback_no'])) {
|
|
|
|
abort(500, 'handle error');
|
|
|
|
}
|
2021-05-26 00:38:57 +08:00
|
|
|
die(isset($paymentService->customResult) ? $paymentService->customResult : 'success');
|
2021-04-29 00:39:45 +08:00
|
|
|
} catch (\Exception $e) {
|
|
|
|
abort(500, 'fail');
|
2021-04-28 16:56:08 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private function handle($tradeNo, $callbackNo)
|
|
|
|
{
|
|
|
|
$order = Order::where('trade_no', $tradeNo)->first();
|
|
|
|
if (!$order) {
|
|
|
|
abort(500, 'order is not found');
|
|
|
|
}
|
2021-04-28 17:29:28 +08:00
|
|
|
if ($order->status === 1) return true;
|
2021-04-28 16:56:08 +08:00
|
|
|
$orderService = new OrderService($order);
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|