From e63dade12e5e053892d8b96554d63f9f5f34071a Mon Sep 17 00:00:00 2001 From: zcy Date: Wed, 27 Apr 2022 12:56:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=8B=E5=8D=95=E8=BF=94=E5=9B=9Eurl?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Controllers/Api/OrderApiController.php | 25 ++++++----- app/Http/Controllers/Web/OrderController.php | 15 +++++++ app/ServicePay/ApiOrderServices.php | 44 +++++++++++++++++++ app/ServicePay/GuMaPayServices.php | 18 ++++++-- app/ServicePay/PayApiInterface.php | 2 +- app/ServicePay/traits/ReturnTrait.php | 19 ++++++++ routes/web.php | 1 + 7 files changed, 110 insertions(+), 14 deletions(-) create mode 100644 app/ServicePay/traits/ReturnTrait.php diff --git a/app/Http/Controllers/Api/OrderApiController.php b/app/Http/Controllers/Api/OrderApiController.php index c7fe830..8d8f330 100644 --- a/app/Http/Controllers/Api/OrderApiController.php +++ b/app/Http/Controllers/Api/OrderApiController.php @@ -148,18 +148,23 @@ class OrderApiController extends BaseController ]; return $this->json($data); } - if($order->ewm_mark || $order->ewm_account) - { - $data = [ - 'error' => 1, - 'msg' => '你已经提交过', - 'backurl' => '', - ]; - return $this->json($data); + if ($order->ewm_mark) { + if ($order->ewm_account == $pay_account) { + $data = [ + 'error' => 1, + 'msg' => '你已经提交过', + 'backurl' => '', + ]; + return $this->json($data); + } } //xieru - $order->ewm_mark = $mark; - $order->ewm_account = $pay_account; + if (empty($order->ewm_mark)) { + $order->ewm_mark = $mark; + } + if (empty($order->ewm_account)) { + $order->ewm_account = $pay_account; + } $r = $order->save(); if ($r) { $data = [ diff --git a/app/Http/Controllers/Web/OrderController.php b/app/Http/Controllers/Web/OrderController.php index 25347d3..9dcbec5 100644 --- a/app/Http/Controllers/Web/OrderController.php +++ b/app/Http/Controllers/Web/OrderController.php @@ -53,6 +53,21 @@ class OrderController extends BaseController } + /** + * 显示订单 + * @param Request $request + * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse|\Illuminate\View\View|void + * + */ + public function showOrder(Request $request){ + if($request->input('out_trade_sn')){ + $pay = new ApiOrderServices(); + return $pay->showOrder($request); + }else{ + return abort(403,'缺少参数'); + } + } + /** * 检查订单 * @param Request $request diff --git a/app/ServicePay/ApiOrderServices.php b/app/ServicePay/ApiOrderServices.php index c2104a5..e6f3f7e 100644 --- a/app/ServicePay/ApiOrderServices.php +++ b/app/ServicePay/ApiOrderServices.php @@ -20,6 +20,50 @@ class ApiOrderServices * @return \Illuminate\Contracts\View\Factory|\Illuminate\Http\JsonResponse|\Illuminate\View\View|void */ + public function showOrder($request){ + $out_trade_sn = $request->input('out_trade_sn'); + $has_order = Order::where('out_trade_sn', $out_trade_sn)->first(); + if (!empty($has_order)) { + $this->order = $has_order; + $this->pay_type = $this->order->pay_type; + $this->pay_method = $this->order->gateway_method; + + //判断是否已经支持 + //订单无效 + if ($has_order->status == 4) { + + return abort(403, '订单已取消'); + } + if ($has_order->status == 3) { + + return abort(403, '订单已取消'); + } + //如果支付,2进行跳转 + if (in_array($has_order->pay_status, [1, 2])) { + return $this->merchantReturnSend(); + //进行跳转回去。 + } + //判断订单是否无效,15分钟有效 + if (strtotime($has_order->created_at) <= (time() - 60 * $this->timeOut)) { + return abort(403, '订单已过期'); + } + //如果没有支付,则 + if ($has_order->pay_status == 0) { + $this->setPayService($this->pay_type); + //指定通道 + $this->pay_service->getGatewayInfo($this->order->gateway_id, $this->order->gateway_method); + $this->pay_service->payConfig($this->pay_type); + $data = $this->orderPayData();; + $this->pay_service->setOrder($this->order); + //发送支付请求 + return $this->paySend($data, $this->order); + } + return $this->msg(['error' => 1, 'msg' => '提交失败']); + }else{ + return abort(403,'订单不存在'); + } + } + public function order($request) { diff --git a/app/ServicePay/GuMaPayServices.php b/app/ServicePay/GuMaPayServices.php index cce9e51..c172021 100644 --- a/app/ServicePay/GuMaPayServices.php +++ b/app/ServicePay/GuMaPayServices.php @@ -4,6 +4,7 @@ namespace App\ServicePay; use App\Models\Merchant; use App\Models\Message; +use App\ServicePay\traits\ReturnTrait; use App\ServicePay\TransCard\BaseCard; use App\ServicePay\TransCard\GetTransInfo; use Illuminate\Support\Facades\Log; @@ -11,6 +12,7 @@ use Illuminate\Support\Facades\Log; class GuMaPayServices implements PayApiInterface { use PayTrait; + use ReturnTrait; public $gateway_list;//当前类型的支付通道列表 public $pay_type;//支付类型 public $pay_method;//支付方法 @@ -78,9 +80,19 @@ class GuMaPayServices implements PayApiInterface } - public function pay($pay_data,$order) + public function pay($pay_data) { - + $return = request()->all(); + $re_type = 'json'; + if (isset($return['re_type'])) { + $re_type = $return['re_type']; + } + if (isset($return['app_id'])) { + $host = request()->getSchemeAndHttpHost(); + $url = 'order/show?out_trade_sn=' . $this->order->out_trade_sn; + $url = $host . '/' . $url; + return $this->returnPayRes($re_type, '', 1, $url); + } //订单开始时间,倒计时 $time_only = ((strtotime($this->order->created_at) + $this->timeOut * 60) - time()); @@ -98,7 +110,7 @@ class GuMaPayServices implements PayApiInterface 'pay_status' => $this->order->pay_status == 1 ? '已支付' : '等待支付', 'only_time' =>$time_only ]; - $lange = $order->language ?? 'zh_cn'; + $lange = $this->order->language ?? 'zh_cn'; $appPath = base_path(); $dir = $appPath . DIRECTORY_SEPARATOR . 'resources' . DIRECTORY_SEPARATOR . 'views' . DIRECTORY_SEPARATOR . 'web' . DIRECTORY_SEPARATOR . 'order' . DIRECTORY_SEPARATOR; $file = $lange == 'zh_cn' ? '' : $lange; diff --git a/app/ServicePay/PayApiInterface.php b/app/ServicePay/PayApiInterface.php index 2540dc3..adb73c0 100644 --- a/app/ServicePay/PayApiInterface.php +++ b/app/ServicePay/PayApiInterface.php @@ -18,7 +18,7 @@ interface PayApiInterface public function payConfig($type, $setConfig = []); //统一下单支付 - public function pay($pay_data,$order); + public function pay($pay_data); //统一验证签名 public function verify(); diff --git a/app/ServicePay/traits/ReturnTrait.php b/app/ServicePay/traits/ReturnTrait.php new file mode 100644 index 0000000..175e883 --- /dev/null +++ b/app/ServicePay/traits/ReturnTrait.php @@ -0,0 +1,19 @@ + 1, 'qrurl' => $url], 256); + } else { + return redirect()->away($url); + } + } else { + if ($re_type == 'json') { + return json_encode(['code' => 0, 'msg' => $msg], 256); + } else { + return $msg; + } + } + } +} \ No newline at end of file diff --git a/routes/web.php b/routes/web.php index d6a2f53..ea09d41 100644 --- a/routes/web.php +++ b/routes/web.php @@ -43,6 +43,7 @@ Route::name('web.')->group(function ($route) { }); Route::group(['prefix' => 'order'], function ($route) { $route->get('/', 'OrderController@index')->name('order.index'); + $route->get('/show', 'OrderController@showOrder')->name('order.showOrder'); $route->post('/order', 'OrderController@orderPost')->name('order.orderPost'); $route->post('/check', 'OrderController@orderCheck')->name('order.orderCheck');//检查订单 $route->post('/notify', 'OrderController@notify')->name('order.notify');//notify