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) { //判断这个外站订单是否已经提交 $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 $this->msg(['error' => 403, 'msg' => '订单已取消']); } if ($has_order->status == 3) { return $this->msg(['error' => 403, 'msg' => '订单已取消']); } //如果支付,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 $this->msg(['error' => 403, 'msg' => '订单已过期']); } //如果没有支付,则 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' => '提交失败']); } //验证表单数据 $this->checkPost($request); //如果是citpay需要增加手机号码 if ($request->input('pay_type') == 'citpay') { if (!$request->input('mobile')) { return $this->msg(['error' => 1,'msg' => '手机号码不能为空']); } if ($request->input('mobile')) { if (!preg_match("/^1\d{10}$/", $request->input('mobile'))) { return $this->msg(['error' => 1,'msg' => '手机号码格式不正确不能为空']); } } if ($request->input('money') < 100) { return $this->msg(['error' => 1,'msg' => '当前支付通道最低100元']); } } //取得商户信息 $this->merchant = get_merchant($request->input('app_id')); //检查商户 $this->checkMerchant($request); //检查签名 $this->checkSign($this->merchant, $request); //通道检查 $this->checkGateway($request); if (count(self::$errorArr) > 0) { return $this->msg($this->errorFormat()); } //创建会员 $this->createUser($request); //设置订单数据 $this->setOrderData($request); //设置附加订单数据 $this->setOrderInfo($request); $this->pay_service->payConfig($this->pay_type); $this->pay_service->beforeCreateOrder(self::$orderData,self::$orderInfoData); if (count($this->pay_service->getErrors()) > 0) { return $this->msg($this->pay_service->errorFormat()); } $this->debugLog('订单数据是---' . json_encode(self::$orderData)); if ($this->createOrder()) { $this->debugLog('选择通道是---' . $this->gateway['id'] . '方式是--' . $this->pay_method); //支付通道配置,签名之类的 $this->pay_service->payConfig($this->pay_type); $data = $this->orderTypeData(); $data['created_at'] = date('Y-m-d H:i:s'); $this->pay_service->setOrder($this->order); //发送支付请求 return $this->paySend($data, $this->order); } else { return $this->msg(['error' => 1, 'msg' => '提交失败']); } } public function orderTypeData() { switch ($this->pay_type) { case 'weixin': case 'weixinh5': case 'weixinscan': $order_pay = [ 'out_trade_no' => self::$orderData['order_sn'], 'total_fee' => self::$orderData['order_money'] * 100, 'body' => self::$orderData['order_sn'] . '定制' //$request->input('title','测试数据') ]; break; case 'alipay': $order_pay = [ 'out_trade_no' => self::$orderData['order_sn'], 'total_amount' => self::$orderData['order_money'], 'subject' => self::$orderData['order_sn'] . '定制' //$request->input('title','测试数据') ]; break; case 'unionpay': $order_pay = [ 'orderId' => self::$orderData['order_sn'], 'orderDesc' => self::$orderData['order_sn'] . '定制', //$request->input('title','测试数据'), 'txnTime' => date('YmdHis'), 'txnAmt' => self::$orderData['order_money'] * 100, //订单价格,单位是:"分" 1x100 ]; break; case 'citpay': $order_pay = [ 'order_no' => self::$orderData['order_sn'], 'customer_name' => self::$orderData['username'], //$request->input('title','测试数据'), 'customer_mobile' => '+86,' . request()->input('mobile'), 'legalB_amount' => self::$orderData['order_money'], //订单价格 ]; break; case 'usdtpay': $order_pay = [ 'order_no' => self::$orderData['order_sn'], 'user_id' => self::$orderData['local_user_id'], //$request->input('title','测试数据'), 'customer_mobile' => '+86,' . request()->input('mobile'), 'total_amount' => self::$orderData['order_money'], //订单价格 ]; break; default: $order_pay = [ 'out_trade_no' => self::$orderData['order_sn'], 'total_amount' => self::$orderData['order_money'], 'subject' => self::$orderData['order_sn'] . '定制' //$request->input('title','测试数据') ]; break; } return $order_pay; } public function orderPayData() { switch ($this->pay_type) { case 'weixin': case 'weixinh5': case 'weixinscan': $order_pay = [ 'out_trade_no' => $this->order['order_sn'], 'total_fee' => $this->order['order_money'] * 100, 'body' => $this->order['order_sn'] . '定制' //$request->input('title','测试数据') ]; break; case 'alipay': $order_pay = [ 'out_trade_no' => $this->order['order_sn'], 'total_amount' => $this->order['order_money'], 'subject' => $this->order['order_sn'] . '定制' //$request->input('title','测试数据') ]; break; case 'unionpay': $order_pay = [ 'orderId' => $this->order['order_sn'], 'orderDesc' => $this->order['order_sn'] . '定制', //$request->input('title','测试数据'), 'txnTime' => date('YmdHis'), 'txnAmt' => $this->order['order_money'] * 100, //订单价格,单位是:"分" 1x100 ]; break; case 'citpay': $order_pay = [ 'order_no' => $this->order['order_sn'], 'customer_name' => $this->order['username'], //$request->input('title','测试数据'), 'customer_mobile' => '+86,' . request()->input('mobile'), 'legalB_amount' => $this->order['order_money'], //订单价格 ]; break; case 'usdtpay': $order_pay = [ 'order_no' => $this->order['order_sn'], 'user_id' => $this->order['local_user_id'], //$request->input('title','测试数据'), 'customer_mobile' => '+86,' . request()->input('mobile'), 'total_amount' => $this->order['order_money'], //订单价格 ]; break; default: $order_pay = [ 'out_trade_no' => $this->order['order_sn'], 'total_amount' => $this->order['order_money'], 'subject' => $this->order['order_sn'] . '定制' //$request->input('title','测试数据') ]; break; } return $order_pay; } }