user = $this->getUser();; } /** * 订单列表 */ public function lists() { $model = new OrderModel; return $this->renderSuccess('', [ // 列表 'list' => $model->getList($this->user['user_id'],$this->postData()), ]); } /** *详情 */ public function detail($id) { $detail = OrderModel::detail($id); return $this->renderSuccess('', compact('detail')); } /** *提交上传 */ public function submit() { $params = $this->request->param(); // 用户信息 $user = $this->getUser(); // 生成记录 $model = new OrderModel(); $id = $model->submit($user,$params); if (!$id) { return $this->renderError($model->getError() ?: '提交失败'); } // 在线支付 $payment = OrderModel::onOrderPayment($user, $model, $params['pay_type'], $params['pay_source']); // 返回结算信息 return $this->renderSuccess(['success' => '支付成功', 'error' => '订单未支付'], [ 'id' => $id, // 订单id 'pay_type' => $params['pay_type'], // 支付方式 'payment' => $payment, // 微信支付参数 'order_type' => OrderTypeEnum::RELEASE, //订单类型 ]); } /** *创建订单 */ public function createOrder() { $params = $this->request->param(); // 用户信息 $user = $this->getUser(); // 生成记录 $model = new OrderModel(); $result = $model->createOrder($user,$params); if(!$result){ return $this->renderError($model->getError() ?: '操作失败'); } return $this->renderSuccess('操作成功'); } /** * 订单支付 */ public function pay() { $params = $this->request->param(); // 用户信息 $user = $this->getUser(); $model = new OrderModel(); $detail = $model::detail($params["id"]); if (!$detail) { return $this->renderError($detail->getError() ?: '失败'); } if($params["pay_type"] == OrderPayTypeEnum::BALANCE){ (new OrderModel())->onPaymentByBalance($detail['order_no']); } // 在线支付 $payment = OrderModel::onOrderPayment($user, $detail, $params['pay_type'], $params['pay_source']); // 返回结算信息 return $this->renderSuccess(['success' => '支付成功', 'error' => '订单未支付'], [ 'id' => $detail["id"], // 订单id 'pay_type' => $params['pay_type'], // 支付方式 'payment' => $payment, // 微信支付参数 'order_type' => OrderTypeEnum::RELEASE, //订单类型 ]); } /** *完成订单 */ public function finish($id) { $params = $this->request->param(); $model = OrderModel::detail($id); if($model["is_settled"] == 2){ return $this->renderError('该订单已完成'); } $result = $model->finish($params); if(!$result){ return $this->renderError($model->getError() ?: '操作失败'); } return $this->renderSuccess('操作成功'); } /** * 取消订单 */ public function cancel($id) { $model = OrderModel::detail($id); $user = $this->getUser(); if ($model->cancel($user)) { return $this->renderSuccess('取消成功'); } return $this->renderError($model->getError() ?: '取消失败'); } }