diff --git a/app/Controller/Payment/NotifyController.php b/app/Controller/Payment/NotifyController.php index d4e77da..6c62008 100644 --- a/app/Controller/Payment/NotifyController.php +++ b/app/Controller/Payment/NotifyController.php @@ -110,7 +110,7 @@ class NotifyController extends AbstractController 'transaction_id' => $params['transactionId'] ?? '', 'out_transaction_id' => $params['outTransactionId'] ?? '', ]; - $order = $this->paymentService->updateOrder($info); + $order = $this->paymentService->updateOrder($info, 'APPLY_SUCCESS'); if (empty($order)) { return $baofu->notifySuccess(); } @@ -151,7 +151,7 @@ class NotifyController extends AbstractController 'amount' => $params['orderMoney'], 'finished_at' => $params['finishTime'], ]; - $order = $this->paymentService->updateOrder($info, 'PROCESS'); + $order = $this->paymentService->updateOrder($info, 'SUCCESS'); if (empty($order)) { return $baofu->notifySuccess(); } diff --git a/app/Service/PaymentService.php b/app/Service/PaymentService.php index 08a0a20..ce5b105 100644 --- a/app/Service/PaymentService.php +++ b/app/Service/PaymentService.php @@ -261,11 +261,12 @@ class PaymentService extends AbstractService return [$order, $orderSplitInfos]; } - public function updateOrder($params, $status = 'APPLY_SUCCESS') { - $order = Order::where('order_no', $params['order_no'])->where('status', $status)->first(); + public function updateOrder($params, $status = null) { + $order = Order::where('order_no', $params['order_no'])->first(); if (empty($order)) { return null; } + $order->third_order_no = $params['third_order_no']; $order->status = $params['status']; $order->finished_at = date('Y-m-d H:i:s', strtotime($params['finished_at'])); @@ -479,27 +480,25 @@ class PaymentService extends AbstractService if (empty($order)) { throw new BusinessException('订单不存在'); } - try { - $baofu = new Baofu(); - $result = $baofu->queryOrder([ - 'loginNo' => $order->member_id, - 'tradeId' => $order->order_no, - ]); - - $info = [ - 'member_id' => $order->member_id, - 'order_no' => $order->order_no, - 'third_order_no' => $result['requestNo'] ?? '', - 'status' => $result['status'], - 'amount' => $result['amount'], - 'finished_at' => $result['finishDate'], - 'error_message' => $result['errorMsg'] ?? '', - 'transaction_id' => $result['transactionId'] ?? '', - 'out_transaction_id' => $result['outTransactionId'] ?? '', - ]; - return $this->updateOrder($info); - } catch (ApiException $e) { - throw $e; - } + + $baofu = new Baofu(); + $result = $baofu->queryOrder([ + 'loginNo' => $order->member_id, + 'tradeId' => $order->order_no, + ]); + + $info = [ + 'member_id' => $order->member_id, + 'order_no' => $order->order_no, + 'third_order_no' => $result['requestNo'] ?? '', + 'status' => $result['status'], + 'amount' => $result['amount'], + 'finished_at' => $result['finishDate'], + 'error_message' => $result['errorMsg'] ?? '', + 'transaction_id' => $result['transactionId'] ?? '', + 'out_transaction_id' => $result['outTransactionId'] ?? '', + ]; + return $this->updateOrder($info); + } }