renderError('很抱歉,解锁功能暂时仅支持微信小程序端'); } // 生成订单 $model = new UnlockOrder(); if (!$order = $model->createOrder($this->request->param(), 1)) { return $this->renderError($model->getError() ?: '解锁提交失败'); } $payment = PaymentService::wechat( $order['order_id'], $order['order_no'], $order['total_price'], OrderTypeEnum::LOCKED ); // 充值状态提醒 $order = ['order_id'=> $order['order_id'],'type'=>'普通解锁订单','message' => '解锁提交成功']; return $this->renderSuccess(compact('payment','order')); } /** * 全解 * @return \think\response\Json */ public function submitAll() { if (getPlatform() !== 'MP-WEIXIN') { return $this->renderError('很抱歉,解锁功能暂时仅支持微信小程序端'); } // 生成订单 $model = new UnlockOrder(); if (!$order = $model->createOrder($this->request->param(), 2)) { return $this->renderError($model->getError() ?: '解锁提交失败'); } $payment = PaymentService::wechat( $order['order_id'], $order['order_no'], $order['total_price'], OrderTypeEnum::LOCKED ); // 充值状态提醒 $order = ['order_id'=> $order['order_id'],'type'=>'普通解锁订单','message' => '解锁提交成功']; return $this->renderSuccess(compact('payment','order')); } /** * 解锁订单支付 * @param int $order_id * @return \think\response\Json * @throws \app\common\exception\BaseException * @throws \cores\exception\BaseException * @throws \think\db\exception\DataNotFoundException * @throws \think\db\exception\DbException * @throws \think\db\exception\ModelNotFoundException */ public function pay(int $order_id) { // 订单信息 $model = new UnlockOrder(); $model = $model::getUserOrderDetail($order_id); if (!$model) { return $this->renderError($model->getError() ?: '报名订单不存在'); } // 验证 if(!$model->checkPay($model)) { return $this->renderError($model->getError() ?: '订单支付失败'); } $pilOrder = false; $userInfo = UserService::getCurrentLoginUser(true); $userId = isset($userInfo['user_id'])? $userInfo['user_id'] : 0; if($userId != $model['user_id']) { return $this->renderError('无权操作'); } // 构建微信支付 try { $payment = PaymentService::wechat( $model['order_id'], $model['order_no'], $model['total_price'], OrderTypeEnum::LOCKED ); } catch (\Exception $exception) { $data = ['order_no'=> 'LC'.\app\common\service\Order::createOrderNo()]; $model->save($data); $payment = PaymentService::wechat( $model['order_id'], $model['order_no'], $model['total_price'], OrderTypeEnum::LOCKED ); } // $message = ['success' => '解锁成功', 'error' => '订单支付中']; return $this->renderSuccess(compact('payment', 'message')); } }