middleware('auth'); } private function getpayOrder(Order $order, $type) { $payOrder = Payment::create([ 'order_id' => $order->id, 'type' => $type, 'amount' => $order->total - $order->score, ]); return $payOrder; } public function order(Request $request, $orderid) { $order = Order::where('orderid', $orderid)->findOrFail(); return view('pay.order', compact('order')); } /** * 微信支付 * @param Request $request [description] * @param [type] $orderid [description] * @return [type] [description] */ public function wechat(Request $request, $orderid) { $order = Order::where('orderid', $orderid)->firstOrFail(); $openid = $order->user->openid; $amount = $order->amount - $order->score; $payOrder = $this->getpayOrder($order, 'WECHAT'); if ($amount != $payOrder->amount) { $payOrder->amount = $amount; $payOrder->save(); } if ($order->card_id) { $card = Card::find($order->card_id); if ($card && in_array($card->status, [0, 5])) { return $this->error('提货卡被禁用或被使用'); } } $app = app('wechat.payment'); $amount = $payOrder->amount; if (config('pick.DEBUG')) { $amount = 0.01; } $result = $app->order->unify([ 'body' => '商城订单', 'out_trade_no' => $payOrder->trade_no, 'total_fee' => $amount * 100, 'notify_url' => route('notify.payment'), 'trade_type' => 'JSAPI', 'openid' => $openid, ]); if ($result['return_code'] == 'SUCCESS' && isset($result['prepay_id'])) { $json = $app->jssdk->bridgeConfig($result['prepay_id']); return $this->success($json); } else { return $this->error($result['return_msg']); } } }