From 615a966aa5b8586b2a32eecb63487877ee6361d9 Mon Sep 17 00:00:00 2001 From: ljl Date: Thu, 15 Jun 2023 14:44:30 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/Controller/Payment/PayController.php | 5 ++++ app/Service/PaymentService.php | 30 ++++++++++++++++++++++++ config/routes.php | 1 + 3 files changed, 36 insertions(+) diff --git a/app/Controller/Payment/PayController.php b/app/Controller/Payment/PayController.php index 597f663..3304439 100644 --- a/app/Controller/Payment/PayController.php +++ b/app/Controller/Payment/PayController.php @@ -61,6 +61,11 @@ class PayController extends AbstractController return $this->success($data); } + public function query(RequestInterface $request) { + $data = $this->paymentService->query($request->all()); + return $this->success($data); + } + public function payment(RequestInterface $request) { $data = $this->paymentService->payment($request->all()); return $this->success($data); diff --git a/app/Service/PaymentService.php b/app/Service/PaymentService.php index dd4b37e..2da558e 100644 --- a/app/Service/PaymentService.php +++ b/app/Service/PaymentService.php @@ -363,4 +363,34 @@ class PaymentService extends AbstractService return ['payUrl' => 'http://146.70.113.165:9501/payment.html?token=' . $token]; } + + public function query($params) + { + $req = new PaymentQueryRequest($params); + $data = $req->getData(); + $app = $req->getApp(); + + if (empty($data['outOrderNo'])) { + throw new BusinessException('订单号不能为空'); + } + + $order = Order::where('app_id', $app->app_id)->where('out_order_no', $data['outOrderNo'])->first(); + if ($order) { + throw new BusinessException('订单不存在'); + } + + $result = Api::paymentQuery(['outTradeNo' => $order->order_no]); + if (!$result->isSuccess()) { + throw new BusinessException($result->getMessage()); + } + + $this->handlePayResult($result, $order); + + return [ + 'outOrderNo' => $data['outOrderNo'], + 'orderNo' => $order->order_no, + 'payState' => $result->get('payState'), + 'amount' => $result->get('amount'), + ]; + } } diff --git a/config/routes.php b/config/routes.php index 94119e5..4c88573 100644 --- a/config/routes.php +++ b/config/routes.php @@ -21,6 +21,7 @@ Router::addGroup('/payment',function () { Router::post('/protocol-pay-confirm', [PayController::class, 'protocolPayConfirm']); Router::post('/refund-query', [PayController::class, 'refundQuery']); Router::post('/payment-query', [PayController::class, 'paymentQuery']); + Router::post('/query', [PayController::class, 'query']); Router::post('/pay', [PayController::class, 'payment']); }, ['middleware' => [\App\Middleware\RequestLogMiddleware::class]]);