request->post('cart_id', []); $addressId = (int)$this->request->post('address_id'); // $pay_type = (int)$this->request->post('pay_type'); // $auth_code = $this->request->post('auth_code'); //微信支付条码 $params = $this->request->post(); $user = User::where('id', $this->userId)->find(); $res = OrderLogic::cartIdByOrderInfo($cartId, $addressId, $user, $params); if ($res == false) { $msg = OrderLogic::getError(); if ($msg == '购物车为空') { return $this->data([]); } return $this->fail(OrderLogic::getError()); } return $this->data($res); } /** * 创建订单 */ public function createOrder() { $cartId = (array)$this->request->post('cart_id', []); $store_id = (array)$this->request->post('store_id', 0); $pay_type = (int)$this->request->post('pay_type'); $addressId = (int)$this->request->post('address_id'); $auth_code = $this->request->post('auth_code'); //微信支付条码 $params = $this->request->post(); if ($store_id <= 0 && $pay_type != 9) { return $this->fail('自提点不能为空'); } if (count($cartId) > 100) { return $this->fail('购物车商品不能超过100个'); } $user = User::where('id', $this->userId)->find(); if ($pay_type == PayEnum::PURCHASE_FUNDS || $pay_type == PayEnum::BALANCE_PAY) { if (!isset($params['password'])) { return $this->fail('缺失参数'); } if (empty($user['pay_password'])) { return $this->fail('请设置密码'); } if (!password_verify($params['password'], $user['pay_password'])) { return $this->fail('密码错误'); } } $order = OrderLogic::createOrder($cartId, $addressId, $user, $params); if ($order != false) { if ($order['pay_price'] <= 0) { $pay_type = 3; } switch ($pay_type) { case PayEnum::PURCHASE_FUNDS: //采购款支付 PayNotifyLogic::handle('purchase_funds', $order['order_id']); return $this->success('采购款支付成功'); case PayEnum::BALANCE_PAY: //余额支付 PayNotifyLogic::handle('balancePay', $order['order_id']); return $this->success('余额支付成功'); case PayEnum::CASH_PAY: //现金支付 PayNotifyLogic::handle('cash_pay', $order['order_id']); return $this->success('现金支付成功'); case PayEnum::WECHAT_PAY_MINI: //微信小程序支付 PayNotifyLogic::handle('wechat_common', $order['order_id']); return $this->success('微信小程序支付成功'); case PayEnum::WECHAT_PAY_BARCODE: //微信条码支付 PayNotifyLogic::handle('wechat_common', $order['order_id'], $order); return $this->success('微信条码支付成功'); case PayEnum::ALIPAY_BARCODE: //支付宝条码支付 PayNotifyLogic::handle('alipay_cashier', $order['order_id'], $order); return $this->success('支付宝条码支付成功' ); default: return $this->fail('支付方式错误'); } // return $this->data(['order_id' => $order->id]); } else { return $this->fail(OrderLogic::getError()); } } }